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/FEModule.cpp | .cpp | 3,356 | 155 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEModule.h"
#include <vector>
#include <cstring>
class FEModule::Impl
{
public:
const char* szname = 0; // name of module
const char* szdesc = 0; // description of module (optional, can be null)
unsigned int id = 0; // unqiue ID (starting at one)
int alloc_id = -1; // ID of allocator
int m_status = FEModule::RELEASED; // Status of module
std::vector<int> depMods; // module dependencies
public:
void AddDependency(int mid)
{
for (size_t i = 0; i < depMods.size(); ++i)
{
if (depMods[i] == mid) return;
}
depMods.push_back(mid);
}
void AddDependencies(const std::vector<int>& mid)
{
for (size_t i = 0; i < mid.size(); ++i)
{
AddDependency(mid[i]);
}
}
};
FEModule::FEModule() : im(new FEModule::Impl)
{
}
FEModule::FEModule(const char* szname, const char* szdescription) : im(new FEModule::Impl)
{
SetName(szname);
SetDescription(szdescription);
}
FEModule::~FEModule()
{
delete im;
}
void FEModule::InitModel(FEModel* fem)
{
}
int FEModule::GetModuleID() const
{
return im->id;
}
void FEModule::SetAllocID(int id)
{
im->alloc_id = id;
}
int FEModule::GetAllocID() const
{
return im->alloc_id;
}
const char* FEModule::GetName() const
{
return im->szname;
}
const char* FEModule::GetDescription() const
{
return im->szdesc;
}
void FEModule::SetStatus(FEModule::Status status)
{
im->m_status = status;
}
int FEModule::GetStatus() const
{
return im->m_status;
}
bool FEModule::HasDependent(int modId) const
{
if (modId == im->id) return true;
for (int i : im->depMods)
{
if (i == modId) return true;
}
return false;
}
void FEModule::AddDependency(FEModule& mod)
{
im->AddDependency(mod.GetModuleID());
im->AddDependencies(mod.im->depMods);
}
void FEModule::ClearDependencies()
{
im->depMods.clear();
}
std::vector<int> FEModule::GetDependencies() const
{
return im->depMods;
}
void FEModule::SetID(int newId)
{
im->id = newId;
}
void FEModule::SetName(const char* szname)
{
im->szname = szname;
}
void FEModule::SetDescription(const char* szdesc)
{
im->szdesc = szdesc;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEParabolicMap.h | .h | 1,639 | 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 "FEDataGenerator.h"
#include "FEDofList.h"
class FESurface;
class FECORE_API FEParabolicMap : public FEFaceDataGenerator
{
public:
FEParabolicMap(FEModel* fem);
~FEParabolicMap();
FEDataMap* Generate() override;
void SetDOFConstraint(const FEDofList& dofs);
private:
double m_scale;
FEDofList m_dofs;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FETrussDomain.cpp | .cpp | 2,814 | 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 "FETrussDomain.h"
#include "FEMesh.h"
//-----------------------------------------------------------------------------
FETrussDomain::FETrussDomain(FEModel* fem) : FEBeamDomain(fem)
{
}
//-----------------------------------------------------------------------------
bool FETrussDomain::Create(int nsize, FE_Element_Spec espec)
{
m_Elem.resize(nsize);
for (int i = 0; i < nsize; ++i)
{
FETrussElement& el = m_Elem[i];
el.SetLocalID(i);
el.SetMeshPartition(this);
}
if (espec.etype != FE_ELEM_INVALID_TYPE)
for (int i=0; i<nsize; ++i) m_Elem[i].SetType(espec.etype);
return true;
}
//-----------------------------------------------------------------------------
bool FETrussDomain::Init()
{
if (FEBeamDomain::Init() == false) return false;
FEMesh& mesh = *GetMesh();
for (FETrussElement& el : m_Elem)
{
vec3d r0[2];
r0[0] = mesh.Node(el.m_node[0]).m_r0;
r0[1] = mesh.Node(el.m_node[1]).m_r0;
el.m_L0 = (r0[1] - r0[0]).Length();
el.m_Lt = el.m_L0;
}
return true;
}
//-----------------------------------------------------------------------------
vec3d FETrussDomain::GetTrussAxisVector(FETrussElement& el)
{
vec3d rt[2];
rt[0] = m_pMesh->Node(el.m_node[0]).m_rt;
rt[1] = m_pMesh->Node(el.m_node[1]).m_rt;
vec3d n = rt[1] - rt[0];
n.unit();
return n;
}
//-----------------------------------------------------------------------------
void FETrussDomain::ForEachTrussElement(std::function<void(FETrussElement& el)> f)
{
for (FETrussElement& el : m_Elem)
{
f(el);
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEOctree.h | .h | 2,955 | 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.*/
#pragma once
#include "vec3d.h"
#include "vector.h"
#include <set>
class FESurface;
//-----------------------------------------------------------------------------
//! This is a class for an octree node
class OTnode
{
public:
OTnode();
~OTnode();
void Clear();
void CreateChildren(const int max_level, const int max_elem);
void FillNode(const std::vector<int>& parent_selist);
bool ElementIntersectsNode(const int j);
void PrintNodeContent();
bool RayIntersectsNode(const vec3d& p, const vec3d& n);
void FindIntersectedLeaves(const vec3d& p, const vec3d& n, std::set<int>& sel, double srad);
void CountNodes(int& nnode, int& nlevel);
public:
int level; //!< node level
vec3d cmin, cmax; //!< node bounding box
std::vector<int> selist; //!< list of surface elements inside this node
std::vector<OTnode> children; //!< children of this node
FESurface* m_ps; //!< the surface to search
};
//-----------------------------------------------------------------------------
//! This class is a helper class to find ray intersection with a surface
class FECORE_API FEOctree
{
public:
FEOctree(FESurface* ps = 0);
~FEOctree();
//! attach to a surface
void Attach(FESurface* ps) { m_ps = ps; }
//! initialize search structures
void Init(const double stol);
//! find all candidate surface elements intersected by ray
void FindCandidateSurfaceElements(vec3d p, vec3d n, std::set<int>& sel, double srad);
protected:
FESurface* m_ps; //!< the surface to search
OTnode root; //!< root node in octree
int max_level; //!< maximum allowable number of levels in octree
int max_elem; //!< maximum allowable number of elements in any node
};
| Unknown |
3D | febiosoftware/FEBio | FECore/vec2d.h | .h | 3,370 | 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 <math.h>
#include "fecore_api.h"
class vec2d
{
public:
// constructor
vec2d() { r[0] = r[1] = 0; }
explicit vec2d(double v) { r[0] = r[1] = v; }
vec2d(double x, double y) { r[0] = x; r[1] = y; }
bool operator == (const vec2d& r) const { return (r[0] == r.r[0]) && (r[1] == r.r[1]); }
// access operators
double operator [] (int i) const { return r[i]; }
double& operator [] (int i) { return r[i]; }
double& x() { return r[0]; }
double& y() { return r[1]; }
double x() const { return r[0]; }
double y() const { return r[1]; }
double norm() const { return sqrt(r[0] * r[0] + r[1] * r[1]); }
double norm2() const { return r[0] * r[0] + r[1] * r[1]; }
double unit() { double R = norm(); if (R != 0) { r[0] /= R; r[1] /= R; }; return R; }
public: // arithmetic operators
vec2d operator + (const vec2d& v) const { return vec2d(r[0]+v.r[0], r[1]+v.r[1]); }
vec2d operator - (const vec2d& v) const { return vec2d(r[0]-v.r[0], r[1]-v.r[1]); }
vec2d operator * (double g) const { return vec2d(r[0]*g, r[1]*g); }
vec2d operator / (double g) const { return vec2d(r[0]/g, r[1]/g); }
vec2d& operator += (const vec2d& v) { r[0] += v.r[0]; r[1] += v.r[1]; return *this; }
vec2d& operator -= (const vec2d& v) { r[0] -= v.r[0]; r[1] -= v.r[1]; return *this; }
vec2d& operator *= (double g) { r[0] *= g; r[1] *= g; return *this; }
vec2d& operator /= (double g) { r[0] /= g; r[1] /= g; return *this; }
vec2d operator - () const { return vec2d(-r[0], -r[1]); }
// dot product
double operator * (const vec2d& v) const { return r[0]*v[0] + r[1]*v[1]; }
public:
double r[2];
};
//-----------------------------------------------------------------------------
class vec2i
{
public:
vec2i() { x = y = 0; }
vec2i(int X, int Y) { x = X; y = Y; }
bool operator == (const vec2i& r) const { return (x == r.x) && (y == r.y); }
public:
int x, y;
};
//-----------------------------------------------------------------------------
class vec2f
{
public:
vec2f() { x = y = 0.f; }
vec2f(float rx, float ry) { x = rx; y = ry; }
public:
float x, y;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMesh.h | .h | 10,249 | 354 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENode.h"
#include "FENodeElemList.h"
#include "FEElemElemList.h"
#include "FENodeSet.h"
#include "FEFacetSet.h"
#include "FEDiscreteSet.h"
#include "FESegmentSet.h"
#include "FEElementSet.h"
#include "FESurfacePair.h"
#include "FEBoundingBox.h"
#include "FESolidElement.h"
#include "FEShellElement.h"
#include "FEDomainList.h"
//-----------------------------------------------------------------------------
class FEEdge;
class FESurface;
class FEDomain;
class FEModel;
class FETimeInfo;
class FEDataMap;
class DumpStream;
//---------------------------------------------------------------------------------------
// Helper class for faster lookup of nodes based on their ID
class FECORE_API FENodeLUT
{
public:
FENodeLUT(FEMesh& mesh);
// Find an element from its ID
FENode* Find(int nodeID) const;
// return an element's zero-based index
int FindIndex(int nodeID) const;
private:
vector<int> m_node;
int m_minID, m_maxID;
FEMesh* m_mesh;
};
//---------------------------------------------------------------------------------------
// Helper class for faster lookup of elements based on their ID
class FECORE_API FEElementLUT
{
public:
FEElementLUT(FEMesh& mesh);
// Find an element from its ID
FEElement* Find(int elemID) const;
// return an element's zero-based index
int FindIndex(int elemID) const;
private:
vector<FEElement*> m_elem;
vector<int> m_elid;
int m_minID, m_maxID;
};
//-----------------------------------------------------------------------------
//! Defines a finite element mesh
//! All the geometry data is stored in this class.
class FECORE_API FEMesh
{
public:
//! constructor
FEMesh(FEModel* fem);
//! destructor
virtual ~FEMesh();
//! initialize material points in mesh
void InitMaterialPoints();
//! clear the mesh
void Clear();
//! allocate storage for mesh data
void CreateNodes(int nodes);
void AddNodes(int nodes);
//! return number of nodes
int Nodes() const;
//! return total nr of elements
int Elements() const;
//! return the nr of elements of a specific domain type
int Elements(int ndom_type) const;
//! return reference to a node
FENode& Node(int i);
const FENode& Node(int i) const;
//! Set the number of degrees of freedom on this mesh
void SetDOFS(int n);
//! update bounding box
void UpdateBox();
//! retrieve the bounding box
FEBoundingBox& GetBoundingBox() { return m_box; }
//! remove isolated vertices
int RemoveIsolatedVertices();
//! Reset the mesh data
void Reset();
//! Calculates an elements volume in reference configuration
double ElementVolume(FEElement& el);
//! calculates element volume in current configuration
double CurrentElementVolume(FEElement& el);
//! Finds a node from a given ID
FENode* FindNodeFromID(int nid);
//! Finds node index from a given ID
int FindNodeIndexFromID(int nid);
//! return an element (expensive way!)
FEElement* Element(int i);
//! Finds an element from a given ID
FEElement* FindElementFromID(int elemID);
int FindElementIndexFromID(int elemID);
//! Finds the solid element in which y lies
FESolidElement* FindSolidElement(vec3d y, double r[3]);
FENodeElemList& NodeElementList();
FEElemElemList& ElementElementList();
//! See if all elements are of a particular shape
bool IsType(FE_Element_Shape eshape);
// --- NODESETS ---
//! adds a node set to the mesh
void AddNodeSet(FENodeSet* pns) { m_NodeSet.push_back(pns); }
//! number of nodesets
int NodeSets() { return (int) m_NodeSet.size(); }
//! return a node set
FENodeSet* NodeSet(int i) { return m_NodeSet[i]; }
//! Find a nodeset by name
FENodeSet* FindNodeSet(const std::string& name);
// --- ELEMENT SETS ---
int ElementSets() { return (int) m_ElemSet.size(); }
FEElementSet& ElementSet(int n) { return *m_ElemSet[n]; }
void AddElementSet(FEElementSet* pg) { m_ElemSet.push_back(pg); }
//! Find a element set by name
FEElementSet* FindElementSet(const std::string& name);
// --- DOMAINS ---
int Domains();
FEDomain& Domain(int n);
void AddDomain(FEDomain* pd);
FEDomain* FindDomain(const std::string& name);
int FindDomainIndex(const std::string& name);
FEDomain* FindDomain(int domId);
//! clear all domains
void ClearDomains();
//! Rebuild the LUT
void RebuildLUT();
// --- SURFACES ---
int Surfaces() { return (int) m_Surf.size(); }
FESurface& Surface(int n) { return *m_Surf[n]; }
void AddSurface(FESurface* ps) { m_Surf.push_back(ps); }
FESurface* FindSurface(const std::string& name);
int FindSurfaceIndex(const std::string& name);
// create a surface from a facet set
FESurface* CreateSurface(FEFacetSet& facetSet);
// --- EDGES ---
int Edges() { return (int) m_Edge.size(); }
FEEdge& Edge(int n) { return *m_Edge[n]; }
void AddEdge(FEEdge* ps) { m_Edge.push_back(ps); }
// --- Segment Sets ---
int SegmentSets() { return (int) m_LineSet.size(); }
FESegmentSet& SegmentSet(int n) { return *m_LineSet[n]; }
void AddSegmentSet(FESegmentSet* ps) { m_LineSet.push_back(ps); }
FESegmentSet* FindSegmentSet(const std::string& name);
// --- Discrete Element Sets ---
int DiscreteSets() { return (int) m_DiscSet.size(); }
FEDiscreteSet& DiscreteSet(int n) { return *m_DiscSet[n]; }
void AddDiscreteSet(FEDiscreteSet* ps) { m_DiscSet.push_back(ps); }
FEDiscreteSet* FindDiscreteSet(const std::string& name);
// --- FACETSETS ---
int FacetSets() { return (int)m_FaceSet.size(); }
FEFacetSet& FacetSet(int n) { return *m_FaceSet[n]; }
void AddFacetSet(FEFacetSet* ps) { m_FaceSet.push_back(ps); }
FEFacetSet* FindFacetSet(const std::string& name);
// --- surface pairs ---
int SurfacePairs() { return (int)m_SurfPair.size(); }
FESurfacePair& SurfacePair(int n) { return *m_SurfPair[n]; }
void AddSurfacePair(FESurfacePair* ps) { m_SurfPair.push_back(ps); }
FESurfacePair* FindSurfacePair(const std::string& name);
public:
size_t DomainLists() const { return m_DomList.size(); }
FEDomainList* DomainList(size_t n) { return m_DomList[n]; }
void AddDomainList(FEDomainList* dl) { m_DomList.push_back(dl); }
FEDomainList* FindDomainList(const std::string& name);
public:
//! stream mesh data
void Serialize(DumpStream& dmp);
void SerializeDomains(DumpStream& ar);
static void SaveClass(DumpStream& ar, FEMesh* p);
static FEMesh* LoadClass(DumpStream& ar, FEMesh* p);
// create a copy of this mesh
void CopyFrom(FEMesh& mesh);
public:
//! Calculate the surface representing the element boundaries
//! boutside : include all exterior facets
//! binside : include all interior facets
FESurface* ElementBoundarySurface(bool boutside = true, bool binside = false);
//! Calculate the surface representing the element boundaries
//! domains : a list of which domains to create the surface from
//! boutside : include all exterior facets
//! binside : include all interior facets
FESurface* ElementBoundarySurface(std::vector<FEDomain*> domains, bool boutside = true, bool binside = false);
FEFacetSet* DomainBoundary(std::vector<FEDomain*> domains, bool boutside = true, bool binside = false);
FEFacetSet* DomainBoundary(FEDomainList& domainList, bool boutside = true, bool binside = false);
//! get the nodal coordinates in reference configuration
void GetInitialNodalCoordinates(const FEElement& el, vec3d* node);
//! get the nodal coordinates in current configuration
void GetNodalCoordinates(const FEElement& el, vec3d* node);
// Get the FE model
FEModel* GetFEModel() const { return m_fem; }
// update the domains of the mesh
void Update(const FETimeInfo& tp);
public: // data maps
void ClearDataMaps();
void AddDataMap(FEDataMap* map);
FEDataMap* FindDataMap(const std::string& map);
int DataMaps() const;
FEDataMap* GetDataMap(int i);
private:
vector<FENode> m_Node; //!< nodes
vector<FEDomain*> m_Domain; //!< list of domains
vector<FESurface*> m_Surf; //!< surfaces
vector<FEEdge*> m_Edge; //!< Edges
vector<FENodeSet*> m_NodeSet; //!< node sets
vector<FESegmentSet*> m_LineSet; //!< segment sets
vector<FEElementSet*> m_ElemSet; //!< element sets
vector<FEDiscreteSet*> m_DiscSet; //!< discrete element sets
vector<FEFacetSet*> m_FaceSet; //!< facet sets
vector<FESurfacePair*> m_SurfPair; //!< facet set pairs
vector<FEDomainList*> m_DomList; //!< named domain lists
vector<FEDataMap*> m_DataMap; //!< all data maps
FEBoundingBox m_box; //!< bounding box
FENodeElemList m_NEL;
FEElementLUT* m_ELT;
FENodeLUT* m_NLT;
FEElemElemList m_EEL;
FEModel* m_fem;
private:
//! hide the copy constructor
FEMesh(FEMesh& m){}
//! hide assignment operator
void operator =(FEMesh& m) {}
};
class FECORE_API FEElementIterator
{
public:
FEElementIterator(FEMesh* mesh, FEElementSet* elemSet = nullptr);
FEElement& operator *() { return *m_el; }
bool isValid() { return (m_el != nullptr); }
void operator++();
void reset();
private:
FEElement* m_el;
FEMesh* m_mesh;
FEElementSet* m_eset;
int m_index;
int m_dom;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfaceBC.cpp | .cpp | 1,727 | 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.*/
#include "stdafx.h"
#include "FESurfaceBC.h"
#include "FESurface.h"
FESurfaceBC::FESurfaceBC(FEModel* fem) : FEBoundaryCondition(fem)
{
m_surface = nullptr;
}
void FESurfaceBC::SetSurface(FESurface* surface)
{
m_surface = surface;
}
FESurface* FESurfaceBC::GetSurface()
{
return m_surface;
}
bool FESurfaceBC::Init()
{
if (m_surface == nullptr) return false;
if (m_surface->Init() == false) return false;
return FEBoundaryCondition::Init();
}
| C++ |
3D | febiosoftware/FEBio | FECore/gamma.h | .h | 1,672 | 42 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
// natural log of Gamma function (x ≥ 0)
FECORE_API double gammaln(double x);
// inverse of Gamma function (any x)
FECORE_API double gammainv(double x);
// lower incomplete Gamma function P
FECORE_API double gamma_inc_P(double a, double x);
// upper incomplete Gamma function Q
FECORE_API double gamma_inc_Q(double a, double x);
| Unknown |
3D | febiosoftware/FEBio | FECore/FEGlobalMatrix.cpp | .cpp | 9,708 | 321 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEGlobalMatrix.h"
#include "FEModel.h"
#include "FEDomain.h"
#include "FESurface.h"
//-----------------------------------------------------------------------------
FEElementMatrix::FEElementMatrix(const FEElement& el)
{
m_node = el.m_node;
}
//-----------------------------------------------------------------------------
FEElementMatrix::FEElementMatrix(const FEElementMatrix& ke) : matrix(ke)
{
m_node = ke.m_node;
m_lmi = ke.m_lmi;
m_lmj = ke.m_lmj;
}
//-----------------------------------------------------------------------------
FEElementMatrix::FEElementMatrix(const FEElementMatrix& ke, double scale)
{
m_node = ke.m_node;
m_lmi = ke.m_lmi;
m_lmj = ke.m_lmj;
matrix& T = *this;
const matrix& K = ke;
T = (scale == 1.0 ? K : K*scale);
}
//-----------------------------------------------------------------------------
FEElementMatrix::FEElementMatrix(const FEElement& el, const vector<int>& lmi) : matrix((int)lmi.size(), (int)lmi.size())
{
m_node = el.m_node;
m_lmi = lmi;
m_lmj = lmi;
}
//-----------------------------------------------------------------------------
FEElementMatrix::FEElementMatrix(const FEElement& el, vector<int>& lmi, vector<int>& lmj) : matrix((int)lmi.size(), (int)lmj.size())
{
m_node = el.m_node;
m_lmi = lmi;
m_lmj = lmj;
};
//-----------------------------------------------------------------------------
// assignment operator
void FEElementMatrix::operator = (const matrix& ke)
{
matrix::operator=(ke);
}
//-----------------------------------------------------------------------------
//! Takes a SparseMatrix structure that defines the structure of the global matrix.
FEGlobalMatrix::FEGlobalMatrix(SparseMatrix* pK, bool del)
{
m_pA = pK;
m_LM.resize(MAX_LM_SIZE);
m_pMP = 0;
m_nlm = 0;
m_delA = del;
}
//-----------------------------------------------------------------------------
//! Deletes the SparseMatrix variable.
FEGlobalMatrix::~FEGlobalMatrix()
{
if (m_delA) delete m_pA;
m_pA = 0;
if (m_pMP) delete m_pMP;
}
//-----------------------------------------------------------------------------
void FEGlobalMatrix::Clear()
{
if (m_pA) m_pA->Clear();
}
//-----------------------------------------------------------------------------
//! Start building the profile. That is delete the old profile (if there was one)
//! and create a new one.
void FEGlobalMatrix::build_begin(int neq)
{
if (m_pMP) delete m_pMP;
m_pMP = new SparseMatrixProfile(neq, neq);
// initialize it to a diagonal matrix
// TODO: Is this necessary?
m_pMP->CreateDiagonal();
m_nlm = 0;
}
//-----------------------------------------------------------------------------
//! Add an "element" to the matrix profile. The definition of an element is quite
//! general at this point. Any two or more degrees of freedom that are connected
//! somehow are considered an element. This function takes one argument, namely a
//! list of degrees of freedom that are part of such an "element". Elements are
//! first copied into a local LM array. When this array is full it is flushed and
//! all elements in this array are added to the matrix profile.
void FEGlobalMatrix::build_add(vector<int>& lm)
{
if (lm.empty() == false)
{
m_LM[m_nlm++] = lm;
if (m_nlm >= MAX_LM_SIZE) build_flush();
}
}
//-----------------------------------------------------------------------------
//! Flush the LM array. The LM array stores a buffer of elements that have to be
//! added to the profile. When this buffer is full it needs to be flushed. This
//! flushin operation causes the actual update of the matrix profile.
void FEGlobalMatrix::build_flush()
{
int i, j, n, *lm;
// Since prescribed dofs have an equation number of < -1 we need to modify that
// otherwise no storage will be allocated for these dofs (even not diagonal elements!).
for (i=0; i<m_nlm; ++i)
{
n = (int)m_LM[i].size();
if (n > 0)
{
lm = &(m_LM[i])[0];
for (j=0; j<n; ++j) if (lm[j] < -1) lm[j] = -lm[j]-2;
}
}
m_pMP->UpdateProfile(m_LM, m_nlm);
m_nlm = 0;
}
//-----------------------------------------------------------------------------
//! This function makes sure the LM buffer is flushed and creates the actual
//! sparse matrix from the matrix profile.
void FEGlobalMatrix::build_end()
{
if (m_nlm > 0) build_flush();
m_pA->Create(*m_pMP);
}
//-----------------------------------------------------------------------------
bool FEGlobalMatrix::Create(FEModel* pfem, int neq, bool breset)
{
// The first time we come here we build the "static" profile.
// This static profile stores the contribution to the matrix profile
// of the "elements" that do not change. Most elements are static except
// for instance contact elements which can change connectivity in between
// calls to the Create() function. Storing the static profile instead of
// reconstructing it every time we come here saves us a lot of time. The
// static profile is stored in the variable m_MPs.
// begin building the profile
build_begin(neq);
{
// The first time we are here we construct the "static"
// profile. This profile contains the contribution from
// all static elements. A static element is defined as
// an element that never changes its connectity. This
// static profile is stored in the MP object. Next time
// we come here we simply copy the MP object in stead
// of building it from scratch.
if (breset)
{
m_MPs.Clear();
// build the matrix profile
pfem->BuildMatrixProfile(*this, true);
// copy the static profile to the MP object
// Make sure the LM buffer is flushed first.
build_flush();
m_MPs = *m_pMP;
}
else
{
// copy the old static profile
*m_pMP = m_MPs;
}
// Add the "dynamic" profile
pfem->BuildMatrixProfile(*this, false);
}
// All done! We can now finish building the profile and create
// the actual sparse matrix. This is done in the following function
build_end();
return true;
}
//-----------------------------------------------------------------------------
//! Constructs the stiffness matrix from a FEMesh object.
bool FEGlobalMatrix::Create(FEMesh& mesh, int neq)
{
// begin building the profile
build_begin(neq);
{
// 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(*this);
}
}
// All done! We can now finish building the profile and create
// the actual sparse matrix. This is done in the following function
build_end();
return true;
}
//-----------------------------------------------------------------------------
//! construct the stiffness matrix from a mesh
bool FEGlobalMatrix::Create(FEMesh& mesh, int nstart, int nend)
{
if (nstart > nend) return false;
int neq = nend - nstart + 1;
// begin building the profile
build_begin(neq);
{
// Add all elements to the profile
// Loop over all active domains
for (int nd = 0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
vector<int> elm, lm;
const int NE = d.Elements();
for (int j = 0; j<NE; ++j)
{
FEElement& el = d.ElementRef(j);
d.UnpackLM(el, elm);
lm.clear();
for (int k = 0; k < elm.size(); ++k)
{
int nk = elm[k];
if (nk < -1) nk = -nk - 2;
if ((nk >= nstart) && (nk <= nend))
{
if (elm[k] < -1) lm.push_back(elm[k] + nstart);
else lm.push_back(elm[k] - nstart);
}
}
build_add(lm);
}
}
}
// All done! We can now finish building the profile and create
// the actual sparse matrix. This is done in the following function
build_end();
return true;
}
//! construct a stiffness matrix from a surface
bool FEGlobalMatrix::Create(const FESurface& surf, const std::vector<int>& equationIDs)
{
int N = surf.Nodes();
if ((int)equationIDs.size() != N) return false;
// count equations
int neq = 0;
for (int i = 0; i < N; ++i) if (equationIDs[i] != -1) neq++;
if (neq == 0) return false;
// build the matrix, assuming one degree of freedom per node
build_begin(neq);
for (int i = 0; i<surf.Elements(); ++i) {
const FESurfaceElement& el = surf.Element(i);
vector<int> elm(el.Nodes(), -1);
for (int j = 0; j<el.Nodes(); ++j)
elm[j] = equationIDs[el.m_lnode[j]];
build_add(elm);
}
build_end();
return true;
}
void FEGlobalMatrix::Assemble(const FEElementMatrix& ke)
{
m_pA->Assemble(ke, ke.RowIndices(), ke.ColumnsIndices());
}
| C++ |
3D | febiosoftware/FEBio | FECore/FaceDataRecord.cpp | .cpp | 3,374 | 101 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FaceDataRecord.h"
#include "FECoreKernel.h"
#include "FEModel.h"
#include "FESurface.h"
//-----------------------------------------------------------------------------
FELogFaceData::FELogFaceData(FEModel* fem) : FELogData(fem) {}
//-----------------------------------------------------------------------------
FELogFaceData::~FELogFaceData() {}
//-----------------------------------------------------------------------------
FaceDataRecord::FaceDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_FACE)
{
m_surface = nullptr;
}
//-----------------------------------------------------------------------------
int FaceDataRecord::Size() const { return (int)m_Data.size(); }
//-----------------------------------------------------------------------------
void FaceDataRecord::SetData(const char* szexpr)
{
char szcopy[MAX_STRING] = { 0 };
strcpy(szcopy, szexpr);
char* sz = szcopy, *ch;
m_Data.clear();
strcpy(m_szdata, szexpr);
do
{
ch = strchr(sz, ';');
if (ch) *ch++ = 0;
FELogFaceData* pdata = fecore_new<FELogFaceData>(sz, GetFEModel());
if (pdata) m_Data.push_back(pdata);
else throw UnknownDataField(sz);
sz = ch;
}
while (ch);
}
//-----------------------------------------------------------------------------
bool FaceDataRecord::Initialize()
{
return (m_item.empty() == false);
}
//-----------------------------------------------------------------------------
double FaceDataRecord::Evaluate(int item, int ndata)
{
int nface = item - 1;
return m_Data[ndata]->value(m_surface->Element(nface));
}
//-----------------------------------------------------------------------------
void FaceDataRecord::SelectAllItems()
{
assert(false);
}
void FaceDataRecord::SetItemList(FEItemList* itemList, const std::vector<int>& selection)
{
FEFacetSet* facetSet = dynamic_cast<FEFacetSet*>(itemList); assert(facetSet);
m_surface = facetSet->GetSurface(); assert(m_surface);
int n = m_surface->Elements();
if (selection.empty())
{
m_item.resize(n);
for (int i = 0; i < n; ++i) m_item[i] = i + 1;
}
else
{
m_item = selection;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEElementSet.cpp | .cpp | 5,884 | 225 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEElementSet.h"
#include "FEElement.h"
#include "FEMesh.h"
#include "FEDomain.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
FEElementSet::FEElementSet(FEModel* fem) : FEItemList(fem, FEItemList::FE_ELEMENT_SET)
{
m_minID = -1;
m_maxID = -1;
}
FEElementSet::FEElementSet(FEMesh* mesh) : FEItemList(mesh, FEItemList::FE_ELEMENT_SET)
{
m_minID = -1;
m_maxID = -1;
}
//-----------------------------------------------------------------------------
void FEElementSet::Create(const std::vector<int>& elemList)
{
m_dom.Clear();
m_Elem = elemList;
BuildLUT();
}
//-----------------------------------------------------------------------------
void FEElementSet::Create(FEDomain* dom, const std::vector<int>& elemList)
{
m_dom.Clear();
m_dom.AddDomain(dom);
m_Elem = elemList;
BuildLUT();
}
//-----------------------------------------------------------------------------
void FEElementSet::CopyFrom(FEElementSet& eset)
{
SetName(eset.GetName());
m_Elem = eset.m_Elem;
FEMesh* mesh = GetMesh(); assert(mesh);
m_dom.Clear();
FEDomainList& dl = eset.GetDomainList();
for (int i = 0; i < dl.Domains(); ++i)
{
FEDomain* di = dl.GetDomain(i);
FEDomain* newdi = mesh->FindDomain(di->GetName()); assert(newdi);
m_dom.AddDomain(newdi);
}
BuildLUT();
}
//-----------------------------------------------------------------------------
void FEElementSet::Create(FEDomain* dom)
{
m_dom.Clear();
m_dom.AddDomain(dom);
SetMesh(dom->GetMesh());
int NE = dom->Elements();
m_Elem.resize(NE, -1);
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom->ElementRef(i);
m_Elem[i] = el.GetID();
}
BuildLUT();
}
//-----------------------------------------------------------------------------
// add another element set
void FEElementSet::Add(const FEElementSet& set)
{
// add the domain list
m_dom.AddDomainList(set.GetDomainList());
// add the elements
m_Elem.insert(m_Elem.end(), set.m_Elem.begin(), set.m_Elem.end());
BuildLUT();
}
//-----------------------------------------------------------------------------
void FEElementSet::Create(FEDomainList& domList)
{
int NT = 0;
m_dom.Clear();
for (int n = 0; n < domList.Domains(); ++n)
{
FEDomain* dom = domList.GetDomain(n);
m_dom.AddDomain(dom);
NT += dom->Elements();
}
m_Elem.resize(NT, -1);
NT = 0;
for (int n = 0; n < domList.Domains(); ++n)
{
FEDomain* dom = domList.GetDomain(n);
int NE = dom->Elements();
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom->ElementRef(i);
m_Elem[NT + i] = el.GetID();
}
NT += NE;
}
BuildLUT();
}
//-----------------------------------------------------------------------------
void FEElementSet::BuildLUT()
{
FEMesh* mesh = GetMesh();
int N = (int)m_Elem.size();
m_minID = m_maxID = -1;
for (int i = 0; i < N; ++i)
{
FEElement* pe = mesh->FindElementFromID(m_Elem[i]);
int id = pe->GetID();
if ((id < m_minID) || (m_minID == -1)) m_minID = id;
if ((id > m_maxID) || (m_maxID == -1)) m_maxID = id;
}
int lutSize = m_maxID - m_minID + 1;
m_LUT.resize(lutSize, -1);
for (int i = 0; i < N; ++i)
{
FEElement* pe = mesh->FindElementFromID(m_Elem[i]);
int id = pe->GetID() - m_minID;
m_LUT[id] = i;
}
}
//-----------------------------------------------------------------------------
FEElement& FEElementSet::Element(int i)
{
FEMesh* mesh = GetMesh();
return *mesh->FindElementFromID(m_Elem[i]);
}
//-----------------------------------------------------------------------------
const FEElement& FEElementSet::Element(int i) const
{
FEMesh* mesh = GetMesh();
return *mesh->FindElementFromID(m_Elem[i]);
}
//-----------------------------------------------------------------------------
void FEElementSet::Serialize(DumpStream& ar)
{
FEItemList::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Elem;
ar & m_LUT;
ar & m_minID & m_maxID;
}
void FEElementSet::SaveClass(DumpStream& ar, FEElementSet* p) {}
FEElementSet* FEElementSet::LoadClass(DumpStream& ar, FEElementSet* p)
{
p = new FEElementSet(&ar.GetFEModel());
return p;
}
//-----------------------------------------------------------------------------
// create node list from this element set
FENodeList FEElementSet::GetNodeList() const
{
FEMesh* mesh = GetMesh();
FENodeList set(mesh);
vector<int> tag(mesh->Nodes(), 0);
for (int i = 0; i<Elements(); ++i)
{
const FEElement& el = Element(i);
int ne = el.Nodes();
for (int j = 0; j<ne; ++j)
{
if (tag[el.m_node[j]] == 0)
{
set.Add(el.m_node[j]);
tag[el.m_node[j]] = 1;
}
}
}
return set;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDomainMap.h | .h | 3,643 | 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.*/
#pragma once
#include "FEDataMap.h"
#include "FEDomain.h"
#include "FEElementSet.h"
#include "FEMaterialPoint.h"
class FECORE_API FEDomainMap : public FEDataMap
{
public:
//! default constructor
FEDomainMap();
FEDomainMap(FEDataType dataType, Storage_Fmt format = FMT_MULT);
//! copy constructor
FEDomainMap(const FEDomainMap& map);
//! assignment operator
FEDomainMap& operator = (const FEDomainMap& map);
//! Create a surface data map for this surface
bool Create(FEElementSet* ps, double val = 0.0);
//! serialization
void Serialize(DumpStream& ar) override;
//! get the value at a material point
double value(const FEMaterialPoint& pt) override;
vec3d valueVec3d(const FEMaterialPoint& pt) override;
mat3d valueMat3d(const FEMaterialPoint& pt) override;
mat3ds valueMat3ds(const FEMaterialPoint& pt) override;
//! get the value at a node (only works with FMT_NODE!!)
double NodalValue(int nid);
//! Get the element set
const FEElementSet* GetElementSet() const { return m_elset; }
//! return max nr of nodes
int MaxNodes() const { return m_maxElemNodes; }
//! return storage format
int StorageFormat() const { return m_fmt; }
// return the item list associated with this map
FEItemList* GetItemList() override;
// merge with another map
bool Merge(FEDomainMap& map);
public:
template <typename T> T value(int nelem, int node)
{
return get<T>(nelem*m_maxElemNodes + node);
}
template <typename T> void setValue(int nelem, int node, const T& v)
{
set<T>(nelem*m_maxElemNodes + node, v);
}
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;
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;
private:
void Realloc(int newElemSize, int newMaxElemNodes);
private:
int m_fmt; //!< storage format
int m_maxElemNodes; //!< max number of nodes for each element
FEElementSet* m_elset; //!< the element set on which this map is defined
vector<int> m_NLT; //!< node index lookup table for FMT_NODE
int m_imin; //!< min index for lookup for FMT_NODE
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tens5d.cpp | .cpp | 1,317 | 31 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "tens5d.h"
| C++ |
3D | febiosoftware/FEBio | FECore/tens5d.h | .h | 2,901 | 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 "tensor_base.h"
//-----------------------------------------------------------------------------
// Classes defined in this file
class tens5ds;
class tens5d;
//-----------------------------------------------------------------------------
// traits for these classes defining the number of components
template <> class tensor_traits<tens5ds> {public: enum { NNZ = 21}; };
template <> class tensor_traits<tens5d > {public: enum { NNZ = 243}; };
//-----------------------------------------------------------------------------
//! Class for 5th order tensors with full symmetry (any pair of indices can be swapped)
//
class tens5ds : public tensor_base<tens5ds>
{
public:
// default constructor
tens5ds() {}
// access operator
// TODO: implement this
// double operator () (int i, int j, int k, int l, int m) const;
};
//-----------------------------------------------------------------------------
//! Class for 5th order tensors (no symmetries)
//! This is stored as a 27x9 matrix
//
// / 0 27 54 81 108 135 162 189 216 \
// A = | . . |
// | . . |
// | . . |
// \ 26 242 /
//
class tens5d : public tensor_base<tens5d>
{
public:
// default constructor
tens5d() {}
// access operators
double operator () (int i, int j, int k, int l, int m) const;
double& operator () (int i, int j, int k, int l, int m);
};
// The following file contains the actual definition of the class functions
#include "tens5d.hpp"
#include "tens5ds.hpp"
| Unknown |
3D | febiosoftware/FEBio | FECore/QuadricFit.h | .h | 2,609 | 75 | /*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio-Studio.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 <vector>
#include <string>
#include "Quadric.h"
#include "quatd.h"
#include "fecore_api.h"
class FECORE_API QuadricFit
{
public:
enum Q_TYPE { Q_ELLIPSOID, Q_ELLIPTIC_PARABOLOID, Q_HYPERBOLIC_PARABOLOID,
Q_ELLIPTIC_HYPERBOLOID_1, Q_ELLIPTIC_HYPERBOLOID_2, Q_ELLIPTIC_CONE,
Q_ELLIPTIC_CYLINDER, Q_HYPERBOLIC_CYLINDER, Q_PARABOLIC_CYLINDER,
Q_SPHEROID, Q_SPHERE, Q_CIRCULAR_PARABOLOID, Q_CIRCULAR_HYPERBOLOID_1,
Q_CIRCULAR_HYPERBOLOID_2, Q_CIRCULAR_CONE, Q_CIRCULAR_CYLINDER, Q_UNKNOWN
};
public:
QuadricFit();
QuadricFit(const QuadricFit& qf);
virtual ~QuadricFit();
bool Fit(std::vector<vec3d>& pc);
Q_TYPE GetType();
std::string GetStringType(Q_TYPE qtype);
protected:
vec3d Transform(vec3d& rc, quatd& q, const vec3d& p)
{
vec3d r = p - rc;
q.RotateVector(r);
return r;
}
void GetOrientation();
bool isSame(const double& a, const double&b);
public:
vec3d m_rc; // center of quadric
vec3d m_ax[3];// quadric axes
vec3d m_c2; // coefficients of square terms
vec3d m_v; // coefficients of linear terms
double m_c; // constant
double m_eps; // tolerance
Quadric* m_quad; // quadric object
};
| Unknown |
3D | febiosoftware/FEBio | FECore/DenseMatrix.cpp | .cpp | 3,533 | 130 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "DenseMatrix.h"
using namespace FECore;
using namespace std;
//-----------------------------------------------------------------------------
DenseMatrix::DenseMatrix()
{
m_pr = 0;
m_pd = 0;
}
//-----------------------------------------------------------------------------
DenseMatrix::~DenseMatrix()
{
delete [] m_pd; m_pd = 0;
delete [] m_pr; m_pr = 0;
}
//-----------------------------------------------------------------------------
void DenseMatrix::Zero()
{
memset(m_pd, 0, m_nsize*sizeof(double));
}
//-----------------------------------------------------------------------------
void DenseMatrix::Clear()
{
if (m_pd) delete [] m_pd; m_pd = 0;
if (m_pr) delete [] m_pr; m_pr = 0;
SparseMatrix::Clear();
}
//-----------------------------------------------------------------------------
void DenseMatrix::Create(SparseMatrixProfile& mp)
{
Create(mp.Rows(), mp.Columns());
}
//-----------------------------------------------------------------------------
// Creat a dense matrix of size N x N
void DenseMatrix::Create(int rows, int cols)
{
if ((rows != m_nrow) || (cols != m_ncol))
{
if (m_pd) delete [] m_pd;
if (m_pr) delete [] m_pr;
m_pd = new double[rows*cols];
m_pr = new double*[rows];
for (int i=0; i<rows; ++i) m_pr[i] = m_pd + i*cols;
m_nrow = rows;
m_ncol = cols;
m_nsize = rows*cols;
}
}
//-----------------------------------------------------------------------------
//! This function assembles the local stiffness matrix
//! into the global stiffness matrix which is in dense format
//!
void DenseMatrix::Assemble(const matrix& ke, const vector<int>& lm)
{
int I, J;
const int N = ke.rows();
const int M = ke.columns();
for (int i=0; i<N; ++i)
{
if ((I = lm[i])>=0)
{
for (int j=0; j<M; ++j)
{
if ((J = lm[j]) >= 0) m_pr[I][J] += ke[i][j];
}
}
}
}
//-----------------------------------------------------------------------------
void DenseMatrix::Assemble(const matrix& ke, const vector<int>& LMi, const vector<int>& LMj)
{
int I, J;
const int N = ke.rows();
const int M = ke.columns();
for (int i=0; i<N; ++i)
{
if ((I = LMi[i])>=0)
{
for (int j=0; j<M; ++j)
{
if ((J = LMj[j]) >= 0) m_pr[I][J] += ke[i][j];
}
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens3d.cpp | .cpp | 1,317 | 31 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "tens3d.h"
| C++ |
3D | febiosoftware/FEBio | FECore/FEScalarValuator.cpp | .cpp | 7,132 | 307 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEScalarValuator.h"
#include "FEMaterialPoint.h"
#include "FEModelParam.h"
#include "FEModel.h"
#include "DumpStream.h"
#include "log.h"
//=============================================================================
bool FEMathExpression::Init(const std::string& expr, FECoreBase* pc)
{
Clear();
AddVariable("X");
AddVariable("Y");
AddVariable("Z");
AddVariable("t");
bool b = Create(expr, true);
// lookup all the other variables.
if (Variables() > 4)
{
if (pc == nullptr) return false;
for (int i = 4; i < Variables(); ++i)
{
MVariable* vari = Variable(i);
ParamString ps(vari->Name().c_str());
FEParam* p = pc->FindParameter(ps);
if (p)
{
assert((p->type() == FE_PARAM_DOUBLE_MAPPED) || (p->type() == FE_PARAM_DOUBLE) || (p->type() == FE_PARAM_INT));
MathParam mp;
mp.type = 0;
mp.pp = p;
m_vars.push_back(mp);
}
else
{
// see if it's a data map
FEModel* fem = pc->GetFEModel();
// see if it's a global variable
p = fem->FindParameter(ps);
if (p)
{
MathParam mp;
mp.type = 0;
mp.pp = p;
m_vars.push_back(mp);
}
else
{
FEMesh& mesh = fem->GetMesh();
FEDataMap* map = mesh.FindDataMap(vari->Name());
assert(map);
if (map == nullptr) {
const char* szvar = vari->Name().c_str();
feLogErrorEx(fem, "Don't understand variable name \"%s\" in math expression.", szvar);
return false;
}
if (map->DataType() != FEDataType::FE_DOUBLE) {
const char* szvar = vari->Name().c_str();
feLogErrorEx(fem, "Variable \"%s\" is not a scalar variable.", szvar);
return false;
}
MathParam mp;
mp.type = 1;
mp.map = map;
m_vars.push_back(mp);
}
}
}
}
assert(b);
return b;
}
void FEMathExpression::operator = (const FEMathExpression& me)
{
MSimpleExpression::operator=(me);
m_vars = me.m_vars;
}
double FEMathExpression::value(FEModel* fem, const FEMaterialPoint& pt)
{
std::vector<double> var(4 + m_vars.size());
var[0] = pt.m_r0.x;
var[1] = pt.m_r0.y;
var[2] = pt.m_r0.z;
var[3] = fem->GetTime().currentTime;
if (m_vars.empty() == false)
{
for (int i = 0; i < (int)m_vars.size(); ++i)
{
MathParam& mp = m_vars[i];
if (mp.type == 0)
{
FEParam* pi = mp.pp;
switch (pi->type())
{
case FE_PARAM_INT: var[4 + i] = (double)pi->value<int>(); break;
case FE_PARAM_DOUBLE: var[4 + i] = pi->value<double>(); break;
case FE_PARAM_DOUBLE_MAPPED: var[4 + i] = pi->value<FEParamDouble>()(pt); break;
}
}
else
{
FEDataMap& map = *mp.map;
var[4 + i] = map.value(pt);
}
}
}
return value_s(var);
}
//=============================================================================
BEGIN_FECORE_CLASS(FEConstValue, FEScalarValuator)
ADD_PARAMETER(m_val, "const");
END_FECORE_CLASS();
FEScalarValuator* FEConstValue::copy()
{
FEConstValue* val = fecore_alloc(FEConstValue, GetFEModel());
val->m_val = m_val;
return val;
}
//=============================================================================
BEGIN_FECORE_CLASS(FEMathValue, FEScalarValuator)
ADD_PARAMETER(m_expr, "math");
END_FECORE_CLASS();
FEMathValue::FEMathValue(FEModel* fem) : FEScalarValuator(fem)
{
m_parent = nullptr;
}
void FEMathValue::setMathString(const std::string& s)
{
m_expr = s;
}
bool FEMathValue::Init()
{
return create();
}
void FEMathValue::Serialize(DumpStream& ar)
{
FEScalarValuator::Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
ar << m_parent;
}
else if (ar.IsLoading())
{
ar >> m_parent;
create(m_parent);
}
}
bool FEMathValue::create(FECoreBase* pc)
{
// see if this is already initialized
if (m_math.Variables() > 0) return true;
if (pc == nullptr)
{
// try to find the owner of this parameter
// First, we need the model parameter
FEModelParam* param = GetModelParam();
if (param == nullptr) return false;
// we'll need the model for this
FEModel* fem = GetFEModel();
if (fem == nullptr) return false;
// Now try to find the owner of this parameter
pc = fem->FindParameterOwner(param);
}
m_parent = pc;
// initialize the math expression
bool b = m_math.Init(m_expr, pc);
return b;
}
FEMathValue::~FEMathValue()
{
}
FEScalarValuator* FEMathValue::copy()
{
FEMathValue* newExpr = fecore_alloc(FEMathValue, GetFEModel());
newExpr->m_expr = m_expr;
newExpr->m_math = m_math;
return newExpr;
}
double FEMathValue::operator()(const FEMaterialPoint& pt)
{
return m_math.value(GetFEModel(), pt);
}
//---------------------------------------------------------------------------------------
FEMappedValue::FEMappedValue(FEModel* fem) : FEScalarValuator(fem), m_val(nullptr)
{
m_scale = 1.0;
}
void FEMappedValue::setDataMap(FEDataMap* val)
{
m_val = val;
}
FEDataMap* FEMappedValue::dataMap()
{
return m_val;
}
void FEMappedValue::setScaleFactor(double s)
{
m_scale = s;
}
double FEMappedValue::operator()(const FEMaterialPoint& pt)
{
return m_scale*m_val->value(pt);
}
FEScalarValuator* FEMappedValue::copy()
{
FEMappedValue* map = fecore_alloc(FEMappedValue, GetFEModel());
map->setDataMap(m_val);
map->m_scale = m_scale;
return map;
}
void FEMappedValue::Serialize(DumpStream& dmp)
{
if (dmp.IsShallow()) return;
dmp & m_scale;
dmp & m_val;
}
//---------------------------------------------------------------------------------------
FENodeMappedValue::FENodeMappedValue(FEModel* fem) : FEScalarValuator(fem), m_val(nullptr)
{
}
void FENodeMappedValue::setDataMap(FENodeDataMap* val)
{
m_val = val;
}
double FENodeMappedValue::operator()(const FEMaterialPoint& pt)
{
return m_val->getValue(pt.m_index);
}
FEScalarValuator* FENodeMappedValue::copy()
{
FENodeMappedValue* map = fecore_alloc(FENodeMappedValue, GetFEModel());
map->setDataMap(m_val);
return map;
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens3d.hpp | .hpp | 6,396 | 173 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 tens3drs.h
// Users should not include this file manually!
// access operator
inline double tens3d::operator()(int i, int j, int k) const
{
return d[i*9 + j*3 + k];
}
// access operator
inline double& tens3d::operator()(int i, int j, int k)
{
return d[i*9 + j*3 + k];
}
inline tens3d::tens3d(double a)
{
int nnz = tensor_traits<tens3d>::NNZ;
for (int i = 0; i < nnz; ++i) d[i] = a;
}
// symmetrize a general 3o tensor
inline tens3ds tens3d::symm()
{
tens3ds t;
t.d[0] = d[0];
t.d[1] = (d[1] + d[3] + d[9])/3.;
t.d[2] = (d[2] + d[6] + d[18])/3.;
t.d[3] = (d[4] + d[10] + d[12])/3.;
t.d[4] = (d[5] + d[11] + d[21] + d[7] + d[19] + d[15])/6.;
t.d[5] = (d[8] + d[20] + d[24])/3.;
t.d[6] = d[13];
t.d[7] = (d[14] + d[16] + d[22])/3.;
t.d[8] = (d[17] + d[23] + d[25])/3.;
t.d[9] = d[26];
return t;
}
// return transpose of right side
// [T] = [T111 T112 T113 T121 T122 T123 T131 T132 T133 T211 T212 T213 T221 T222 T223 T231 T232 T233 T311 T312 T313 T321 T322 T323 T331 T332 T333
// = T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16 T17 T18 T19 T20 T21 T22 T23 T24 T25 T26
inline tens3d tens3d::transposer()
{
tens3d s;
s.d[ 0] = d[ 0];
s.d[ 1] = d[ 3];
s.d[ 2] = d[ 6];
s.d[ 3] = d[ 1];
s.d[ 4] = d[ 4];
s.d[ 5] = d[ 7];
s.d[ 6] = d[ 2];
s.d[ 7] = d[ 5];
s.d[ 8] = d[ 8];
s.d[ 9] = d[ 9];
s.d[10] = d[12];
s.d[11] = d[15];
s.d[12] = d[10];
s.d[13] = d[13];
s.d[14] = d[16];
s.d[15] = d[11];
s.d[16] = d[14];
s.d[17] = d[17];
s.d[18] = d[18];
s.d[19] = d[21];
s.d[20] = d[24];
s.d[21] = d[19];
s.d[22] = d[22];
s.d[23] = d[25];
s.d[24] = d[20];
s.d[25] = d[23];
s.d[26] = d[26];
return s;
}
// contract the right two legs by a 2o tensor xi = Gijk*Sjk
// [T] = [T111 T112 T113 T121 T122 T123 T131 T132 T133 T211 T212 T213 T221 T222 T223 T231 T232 T233 T311 T312 T313 T321 T322 T323 T331 T332 T333
// = T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16 T17 T18 T19 T20 T21 T22 T23 T24 T25 T26
inline vec3d tens3d::contract2(const mat3d& s) const
{
vec3d x;
x.x = d[0]*s[0][0] + d[1]*s[0][1] + d[2]*s[0][2] + d[3]*s[1][0] + d[4]*s[1][1] + d[5]*s[1][2] + d[6]*s[2][0] + d[7]*s[2][1] + d[8]*s[2][2];
x.y = d[9]*s[0][0] + d[10]*s[0][1] + d[11]*s[0][2] + d[12]*s[1][0] + d[13]*s[1][1] + d[14]*s[1][2] + d[15]*s[2][0] + d[16]*s[2][1] + d[17]*s[2][2];
x.z = d[18]*s[0][0] + d[19]*s[0][1] + d[20]*s[0][2] + d[21]*s[1][0] + d[22]*s[1][1] + d[23]*s[1][2] + d[24]*s[2][0] + d[25]*s[2][1] + d[26]*s[2][2];
return x;
}
// contract the right leg by a vector xij = Gijk*vk
// [T] = [T111 T112 T113 T121 T122 T123 T131 T132 T133 T211 T212 T213 T221 T222 T223 T231 T232 T233 T311 T312 T313 T321 T322 T323 T331 T332 T333
// = T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16 T17 T18 T19 T20 T21 T22 T23 T24 T25 T26
inline mat3d tens3d::contract1(const vec3d& v) const
{
mat3d x;
x[0][0] = d[0]*v.x + d[1]*v.y + d[2]*v.z;
x[0][1] = d[3]*v.x + d[4]*v.y + d[5]*v.z;
x[0][2] = d[6]*v.x + d[7]*v.y + d[8]*v.z;
x[1][0] = d[9]*v.x + d[10]*v.y + d[11]*v.z;
x[1][1] = d[12]*v.x + d[13]*v.y + d[14]*v.z;
x[1][2] = d[15]*v.x + d[16]*v.y + d[17]*v.z;
x[2][0] = d[18]*v.x + d[19]*v.y + d[20]*v.z;
x[2][1] = d[21]*v.x + d[22]*v.y + d[23]*v.z;
x[2][2] = d[24]*v.x + d[25]*v.y + d[26]*v.z;
return x;
}
inline tens3d operator + (const tens3dls& l, const tens3drs& r)
{
tens3d s;
s.d[ 0] = l.d[ 0] + r.d[ 0]; // S111 = L111 + R111
s.d[ 1] = l.d[ 1] + r.d[ 1]; // S112 = L112 + R112
s.d[ 2] = l.d[ 2] + r.d[ 2]; // S113 = L113 + R113
s.d[ 3] = l.d[ 3] + r.d[ 1]; // S121 = L121 + R112
s.d[ 4] = l.d[ 4] + r.d[ 3]; // S122 = L122 + R122
s.d[ 5] = l.d[ 5] + r.d[ 4]; // S123 = L123 + R123
s.d[ 6] = l.d[ 6] + r.d[ 2]; // S131 = L131 + R113
s.d[ 7] = l.d[ 7] + r.d[ 4]; // S132 = L132 + R123
s.d[ 8] = l.d[ 8] + r.d[ 5]; // S133 = L133 + R133
s.d[ 9] = l.d[ 3] + r.d[ 6]; // S211 = L121 + R211
s.d[10] = l.d[ 4] + r.d[ 7]; // S212 = L122 + R212
s.d[11] = l.d[ 5] + r.d[ 8]; // S213 = L123 + R213
s.d[12] = l.d[ 9] + r.d[ 7]; // S221 = L221 + R212
s.d[13] = l.d[10] + r.d[ 9]; // S222 = L222 + R222
s.d[14] = l.d[11] + r.d[10]; // S223 = L223 + R223
s.d[15] = l.d[12] + r.d[ 8]; // S231 = L231 + R213
s.d[16] = l.d[13] + r.d[10]; // S232 = L232 + R223
s.d[17] = l.d[14] + r.d[11]; // S233 = L233 + R233
s.d[18] = l.d[ 6] + r.d[12]; // S311 = L131 + R311
s.d[19] = l.d[ 7] + r.d[13]; // S312 = L132 + R312
s.d[20] = l.d[ 8] + r.d[14]; // S313 = L133 + R313
s.d[21] = l.d[12] + r.d[13]; // S321 = L231 + R312
s.d[22] = l.d[13] + r.d[15]; // S322 = L232 + R322
s.d[23] = l.d[14] + r.d[16]; // S323 = L233 + R323
s.d[24] = l.d[15] + r.d[14]; // S331 = L331 + R313
s.d[25] = l.d[16] + r.d[16]; // S332 = L332 + R323
s.d[26] = l.d[17] + r.d[17]; // S333 = L333 + R333
return s;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/expint_Ei.cpp | .cpp | 2,613 | 73 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "expint_Ei.h"
#include <limits>
#include <math.h>
// This is our homemade function for evaluating the exponential integral Ei(x), valid for
// negative and positive values of x.
double expint_Ei(double x)
{
const int MAXITER = 100;
if (x == 0) return -INFINITY;
const double eps = 10*std::numeric_limits<double>::epsilon();
const double gamma = 0.5772156649015328606065120900824024310421;
double ei = 0;
// use series expansion if x is sufficiently small
if (fabs(x) < fabs(log(eps))) {
// use series expansion if x is sufficiently small
ei = gamma;
ei += (x > 0) ? log(x) : log(-x);
double d = x;
int i=0;
bool convgd = false;
while (!convgd) {
++i;
ei += d;
if ((fabs(d) < eps*fabs(ei)) || (i > MAXITER)) convgd = true;
else d *= (i*x)/pow(i+1,2);
}
}
else {
// use asymptotic expansion for sufficiently large x
ei = 1;
double d = 1./x;
int i=0;
bool convgd = false;
while (!convgd) {
++i;
ei += d;
if ((fabs(d) < eps*fabs(ei)) || (i > MAXITER)) convgd = true;
else d *= (i+1)/x;
}
ei *= exp(x)/x;
}
return ei;
}
| C++ |
3D | febiosoftware/FEBio | FECore/BFGSSolver.cpp | .cpp | 5,832 | 210 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "BFGSSolver.h"
#include "FESolver.h"
#include "FEException.h"
#include "FENewtonSolver.h"
#include "log.h"
//-----------------------------------------------------------------------------
// BFGSSolver
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(BFGSSolver, FENewtonStrategy)
ADD_PARAMETER(m_maxups, "max_ups");
ADD_PARAMETER(m_max_buf_size, FE_RANGE_GREATER_OR_EQUAL(0), "max_buffer_size");
ADD_PARAMETER(m_cycle_buffer, "cycle_buffer");
ADD_PARAMETER(m_cmax, FE_RANGE_GREATER_OR_EQUAL(0.0), "cmax");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
BFGSSolver::BFGSSolver(FEModel* fem) : FENewtonStrategy(fem)
{
m_neq = 0;
// pointer to linear solver
m_plinsolve = 0;
}
//-----------------------------------------------------------------------------
// Initialization method
bool BFGSSolver::Init()
{
if (m_pns == nullptr) return false;
if (m_max_buf_size <= 0) m_max_buf_size = m_maxups;
int neq = m_pns->m_neq;
// allocate storage for BFGS update vectors
m_V.resize(m_max_buf_size, neq);
m_W.resize(m_max_buf_size, neq);
m_D.resize(neq);
m_G.resize(neq);
m_H.resize(neq);
m_neq = neq;
m_nups = 0;
m_plinsolve = m_pns->GetLinearSolver();
return true;
}
//-----------------------------------------------------------------------------
//! This function performs a BFGS stiffness update.
//! The last line search step is input to this function.
//! This function performs the update assuming the stiffness matrix
//! is positive definite. In the case that this is not the case
//! the function returns false. The function also returns false if
//! the condition number is too big. A too big condition number might
//! be an indication of an ill-conditioned matrix and the update should
//! not be performed.
bool BFGSSolver::Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1)
{
// for full-Newton, we skip QN update
if (m_maxups == 0) return false;
// make sure we didn't reach max updates
if (m_nups >= m_maxups - 1)
{
feLogWarning("Max nr of iterations reached.\nStiffness matrix will now be reformed.");
return false;
}
// calculate the BFGS update vectors
int neq = m_neq;
for (int i = 0; i<neq; ++i)
{
m_D[i] = s*ui[i];
m_G[i] = R0[i] - R1[i];
m_H[i] = R0[i]*s;
}
double dg = m_D*m_G;
double dh = m_D*m_H;
double dgi = 1.0 / dg;
double r = dg / dh;
// check to see if this is still a pos definite update
// if (r <= 0)
// {
// feLogWarning("The QN update has failed.\nStiffness matrix will now be reformed.");
// return false;
// }
// calculate the condition number
// c = sqrt(r);
double c = sqrt(fabs(r));
// make sure c is less than the the maximum.
if (c > m_cmax) return false;
// get the correct buffer to fill
int n = (m_nups % m_max_buf_size);
// do the update only when allowed
if ((m_nups < m_max_buf_size) || (m_cycle_buffer == true))
{
double* vn = m_V[n];
double* wn = m_W[n];
for (int i=0; i<neq; ++i)
{
vn[i] = -m_H[i]*c - m_G[i];
wn[i] = m_D[i]*dgi;
}
}
// increment update counter
++m_nups;
return true;
}
//-----------------------------------------------------------------------------
// This function solves a system of equations using the BFGS update vectors
// The variable m_nups keeps track of how many updates have been made so far.
//
void BFGSSolver::SolveEquations(vector<double>& x, vector<double>& b)
{
// make sure we need to do work
if (m_neq ==0) return;
// create temporary storage
tmp = b;
// number of updates can be larger than buffer size, so clamp it
int nups = (m_nups> m_max_buf_size ? m_max_buf_size : m_nups);
// get the "0" buffer index
int n0 = 0;
if ((m_nups > m_max_buf_size) && (m_cycle_buffer == true))
{
n0 = m_nups % m_max_buf_size;
}
// loop over all update vectors
for (int i=nups-1; i>=0; --i)
{
int n = (n0 + i) % m_max_buf_size;
double* vi = m_V[n];
double* wi = m_W[n];
double wr = 0;
for (int j = 0; j<m_neq; j++) wr += wi[j] * tmp[j];
for (int j = 0; j<m_neq; j++) tmp[j] += vi[j] * wr;
}
// perform a backsubstitution
if (m_plinsolve->BackSolve(x, tmp) == false)
{
throw LinearSolverFailed();
}
// loop again over all update vectors
for (int i = 0; i<nups; ++i)
{
int n = (n0 + i) % m_max_buf_size;
double* vi = m_V[n];
double* wi = m_W[n];
double vr = 0;
for (int j = 0; j<m_neq; ++j) vr += vi[j] * x[j];
for (int j = 0; j<m_neq; ++j) x[j] += wi[j] * vr;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEPlotDataStore.cpp | .cpp | 3,852 | 123 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEPlotDataStore.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
FEPlotVariable::FEPlotVariable() {}
//-----------------------------------------------------------------------------
FEPlotVariable::FEPlotVariable(const FEPlotVariable& pv)
{
m_svar = pv.m_svar;
m_sdom = pv.m_sdom;
m_item = pv.m_item;
}
//-----------------------------------------------------------------------------
void FEPlotVariable::operator = (const FEPlotVariable& pv)
{
m_svar = pv.m_svar;
m_sdom = pv.m_sdom;
m_item = pv.m_item;
}
FEPlotVariable::FEPlotVariable(const std::string& var, std::vector<int>& item, const char* szdom)
{
m_svar = var;
if (szdom) m_sdom = szdom;
m_item = item;
}
void FEPlotVariable::Serialize(DumpStream& ar)
{
ar & m_svar;
ar & m_sdom;
ar & m_item;
}
//=======================================================================================
FEPlotDataStore::FEPlotDataStore()
{
m_splot_type = "febio";
m_plot.clear();
m_nplot_compression = 0;
}
//-----------------------------------------------------------------------------
FEPlotDataStore::FEPlotDataStore(const FEPlotDataStore& plt)
{
m_splot_type = plt.m_splot_type;
m_nplot_compression = plt.m_nplot_compression;
m_plot = plt.m_plot;
}
//-----------------------------------------------------------------------------
void FEPlotDataStore::operator = (const FEPlotDataStore& plt)
{
m_splot_type = plt.m_splot_type;
m_nplot_compression = plt.m_nplot_compression;
m_plot = plt.m_plot;
}
//-----------------------------------------------------------------------------
void FEPlotDataStore::AddPlotVariable(const char* szvar, std::vector<int>& item, const char* szdom)
{
FEPlotVariable var(szvar, item, szdom);
m_plot.push_back(var);
}
//-----------------------------------------------------------------------------
int FEPlotDataStore::GetPlotCompression() const
{
return m_nplot_compression;
}
//-----------------------------------------------------------------------------
void FEPlotDataStore::SetPlotCompression(int n)
{
m_nplot_compression = n;
}
//-----------------------------------------------------------------------------
void FEPlotDataStore::SetPlotFileType(const std::string& fileType)
{
m_splot_type = fileType;
}
std::string FEPlotDataStore::GetPlotFileType()
{
return m_splot_type;
}
void FEPlotDataStore::Serialize(DumpStream& ar)
{
ar & m_nplot_compression;
ar & m_splot_type;
ar & m_plot;
}
| C++ |
3D | febiosoftware/FEBio | FECore/MFunctions.h | .h | 2,123 | 69 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "math.h"
#include "fecore_api.h"
typedef double (*FUNCPTR) (double);
typedef double (*FUNC2PTR) (double, double);
typedef double (*FUNCNPTR) (double*, int);
// trigonometric functions
double csc(double x);
double sec(double x);
double cot(double x);
double sinc(double x);
// Bessel functions
#ifdef WIN32
double jn(double x, double y);
double yn(double x, double y);
#endif
// multi-variate functions
double fmax(double* x, int n);
double fmin(double* x, int n);
double avg(double* x, int n);
// special polynomials
double chebyshev(double f, double x);
// additional functios
double fl(double x);
double sgn(double x);
double fac(double x); // factorials
double heaviside(double x);
double unit_step(double x);
// binomials
double binomial(double n, double r);
// gamma function
FECORE_API double gamma(double x);
| Unknown |
3D | febiosoftware/FEBio | FECore/FENodalLoad.h | .h | 3,501 | 123 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEModelLoad.h"
#include "FENodeDataMap.h"
#include "FEDofList.h"
#include "FEModelParam.h"
//-----------------------------------------------------------------------------
class FENodeSet;
//-----------------------------------------------------------------------------
//! Nodal load boundary condition
class FECORE_API FENodalLoad : public FEModelLoad
{
FECORE_BASE_CLASS(FENodalLoad)
public:
//! constructor
FENodalLoad(FEModel* pfem);
//! initialization
bool Init() override;
//! activation
void Activate() override;
//! Get the DOF list
const FEDofList& GetDOFList() const;
//! add a node set
void SetNodeSet(FENodeSet* ns);
//! get the nodeset
FENodeSet* GetNodeSet();
//! serialiation
void Serialize(DumpStream& ar) override;
public:
//! Get the DOF list
//! This must be implemented by derived classes.
virtual bool SetDofList(FEDofList& dofList) = 0;
//! Get the nodal value
//! This must be implemented by derived classes.
//! The vals array will have the same size as the dof list.
virtual void GetNodalValues(int inode, std::vector<double>& vals) = 0;
public:
//! evaluate the contribution to the residual
virtual void LoadVector(FEGlobalVector& R) override;
//! evaluate the contribution to the global stiffness matrix
virtual void StiffnessMatrix(FELinearSystem& LS) override;
protected:
FEDofList m_dofs;
FENodeSet* m_nodeSet;
bool m_brelative;
vector<vector<double> > m_rval;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// Class for prescribing the "load" on a degree of freedom.
class FECORE_API FENodalDOFLoad : public FENodalLoad
{
public:
FENodalDOFLoad(FEModel* fem);
//! Set the DOF list
bool SetDofList(FEDofList& dofList) override;
//! get/set degree of freedom
void SetDOF(int ndof) { m_dof = ndof; }
int GetDOF() const { return m_dof; }
//! get/set load
void SetLoad(double s);
void GetNodalValues(int n, std::vector<double>& val) override;
double NodeValue(int n);
void SetDtScale(bool b);
private:
int m_dof; //!< degree of freedom index
FEParamDouble m_scale; //!< applied load scale factor
bool m_dtscale;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEElementShape.h | .h | 1,797 | 45 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_enum.h"
//=============================================================================
// Base class for defining element shape classes.
// The element shape classes are used for evaluating shape functions and their derivatives.
class FEElementShape
{
public:
FEElementShape(FE_Element_Shape eshape, int nodes);
virtual ~FEElementShape();
FE_Element_Shape shape() const { return m_shape; }
int nodes() const { return m_nodes; }
private:
FE_Element_Shape m_shape;
int m_nodes;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEPointFunction.h | .h | 3,744 | 127 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEFunction1D.h"
#include "PointCurve.h"
#include <vector>
//-----------------------------------------------------------------------------
class DumpStream;
//-----------------------------------------------------------------------------
//! This class implements a function defined by a set of ordered (point,value) pairs.
//! It uses an interpolation scheme to interpolate between data points and also
//! has a way of specifying the function value outside of the domain defined by the first and
//! last data point.
class FECORE_API FEPointFunction : public FEFunction1D
{
public:
//! Load point structure
struct LOADPOINT
{
double time;
double value;
};
public:
//! default constructor
FEPointFunction(FEModel* fem);
//! destructor
~FEPointFunction();
//! initialize
bool Init() override;
//! adds a point to the point curve
void Add(double x, double y);
//! Clears the loadcurve data
void Clear() override;
//! set the x and y value of point i
void SetPoint(int i, double x, double y);
//! Set the type of interpolation
void SetInterpolation(int n);
//! Set the extend mode
void SetExtendMode(int n);
//! returns point i
LOADPOINT LoadPoint(int i) const;
//! return nr of points
int Points() const;
//! set the points
void SetPoints(const std::vector<vec2d>& pts);
//! Serialize data to archive
void Serialize(DumpStream& ar) override;
// copy data from other curve
FEFunction1D* copy() override;
// copy from another function
void CopyFrom(const FEPointFunction& f);
void CopyFrom(const PointCurve& f);
public: // operations
// scale all y points by s
void Scale(double s);
public: // implement from base class
//! returns the value of the load curve at time
double value(double x) const override;
//! returns the derivative value at time
double derive(double x) const override;
//! returns the second derivative value at time
double deriv2(double x) const override;
//! returns the definite integral value between a and b
double integrate(double a, double b) const override;
// TODO: I need to make this public so the parameters can be mapped to the FELoadCurve
private:
int m_int; //!< interpolation function
int m_ext; //!< extend mode
bool m_bln; //!< points represent (ln(x),y) instead of (x,y)
std::vector<vec2d> m_points;
private:
PointCurve m_fnc;
DECLARE_FECORE_CLASS();
};
typedef FEPointFunction::LOADPOINT LOADPOINT;
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfaceConstraint.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 "FESurfaceConstraint.h"
FESurfaceConstraint::FESurfaceConstraint(FEModel* fem) : FENLConstraint(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELogElemMath.h | .h | 1,676 | 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 "ElementDataRecord.h"
#include "MathObject.h"
#include <string>
#include "fecore_api.h"
class FECORE_API FELogElemMath : public FELogElemData
{
public:
FELogElemMath(FEModel* pfem);
~FELogElemMath();
double value(FEElement& el);
bool SetExpression(const std::string& smath);
private:
void Clear();
private:
MSimpleExpression m;
std::vector<FELogElemData*> m_data;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataExport.h | .h | 2,092 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_enum.h"
#include "FEDataStream.h"
//-----------------------------------------------------------------------------
// This class is used by domain classes to define their data exports.
// This is part of an experimental feature that allows domain classes to handle
// the data that they want to export.
class FECORE_API FEDataExport
{
public:
FEDataExport(Var_Type itype, Storage_Fmt ifmt, void* pd, const char* szname)
{
m_pd = pd;
m_type = itype;
m_fmt = ifmt;
m_szname = szname;
}
virtual ~FEDataExport(){}
virtual void Serialize(FEDataStream& d);
public:
Var_Type m_type;
Storage_Fmt m_fmt;
void* m_pd; //!< pointer to data field
const char* m_szname;
};
#define EXPORT_DATA(iType, iFmt, pVar, Name) AddDataExport(new FEDataExport(iType, iFmt, pVar, Name)); | Unknown |
3D | febiosoftware/FEBio | FECore/MEvaluate.cpp | .cpp | 11,696 | 528 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "MEvaluate.h"
#include "MMath.h"
#include <map>
using namespace std;
//-----------------------------------------------------------------------------
void MEvaluate(MathObject* po)
{
if (dynamic_cast<MSimpleExpression*>(po))
{
MSimpleExpression* pe = dynamic_cast<MSimpleExpression*>(po);
MITEM it = MEvaluate(pe->GetExpression());
pe->SetExpression(it);
}
}
//-----------------------------------------------------------------------------
MITEM MEvaluate(const MITEM& i)
{
MITEM a;
switch (i.Type())
{
case MNEG: a = -MEvaluate(i.Item()); break;
case MADD:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = MAddition(l, r);
}
break;
case MSUB:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = MAddition(l, -r);
}
break;
case MMUL:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = MMultiply(l, r);
}
break;
case MDIV:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = MDivide(l, r);
}
break;
case MPOW:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = (l ^ r);
}
break;
case MEQUATION:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
a = MITEM(new MEquation(l.copy(), r.copy()));
}
break;
case MEQUALITY:
{
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
bool b = is_equal(l.ItemPtr(), r.ItemPtr());
a = MITEM(new MBoolean(b));
}
break;
case MMATRIX:
{
const MMatrix& A = *mmatrix(i);
a = MEvaluate(A);
}
break;
case MF1D:
{
const MFunc1D* pf = mfnc1d(i);
string s = pf->Name();
MITEM p = MEvaluate(i.Item());
if (s.compare("sin" ) == 0) return Sin (p);
if (s.compare("cos" ) == 0) return Cos (p);
if (s.compare("tan" ) == 0) return Tan (p);
if (s.compare("cot" ) == 0) return Cot (p);
if (s.compare("sec" ) == 0) return Sec (p);
if (s.compare("csc" ) == 0) return Csc (p);
if (s.compare("atan") == 0) return Atan (p);
if (s.compare("cosh") == 0) return Cosh (p);
if (s.compare("sinh") == 0) return Sinh (p);
if (s.compare("exp" ) == 0) return Exp (p);
if (s.compare("ln" ) == 0) return Log (p);
if (s.compare("log" ) == 0) return Log10(p);
if (s.compare("sqrt") == 0) return Sqrt (p);
if (s.compare("fl" ) == 0) return Float(p);
if (s.compare("abs" ) == 0) return Abs (p);
if (s.compare("sgn" ) == 0) return Sgn (p);
#ifdef WIN32
if (s.compare("J0" ) == 0) return J0 (p);
if (s.compare("J1" ) == 0) return J1 (p);
if (s.compare("Y0" ) == 0) return Y0 (p);
if (s.compare("Y1" ) == 0) return Y1 (p);
#endif
if (s.compare("fac" ) == 0) return Fac (p);
if (s.compare("erf" ) == 0) return Erf (p);
if (s.compare("erfc") == 0) return Erfc (p);
return i;
}
break;
case MF2D:
{
const MFunc2D* pf = mfnc2d(i);
string s = pf->Name();
MITEM a = MEvaluate(i.Left());
MITEM b = MEvaluate(i.Right());
if (s.compare("binomial") == 0) return Binomial(a, b);
#ifdef WIN32
else if (s.compare("Jn")==0) return Jn(a,b);
else if (s.compare("Yn")==0) return Yn(a,b);
#endif
else if (s.compare("Tn")==0) return Tn(a,b);
return i;
}
break;
case MFMAT:
{
const MFuncMat* pfm = mfncmat(i);
MITEM m = MEvaluate(i.Item());
const MMatrix& A = *mmatrix(m.ItemPtr());
FUNCMATPTR pf = pfm->funcptr();
a = pf(A);
}
break;
case MFMAT2:
{
const MFuncMat2* pfm = mfncmat2(i);
MITEM l = MEvaluate(i.Left());
MITEM r = MEvaluate(i.Right());
const MMatrix& A = *mmatrix(l.ItemPtr());
const MMatrix& B = *mmatrix(r.ItemPtr());
FUNCMAT2PTR pf = pfm->funcptr();
a = pf(A, B);
}
break;
case MSFNC:
{
const MSFuncND* pf = msfncnd(i);
MITEM v = pf->Value()->copy();
MITEM e = MEvaluate(v);
// if (is_rconst(e.ItemPtr())) return e; else return i;
return e;
}
break;
default:
return i;
}
if (a.Type() != i.Type()) a = MEvaluate(a);
return a;
}
//-----------------------------------------------------------------------------
MITEM MEvaluate(const MMatrix& A)
{
MMatrix& B = *(new MMatrix());
B.Create(A.rows(), A.columns());
for (int i=0; i<A.rows(); ++i)
for (int j=0; j<A.columns(); ++j)
{
MITEM aij = A[i][j]->copy();
B[i][j] = MEvaluate(aij).copy();
}
return (&B);
}
//-----------------------------------------------------------------------------
MITEM MMultiply(const MITEM& l, const MITEM& r)
{
MProduct M(l*r);
return M.Item();
}
//-----------------------------------------------------------------------------
MITEM MDivide(const MITEM& n, const MITEM& d)
{
if (d == 0.0) throw DivisionByZero();
if (n == d) return 1.0;
MProduct L(n), D(d);
return L / D;
}
//-----------------------------------------------------------------------------
MProduct::MProduct(const MITEM& a)
{
m_p.push_back(1.0);
Multiply(a);
}
//-----------------------------------------------------------------------------
void MProduct::Multiply(const MITEM& a)
{
if (is_mul(a))
{
MITEM l = a.Left();
MITEM r = a.Right();
Multiply(l);
Multiply(r);
}
else
{
if (isConst(a))
{
MITEM& i0 = *m_p.begin();
if (isConst(i0)) i0 = (a.value()*i0.value()); else m_p.push_front(a);
}
else
{
// see if a already appears in the product
bool binsert = true;
MITEM b(a), pb(1.0);
if (is_pow(a))
{
b = a.Left();
pb = a.Right();
}
list<MITEM>::iterator ic;
for (ic=m_p.begin(); ic != m_p.end(); ++ic)
{
MITEM c(*ic), pc(1.0);
if (is_pow(c))
{
c = (*ic).Left();
pc = (*ic).Right();
}
if (b == c)
{
(*ic) = c^(pc + pb);
binsert = false;
break;
}
}
if (binsert) m_p.push_back(a);
}
}
}
//-----------------------------------------------------------------------------
MITEM MProduct::Item()
{
MITEM c(1.0), r(1.0);
list<MITEM>::iterator it;
for (it=m_p.begin(); it != m_p.end(); ++it)
{
if (isConst(*it)) c = c*(*it);
else r = (r*(*it));
}
return c*r;
}
//-----------------------------------------------------------------------------
MITEM MProduct::operator / (const MProduct& d)
{
MProduct tmp(d);
list<MITEM>::iterator ib;
list<MITEM>::iterator ia;
for (ib = tmp.m_p.begin(); ib != tmp.m_p.end();)
{
MITEM b(*ib), pb(1.0);
bool binc = true;
if (b != 0.0)
{
if (is_pow(b))
{
b = (*ib).Left();
pb = (*ib).Right();
}
for (ia = m_p.begin(); ia != m_p.end(); ++ia)
{
MITEM a(*ia), pa(1.0);
if (is_pow(a))
{
a = (*ia).Left();
pa = (*ia).Right();
}
if (a == b)
{
(*ia) = a^(pa - pb);
ib = tmp.m_p.erase(ib);
binc = false;
break;
}
}
}
if (binc) ++ib;
}
if (!tmp.m_p.empty())
{
if (isConst(*m_p.begin()) && isConst(*tmp.m_p.begin()))
{
MITEM& a = *m_p.begin();
MITEM& b = *tmp.m_p.begin();
double n = a.value();
double d = b.value();
if ((d != 0) && is_int(n) && is_int(d))
{
long c = gcf((long) n, (long) d);
n /= (double) c;
d /= (double) c;
a = n;
b = d;
}
}
}
return Item() / tmp.Item();
}
//-----------------------------------------------------------------------------
bool MProduct::operator==(const MProduct& b)
{
list<MITEM>::iterator pf;
for (pf = m_p.begin(); pf != m_p.end(); ++pf)
{
MITEM& i = *pf;
if (b.contains(i) == false) return false;
}
return true;
}
//-----------------------------------------------------------------------------
bool MProduct::contains(const MITEM& a) const
{
list<MITEM>::const_iterator pf;
for (pf = m_p.begin(); pf != m_p.end(); ++pf)
{
const MITEM& i = *pf;
if (i == a) return true;
}
return false;
}
//-----------------------------------------------------------------------------
MITEM MAddition(const MITEM& l, const MITEM& r)
{
MSum S(l+r);
return S.Item();
}
//-----------------------------------------------------------------------------
MSum::MSum(const MITEM& a)
{
m_c = 0.0;
Add(a);
}
//-----------------------------------------------------------------------------
MSum::MTerm::MTerm(const MITEM& i) : m_s(1.0)
{
// extract the scalar from i
if (is_mul(i))
{
MITEM l = i.Left();
if (isConst(l))
{
m_s = l.value();
m_a = i.Right();
}
else m_a = i;
}
else if (is_div(i))
{
MITEM n = i.Left();
MITEM d = i.Right();
if (is_mul(n))
{
MITEM l = n.Left();
if (isConst(l))
{
m_s = l.value();
n = n.Right();
}
}
if (is_mul(d))
{
MITEM l = d.Left();
if (isConst(l))
{
m_s /= l.value();
d = d.Right();
}
}
else if (isConst(d))
{
m_s /= d.value();
d = 1.0;
}
m_a = MDivide(n, d);
}
else m_a = i;
}
//-----------------------------------------------------------------------------
void MSum::Add(const MITEM& a)
{
if (is_add(a))
{
Add(a.Left());
Add(a.Right());
}
else if (is_sub(a))
{
Add(a.Left());
Sub(a.Right());
}
else if (isConst(a)) m_c += a.value();
else if (is_frac(a)) m_c += mfrac(a)->fraction();
else if (m_t.empty()) m_t.push_back(MTerm(a));
else
{
MTerm b(a);
bool badd = true;
// see if term already exists
list<MTerm>::iterator pt;
for (pt = m_t.begin(); pt != m_t.end(); ++pt)
{
if (b.m_a == pt->m_a)
{
badd = false;
pt->m_s += b.m_s;
break;
}
}
if (badd) m_t.push_back(b);
}
}
//-----------------------------------------------------------------------------
void MSum::Sub(const MITEM& a)
{
if (is_add(a))
{
Sub(a.Left());
Sub(a.Right());
}
else if (is_sub(a))
{
Sub(a.Left());
Add(a.Right());
}
else if (isConst(a)) m_c -= a.value();
else if (is_frac(a)) m_c -= mfrac(a)->fraction();
else
{
MTerm b(a);
bool badd = true;
// see if term already exists
list<MTerm>::iterator pt;
for (pt = m_t.begin(); pt != m_t.end(); ++pt)
{
if (b.m_a == pt->m_a)
{
badd = false;
pt->m_s -= b.m_s;
break;
}
}
if (badd) { b.m_s = -b.m_s; m_t.push_back(b); }
}
}
//-----------------------------------------------------------------------------
MITEM MSum::Item()
{
if (m_t.empty()) return Fraction(m_c.n, m_c.d);
list<MTerm>::iterator pt = m_t.begin();
MITEM g = Fraction(pt->m_s.n, pt->m_s.d);
MITEM s = g*pt->m_a;
++pt;
for (; pt != m_t.end(); ++pt)
{
g = Fraction(pt->m_s.n, pt->m_s.d);
s = s + g*pt->m_a;
}
if (m_c.n != 0.0) s = s + Fraction(m_c.n, m_c.d);
return s;
}
| C++ |
3D | febiosoftware/FEBio | FECore/NLConstraintDataRecord.h | .h | 2,245 | 60 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "DataRecord.h"
#include "FENLConstraint.h"
//-----------------------------------------------------------------------------
//! Base class for nonlinear constraints log data (e.g. rigid connectors)
class FECORE_API FELogNLConstraintData : public FELogData
{
FECORE_SUPER_CLASS(FELOGNLCONSTRAINTDATA_ID)
FECORE_BASE_CLASS(FELogNLConstraintData)
public:
FELogNLConstraintData(FEModel* fem) : FELogData(fem) {}
virtual ~FELogNLConstraintData(){}
virtual double value(FENLConstraint& rc) = 0;
};
//-----------------------------------------------------------------------------
class FECORE_API NLConstraintDataRecord : public DataRecord
{
public:
NLConstraintDataRecord(FEModel* pfem);
double Evaluate(int item, int ndata) override;
void SetData(const char* sz) override;
void SelectAllItems() override;
int Size() const override;
private:
vector<FELogNLConstraintData*> m_Data;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogNodeData.cpp | .cpp | 1,401 | 31 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2025 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELogNodeData.h"
FELogNodeData::FELogNodeData(FEModel* fem) : FELogData(fem) {}
FELogNodeData::~FELogNodeData() {}
| C++ |
3D | febiosoftware/FEBio | FECore/FESolidDomain.cpp | .cpp | 92,273 | 2,718 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FESolidDomain.h"
#include "FEMaterial.h"
#include "tools.h"
#include "log.h"
#include "FEModel.h"
BEGIN_FECORE_CLASS(FESolidDomain, FEDomain)
ADD_PROPERTY(m_matAxis, "mat_axis", FEProperty::Optional);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FESolidDomain::FESolidDomain(FEModel* pfem) : FEDomain(FE_DOMAIN_SOLID, pfem), m_dofU(pfem), m_dofSU(pfem)
{
if (pfem)
{
m_dofU.AddDof(pfem->GetDOFIndex("x"));
m_dofU.AddDof(pfem->GetDOFIndex("y"));
m_dofU.AddDof(pfem->GetDOFIndex("z"));
m_dofSU.AddDof(pfem->GetDOFIndex("sx"));
m_dofSU.AddDof(pfem->GetDOFIndex("sy"));
m_dofSU.AddDof(pfem->GetDOFIndex("sz"));
}
}
//-----------------------------------------------------------------------------
bool FESolidDomain::Create(int nsize, FE_Element_Spec espec)
{
// allocate elements
m_Elem.resize(nsize);
for (int i = 0; i < nsize; ++i)
{
FESolidElement& el = m_Elem[i];
el.SetLocalID(i);
el.SetMeshPartition(this);
}
// set element type
if (espec.etype != FE_ELEM_INVALID_TYPE)
ForEachElement([=](FEElement& el) { el.SetType(espec.etype); });
m_elemSpec = espec;
return true;
}
//-----------------------------------------------------------------------------
FE_Element_Spec FESolidDomain::GetElementSpec() const
{
return m_elemSpec;
}
//-----------------------------------------------------------------------------
//! return nr of elements
int FESolidDomain::Elements() const { return (int)m_Elem.size(); }
//-----------------------------------------------------------------------------
//! loop over elements
void FESolidDomain::ForEachSolidElement(std::function<void(FESolidElement& el)> f)
{
int NE = Elements();
for (int i = 0; i < NE; ++i) f(m_Elem[i]);
}
//-----------------------------------------------------------------------------
FESolidElement& FESolidDomain::Element(int n) { return m_Elem[n]; }
//-----------------------------------------------------------------------------
void FESolidDomain::CopyFrom(FEMeshPartition* pd)
{
FEDomain::CopyFrom(pd);
FESolidDomain* psd = dynamic_cast<FESolidDomain*>(pd);
m_Elem = psd->m_Elem;
ForEachElement([=](FEElement& el) { el.SetMeshPartition(this); });
}
//-----------------------------------------------------------------------------
//! initialize element data
bool FESolidDomain::Init()
{
// base class first
if (FEDomain::Init() == false) return false;
// init solid element data
// TODO: In principle I could parallelize this, but right now this cannot be done
// because of the try block.
try {
ForEachSolidElement([=](FESolidElement& el) {
// evaluate nodal coordinates
const int NELN = FEElement::MAX_NODES;
vec3d r0[NELN], r[NELN], v[NELN], a[NELN];
int neln = el.Nodes();
for (int j = 0; j < neln; ++j)
{
FENode& node = m_pMesh->Node(el.m_node[j]);
r0[j] = node.m_r0;
}
// initialize reference Jacobians
double Ji[3][3];
// loop over the integration points
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
// initiali Jacobian
mp.m_J0 = invjac0(el, Ji, n);
el.m_J0i[n] = mat3d(Ji);
// material point coordinates
mp.m_r0 = el.Evaluate(r0, n);
}
});
}
catch (NegativeJacobian e)
{
feLogError("Negative jacobian detected during domain initialization\nDomain: %s\nElement %d, vol = %lg\n", GetName().c_str(), e.m_iel, e.m_vol);
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Reset data
void FESolidDomain::Reset()
{
// re-evaluate the material points initial position and jacobian
ForEachSolidElement([=](FESolidElement& el) {
// evaluate nodal coordinates
const int NELN = FEElement::MAX_NODES;
vec3d r0[NELN], r[NELN], v[NELN], a[NELN];
int neln = el.Nodes();
for (int j = 0; j < neln; ++j)
{
FENode& node = m_pMesh->Node(el.m_node[j]);
r0[j] = node.m_r0;
}
// initialize reference Jacobians
double Ji[3][3];
// loop over the integration points
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
// initial Jacobian
mp.m_J0 = invjac0(el, Ji, n);
el.m_J0i[n] = mat3d(Ji);
// material point coordinates
mp.m_r0 = el.Evaluate(r0, n);
}
});
ForEachMaterialPoint([](FEMaterialPoint& mp) {
mp.Init();
});
}
//-----------------------------------------------------------------------------
//! This function finds the element in which point y lies and returns
//! the isoparametric coordinates in r if an element is found
//! (This has only been implemeneted for hexes!)
FESolidElement* FESolidDomain::FindElement(const vec3d& y, double r[3])
{
int i, j;
int NE = Elements();
vec3d x[FEElement::MAX_NODES];
for (i=0; i<NE; ++i)
{
// get the next element
FESolidElement& e = Element(i);
assert(e.Type() == FE_HEX8G8);
// get the element nodal coordinates
int neln = e.Nodes();
for (j=0; j<neln; ++j) x[j] = m_pMesh->Node(e.m_node[j]).m_rt;
// first, as a quick check, we see if y lies in the bounding box defined by x
FEBoundingBox box(x[0]);
for (j=1; j<neln; ++j) box.add(x[j]);
if (box.IsInside(y))
{
// If the point y lies inside the box, we apply a Newton method to find
// the isoparametric coordinates r
ProjectToElement(e, y, r);
// see if the point r lies inside the element
const double eps = 1.0001;
if ((r[0] >= -eps) && (r[0] <= eps) &&
(r[1] >= -eps) && (r[1] <= eps) &&
(r[2] >= -eps) && (r[2] <= eps)) return &e;
}
}
return 0;
}
//-----------------------------------------------------------------------------
//! This function finds the element in which point y lies and returns
//! the isoparametric coordinates in r if an element is found
FESolidElement* FESolidDomain::FindReferenceElement(const vec3d& y, double r[3])
{
int NE = Elements();
vec3d x[FEElement::MAX_NODES];
for (int i = 0; i<NE; ++i)
{
// get the next element
FESolidElement& e = Element(i);
// get the element nodal coordinates
int neln = e.Nodes();
for (int j = 0; j<neln; ++j) x[j] = m_pMesh->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]);
if (box.IsInside(y))
{
// If the point y lies inside the box, we apply a Newton method to find
// the isoparametric coordinates r
if (ProjectToReferenceElement(e, y, r)) return &e;
}
}
return 0;
}
//-----------------------------------------------------------------------------
void FESolidDomain::ProjectToElement(FESolidElement& el, const vec3d& p, double r[3])
{
const int MN = FEElement::MAX_NODES;
vec3d rt[MN];
// get the element nodal coordinates
int ne = el.Nodes();
for (int i = 0; i<ne; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_rt;
r[0] = r[1] = r[2] = 0;
const double tol = 1e-5;
double dr[3], norm;
double H[MN], Gr[MN], Gs[MN], Gt[MN];
do
{
// evaluate shape functions
el.shape_fnc(H, r[0], r[1], r[2]);
// evaluate shape function derivatives
el.shape_deriv(Gr, Gs, Gt, r[0], r[1], r[2]);
// solve for coordinate increment
double R[3] = {0}, A[3][3] = {0};
for (int i=0; i<ne; ++i)
{
R[0] += rt[i].x*H[i];
R[1] += rt[i].y*H[i];
R[2] += rt[i].z*H[i];
A[0][0] -= rt[i].x*Gr[i]; A[0][1] -= rt[i].x*Gs[i]; A[0][2] -= rt[i].x*Gt[i];
A[1][0] -= rt[i].y*Gr[i]; A[1][1] -= rt[i].y*Gs[i]; A[1][2] -= rt[i].y*Gt[i];
A[2][0] -= rt[i].z*Gr[i]; A[2][1] -= rt[i].z*Gs[i]; A[2][2] -= rt[i].z*Gt[i];
}
R[0] = p.x - R[0];
R[1] = p.y - R[1];
R[2] = p.z - R[2];
solve_3x3(A, R, dr);
r[0] -= dr[0];
r[1] -= dr[1];
r[2] -= dr[2];
norm = dr[0]*dr[0] + dr[1]*dr[1] + dr[2]*dr[2];
}
while (norm > tol);
}
//-----------------------------------------------------------------------------
bool FESolidDomain::ProjectToReferenceElement(FESolidElement& el, const vec3d& p, double r[3])
{
const int MN = FEElement::MAX_NODES;
vec3d rt[MN];
// get the element nodal coordinates
int ne = el.Nodes();
for (int i = 0; i<ne; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_r0;
r[0] = r[1] = r[2] = 0;
const double tol = 1e-5;
double dr[3], norm;
double H[MN], Gr[MN], Gs[MN], Gt[MN];
int ncount = 0;
do
{
// evaluate shape functions
el.shape_fnc(H, r[0], r[1], r[2]);
// evaluate shape function derivatives
el.shape_deriv(Gr, Gs, Gt, r[0], r[1], r[2]);
// solve for coordinate increment
double R[3] = {0}, A[3][3] = {0};
for (int i=0; i<ne; ++i)
{
R[0] += rt[i].x*H[i];
R[1] += rt[i].y*H[i];
R[2] += rt[i].z*H[i];
A[0][0] -= rt[i].x*Gr[i]; A[0][1] -= rt[i].x*Gs[i]; A[0][2] -= rt[i].x*Gt[i];
A[1][0] -= rt[i].y*Gr[i]; A[1][1] -= rt[i].y*Gs[i]; A[1][2] -= rt[i].y*Gt[i];
A[2][0] -= rt[i].z*Gr[i]; A[2][1] -= rt[i].z*Gs[i]; A[2][2] -= rt[i].z*Gt[i];
}
R[0] = p.x - R[0];
R[1] = p.y - R[1];
R[2] = p.z - R[2];
solve_3x3(A, R, dr);
r[0] -= dr[0];
r[1] -= dr[1];
r[2] -= dr[2];
if (ncount++ > 100) return false;
norm = dr[0]*dr[0] + dr[1]*dr[1] + dr[2]*dr[2];
}
while (norm > tol);
// check if point is inside element
if ((el.Shape() == ET_HEX8) || (el.Shape() == ET_HEX20) || (el.Shape() == ET_HEX27))
{
const double eps = 1.0001;
if ((r[0] >= -eps) && (r[0] <= eps) &&
(r[1] >= -eps) && (r[1] <= eps) &&
(r[2] >= -eps) && (r[2] <= eps)) return true;
}
else if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5) || (el.Shape() == ET_TET10))
{
const double eps = 0.0001;
if ((r[0] >= -eps) && (r[0] <= 1.0 + eps) &&
(r[1] >= -eps) && (r[1] <= 1.0 + eps) &&
(r[2] >= -eps) && (r[2] <= 1.0 + eps) &&
(r[0] + r[1] + r[2] <= 1 + eps)) return true;
}
else if ((el.Shape() == ET_PENTA6) || (el.Shape() == ET_PENTA15))
{
const double eps = 0.0001;
if ((r[0] >= -eps) && (r[0] <= 1.0 + eps) &&
(r[1] >= -eps) && (r[1] <= 1.0 + eps) &&
(r[2] >= -1.0 - eps) && (r[2] <= 1.0 + eps) &&
(r[0] + r[1] <= 1 + eps)) return true;
}
else {
assert(false);
return false;
}
return false;
}
//-----------------------------------------------------------------------------
//! get the current nodal coordinates
void FESolidDomain::GetCurrentNodalCoordinates(const FESolidElement& el, vec3d* rt)
{
int neln = el.Nodes();
for (int i = 0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_rt;
// check for solid-shell interface nodes
if (el.m_bitfc.empty() == false)
{
for (int i = 0; i<neln; ++i)
{
if (el.m_bitfc[i])
{
FENode& nd = m_pMesh->Node(el.m_node[i]);
rt[i] -= nd.m_dt;
}
}
}
}
//-----------------------------------------------------------------------------
//! get the current nodal coordinates
void FESolidDomain::GetCurrentNodalCoordinates(const FESolidElement& el, vec3d* rt, double alpha)
{
int neln = el.Nodes();
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);
}
// check for solid-shell interface nodes
if (el.m_bitfc.empty() == false)
{
for (int i = 0; i<neln; ++i)
{
if (el.m_bitfc[i]) {
FENode& nd = m_pMesh->Node(el.m_node[i]);
rt[i] = nd.m_r0 - nd.m_d0 \
+ nd.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2])*alpha \
+ nd.get_vec3d_prev(m_dofSU[0], m_dofSU[1], m_dofSU[2])*(1 - alpha);
}
}
}
}
//-----------------------------------------------------------------------------
//! get the reference nodal coordinates
void FESolidDomain::GetReferenceNodalCoordinates(const FESolidElement& el, vec3d* r0)
{
int neln = el.Nodes();
for (int i = 0; i<neln; ++i) r0[i] = m_pMesh->Node(el.m_node[i]).m_r0;
// check for solid-shell interface nodes
if (el.m_bitfc.empty() == false)
{
for (int i = 0; i<neln; ++i)
{
if (el.m_bitfc[i])
{
FENode& nd = m_pMesh->Node(el.m_node[i]);
r0[i] -= nd.m_d0;
}
}
}
}
//-----------------------------------------------------------------------------
//! get the previous nodal coordinates
void FESolidDomain::GetPreviousNodalCoordinates(const FESolidElement& el, vec3d* rp)
{
int neln = el.Nodes();
for (int i = 0; i<neln; ++i) rp[i] = m_pMesh->Node(el.m_node[i]).m_rp;
// check for solid-shell interface nodes
if (el.m_bitfc.empty() == false)
{
for (int i = 0; i<neln; ++i)
{
if (el.m_bitfc[i])
{
FENode& nd = m_pMesh->Node(el.m_node[i]);
rp[i] -= nd.m_dp;
}
}
}
}
//-----------------------------------------------------------------------------
//! Calculate the deformation gradient of element el at integration point n.
//! The deformation gradient is returned in F and its determinant is the return
//! value of the function
double FESolidDomain::defgrad(FESolidElement &el, mat3d &F, int n)
{
// nodal points
vec3d r[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, r);
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
mat3d& Ji = el.m_J0i[n];
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
return D;
}
//-----------------------------------------------------------------------------
//! Calculate the gradJ of element el at integration point n.
//! Mult GradJ by F-1
vec3d FESolidDomain::GradJ(FESolidElement &el, int n)
{
// nodal points
vec3d r[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, r);
mat3d F;
vec3d g[3], dg[3][3];
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
//Ji for Grad
mat3d& Ji = el.m_J0i[n];
ContraBaseVectors0(el, n, g);
ContraBaseVectorDerivatives0(el, n, dg);
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// get the shape function derivatives
double* Grr = el.Grr(n); double* Grs = el.Grs(n); double* Grt = el.Grt(n);
double* Gsr = el.Gsr(n); double* Gss = el.Gss(n); double* Gst = el.Gst(n);
double* Gtr = el.Gtr(n); double* Gts = el.Gts(n); double* Gtt = el.Gtt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
//Initialize gradTF tens3d (gradiFjk)
tens3d gradTF;
mat3d gradTF1, gradTF2, gradTF3;
gradTF.d[ 0] = gradTF.d[ 1] = gradTF.d[ 2] = gradTF.d[ 3] = gradTF.d[ 4] = gradTF.d[ 5] = gradTF.d[ 6] = gradTF.d[ 7] = gradTF.d[ 8] = gradTF.d[ 9] = gradTF.d[10] = gradTF.d[11] = gradTF.d[12] = gradTF.d[13] = gradTF.d[14] = gradTF.d[15] = gradTF.d[16] = gradTF.d[17] = gradTF.d[18] = gradTF.d[19] = gradTF.d[20] = gradTF.d[21] = gradTF.d[22] = gradTF.d[23] = gradTF.d[24] = gradTF.d[25] = gradTF.d[26] = 0.0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double Grri = Grr[i]; double Grsi = Grs[i]; double Grti = Grt[i];
double Gsri = Gsr[i]; double Gssi = Gss[i]; double Gsti = Gst[i];
double Gtri = Gtr[i]; double Gtsi = Gts[i]; double Gtti = Gtt[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
// calculate GradTF
mat3d gradgrad = (((dg[0][0] & g[0]) + (dg[0][1] & g[1]) + (dg[0][2] & g[2]))*Gri
+ ((dg[1][0] & g[0]) + (dg[1][1] & g[1]) + (dg[1][2] & g[2]))*Gsi
+ ((dg[2][0] & g[0]) + (dg[2][1] & g[1]) + (dg[2][2] & g[2]))*Gti
+ (g[0] & g[0])*Grri + (g[0] & g[1])*Gsri + (g[0] & g[2])*Gtri
+ (g[1] & g[0])*Grsi + (g[1] & g[1])*Gssi + (g[1] & g[2] )*Gtsi
+ (g[2] & g[0])*Grti + (g[2] & g[1])*Gsti + (g[2] & g[2])*Gtti);
gradTF1 = gradgrad*x;
gradTF2 = gradgrad*y;
gradTF3 = gradgrad*z;
gradTF.d[0] += gradTF1[0][0]; gradTF.d[1] += gradTF1[1][0]; gradTF.d[2] += gradTF1[2][0];
gradTF.d[3] += gradTF2[0][0]; gradTF.d[4] += gradTF2[1][0]; gradTF.d[5] += gradTF2[2][0];
gradTF.d[6] += gradTF3[0][0]; gradTF.d[7] += gradTF3[1][0]; gradTF.d[8] += gradTF3[2][0];
gradTF.d[9] += gradTF1[0][1]; gradTF.d[10] += gradTF1[1][1]; gradTF.d[11] += gradTF1[2][1];
gradTF.d[12] += gradTF2[0][1]; gradTF.d[13] += gradTF2[1][1]; gradTF.d[14] += gradTF2[2][1];
gradTF.d[15] += gradTF3[0][1]; gradTF.d[16] += gradTF3[1][1]; gradTF.d[17] += gradTF3[2][1];
gradTF.d[18] += gradTF1[0][2]; gradTF.d[19] += gradTF1[1][2]; gradTF.d[20] += gradTF1[2][2];
gradTF.d[21] += gradTF2[0][2]; gradTF.d[22] += gradTF2[1][2]; gradTF.d[23] += gradTF2[2][2];
gradTF.d[24] += gradTF3[0][2]; gradTF.d[25] += gradTF3[1][2]; gradTF.d[26] += gradTF3[2][2];
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
mat3d FinvT = F.transinv();
vec3d gJ = gradTF.contract2(FinvT)*D;
return gJ;
}
//-----------------------------------------------------------------------------
//! Calculate the gradJ of element el at integration point n prev time.
vec3d FESolidDomain::GradJp(FESolidElement &el, int n)
{
// nodal points
vec3d r[FEElement::MAX_NODES];
GetPreviousNodalCoordinates(el, r);
mat3d F;
vec3d g[3], dg[3][3];
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
//Ji for Grad
mat3d& Ji = el.m_J0i[n];
ContraBaseVectors0(el, n, g);
ContraBaseVectorDerivatives0(el, n, dg);
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// get the shape function derivatives
double* Grr = el.Grr(n); double* Grs = el.Grs(n); double* Grt = el.Grt(n);
double* Gsr = el.Gsr(n); double* Gss = el.Gss(n); double* Gst = el.Gst(n);
double* Gtr = el.Gtr(n); double* Gts = el.Gts(n); double* Gtt = el.Gtt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
//Initialize gradTF tens3d (gradiFjk)
tens3d gradTF;
mat3d gradTF1, gradTF2, gradTF3;
gradTF.d[ 0] = gradTF.d[ 1] = gradTF.d[ 2] = gradTF.d[ 3] = gradTF.d[ 4] = gradTF.d[ 5] = gradTF.d[ 6] = gradTF.d[ 7] = gradTF.d[ 8] = gradTF.d[ 9] = gradTF.d[10] = gradTF.d[11] = gradTF.d[12] = gradTF.d[13] = gradTF.d[14] = gradTF.d[15] = gradTF.d[16] = gradTF.d[17] = gradTF.d[18] = gradTF.d[19] = gradTF.d[20] = gradTF.d[21] = gradTF.d[22] = gradTF.d[23] = gradTF.d[24] = gradTF.d[25] = gradTF.d[26] = 0.0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double Grri = Grr[i]; double Grsi = Grs[i]; double Grti = Grt[i];
double Gsri = Gsr[i]; double Gssi = Gss[i]; double Gsti = Gst[i];
double Gtri = Gtr[i]; double Gtsi = Gts[i]; double Gtti = Gtt[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
// calculate gradTF
mat3d gradgrad = (((dg[0][0] & g[0]) + (dg[0][1] & g[1]) + (dg[0][2] & g[2]))*Gri
+ ((dg[1][0] & g[0]) + (dg[1][1] & g[1]) + (dg[1][2] & g[2]))*Gsi
+ ((dg[2][0] & g[0]) + (dg[2][1] & g[1]) + (dg[2][2] & g[2]))*Gti
+ (g[0] & g[0])*Grri + (g[0] & g[1])*Gsri + (g[0] & g[2])*Gtri
+ (g[1] & g[0])*Grsi + (g[1] & g[1])*Gssi + (g[1] & g[2] )*Gtsi
+ (g[2] & g[0])*Grti + (g[2] & g[1])*Gsti + (g[2] & g[2])*Gtti);
gradTF1 = gradgrad*x;
gradTF2 = gradgrad*y;
gradTF3 = gradgrad*z;
gradTF.d[0] += gradTF1[0][0]; gradTF.d[1] += gradTF1[1][0]; gradTF.d[2] += gradTF1[2][0];
gradTF.d[3] += gradTF2[0][0]; gradTF.d[4] += gradTF2[1][0]; gradTF.d[5] += gradTF2[2][0];
gradTF.d[6] += gradTF3[0][0]; gradTF.d[7] += gradTF3[1][0]; gradTF.d[8] += gradTF3[2][0];
gradTF.d[9] += gradTF1[0][1]; gradTF.d[10] += gradTF1[1][1]; gradTF.d[11] += gradTF1[2][1];
gradTF.d[12] += gradTF2[0][1]; gradTF.d[13] += gradTF2[1][1]; gradTF.d[14] += gradTF2[2][1];
gradTF.d[15] += gradTF3[0][1]; gradTF.d[16] += gradTF3[1][1]; gradTF.d[17] += gradTF3[2][1];
gradTF.d[18] += gradTF1[0][2]; gradTF.d[19] += gradTF1[1][2]; gradTF.d[20] += gradTF1[2][2];
gradTF.d[21] += gradTF2[0][2]; gradTF.d[22] += gradTF2[1][2]; gradTF.d[23] += gradTF2[2][2];
gradTF.d[24] += gradTF3[0][2]; gradTF.d[25] += gradTF3[1][2]; gradTF.d[26] += gradTF3[2][2];
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
mat3d FinvT = F.transinv();
vec3d gJ = gradTF.contract2(FinvT)*D;
return gJ;
}
//-----------------------------------------------------------------------------
//! Calculate the Gradb of element el at integration point n.
//! Mult Gradb by F-1 later
tens3dls FESolidDomain::Gradb(FESolidElement &el, int n)
{
// nodal points
vec3d r[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, r);
mat3d F, b;
vec3d g[3], dg[3][3];
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
//Ji for Grad
mat3d& Ji = el.m_J0i[n];
ContraBaseVectors0(el, n, g);
ContraBaseVectorDerivatives0(el, n, dg);
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
b[0][0] = b[0][1] = b[0][2] = 0;
b[1][0] = b[1][1] = b[1][2] = 0;
b[2][0] = b[2][1] = b[2][2] = 0;
//Initialize gradTF tens3d (gradiFjk)
tens3dls GB;
GB.zero();
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
// calculate GB Grad(FikFjk)l
// [G] = [G111 G112 G113 G121 G122 G123 G131 G132 G133 G221 G222 G223 G231 G232 G233 G331 G332 G333]
// = G0 G1 G2 G3 G4 G5 G6 G7 G8 G9 G10 G11 G12 G13 G14 G15 G16 G17
GB.d[ 0] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GX;
GB.d[ 1] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GY;
GB.d[ 2] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GZ;
GB.d[ 3] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GX;
GB.d[ 4] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GY;
GB.d[ 5] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GZ;
GB.d[ 6] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GX;
GB.d[ 7] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GY;
GB.d[ 8] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GZ;
GB.d[ 9] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GX;
GB.d[10] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GY;
GB.d[11] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GZ;
GB.d[12] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GX;
GB.d[13] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GY;
GB.d[14] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GZ;
GB.d[15] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GX;
GB.d[16] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GY;
GB.d[17] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GZ;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
b = F*F.transpose();
return GB;
}
//-----------------------------------------------------------------------------
//! Calculate the Gradb of element el at integration point n.
//! Mult Gradb by F-1 later
tens3dls FESolidDomain::Gradbp(FESolidElement &el, int n)
{
// nodal points
vec3d r[FEElement::MAX_NODES];
GetPreviousNodalCoordinates(el, r);
mat3d F, b;
vec3d g[3], dg[3][3];
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
//Ji for Grad
mat3d& Ji = el.m_J0i[n];
ContraBaseVectors0(el, n, g);
ContraBaseVectorDerivatives0(el, n, dg);
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
b[0][0] = b[0][1] = b[0][2] = 0;
b[1][0] = b[1][1] = b[1][2] = 0;
b[2][0] = b[2][1] = b[2][2] = 0;
//Initialize gradTF tens3d (gradiFjk)
tens3dls GB;
GB.zero();
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
// calculate GB
// [G] = [G111 G112 G113 G121 G122 G123 G131 G132 G133 G221 G222 G223 G231 G232 G233 G331 G332 G333]
// = G0 G1 G2 G3 G4 G5 G6 G7 G8 G9 G10 G11 G12 G13 G14 G15 G16 G17
GB.d[ 0] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GX;
GB.d[ 1] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GY;
GB.d[ 2] += (x*GX*GX*x + x*GY*GY*x + x*GZ*GZ*x)*GZ;
GB.d[ 3] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GX;
GB.d[ 4] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GY;
GB.d[ 5] += (x*GX*GX*y + x*GY*GY*y + x*GZ*GZ*y)*GZ;
GB.d[ 6] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GX;
GB.d[ 7] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GY;
GB.d[ 8] += (x*GX*GX*z + x*GY*GY*z + x*GZ*GZ*z)*GZ;
GB.d[ 9] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GX;
GB.d[10] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GY;
GB.d[11] += (y*GX*GX*y + y*GY*GY*y + y*GZ*GZ*y)*GZ;
GB.d[12] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GX;
GB.d[13] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GY;
GB.d[14] += (y*GX*GX*z + y*GY*GY*z + y*GZ*GZ*z)*GZ;
GB.d[15] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GX;
GB.d[16] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GY;
GB.d[17] += (z*GX*GX*z + z*GY*GY*z + z*GZ*GZ*z)*GZ;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
b = F*F.transpose();
return GB;
}
//-----------------------------------------------------------------------------
//! Calculate the deformation gradient of element el at integration point n.
//! The deformation gradient is returned in F and its determinant is the return
//! value of the function
double FESolidDomain::defgrad(FESolidElement &el, mat3d &F, int n, vec3d* r)
{
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
mat3d& Ji = el.m_J0i[n];
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0] * Gri + Ji[1][0] * Gsi + Ji[2][0] * Gti;
double GY = Ji[0][1] * Gri + Ji[1][1] * Gsi + Ji[2][1] * Gti;
double GZ = Ji[0][2] * Gri + Ji[1][2] * Gsi + Ji[2][2] * Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
return D;
}
//-----------------------------------------------------------------------------
//! Calculate the deformation gradient of element at point r,s,t
double FESolidDomain::defgrad(FESolidElement &el, mat3d &F, double r, double s, double t)
{
// shape function derivatives
const int NME = FEElement::MAX_NODES;
double Gr[NME], Gs[NME], Gt[NME];
el.shape_deriv(Gr, Gs, Gt, r, s, t);
// nodal points
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt);
// calculate inverse jacobian
double Ji[3][3];
invjac0(el, Ji, r, s, t);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Gr[i];
double Gsi = Gs[i];
double Gti = Gt[i];
double x = rt[i].x;
double y = rt[i].y;
double z = rt[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), -1, D, &el);
return D;
}
//-----------------------------------------------------------------------------
//! Calculate the deformation gradient of element el at integration point n.
//! The deformation gradient is returned in F and its determinant is the return
//! value of the function
double FESolidDomain::defgradp(FESolidElement &el, mat3d &F, int n)
{
// nodal coordinates
vec3d r[FEElement::MAX_NODES];
GetPreviousNodalCoordinates(el, r);
// calculate inverse jacobian
// double Ji[3][3];
// invjac0(el, Ji, n);
mat3d& Ji = el.m_J0i[n];
// shape function derivatives
double *Grn = el.Gr(n);
double *Gsn = el.Gs(n);
double *Gtn = el.Gt(n);
// calculate deformation gradient
F[0][0] = F[0][1] = F[0][2] = 0;
F[1][0] = F[1][1] = F[1][2] = 0;
F[2][0] = F[2][1] = F[2][2] = 0;
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
double Gri = Grn[i];
double Gsi = Gsn[i];
double Gti = Gtn[i];
double x = r[i].x;
double y = r[i].y;
double z = r[i].z;
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
double GX = Ji[0][0]*Gri+Ji[1][0]*Gsi+Ji[2][0]*Gti;
double GY = Ji[0][1]*Gri+Ji[1][1]*Gsi+Ji[2][1]*Gti;
double GZ = Ji[0][2]*Gri+Ji[1][2]*Gsi+Ji[2][2]*Gti;
// calculate deformation gradient F
F[0][0] += GX*x; F[0][1] += GY*x; F[0][2] += GZ*x;
F[1][0] += GX*y; F[1][1] += GY*y; F[1][2] += GZ*y;
F[2][0] += GX*z; F[2][1] += GY*z; F[2][2] += GZ*z;
}
double D = F.det();
if (D <= 0) throw NegativeJacobian(el.GetID(), n, D, &el);
return D;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the reference frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjac0(const FESolidElement& el, double Ji[3][3], int n)
{
// nodal coordinates
vec3d r0[FEElement::MAX_NODES];
GetReferenceNodalCoordinates(el, r0);
// calculate Jacobian
double J[3][3] = {0};
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = el.Gr(n)[i];
const double& Gsi = el.Gs(n)[i];
const double& Gti = el.Gt(n)[i];
const double& x = r0[i].x;
const double& y = r0[i].y;
const double& z = r0[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), n+1, det);
// calculate the inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the reference frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjac0(const FESolidElement& el, double Ji[3][3], double r, double s, double t)
{
// nodal coordinates
const int NMAX = FEElement::MAX_NODES;
vec3d r0[NMAX];
GetReferenceNodalCoordinates(el, r0);
// evaluate shape function derivatives
double Gr[NMAX], Gs[NMAX], Gt[NMAX];
el.shape_deriv(Gr, Gs, Gt, r, s, t);
// calculate Jacobian
double J[3][3] = {0};
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = Gr[i];
const double& Gsi = Gs[i];
const double& Gti = Gt[i];
const double& x = r0[i].x;
const double& y = r0[i].y;
const double& z = r0[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), -1, det);
// calculate the inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
double FESolidDomain::invjac0(const FESolidElement& el, double r, double s, double t, mat3d& J)
{
double Ji[3][3];
double J0 = invjac0(el, Ji, r, s, t);
J = mat3d(Ji[0][0], Ji[0][1], Ji[0][2], Ji[1][0], Ji[1][1], Ji[1][2], Ji[2][0], Ji[2][1], Ji[2][2]);
return J0;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the current frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjact(FESolidElement& el, double Ji[3][3], int n)
{
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt);
// calculate jacobian
double J[3][3] = {0};
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = el.Gr(n)[i];
const double& Gsi = el.Gs(n)[i];
const double& Gti = el.Gt(n)[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), n+1, det);
// calculate inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the current frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjact(FESolidElement& el, double Ji[3][3], int n, const vec3d* rt)
{
// calculate jacobian
double J[3][3] = { 0 };
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = el.Gr(n)[i];
const double& Gsi = el.Gs(n)[i];
const double& Gti = el.Gt(n)[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0] * (J[1][1] * J[2][2] - J[1][2] * J[2][1])
+ J[0][1] * (J[1][2] * J[2][0] - J[2][2] * J[1][0])
+ J[0][2] * (J[1][0] * J[2][1] - J[1][1] * J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), n + 1, det);
// calculate inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1] * J[2][2] - J[1][2] * J[2][1]);
Ji[1][0] = deti*(J[1][2] * J[2][0] - J[1][0] * J[2][2]);
Ji[2][0] = deti*(J[1][0] * J[2][1] - J[1][1] * J[2][0]);
Ji[0][1] = deti*(J[0][2] * J[2][1] - J[0][1] * J[2][2]);
Ji[1][1] = deti*(J[0][0] * J[2][2] - J[0][2] * J[2][0]);
Ji[2][1] = deti*(J[0][1] * J[2][0] - J[0][0] * J[2][1]);
Ji[0][2] = deti*(J[0][1] * J[1][2] - J[1][1] * J[0][2]);
Ji[1][2] = deti*(J[0][2] * J[1][0] - J[0][0] * J[1][2]);
Ji[2][2] = deti*(J[0][0] * J[1][1] - J[0][1] * J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the current frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjact(FESolidElement& el, double Ji[3][3], int n, const double alpha)
{
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt, alpha);
// calculate jacobian
int neln = el.Nodes();
double J[3][3] = { 0 };
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Gr(n)[i];
const double& Gsi = el.Gs(n)[i];
const double& Gti = el.Gt(n)[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), n+1, det);
// calculate inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the previous time frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjactp(FESolidElement& el, double Ji[3][3], int n)
{
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetPreviousNodalCoordinates(el, rt);
// calculate jacobian
int neln = el.Nodes();
double J[3][3] = { 0 };
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Gr(n)[i];
const double& Gsi = el.Gs(n)[i];
const double& Gti = el.Gt(n)[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), n+1, det);
// calculate inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the reference frame at
//! integration point n. The inverse jacobian is retured in Ji
//! The return value is the determinant of the Jacobian (not the inverse!)
double FESolidDomain::invjact(FESolidElement& el, double Ji[3][3], double r, double s, double t)
{
// nodal coordinates
const int NMAX = FEElement::MAX_NODES;
vec3d rt[NMAX];
GetCurrentNodalCoordinates(el, rt);
// evaluate shape function derivatives
double Gr[NMAX], Gs[NMAX], Gt[NMAX];
el.shape_deriv(Gr, Gs, Gt, r, s, t);
// calculate Jacobian
double J[3][3] = {0};
const int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = Gr[i];
const double& Gsi = Gs[i];
const double& Gti = Gt[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
// make sure the determinant is positive
if (det <= 0) throw NegativeJacobian(el.GetID(), -1, det);
// calculate the inverse jacobian
double deti = 1.0 / det;
Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]);
Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]);
Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]);
Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]);
Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]);
Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]);
Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]);
Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]);
return det;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points
vec3d FESolidDomain::gradient(FESolidElement& el, double* fn, int n)
{
double Ji[3][3];
invjact(el, Ji, n);
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
double Gx, Gy, Gz;
vec3d gradf;
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i]+Ji[2][0]*Gtn[i];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i]+Ji[2][1]*Gtn[i];
Gz = Ji[0][2]*Grn[i]+Ji[1][2]*Gsn[i]+Ji[2][2]*Gtn[i];
// calculate pressure gradient
gradf.x += Gx*fn[i];
gradf.y += Gy*fn[i];
gradf.z += Gz*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points
vec3d FESolidDomain::gradient(FESolidElement& el, int order, double* fn, int n)
{
double Ji[3][3];
invjact(el, Ji, n);
double* Grn = el.Gr(order, n);
double* Gsn = el.Gs(order, n);
double* Gtn = el.Gt(order, n);
double Gx, Gy, Gz;
vec3d gradf;
int N = el.ShapeFunctions(order);
for (int i = 0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0] * Grn[i] + Ji[1][0] * Gsn[i] + Ji[2][0] * Gtn[i];
Gy = Ji[0][1] * Grn[i] + Ji[1][1] * Gsn[i] + Ji[2][1] * Gtn[i];
Gz = Ji[0][2] * Grn[i] + Ji[1][2] * Gsn[i] + Ji[2][2] * Gtn[i];
// calculate pressure gradient
gradf.x += Gx*fn[i];
gradf.y += Gy*fn[i];
gradf.z += Gz*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points
vec3d FESolidDomain::gradient(FESolidElement& el, vector<double>& fn, int n)
{
double Ji[3][3];
invjact(el, Ji, n);
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
double Gx, Gy, Gz;
vec3d gradf;
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i]+Ji[2][0]*Gtn[i];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i]+Ji[2][1]*Gtn[i];
Gz = Ji[0][2]*Grn[i]+Ji[1][2]*Gsn[i]+Ji[2][2]*Gtn[i];
// calculate pressure gradient
gradf.x += Gx*fn[i];
gradf.y += Gy*fn[i];
gradf.z += Gz*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
mat3d FESolidDomain::gradient(FESolidElement& el, vec3d* fn, int n)
{
double Ji[3][3];
invjact(el, Ji, n);
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
mat3d gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
gradf += fn[i] & (g1*Gr[i] + g2*Gs[i] + g3*Gt[i]);
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points at intermediate time
vec3d FESolidDomain::gradient(FESolidElement& el, vector<double>& fn, int n, const double alpha)
{
double Ji[3][3];
invjact(el, Ji, n, alpha);
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
double Gx, Gy, Gz;
vec3d gradf;
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i]+Ji[2][0]*Gtn[i];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i]+Ji[2][1]*Gtn[i];
Gz = Ji[0][2]*Grn[i]+Ji[1][2]*Gsn[i]+Ji[2][2]*Gtn[i];
// calculate pressure gradient
gradf.x += Gx*fn[i];
gradf.y += Gy*fn[i];
gradf.z += Gz*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points at intermediate time
mat3d FESolidDomain::gradient(FESolidElement& el, vec3d* fn, int n, const double alpha)
{
double Ji[3][3];
invjact(el, Ji, n, alpha);
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
mat3d gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
gradf += fn[i] & (g1*Gr[i] + g2*Gs[i] + g3*Gt[i]);
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
//! at previous time
mat3d FESolidDomain::gradientp(FESolidElement& el, vec3d* fn, int n)
{
double Ji[3][3];
invjactp(el, Ji, n);
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
mat3d gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
gradf += fn[i] & (g1*Gr[i] + g2*Gs[i] + g3*Gt[i]);
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
tens3dls FESolidDomain::gradient(FESolidElement& el, mat3ds* fn, int n)
{
double Ji[3][3];
invjact(el, Ji, n);
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
tens3dls gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
gradf += dyad3ls(fn[i], (g1*Gr[i] + g2*Gs[i] + g3*Gt[i]));
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
//! at previous time
tens3dls FESolidDomain::gradientp(FESolidElement& el, mat3ds* fn, int n)
{
double Ji[3][3];
invjactp(el, Ji, n);
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
tens3dls gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
gradf += dyad3ls(fn[i], (g1*Gr[i] + g2*Gs[i] + g3*Gt[i]));
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate material gradient of function at integration points
vec3d FESolidDomain::Gradient(FESolidElement& el, vector<double>& fn, int n)
{
double Ji[3][3];
invjac0(el, Ji, n);
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
double Gx, Gy, Gz;
vec3d Gradf;
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i]+Ji[2][0]*Gtn[i];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i]+Ji[2][1]*Gtn[i];
Gz = Ji[0][2]*Grn[i]+Ji[1][2]*Gsn[i]+Ji[2][2]*Gtn[i];
// calculate pressure gradient
Gradf.x += Gx*fn[i];
Gradf.y += Gy*fn[i];
Gradf.z += Gz*fn[i];
}
return Gradf;
}
//-----------------------------------------------------------------------------
//! calculate material gradient of function at integration points
vec3d FESolidDomain::Gradient(FESolidElement& el, double* fn, int n)
{
double Ji[3][3];
invjac0(el, Ji, n);
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
double Gx, Gy, Gz;
vec3d Gradf;
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i]+Ji[2][0]*Gtn[i];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i]+Ji[2][1]*Gtn[i];
Gz = Ji[0][2]*Grn[i]+Ji[1][2]*Gsn[i]+Ji[2][2]*Gtn[i];
// calculate pressure gradient
Gradf.x += Gx*fn[i];
Gradf.y += Gy*fn[i];
Gradf.z += Gz*fn[i];
}
return Gradf;
}
//-----------------------------------------------------------------------------
//! calculate material gradient of function at integration points
mat3d FESolidDomain::Gradient(FESolidElement& el, vec3d* fn, int n)
{
vec3d Gcnt[3];
ContraBaseVectors0(el, n, Gcnt);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
mat3d Gradf;
Gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
Gradf += fn[i] & (Gcnt[0]*Gr[i] + Gcnt[1]*Gs[i] + Gcnt[2]*Gt[i]);
return Gradf;
}
//-----------------------------------------------------------------------------
//! calculate material gradient of function at integration points
tens3dls FESolidDomain::Gradient(FESolidElement& el, mat3ds* fn, int n)
{
vec3d Gcnt[3];
ContraBaseVectors0(el, n, Gcnt);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
tens3dls Gradf;
Gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
Gradf += dyad3ls(fn[i], (Gcnt[0]*Gr[i] + Gcnt[1]*Gs[i] + Gcnt[2]*Gt[i]));
return Gradf;
}
//-----------------------------------------------------------------------------
//! Calculate jacobian with respect to current frame
double FESolidDomain::detJt(FESolidElement &el, int n)
{
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt);
// shape function derivatives
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
// jacobian matrix
double J[3][3] = {0};
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = Grn[i];
const double& Gsi = Gsn[i];
const double& Gti = Gtn[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate jacobian with respect to current frame
double FESolidDomain::detJt(FESolidElement &el, int n, const double alpha)
{
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt, alpha);
// shape function derivatives
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
// jacobian matrix
int neln = el.Nodes();
double J[3][3] = { 0 };
for (int i=0; i<neln; ++i)
{
const double& Gri = Grn[i];
const double& Gsi = Gsn[i];
const double& Gti = Gtn[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
return det;
}
//-----------------------------------------------------------------------------
//! Calculate jacobian with respect to reference frame
double FESolidDomain::detJ0(FESolidElement &el, int n)
{
// nodal coordinates
vec3d r0[FEElement::MAX_NODES];
GetReferenceNodalCoordinates(el, r0);
// shape function derivatives
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
// jacobian matrix
double J[3][3] = {0};
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
const double& Gri = Grn[i];
const double& Gsi = Gsn[i];
const double& Gti = Gtn[i];
const double& x = r0[i].x;
const double& y = r0[i].y;
const double& z = r0[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double det = J[0][0]*(J[1][1]*J[2][2] - J[1][2]*J[2][1])
+ J[0][1]*(J[1][2]*J[2][0] - J[2][2]*J[1][0])
+ J[0][2]*(J[1][0]*J[2][1] - J[1][1]*J[2][0]);
return det;
}
//-----------------------------------------------------------------------------
//! This function calculates the covariant basis vectors of a solid element
//! in reference configuration at an integration point
void FESolidDomain::CoBaseVectors0(FESolidElement& el, int j, vec3d g[3])
{
// get the shape function derivatives
double* Hr = el.Gr(j);
double* Hs = el.Gs(j);
double* Ht = el.Gt(j);
// nodal coordinates
vec3d r0[FEElement::MAX_NODES];
GetReferenceNodalCoordinates(el, r0);
g[0] = g[1] = g[2] = vec3d(0,0,0);
int n = el.Nodes();
for (int i = 0; i<n; ++i)
{
g[0] += r0[i]*Hr[i];
g[1] += r0[i]*Hs[i];
g[2] += r0[i]*Ht[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the covariant basis vectors of a solid element
//! at an integration point
void FESolidDomain::CoBaseVectors(FESolidElement& el, int j, vec3d g[3])
{
// get the shape function derivatives
double* Hr = el.Gr(j);
double* Hs = el.Gs(j);
double* Ht = el.Gt(j);
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt);
g[0] = g[1] = g[2] = vec3d(0,0,0);
int n = el.Nodes();
for (int i = 0; i<n; ++i)
{
g[0] += rt[i]*Hr[i];
g[1] += rt[i]*Hs[i];
g[2] += rt[i]*Ht[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the covariant basis vectors of a solid element
//! at an integration point
void FESolidDomain::CoBaseVectors(FESolidElement& el, int j, vec3d g[3], const double alpha)
{
// get the shape function derivatives
double* Hr = el.Gr(j);
double* Hs = el.Gs(j);
double* Ht = el.Gt(j);
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
GetCurrentNodalCoordinates(el, rt, alpha);
g[0] = g[1] = g[2] = vec3d(0,0,0);
int n = el.Nodes();
for (int i = 0; i<n; ++i)
{
g[0] += rt[i]*Hr[i];
g[1] += rt[i]*Hs[i];
g[2] += rt[i]*Ht[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the contravariant basis vectors in ref config
//! of a solid element at an integration point
void FESolidDomain::ContraBaseVectors0(FESolidElement& el, int j, vec3d gcnt[3])
{
vec3d gcov[3];
CoBaseVectors0(el, j, gcov);
mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x,
gcov[0].y, gcov[1].y, gcov[2].y,
gcov[0].z, gcov[1].z, gcov[2].z);
mat3d Ji = J.inverse();
gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2));
gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2));
gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2));
}
//-----------------------------------------------------------------------------
//! This function calculates the contravariant basis vectors of a solid element
//! at an integration point
void FESolidDomain::ContraBaseVectors(FESolidElement& el, int j, vec3d gcnt[3])
{
vec3d gcov[3];
CoBaseVectors(el, j, gcov);
mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x,
gcov[0].y, gcov[1].y, gcov[2].y,
gcov[0].z, gcov[1].z, gcov[2].z);
mat3d Ji = J.inverse();
gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2));
gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2));
gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2));
}
//-----------------------------------------------------------------------------
//! This function calculates the contravariant basis vectors of a solid element
//! at an integration point
void FESolidDomain::ContraBaseVectors(FESolidElement& el, int j, vec3d gcnt[3], const double alpha)
{
vec3d gcov[3];
CoBaseVectors(el, j, gcov, alpha);
mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x,
gcov[0].y, gcov[1].y, gcov[2].y,
gcov[0].z, gcov[1].z, gcov[2].z);
mat3d Ji = J.inverse();
gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2));
gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2));
gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2));
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of covariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::CoBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3])
{
FEMesh& m = *m_pMesh;
// get the nr of nodes
int n = el.Nodes();
// get the shape function derivatives
double* Hrr = el.Grr(j); double* Hrs = el.Grs(j); double* Hrt = el.Grt(j);
double* Hsr = el.Gsr(j); double* Hss = el.Gss(j); double* Hst = el.Gst(j);
double* Htr = el.Gtr(j); double* Hts = el.Gts(j); double* Htt = el.Gtt(j);
dg[0][0] = dg[0][1] = dg[0][2] = vec3d(0,0,0); // derivatives of g[0]
dg[1][0] = dg[1][1] = dg[1][2] = vec3d(0,0,0); // derivatives of g[1]
dg[2][0] = dg[2][1] = dg[2][2] = vec3d(0,0,0); // derivatives of g[2]
for (int i=0; i<n; ++i)
{
vec3d rt = m.Node(el.m_node[i]).m_rt;
dg[0][0] += rt*Hrr[i]; dg[0][1] += rt*Hsr[i]; dg[0][2] += rt*Htr[i];
dg[1][0] += rt*Hrs[i]; dg[1][1] += rt*Hss[i]; dg[1][2] += rt*Hts[i];
dg[2][0] += rt*Hrt[i]; dg[2][1] += rt*Hst[i]; dg[2][2] += rt*Htt[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of covariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::CoBaseVectorDerivatives0(FESolidElement& el, int j, vec3d dg[3][3])
{
FEMesh& m = *m_pMesh;
// get the nr of nodes
int n = el.Nodes();
// get the shape function derivatives
double* Hrr = el.Grr(j); double* Hrs = el.Grs(j); double* Hrt = el.Grt(j);
double* Hsr = el.Gsr(j); double* Hss = el.Gss(j); double* Hst = el.Gst(j);
double* Htr = el.Gtr(j); double* Hts = el.Gts(j); double* Htt = el.Gtt(j);
dg[0][0] = dg[0][1] = dg[0][2] = vec3d(0,0,0); // derivatives of g[0]
dg[1][0] = dg[1][1] = dg[1][2] = vec3d(0,0,0); // derivatives of g[1]
dg[2][0] = dg[2][1] = dg[2][2] = vec3d(0,0,0); // derivatives of g[2]
for (int i=0; i<n; ++i)
{
vec3d rt = m.Node(el.m_node[i]).m_r0;
dg[0][0] += rt*Hrr[i]; dg[0][1] += rt*Hsr[i]; dg[0][2] += rt*Htr[i];
dg[1][0] += rt*Hrs[i]; dg[1][1] += rt*Hss[i]; dg[1][2] += rt*Hts[i];
dg[2][0] += rt*Hrt[i]; dg[2][1] += rt*Hst[i]; dg[2][2] += rt*Htt[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of covariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::CoBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3], const double alpha)
{
FEMesh& m = *m_pMesh;
// get the nr of nodes
int n = el.Nodes();
// get the shape function derivatives
double* Hrr = el.Grr(j); double* Hrs = el.Grs(j); double* Hrt = el.Grt(j);
double* Hsr = el.Gsr(j); double* Hss = el.Gss(j); double* Hst = el.Gst(j);
double* Htr = el.Gtr(j); double* Hts = el.Gts(j); double* Htt = el.Gtt(j);
dg[0][0] = dg[0][1] = dg[0][2] = vec3d(0,0,0); // derivatives of g[0]
dg[1][0] = dg[1][1] = dg[1][2] = vec3d(0,0,0); // derivatives of g[1]
dg[2][0] = dg[2][1] = dg[2][2] = vec3d(0,0,0); // derivatives of g[2]
for (int i=0; i<n; ++i)
{
vec3d rt = m.Node(el.m_node[i]).m_rt*alpha + m.Node(el.m_node[i]).m_rp*(1.0-alpha);
dg[0][0] += rt*Hrr[i]; dg[0][1] += rt*Hsr[i]; dg[0][2] += rt*Htr[i];
dg[1][0] += rt*Hrs[i]; dg[1][1] += rt*Hss[i]; dg[1][2] += rt*Hts[i];
dg[2][0] += rt*Hrt[i]; dg[2][1] += rt*Hst[i]; dg[2][2] += rt*Htt[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of contravariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::ContraBaseVectorDerivatives(FESolidElement& el, int j, vec3d dgcnt[3][3])
{
vec3d gcnt[3];
vec3d dgcov[3][3];
ContraBaseVectors(el, j, gcnt);
CoBaseVectorDerivatives(el, j, dgcov);
// derivatives of gcnt[0]
dgcnt[0][0] = -gcnt[0]*(gcnt[0]*dgcov[0][0])-gcnt[1]*(gcnt[0]*dgcov[1][0])-gcnt[2]*(gcnt[0]*dgcov[2][0]);
dgcnt[0][1] = -gcnt[0]*(gcnt[0]*dgcov[0][1])-gcnt[1]*(gcnt[0]*dgcov[1][1])-gcnt[2]*(gcnt[0]*dgcov[2][1]);
dgcnt[0][2] = -gcnt[0]*(gcnt[0]*dgcov[0][2])-gcnt[1]*(gcnt[0]*dgcov[1][2])-gcnt[2]*(gcnt[0]*dgcov[2][2]);
// derivatives of gcnt[1]
dgcnt[1][0] = -gcnt[0]*(gcnt[1]*dgcov[0][0])-gcnt[1]*(gcnt[1]*dgcov[1][0])-gcnt[2]*(gcnt[1]*dgcov[2][0]);
dgcnt[1][1] = -gcnt[0]*(gcnt[1]*dgcov[0][1])-gcnt[1]*(gcnt[1]*dgcov[1][1])-gcnt[2]*(gcnt[1]*dgcov[2][1]);
dgcnt[1][2] = -gcnt[0]*(gcnt[1]*dgcov[0][2])-gcnt[1]*(gcnt[1]*dgcov[1][2])-gcnt[2]*(gcnt[1]*dgcov[2][2]);
// derivatives of gcnt[2]
dgcnt[2][0] = -gcnt[0]*(gcnt[2]*dgcov[0][0])-gcnt[1]*(gcnt[2]*dgcov[1][0])-gcnt[2]*(gcnt[2]*dgcov[2][0]);
dgcnt[2][1] = -gcnt[0]*(gcnt[2]*dgcov[0][1])-gcnt[1]*(gcnt[2]*dgcov[1][1])-gcnt[2]*(gcnt[2]*dgcov[2][1]);
dgcnt[2][2] = -gcnt[0]*(gcnt[2]*dgcov[0][2])-gcnt[1]*(gcnt[2]*dgcov[1][2])-gcnt[2]*(gcnt[2]*dgcov[2][2]);
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of contravariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::ContraBaseVectorDerivatives0(FESolidElement& el, int j, vec3d dgcnt[3][3])
{
vec3d gcnt[3];
vec3d dgcov[3][3];
ContraBaseVectors0(el, j, gcnt);
CoBaseVectorDerivatives0(el, j, dgcov);
// derivatives of gcnt[0]
dgcnt[0][0] = -gcnt[0]*(gcnt[0]*dgcov[0][0])-gcnt[1]*(gcnt[0]*dgcov[1][0])-gcnt[2]*(gcnt[0]*dgcov[2][0]);
dgcnt[0][1] = -gcnt[0]*(gcnt[0]*dgcov[0][1])-gcnt[1]*(gcnt[0]*dgcov[1][1])-gcnt[2]*(gcnt[0]*dgcov[2][1]);
dgcnt[0][2] = -gcnt[0]*(gcnt[0]*dgcov[0][2])-gcnt[1]*(gcnt[0]*dgcov[1][2])-gcnt[2]*(gcnt[0]*dgcov[2][2]);
// derivatives of gcnt[1]
dgcnt[1][0] = -gcnt[0]*(gcnt[1]*dgcov[0][0])-gcnt[1]*(gcnt[1]*dgcov[1][0])-gcnt[2]*(gcnt[1]*dgcov[2][0]);
dgcnt[1][1] = -gcnt[0]*(gcnt[1]*dgcov[0][1])-gcnt[1]*(gcnt[1]*dgcov[1][1])-gcnt[2]*(gcnt[1]*dgcov[2][1]);
dgcnt[1][2] = -gcnt[0]*(gcnt[1]*dgcov[0][2])-gcnt[1]*(gcnt[1]*dgcov[1][2])-gcnt[2]*(gcnt[1]*dgcov[2][2]);
// derivatives of gcnt[2]
dgcnt[2][0] = -gcnt[0]*(gcnt[2]*dgcov[0][0])-gcnt[1]*(gcnt[2]*dgcov[1][0])-gcnt[2]*(gcnt[2]*dgcov[2][0]);
dgcnt[2][1] = -gcnt[0]*(gcnt[2]*dgcov[0][1])-gcnt[1]*(gcnt[2]*dgcov[1][1])-gcnt[2]*(gcnt[2]*dgcov[2][1]);
dgcnt[2][2] = -gcnt[0]*(gcnt[2]*dgcov[0][2])-gcnt[1]*(gcnt[2]*dgcov[1][2])-gcnt[2]*(gcnt[2]*dgcov[2][2]);
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of contravariant basis
//! vectors of a solid element at an integration point
void FESolidDomain::ContraBaseVectorDerivatives(FESolidElement& el, int j, vec3d dgcnt[3][3], const double alpha)
{
vec3d gcnt[3];
vec3d dgcov[3][3];
ContraBaseVectors(el, j, gcnt, alpha);
CoBaseVectorDerivatives(el, j, dgcov, alpha);
// derivatives of gcnt[0]
dgcnt[0][0] = -gcnt[0]*(gcnt[0]*dgcov[0][0])-gcnt[1]*(gcnt[0]*dgcov[1][0])-gcnt[2]*(gcnt[0]*dgcov[2][0]);
dgcnt[0][1] = -gcnt[0]*(gcnt[0]*dgcov[0][1])-gcnt[1]*(gcnt[0]*dgcov[1][1])-gcnt[2]*(gcnt[0]*dgcov[2][1]);
dgcnt[0][2] = -gcnt[0]*(gcnt[0]*dgcov[0][2])-gcnt[1]*(gcnt[0]*dgcov[1][2])-gcnt[2]*(gcnt[0]*dgcov[2][2]);
// derivatives of gcnt[1]
dgcnt[1][0] = -gcnt[0]*(gcnt[1]*dgcov[0][0])-gcnt[1]*(gcnt[1]*dgcov[1][0])-gcnt[2]*(gcnt[1]*dgcov[2][0]);
dgcnt[1][1] = -gcnt[0]*(gcnt[1]*dgcov[0][1])-gcnt[1]*(gcnt[1]*dgcov[1][1])-gcnt[2]*(gcnt[1]*dgcov[2][1]);
dgcnt[1][2] = -gcnt[0]*(gcnt[1]*dgcov[0][2])-gcnt[1]*(gcnt[1]*dgcov[1][2])-gcnt[2]*(gcnt[1]*dgcov[2][2]);
// derivatives of gcnt[2]
dgcnt[2][0] = -gcnt[0]*(gcnt[2]*dgcov[0][0])-gcnt[1]*(gcnt[2]*dgcov[1][0])-gcnt[2]*(gcnt[2]*dgcov[2][0]);
dgcnt[2][1] = -gcnt[0]*(gcnt[2]*dgcov[0][1])-gcnt[1]*(gcnt[2]*dgcov[1][1])-gcnt[2]*(gcnt[2]*dgcov[2][1]);
dgcnt[2][2] = -gcnt[0]*(gcnt[2]*dgcov[0][2])-gcnt[1]*(gcnt[2]*dgcov[1][2])-gcnt[2]*(gcnt[2]*dgcov[2][2]);
}
//-----------------------------------------------------------------------------
//! calculate the laplacian of a vector function at an integration point
vec3d FESolidDomain::lapvec(FESolidElement& el, vec3d* fn, int n)
{
vec3d gcnt[3];
vec3d dgcnt[3][3];
ContraBaseVectors(el, n, gcnt);
ContraBaseVectorDerivatives(el, n, dgcnt);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
// get the shape function derivatives
double* Hrr = el.Grr(n); double* Hrs = el.Grs(n); double* Hrt = el.Grt(n);
double* Hsr = el.Gsr(n); double* Hss = el.Gss(n); double* Hst = el.Gst(n);
double* Htr = el.Gtr(n); double* Hts = el.Gts(n); double* Htt = el.Gtt(n);
vec3d lapv(0,0,0);
int N = el.Nodes();
for (int i=0; i<N; ++i)
lapv += fn[i]*((gcnt[0]*Hrr[i]+dgcnt[0][0]*Gr[i])*gcnt[0]+
(gcnt[0]*Hrs[i]+dgcnt[0][1]*Gr[i])*gcnt[1]+
(gcnt[0]*Hrt[i]+dgcnt[0][2]*Gr[i])*gcnt[2]+
(gcnt[1]*Hsr[i]+dgcnt[1][0]*Gs[i])*gcnt[0]+
(gcnt[1]*Hss[i]+dgcnt[1][1]*Gs[i])*gcnt[1]+
(gcnt[1]*Hst[i]+dgcnt[1][2]*Gs[i])*gcnt[2]+
(gcnt[2]*Htr[i]+dgcnt[2][0]*Gt[i])*gcnt[0]+
(gcnt[2]*Hts[i]+dgcnt[2][1]*Gt[i])*gcnt[1]+
(gcnt[2]*Htt[i]+dgcnt[2][2]*Gt[i])*gcnt[2]);
return lapv;
}
//-----------------------------------------------------------------------------
//! calculate the gradient of the divergence of a vector function at an integration point
vec3d FESolidDomain::gradivec(FESolidElement& el, vec3d* fn, int n)
{
vec3d gcnt[3];
vec3d dgcnt[3][3];
ContraBaseVectors(el, n, gcnt);
ContraBaseVectorDerivatives(el, n, dgcnt);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double* Gt = el.Gt(n);
// get the shape function derivatives
double* Hrr = el.Grr(n); double* Hrs = el.Grs(n); double* Hrt = el.Grt(n);
double* Hsr = el.Gsr(n); double* Hss = el.Gss(n); double* Hst = el.Gst(n);
double* Htr = el.Gtr(n); double* Hts = el.Gts(n); double* Htt = el.Gtt(n);
vec3d gdv(0,0,0);
int N = el.Nodes();
for (int i=0; i<N; ++i)
gdv +=
gcnt[0]*((gcnt[0]*Hrr[i]+dgcnt[0][0]*Gr[i])*fn[i])+
gcnt[1]*((gcnt[0]*Hrs[i]+dgcnt[0][1]*Gr[i])*fn[i])+
gcnt[2]*((gcnt[0]*Hrt[i]+dgcnt[0][2]*Gr[i])*fn[i])+
gcnt[0]*((gcnt[1]*Hsr[i]+dgcnt[1][0]*Gs[i])*fn[i])+
gcnt[1]*((gcnt[1]*Hss[i]+dgcnt[1][1]*Gs[i])*fn[i])+
gcnt[2]*((gcnt[1]*Hst[i]+dgcnt[1][2]*Gs[i])*fn[i])+
gcnt[0]*((gcnt[2]*Htr[i]+dgcnt[2][0]*Gt[i])*fn[i])+
gcnt[1]*((gcnt[2]*Hts[i]+dgcnt[2][1]*Gt[i])*fn[i])+
gcnt[2]*((gcnt[2]*Htt[i]+dgcnt[2][2]*Gt[i])*fn[i]);
return gdv;
}
//-----------------------------------------------------------------------------
//! This function calculates the transpose of the spatial gradient of the shape
//! function spatial gradients, gradT(grad H), at an integration point
void FESolidDomain::gradTgradShape(FESolidElement& el, int j, vector<mat3d>& mn)
{
int N = el.Nodes();
vec3d g[3], dg[3][3];
ContraBaseVectors(el, j, g);
ContraBaseVectorDerivatives(el, j, dg);
// get the shape functions
double* Hr = el.Gr(j);
double* Hs = el.Gs(j);
double* Ht = el.Gt(j);
// get the shape function derivatives
double* Hrr = el.Grr(j); double* Hrs = el.Grs(j); double* Hrt = el.Grt(j);
double* Hsr = el.Gsr(j); double* Hss = el.Gss(j); double* Hst = el.Gst(j);
double* Htr = el.Gtr(j); double* Hts = el.Gts(j); double* Htt = el.Gtt(j);
for (int i=0; i<N; ++i) {
mn[i] = ((g[0] & dg[0][0]) + (g[1] & dg[0][1]) + (g[2] & dg[0][2]))*Hr[i]
+ ((g[0] & dg[1][0]) + (g[1] & dg[1][1]) + (g[2] & dg[1][2]))*Hs[i]
+ ((g[0] & dg[2][0]) + (g[1] & dg[2][1]) + (g[2] & dg[2][2]))*Ht[i]
+ (g[0] & g[0])*Hrr[i] + (g[1] & g[0])*Hsr[i] + (g[2] & g[0])*Htr[i]
+ (g[0] & g[1])*Hrs[i] + (g[1] & g[1])*Hss[i] + (g[2] & g[1])*Hts[i]
+ (g[0] & g[2])*Hrt[i] + (g[1] & g[2])*Hst[i] + (g[2] & g[2])*Htt[i];
}
}
//-----------------------------------------------------------------------------
double FESolidDomain::ShapeGradient(FESolidElement& el, int n, vec3d* GradH)
{
// calculate jacobian
double Ji[3][3];
double detJt = invjact(el, Ji, n);
// evaluate shape function derivatives
int ne = el.Nodes();
for (int i = 0; i<ne; ++i)
{
double Gr = el.Gr(n)[i];
double Gs = el.Gs(n)[i];
double Gt = el.Gt(n)[i];
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
GradH[i].x = Ji[0][0] * Gr + Ji[1][0] * Gs + Ji[2][0] * Gt;
GradH[i].y = Ji[0][1] * Gr + Ji[1][1] * Gs + Ji[2][1] * Gt;
GradH[i].z = Ji[0][2] * Gr + Ji[1][2] * Gs + Ji[2][2] * Gt;
}
return detJt;
}
//-----------------------------------------------------------------------------
double FESolidDomain::ShapeGradient(FESolidElement& el, int n, vec3d* GradH, const double alpha)
{
// calculate jacobian
double Ji[3][3];
double detJt = invjact(el, Ji, n, alpha);
// evaluate shape function derivatives
int ne = el.Nodes();
for (int i = 0; i<ne; ++i)
{
double Gr = el.Gr(n)[i];
double Gs = el.Gs(n)[i];
double Gt = el.Gt(n)[i];
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
GradH[i].x = Ji[0][0] * Gr + Ji[1][0] * Gs + Ji[2][0] * Gt;
GradH[i].y = Ji[0][1] * Gr + Ji[1][1] * Gs + Ji[2][1] * Gt;
GradH[i].z = Ji[0][2] * Gr + Ji[1][2] * Gs + Ji[2][2] * Gt;
}
return detJt;
}
//-----------------------------------------------------------------------------
double FESolidDomain::ShapeGradient0(FESolidElement& el, int n, vec3d* GradH)
{
// calculate jacobian
double Ji[3][3];
double detJ0 = invjac0(el, Ji, n);
// evaluate shape function derivatives
int ne = el.Nodes();
for (int i = 0; i<ne; ++i)
{
double Gr = el.Gr(n)[i];
double Gs = el.Gs(n)[i];
double Gt = el.Gt(n)[i];
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
GradH[i].x = Ji[0][0] * Gr + Ji[1][0] * Gs + Ji[2][0] * Gt;
GradH[i].y = Ji[0][1] * Gr + Ji[1][1] * Gs + Ji[2][1] * Gt;
GradH[i].z = Ji[0][2] * Gr + Ji[1][2] * Gs + Ji[2][2] * Gt;
}
return detJ0;
}
//-----------------------------------------------------------------------------
double FESolidDomain::ShapeGradient(FESolidElement& el, double r, double s, double t, vec3d* GradH)
{
// calculate jacobian
double Ji[3][3];
double detJt = invjact(el, Ji, r, s, t);
// shape function derivatives
double Gr[FEElement::MAX_NODES];
double Gs[FEElement::MAX_NODES];
double Gt[FEElement::MAX_NODES];
el.shape_deriv(Gr, Gs, Gt, r, s, t);
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
GradH[i].x = Ji[0][0] * Gr[i] + Ji[1][0] * Gs[i] + Ji[2][0] * Gt[i];
GradH[i].y = Ji[0][1] * Gr[i] + Ji[1][1] * Gs[i] + Ji[2][1] * Gt[i];
GradH[i].z = Ji[0][2] * Gr[i] + Ji[1][2] * Gs[i] + Ji[2][2] * Gt[i];
}
return detJt;
}
//-----------------------------------------------------------------------------
double FESolidDomain::ShapeGradient0(FESolidElement& el, double r, double s, double t, vec3d* GradH)
{
// calculate jacobian
double Ji[3][3];
double detJ0 = invjac0(el, Ji, r, s, t);
// shape function derivatives
double Gr[FEElement::MAX_NODES];
double Gs[FEElement::MAX_NODES];
double Gt[FEElement::MAX_NODES];
el.shape_deriv(Gr, Gs, Gt, r, s, t);
int neln = el.Nodes();
for (int i = 0; i<neln; ++i)
{
// calculate global gradient of shape functions
// note that we need the transposed of Ji, not Ji itself !
GradH[i].x = Ji[0][0] * Gr[i] + Ji[1][0] * Gs[i] + Ji[2][0] * Gt[i];
GradH[i].y = Ji[0][1] * Gr[i] + Ji[1][1] * Gs[i] + Ji[2][1] * Gt[i];
GradH[i].z = Ji[0][2] * Gr[i] + Ji[1][2] * Gs[i] + Ji[2][2] * Gt[i];
}
return detJ0;
}
//-----------------------------------------------------------------------------
//! calculate the volume of an element
double FESolidDomain::Volume(FESolidElement& el)
{
vec3d r0[FEElement::MAX_NODES];
int neln = el.Nodes();
for (int i = 0; i<neln; ++i) r0[i] = Node(el.m_lnode[i]).m_r0;
int nint = el.GaussPoints();
double *w = el.GaussWeights();
double V = 0;
for (int n = 0; n<nint; ++n)
{
// shape function derivatives
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
// jacobian matrix
double J[3][3] = { 0 };
for (int i = 0; i<neln; ++i)
{
const double& Gri = Grn[i];
const double& Gsi = Gsn[i];
const double& Gti = Gtn[i];
const double& x = r0[i].x;
const double& y = r0[i].y;
const double& z = r0[i].z;
J[0][0] += Gri*x; J[0][1] += Gsi*x; J[0][2] += Gti*x;
J[1][0] += Gri*y; J[1][1] += Gsi*y; J[1][2] += Gti*y;
J[2][0] += Gri*z; J[2][1] += Gsi*z; J[2][2] += Gti*z;
}
// calculate the determinant
double detJ0 = J[0][0] * (J[1][1] * J[2][2] - J[1][2] * J[2][1])
+ J[0][1] * (J[1][2] * J[2][0] - J[2][2] * J[1][0])
+ J[0][2] * (J[1][0] * J[2][1] - J[1][1] * J[2][0]);
V += detJ0*w[n];
}
return V;
}
//-----------------------------------------------------------------------------
//! calculate the volume of an element
double FESolidDomain::CurrentVolume(FESolidElement& el)
{
vec3d rt[FEElement::MAX_NODES];
int neln = el.Nodes();
for (int i = 0; i < neln; ++i) rt[i] = Node(el.m_lnode[i]).m_rt;
int nint = el.GaussPoints();
double* w = el.GaussWeights();
double V = 0;
for (int n = 0; n < nint; ++n)
{
// shape function derivatives
double* Grn = el.Gr(n);
double* Gsn = el.Gs(n);
double* Gtn = el.Gt(n);
// jacobian matrix
double J[3][3] = { 0 };
for (int i = 0; i < neln; ++i)
{
const double& Gri = Grn[i];
const double& Gsi = Gsn[i];
const double& Gti = Gtn[i];
const double& x = rt[i].x;
const double& y = rt[i].y;
const double& z = rt[i].z;
J[0][0] += Gri * x; J[0][1] += Gsi * x; J[0][2] += Gti * x;
J[1][0] += Gri * y; J[1][1] += Gsi * y; J[1][2] += Gti * y;
J[2][0] += Gri * z; J[2][1] += Gsi * z; J[2][2] += Gti * z;
}
// calculate the determinant
double detJ0 = J[0][0] * (J[1][1] * J[2][2] - J[1][2] * J[2][1])
+ J[0][1] * (J[1][2] * J[2][0] - J[2][2] * J[1][0])
+ J[0][2] * (J[1][0] * J[2][1] - J[1][1] * J[2][0]);
V += detJ0 * w[n];
}
return V;
}
//-----------------------------------------------------------------------------
//! return the degrees of freedom of an element for this domain
int FESolidDomain::GetElementDofs(FESolidElement& el)
{
return (int)GetDOFList().Size()*el.Nodes();
}
//-----------------------------------------------------------------------------
// Evaluate an integral over the domain and assemble into global load vector
void FESolidDomain::LoadVector(
FEGlobalVector& R, // the global vector to assembe the load vector in
const FEDofList& dofList, // the degree of freedom list
FEVolumeVectorIntegrand f // the actual integrand function
)
{
FEMesh& mesh = *GetMesh();
// degrees of freedom per node
int dofPerNode = dofList.Size();
// loop over all the elements
int NE = Elements();
#pragma omp parallel for
for (int i = 0; i<NE; ++i)
{
// get the next element
FESolidElement& el = Element(i);
int neln = el.Nodes();
// only consider active elements
if (el.isActive())
{
std::vector<double> val(dofPerNode, 0.0);
// total size of the element vector
int ndof = dofPerNode * el.Nodes();
// setup the element vector
vector<double> fe;
fe.assign(ndof, 0);
// loop over integration points
double* w = el.GaussWeights();
int nint = el.GaussPoints();
for (int n = 0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
mp.m_Jt = detJt(el, n);
mp.m_shape = el.H(n);
// loop over all nodes
for (int j = 0; j<neln; ++j)
{
// get the value of the integrand for this node
f(mp, j, val);
// add it all up
for (int k=0; k<dofPerNode; ++k)
{
fe[dofPerNode*j + k] += val[k] * w[n];
}
}
}
// get the element's LM vector
vector<int> lm(ndof, -1);
for (int j = 0; j < neln; ++j)
{
FENode& node = mesh.Node(el.m_node[j]);
vector<int>& ID = node.m_ID;
for (int k = 0; k < dofPerNode; ++k)
{
lm[dofPerNode*j + k] = ID[dofList[k]];
}
}
// Assemble into global vector
R.Assemble(el.m_node, lm, fe);
}
}
}
//-----------------------------------------------------------------------------
void FESolidDomain::LoadStiffness(FELinearSystem& LS, const FEDofList& dofList_a, const FEDofList& dofList_b, FEVolumeMatrixIntegrand f)
{
#pragma omp parallel shared(f)
{
FEElementMatrix ke;
int dofPerNode_a = dofList_a.Size();
int dofPerNode_b = dofList_b.Size();
FEMesh& mesh = *GetMesh();
vec3d rt[FEElement::MAX_NODES];
matrix kab(dofPerNode_a, dofPerNode_b);
int NE = Elements();
#pragma omp for nowait
for (int m = 0; m < NE; ++m)
{
// get the element
FESolidElement& el = Element(m);
if (el.isActive())
{
// calculate nodal normal tractions
int neln = el.Nodes();
// get the element stiffness matrix
ke.SetNodes(el.m_node);
int ndof_a = dofPerNode_a * neln;
int ndof_b = dofPerNode_b * neln;
ke.resize(ndof_a, ndof_b);
// calculate element stiffness
int nint = el.GaussPoints();
// gauss weights
double* w = el.GaussWeights();
// repeat over integration points
ke.zero();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& pt = *el.GetMaterialPoint(n);
// set the shape function values
pt.m_shape = el.H(n);
// calculate stiffness component
for (int i = 0; i < neln; ++i)
for (int j = 0; j < neln; ++j)
{
// evaluate integrand
kab.zero();
f(pt, i, j, kab);
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();
lma.assign(ndof_a, -1);
lmb.assign(ndof_b, -1);
for (int j = 0; j < neln; ++j)
{
FENode& node = mesh.Node(el.m_node[j]);
std::vector<int>& ID = node.m_ID;
for (int k = 0; k < dofPerNode_a; ++k)
lma[dofPerNode_a * j + k] = ID[dofList_a[k]];
for (int k = 0; k < dofPerNode_b; ++k)
lmb[dofPerNode_b * j + k] = ID[dofList_b[k]];
}
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
} // omp parallel
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELineSearch.h | .h | 1,898 | 55 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
class FENewtonSolver;
class DumpStream;
class FELineSearch
{
public:
FELineSearch(FENewtonSolver* pns);
// Do a line search. ls is the initial search step
double DoLineSearch(double ls = 1.0);
// serialization
void Serialize(DumpStream& ar);
private:
double UpdateModel(std::vector<double>& ul, std::vector<double>& ui, double s);
public:
double m_LSmin; //!< minimum line search step
double m_LStol; //!< line search tolerance
int m_LSiter; //!< max nr of line search iterations
bool m_checkJacobians;//!< check for negative jacobians
private:
FENewtonSolver* m_pns;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEShellElement.cpp | .cpp | 6,395 | 223 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEShellElement.h"
#include "DumpStream.h"
using namespace std;
//=================================================================================================
// FEShellElement
//=================================================================================================
FEShellElement::FEShellElement()
{
m_elem[0] = m_elem[1] = -1;
}
FEShellElement::FEShellElement(const FEShellElement& el)
{
// set the traits of the element
if (el.m_pT) { SetTraits(el.m_pT); m_State = el.m_State; }
// 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 shell data
m_h0 = el.m_h0;
m_ht = el.m_ht;
m_d0 = el.m_d0;
m_g0[0] = el.m_g0[0]; m_g0[1] = el.m_g0[1]; m_g0[2] = el.m_g0[2];
m_gt[0] = el.m_gt[0]; m_gt[1] = el.m_gt[1]; m_gt[2] = el.m_gt[2];
m_gp[0] = el.m_gp[0]; m_gp[1] = el.m_gp[1]; m_gp[2] = el.m_gp[2];
m_G0[0] = el.m_G0[0]; m_G0[1] = el.m_G0[1]; m_G0[2] = el.m_G0[2];
m_Gt[0] = el.m_Gt[0]; m_Gt[1] = el.m_Gt[1]; m_Gt[2] = el.m_Gt[2];
m_elem[0] = el.m_elem[0];
m_elem[1] = el.m_elem[1];
}
//! assignment operator
FEShellElement& FEShellElement::operator = (const FEShellElement& el)
{
// set the traits of the element
if (el.m_pT) { SetTraits(el.m_pT); m_State = el.m_State; }
// 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 shell data
m_h0 = el.m_h0;
m_ht = el.m_ht;
m_d0 = el.m_d0;
m_g0[0] = el.m_g0[0]; m_g0[1] = el.m_g0[1]; m_g0[2] = el.m_g0[2];
m_gt[0] = el.m_gt[0]; m_gt[1] = el.m_gt[1]; m_gt[2] = el.m_gt[2];
m_gp[0] = el.m_gp[0]; m_gp[1] = el.m_gp[1]; m_gp[2] = el.m_gp[2];
m_G0[0] = el.m_G0[0]; m_G0[1] = el.m_G0[1]; m_G0[2] = el.m_G0[2];
m_Gt[0] = el.m_Gt[0]; m_Gt[1] = el.m_Gt[1]; m_Gt[2] = el.m_Gt[2];
m_elem[0] = el.m_elem[0];
m_elem[1] = el.m_elem[1];
return (*this);
}
void FEShellElement::SetTraits(FEElementTraits* ptraits)
{
FEElement::SetTraits(ptraits);
m_h0.assign(Nodes(), 0.0);
m_ht.assign(Nodes(), 0.0);
m_d0.assign(Nodes(), vec3d(0, 0, 0));
m_g0[0].assign(GaussPoints(), vec3d(0, 0, 0));
m_g0[1].assign(GaussPoints(), vec3d(0, 0, 0));
m_g0[2].assign(GaussPoints(), vec3d(0, 0, 0));
m_gt[0].assign(GaussPoints(), vec3d(0, 0, 0));
m_gt[1].assign(GaussPoints(), vec3d(0, 0, 0));
m_gt[2].assign(GaussPoints(), vec3d(0, 0, 0));
m_gp[0].assign(GaussPoints(), vec3d(0, 0, 0));
m_gp[1].assign(GaussPoints(), vec3d(0, 0, 0));
m_gp[2].assign(GaussPoints(), vec3d(0, 0, 0));
m_G0[0].assign(GaussPoints(), vec3d(0, 0, 0));
m_G0[1].assign(GaussPoints(), vec3d(0, 0, 0));
m_G0[2].assign(GaussPoints(), vec3d(0, 0, 0));
m_Gt[0].assign(GaussPoints(), vec3d(0, 0, 0));
m_Gt[1].assign(GaussPoints(), vec3d(0, 0, 0));
m_Gt[2].assign(GaussPoints(), vec3d(0, 0, 0));
}
void FEShellElement::Serialize(DumpStream &ar)
{
FEElement::Serialize(ar);
if (ar.IsShallow() == false) {
ar & m_h0;
ar & m_d0;
ar & m_g0[0] & m_g0[1] & m_g0[2];
ar & m_gt[0] & m_gt[1] & m_gt[2];
ar & m_gp[0] & m_gp[1] & m_gp[2];
ar & m_G0[0] & m_G0[1] & m_G0[2];
ar & m_Gt[0] & m_Gt[1] & m_Gt[2];
ar & m_elem[0] & m_elem[1];
}
ar & m_ht;
}
//=================================================================================================
// FEShellElementOld
//=================================================================================================
FEShellElementOld::FEShellElementOld()
{
}
FEShellElementOld::FEShellElementOld(const FEShellElementOld& el) : FEShellElement(el)
{
m_D0 = el.m_D0;
}
//! assignment operator
FEShellElementOld& FEShellElementOld::operator = (const FEShellElementOld& el)
{
// copy base class
FEShellElement::operator=(el);
// copy this class data
m_D0 = el.m_D0;
return (*this);
}
void FEShellElementOld::SetTraits(FEElementTraits* ptraits)
{
FEShellElement::SetTraits(ptraits);
m_D0.resize(Nodes());
}
void FEShellElementOld::Serialize(DumpStream& ar)
{
FEShellElement::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_D0;
}
//=================================================================================================
// FEShellElementNew
//=================================================================================================
FEShellElementNew::FEShellElementNew()
{
}
FEShellElementNew::FEShellElementNew(const FEShellElementNew& el) : FEShellElement(el)
{
// TODO: What about all the EAS parameters?
}
//! assignment operator
FEShellElementNew& FEShellElementNew::operator = (const FEShellElementNew& el)
{
FEShellElement::operator=(el);
// TODO: What about all the EAS parameters?
return (*this);
}
void FEShellElementNew::SetTraits(FEElementTraits* ptraits)
{
FEShellElement::SetTraits(ptraits);
// TODO: What about all the EAS parameters?
}
void FEShellElementNew::Serialize(DumpStream &ar)
{
FEShellElement::Serialize(ar);
ar & m_fa;
ar & m_Kaai;
ar & m_alpha;
ar & m_alphai;
ar & m_alphat;
ar & m_Kua;
ar & m_Kwa;
ar & m_E;
}
| C++ |
3D | febiosoftware/FEBio | FECore/QuadricFit.cpp | .cpp | 10,274 | 286 | /*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio-Studio.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.*/
// onchoidFit.cpp: implementation of the QuadricFit class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "QuadricFit.h"
#include <stdio.h>
using std::swap;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------
// constructor
QuadricFit::QuadricFit()
{
m_rc = m_c2 = vec3d(0,0,0);
m_c = 0;
m_ax[0] = m_ax[1] = m_ax [2] = vec3d(0,0,0);
m_quad = new Quadric();
m_eps = 1e-3;
}
//-------------------------------------------------------------------------------
// copy constructor
QuadricFit::QuadricFit(const QuadricFit& qf)
{
m_rc = qf.m_rc;
m_c2 = qf.m_c2;
m_c = qf.m_c;
m_ax[0] = qf.m_ax[0];
m_ax[1] = qf.m_ax[1];
m_ax[2] = qf.m_ax[2];
m_quad = new Quadric(*qf.m_quad);
m_eps = qf.m_eps;
}
//-------------------------------------------------------------------------------
// destructor
QuadricFit::~QuadricFit()
{
}
//-------------------------------------------------------------------------------
void QuadricFit::GetOrientation()
{
mat3ds C(m_quad->m_c[0], m_quad->m_c[1], m_quad->m_c[2],
m_quad->m_c[5], m_quad->m_c[3], m_quad->m_c[4]);
vec3d v = vec3d(m_quad->m_c[6], m_quad->m_c[7], m_quad->m_c[8]);
double c = m_quad->m_c[9];
double eval[3];
vec3d evec[3];
C.eigen2(eval, evec); // eigenvalues sorted from smallest to largest
// rectify sign of eigenvalues
double emag = sqrt(eval[0]*eval[0] + eval[1]*eval[1] + eval[2]*eval[2]);
if (eval[2] <= emag*m_eps) {
eval[0] = -eval[0];
eval[1] = -eval[1];
eval[2] = -eval[2];
v = -v;
c = -c;
}
// re-sort eigenvalues and eigenvectors from largest to smalles
if (eval[0] < eval[2]) { swap(eval[0],eval[2]); swap(evec[0], evec[2]); }
if (eval[0] < eval[1]) { swap(eval[0],eval[1]); swap(evec[0], evec[1]); }
if (eval[1] < eval[2]) { swap(eval[1],eval[2]); swap(evec[1], evec[2]); }
// estimate the relative magnitudes of the eigenvalues
if (fabs(eval[0]) < m_eps*emag) eval[0] = 0;
if (fabs(eval[1]) < m_eps*emag) eval[1] = 0;
if (fabs(eval[2]) < m_eps*emag) eval[2] = 0;
// normalize vectors
evec[0].unit(); evec[1].unit(); evec[2].unit();
// clean up vector
if (fabs(evec[0].x) < m_eps) evec[0].x = 0; if (fabs(evec[0].y) < m_eps) evec[0].y = 0; if (fabs(evec[0].z) < m_eps) evec[0].z = 0;
if (fabs(evec[1].x) < m_eps) evec[1].x = 0; if (fabs(evec[1].y) < m_eps) evec[1].y = 0; if (fabs(evec[1].z) < m_eps) evec[1].z = 0;
if (fabs(evec[2].x) < m_eps) evec[2].x = 0; if (fabs(evec[2].y) < m_eps) evec[2].y = 0; if (fabs(evec[2].z) < m_eps) evec[2].z = 0;
evec[0].unit(); evec[1].unit(); evec[2].unit();
// check if basis is right-handed or not
double rh = (evec[0] ^ evec[1])*evec[2];
if (rh < 0) evec[1] = evec[2] ^ evec[0];
// estimate the relative magnitudes of the components of v
if (fabs(v.x) < m_eps*emag) v.x = 0;
if (fabs(v.y) < m_eps*emag) v.y = 0;
if (fabs(v.z) < m_eps*emag) v.z = 0;
mat3d Q(evec[0].x, evec[1].x, evec[2].x,
evec[0].y, evec[1].y, evec[2].y,
evec[0].z, evec[1].z, evec[2].z);
m_ax[0] = evec[0];
m_ax[1] = evec[1];
m_ax[2] = evec[2];
m_c2 = vec3d(eval[0], eval[1], eval[2]);
vec3d d = Q.transpose()*v;
m_v = v;
vec3d X0;
if (m_c2.x*m_c2.y*m_c2.z != 0) {
X0.x = -d.x/(2*m_c2.x);
X0.y = -d.y/(2*m_c2.y);
X0.z = -d.z/(2*m_c2.z);
m_c = c - m_c2.x*pow(X0.x,2) - m_c2.y*pow(X0.y,2) - m_c2.z*pow(X0.z,2);
if (fabs(m_c) < m_eps) m_c = 0;
if (m_c != 0) {
m_c2 /= fabs(m_c);
m_c /= fabs(m_c);
}
}
else if (m_c2.x*m_c2.y != 0) {
X0.x = -d.x/(2*m_c2.x);
X0.y = -d.y/(2*m_c2.y);
X0.z = 0;
m_c = c - m_c2.x*pow(X0.x,2) - m_c2.y*pow(X0.y,2);
if (m_c != 0) {
m_c2 /= fabs(m_c);
m_c /= fabs(m_c);
}
}
else {
X0.x = -d.x/(2*m_c2.x);
X0.y = 0;
X0.z = 0;
m_c = c - m_c2.x*pow(X0.x,2);
if (m_c != 0) {
m_c2 /= fabs(m_c);
m_c /= fabs(m_c);
}
}
m_rc = Q*X0;
// clean up
double rc = m_rc.norm();
if (fabs(m_rc.x) < m_eps*rc) m_rc.x = 0;
if (fabs(m_rc.y) < m_eps*rc) m_rc.y = 0;
if (fabs(m_rc.z) < m_eps*rc) m_rc.z = 0;
}
//-------------------------------------------------------------------------------
// complete fit algorithm
//bool QuadricFit::Fit(PointCloud3d* pc)
bool QuadricFit::Fit(std::vector<vec3d>& pc)
{
// m_quad->SetPointCloud3d(pc);
m_quad->m_p = pc;
if (m_quad->GetQuadricCoeficients())
{
GetOrientation();
return true;
}
else
return false;
}
//-------------------------------------------------------------------------------
bool QuadricFit::isSame(const double& a, const double&b)
{
if (fabs(b-a) < m_eps*fabs(a+b)/2) return true;
else return false;
}
//-------------------------------------------------------------------------------
QuadricFit::Q_TYPE QuadricFit::GetType()
{
// determine quadric type
Q_TYPE type = Q_UNKNOWN;
double A = m_c2.x, B = m_c2.y, C = m_c2.z;
if ((A > 0) && (B > 0)) {
if ((C > 0) && isSame(m_c,-1)) {
type = Q_ELLIPSOID;
if (isSame(A,B)) {
type = Q_SPHEROID;
if (isSame(B,C)) type = Q_SPHERE;
}
}
else if (C == 0) {
if (isSame(m_v.z,-1) && (m_c == 0)) {
type = Q_ELLIPTIC_PARABOLOID;
if (isSame(A,B))
type = Q_CIRCULAR_PARABOLOID;
}
else if ((m_v.z == 0) && isSame(m_c,-1)) {
type = Q_ELLIPTIC_CYLINDER;
if (isSame(A,B))
type = Q_CIRCULAR_CYLINDER;
}
}
else if (C < 0) {
if (isSame(m_c,-1)) {
type = Q_ELLIPTIC_HYPERBOLOID_1;
if (isSame(A,B)) {
type = Q_CIRCULAR_HYPERBOLOID_1;
}
}
else if (isSame(m_c,1)) {
type = Q_ELLIPTIC_HYPERBOLOID_2;
if (isSame(A,B)) {
type = Q_CIRCULAR_HYPERBOLOID_2;
}
}
else if (m_c == 0) {
type = Q_ELLIPTIC_CONE;
if (isSame(A,B)) {
type = Q_CIRCULAR_CONE;
}
}
}
}
else if ((A > 0) && (B < 0)) {
if ((C == 0) && (m_c == 0) && isSame(m_v.z,-1)) {
type = Q_HYPERBOLIC_PARABOLOID;
}
else if ((C == 0) && isSame(m_c,-1) && (m_v.z == 0)) {
type = Q_HYPERBOLIC_CYLINDER;
}
}
else if ((A > 0) && (B == 0)) {
type = Q_PARABOLIC_CYLINDER;
}
return type;
}
//-------------------------------------------------------------------------------
std::string QuadricFit::GetStringType(Q_TYPE qtype)
{
std::string quadric;
switch (qtype) {
case QuadricFit::Q_ELLIPSOID: quadric = std::string("Ellipsoid"); break;
case QuadricFit::Q_ELLIPTIC_PARABOLOID: quadric = std::string("Elliptic Paraboloid"); break;
case QuadricFit::Q_HYPERBOLIC_PARABOLOID: quadric = std::string("Hyperbolic Paraboloid"); break;
case QuadricFit::Q_ELLIPTIC_HYPERBOLOID_1: quadric = std::string("Elliptic Hyperboloid of One Sheet"); break;
case QuadricFit::Q_ELLIPTIC_HYPERBOLOID_2: quadric = std::string("Elliptic Hyperboloid of Two Sheets"); break;
case QuadricFit::Q_ELLIPTIC_CONE: quadric = std::string("Elliptic Cone"); break;
case QuadricFit::Q_ELLIPTIC_CYLINDER: quadric = std::string("Elliptic Cylinder"); break;
case QuadricFit::Q_PARABOLIC_CYLINDER: quadric = std::string("Parabolic Cylinder"); break;
case QuadricFit::Q_SPHEROID: quadric = std::string("Spheroid"); break;
case QuadricFit::Q_SPHERE: quadric = std::string("Sphere"); break;
case QuadricFit::Q_CIRCULAR_PARABOLOID: quadric = std::string("Circular Paraboloid"); break;
case QuadricFit::Q_CIRCULAR_HYPERBOLOID_1: quadric = std::string("Circular Hyperboloid of One Sheet"); break;
case QuadricFit::Q_CIRCULAR_HYPERBOLOID_2: quadric = std::string("Circular Hyperboloid of Two Sheets"); break;
case QuadricFit::Q_CIRCULAR_CONE: quadric = std::string("Circular Cone"); break;
case QuadricFit::Q_CIRCULAR_CYLINDER: quadric = std::string("Circular Cylinder"); break;
case QuadricFit::Q_UNKNOWN: quadric = std::string("Unknown"); break;
default: break;
}
return quadric;
}
| C++ |
3D | febiosoftware/FEBio | FECore/Quadric.h | .h | 2,596 | 67 | /*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio-Studio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "vec3d.h"
#include "fecore_api.h"
class FECORE_API Quadric
{
public:
Quadric() {}
Quadric(std::vector<vec3d>& p) { m_p = p; }
Quadric(Quadric* q);
Quadric(const Quadric& q);
~Quadric();
public:
// assign a point cloud to this bivariate spline object
void SetPoints(std::vector<vec3d>& p) { m_p = p; }
// fit the point cloud to get quadric surface coefficients
bool GetQuadricCoeficients();
// Evaluate the surface normal at point p
vec3d SurfaceNormal(const vec3d p);
// Evaluate the surface principal curvatures kappa and directions v at point p
void SurfaceCurvature(const vec3d p, const vec3d n, vec2d& kappa, vec3d* v);
// Find ray-quadric surface intersections x: p is point on ray, n is normal along ray
void RayQuadricIntersection(const vec3d p, const vec3d n, std::vector<vec3d>* x, std::vector<double>* t = nullptr);
// Find the point on the quadric closest to the point p
vec3d ClosestPoint(const vec3d p);
// Find the point on the quadric closest to the point p
vec3d ClosestPoint(const vec3d p, const vec3d norm);
public:
double m_c[10]; // quadric surface coefficients
std::vector<vec3d> m_p; // point coordinates
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FENodeNodeList.h | .h | 2,441 | 77 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
class FEMesh;
class FEDomain;
class FESurface;
//-----------------------------------------------------------------------------
//! The FENodeNodeList class is a utility class that determines for each node
//! the adjacent nodes
//! This class analyzes a mesh and finds for each node all nodes that are
//! adjacent to this node
class FECORE_API FENodeNodeList
{
public:
//! default constructor
FENodeNodeList();
//! desctructor
virtual ~FENodeNodeList();
//! create the node-node list for a mesh
void Create(FEMesh& mesh);
//! create the node-node list for a domain
void Create(FEDomain& dom);
//! create the node-node list for a surface
void Create(FESurface& surf);
int Size() const { return (int) m_nval.size(); }
int Valence(int i) { return m_nval[i]; }
int* NodeList(int i) { return &m_nref[0] + m_pn[i]; }
void Sort();
protected:
std::vector<int> m_nval; // nodal valences
std::vector<int> m_nref; // adjacent nodes indices
std::vector<int> m_pn; // start index into the nref array
static FENodeNodeList* m_pthis;
static int compare(const void* e1, const void* e2);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/log.h | .h | 2,026 | 43 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
class FEModel;
FECORE_API void write_log(FEModel* fem, int ntag, const char* szmsg, ...);
#define feLog(...) write_log(GetFEModel(), 0, __VA_ARGS__)
#define feLogWarning(...) write_log(GetFEModel(), 1, __VA_ARGS__)
#define feLogError(...) write_log(GetFEModel(), 2, __VA_ARGS__)
#define feLogInfo(...) write_log(GetFEModel(), 3, __VA_ARGS__)
#define feLogDebug(...) write_log(GetFEModel(), 4, __VA_ARGS__)
#define feLogEx(fem, ...) write_log(fem, 0, __VA_ARGS__)
#define feLogWarningEx(fem, ...) write_log(fem, 1, __VA_ARGS__)
#define feLogErrorEx(fem, ...) write_log(fem, 2, __VA_ARGS__)
#define feLogInfoEx(fem, ...) write_log(fem, 3, __VA_ARGS__)
#define feLogDebugEx(fem, ...) write_log(fem, 4, __VA_ARGS__)
| Unknown |
3D | febiosoftware/FEBio | FECore/FELinearConstraint.cpp | .cpp | 9,538 | 290 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELinearConstraint.h"
#include "FEMesh.h"
#include "FEModel.h"
#include "DumpStream.h"
#include "log.h"
BEGIN_FECORE_CLASS(FELinearConstraintDOF, FECoreClass)
ADD_PARAMETER(dof, "dof", 0, "$(dof_list)");
ADD_PARAMETER(node, "node");
ADD_PARAMETER(val, "value");
END_FECORE_CLASS();
FELinearConstraintDOF::FELinearConstraintDOF(FEModel* fem) : FECoreClass(fem)
{
node = dof = -1;
val = 1.0;
}
//=============================================================================
BEGIN_FECORE_CLASS(FELinearConstraint, FEBoundaryCondition)
ADD_PARAMETER(m_parentDof->dof, "dof", 0, "$(dof_list)");
ADD_PARAMETER(m_parentDof->node, "node");
ADD_PARAMETER(m_off, "offset");
ADD_PROPERTY(m_childDof, "child_dof");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FELinearConstraint::FELinearConstraint() : FEBoundaryCondition(nullptr)
{
m_parentDof = nullptr;
m_off = 0.0;
}
//-----------------------------------------------------------------------------
FELinearConstraint::FELinearConstraint(FEModel* pfem) : FEBoundaryCondition(pfem)
{
m_parentDof = new FELinearConstraintDOF(pfem);
m_parentDof->GetParameterList(); // we need to call this to make sure that the parameter list is created.
m_off = 0.0;
}
//-----------------------------------------------------------------------------
FELinearConstraint::~FELinearConstraint()
{
Clear();
}
//-----------------------------------------------------------------------------
// return offset
double FELinearConstraint::GetOffset() const
{
return m_off;
}
//-----------------------------------------------------------------------------
void FELinearConstraint::Clear()
{
if (m_parentDof) delete m_parentDof; m_parentDof = nullptr;
for (size_t i = 0; i < m_childDof.size(); ++i) delete m_childDof[i];
m_childDof.clear();
}
//-----------------------------------------------------------------------------
FELinearConstraint::FELinearConstraint(const FELinearConstraint& LC) : FEBoundaryCondition(LC.GetFEModel())
{
m_parentDof = nullptr;
CopyFrom(&(const_cast<FELinearConstraint&>(LC)));
}
//-----------------------------------------------------------------------------
void FELinearConstraint::CopyFrom(FEBoundaryCondition* pbc)
{
FELinearConstraint& LC = dynamic_cast<FELinearConstraint&>(*pbc);
Clear();
if (LC.m_parentDof)
{
m_parentDof = new FELinearConstraintDOF(GetFEModel());
m_parentDof->GetParameterList(); // NOTE: we need to call this to make sure that the parameter list is created.
m_parentDof->node = LC.m_parentDof->node;
m_parentDof->dof = LC.m_parentDof->dof;
m_parentDof->val = LC.m_parentDof->val;
}
m_off = LC.m_off;
int n = (int)LC.m_childDof.size();
vector<FELinearConstraintDOF*>::const_iterator it = LC.m_childDof.begin();
for (int i = 0; i < n; ++i, ++it)
{
FELinearConstraintDOF* d = new FELinearConstraintDOF(GetFEModel());
d->GetParameterList(); // NOTE: we need to call this to make sure that the parameter list is created.
d->node = (*it)->node;
d->dof = (*it)->dof;
d->val = (*it)->val;
m_childDof.push_back(d);
}
}
//-----------------------------------------------------------------------------
void FELinearConstraint::SetParentDof(int dof, int node)
{
if (m_parentDof == nullptr) {
m_parentDof = new FELinearConstraintDOF(GetFEModel());
m_parentDof->GetParameterList(); // NOTE: we need to call this to make sure that the parameter list is created.
}
m_parentDof->dof = dof;
m_parentDof->node = node;
}
//-----------------------------------------------------------------------------
void FELinearConstraint::SetParentNode(int node)
{
if (m_parentDof == nullptr) {
m_parentDof = new FELinearConstraintDOF(GetFEModel());
m_parentDof->GetParameterList(); // NOTE: we need to call this to make sure that the parameter list is created.
}
m_parentDof->node = node;
}
//-----------------------------------------------------------------------------
void FELinearConstraint::SetParentDof(int dof)
{
if (m_parentDof == nullptr) {
m_parentDof = new FELinearConstraintDOF(GetFEModel());
m_parentDof->GetParameterList(); // NOTE: we need to call this to make sure that the parameter list is created.
}
m_parentDof->dof = dof;
}
//-----------------------------------------------------------------------------
// get the parent dof
int FELinearConstraint::GetParentDof() const
{
return m_parentDof->dof;
}
//-----------------------------------------------------------------------------
int FELinearConstraint::GetParentNode() const
{
return m_parentDof->node;
}
//-----------------------------------------------------------------------------
// get the child DOF
const FELinearConstraintDOF& FELinearConstraint::GetChildDof(int n) const
{
return *m_childDof[n];
}
//-----------------------------------------------------------------------------
size_t FELinearConstraint::Size() const
{
return m_childDof.size();
}
//-----------------------------------------------------------------------------
FELinearConstraint::dof_iterator FELinearConstraint::begin()
{
return m_childDof.begin();
}
//-----------------------------------------------------------------------------
void FELinearConstraint::AddChildDof(int dof, int node, double v)
{
FELinearConstraintDOF* d = new FELinearConstraintDOF(GetFEModel());
d->GetParameterList(); // we need to call this to make sure that the parameter list is created.
d->dof = dof;
d->node = node;
d->val = v;
m_childDof.push_back(d);
}
//-----------------------------------------------------------------------------
void FELinearConstraint::AddChildDof(FELinearConstraintDOF* dof)
{
dof->GetParameterList(); // we need to call this to make sure that the parameter list is created.
m_childDof.push_back(dof);
}
//-----------------------------------------------------------------------------
// Initialization.
// Make sure the parent dof does not appear as a child dof
bool FELinearConstraint::Init()
{
if (m_parentDof == nullptr) return false;
if (m_parentDof->node < 0)
{
feLogError("Invalid node ID for parent node of linear constraint.");
return false;
}
int n = (int)m_childDof.size();
for (int i=0; i<n; ++i)
{
FELinearConstraintDOF& childNode = *m_childDof[i];
if ((childNode.node == m_parentDof->node) && (childNode.dof == m_parentDof->dof)) return false;
if (childNode.node < 0)
{
feLogError("Invalid node ID for child node of linear constraint.");
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
// This is called during model activation (i.e. at the start of an analysis step)
// The parent dof is fixed in order to make sure that they are not assigned an equation number.
void FELinearConstraint::Activate()
{
FEStepComponent::Activate();
FEMesh& mesh = GetFEModel()->GetMesh();
// we need the parent node to be fixed so that no equation is allocated
FENode& node = mesh.Node(m_parentDof->node);
node.set_bc(m_parentDof->dof, DOF_FIXED);
}
//-----------------------------------------------------------------------------
void FELinearConstraint::Deactivate()
{
FEStepComponent::Deactivate();
FEMesh& mesh = GetFEModel()->GetMesh();
FENode& node = mesh.Node(m_parentDof->node);
node.set_bc(m_parentDof->dof, DOF_OPEN);
}
//-----------------------------------------------------------------------------
void FELinearConstraint::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
m_parentDof->Serialize(ar);
int n = (int)m_childDof.size();
ar << n;
vector<FELinearConstraintDOF*>::iterator it = m_childDof.begin();
for (int i = 0; i < n; ++i, ++it) (*it)->Serialize(ar);
}
else
{
m_childDof.clear();
if (m_parentDof == nullptr) {
m_parentDof = new FELinearConstraintDOF(GetFEModel());
m_parentDof->GetParameterList(); // we need to call this to make sure that the parameter list is created.
}
m_parentDof->Serialize(ar);
int n;
ar >> n;
for (int i=0; i<n; ++i)
{
FELinearConstraintDOF* dof = new FELinearConstraintDOF(GetFEModel());
dof->GetParameterList(); // we need to call this to make sure that the parameter list is created.
dof->Serialize(ar);
m_childDof.push_back(dof);
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/BFGSSolver.h | .h | 2,399 | 69 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "matrix.h"
#include "vector.h"
#include "LinearSolver.h"
#include "FENewtonStrategy.h"
//-----------------------------------------------------------------------------
//! The BFGSSolver solves a nonlinear system of equations using the BFGS method.
//! It depends on the NonLinearSystem to evaluate the function and its jacobian.
class FECORE_API BFGSSolver : public FENewtonStrategy
{
public:
//! constructor
BFGSSolver(FEModel* fem);
//! New initialization method
bool Init() override;
//! perform a BFGS udpate
bool Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1) override;
//! solve the equations
void SolveEquations(vector<double>& x, vector<double>& b) override;
public:
// keep a pointer to the linear solver
LinearSolver* m_plinsolve; //!< pointer to linear solver
int m_neq; //!< number of equations
// BFGS update vectors
matrix m_V; //!< BFGS update vector
matrix m_W; //!< BFGS update vector
vector<double> m_D, m_G, m_H; //!< temp vectors for calculating BFGS update vectors
vector<double> tmp;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FSPath.h | .h | 1,484 | 38 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
class FECORE_API FSPath
{
public:
static bool isAbsolute(const char* path);
static bool isPath(const char* path);
static void filePath(char* filename, char* path);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataMathGenerator.h | .h | 1,818 | 56 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDataGenerator.h"
#include <string>
#include "MathObject.h"
class FENodeSet;
class FEFacetSet;
//-----------------------------------------------------------------------------
class FECORE_API FEDataMathGenerator : public FENodeDataGenerator
{
public:
FEDataMathGenerator(FEModel* fem);
bool Init() override;
// set the math expression
void setExpression(const std::string& math);
FEDataMap* Generate() override;
private:
std::string m_math;
vector<MSimpleExpression> m_val;
DECLARE_FECORE_CLASS()
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMathIntervalController.h | .h | 1,918 | 60 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FELoadController.h"
#include "MathObject.h"
#include <vector>
#include <string>
class FEMathIntervalController : public FELoadController
{
public:
//! Extend mode
enum ExtendMode { ZERO, CONSTANT, REPEAT};
public:
FEMathIntervalController(FEModel* fem);
bool Init() override;
protected:
double GetValue(double time) override;
private:
double m_rng[2]; // range of interval
int m_leftExtend; // left extend mode
int m_rightExtend; // right extend mode
std::vector<std::string> m_var;
std::string m_math;
MSimpleExpression m_val;
std::vector<FEParamValue> m_param;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FENewtonStrategy.cpp | .cpp | 2,408 | 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 "FENewtonStrategy.h"
#include "FENewtonSolver.h"
#include "LinearSolver.h"
FENewtonStrategy::FENewtonStrategy(FEModel* fem) : FECoreBase(fem)
{
m_pns = nullptr;
m_maxups = 10;
m_cmax = 1e5;
m_max_buf_size = 0; // when zero, it should default to m_maxups
m_cycle_buffer = true;
m_nups = 0;
}
FENewtonStrategy::~FENewtonStrategy()
{
}
void FENewtonStrategy::SetNewtonSolver(FENewtonSolver* solver)
{
m_pns = solver;
}
//! initialize the linear system
SparseMatrix* FENewtonStrategy::CreateSparseMatrix(Matrix_Type mtype)
{
if (m_pns == 0) return 0;
LinearSolver* plinsolve = m_pns->m_plinsolve;
SparseMatrix* pS = plinsolve->CreateSparseMatrix(mtype);
return pS;
}
bool FENewtonStrategy::ReformStiffness()
{
return m_pns->ReformStiffness();
}
//! calculate the residual
bool FENewtonStrategy::Residual(std::vector<double>& R, bool binit)
{
TRACK_TIME(TimerID::Timer_Residual);
return m_pns->Residual(R);
}
void FENewtonStrategy::Serialize(DumpStream& ar)
{
FECoreBase::Serialize(ar);
ar & m_nups;
ar & m_pns;
}
//! reset data for new run
void FENewtonStrategy::Reset()
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEEdge.h | .h | 3,098 | 105 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEMeshPartition.h"
#include "FENodeList.h"
#include "FESegmentSet.h"
#include <vector>
//-----------------------------------------------------------------------------
class FECORE_API FELineMaterialPoint : public FEMaterialPoint
{
public:
// return the surface element
FELineElement* LineElement() { return (FELineElement*)m_elem; }
void Serialize(DumpStream& ar) override
{
FEMaterialPoint::Serialize(ar);
}
};
//-----------------------------------------------------------------------------
// This class represents an edge of a domain.
class FECORE_API FEEdge : public FEMeshPartition
{
public:
FECORE_SUPER_CLASS(FEEDGE_ID)
FECORE_BASE_CLASS(FEEdge)
public:
//! constructor
FEEdge(FEModel* fem);
//! destructor
virtual ~FEEdge();
//! initialize edge data structure
virtual bool Init() override;
//! creates edge
void Create(int nelems, int elemType = -1);
//! create from edge set
virtual bool Create(FESegmentSet& es);
//! extract node set
FENodeList GetNodeList();
public:
//! return number of edge elements
int Elements() const override { return (int)m_Elem.size(); }
//! return an element of the edge
FELineElement& Element(int i) { return m_Elem[i]; }
//! returns reference to element
FEElement& ElementRef(int n) override { return m_Elem[n]; }
const FEElement& ElementRef(int n) const override { return m_Elem[n]; }
// Create material point data for this surface
virtual FEMaterialPoint* CreateMaterialPoint();
void CreateMaterialPointData();
public:
// Get current coordinates
void GetNodalCoordinates(FELineElement& el, vec3d* rt);
// Get reference coordinates
void GetReferenceNodalCoordinates(FELineElement& el, vec3d* rt);
protected:
bool Create(FESegmentSet& es, int elemType);
protected:
std::vector<FELineElement> m_Elem;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/Integrate.cpp | .cpp | 6,678 | 241 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "Integrate.h"
#include "FESolidDomain.h"
#include "FELinearSystem.h"
#include "FESolver.h"
//-----------------------------------------------------------------------------
void FECORE_API IntegrateBDB(FESolidDomain& dom, FESolidElement& el, double D, matrix& ke)
{
// vector to store global shape functions
const int EN = FEElement::MAX_NODES;
vec3d G[EN];
// loop over all integration points
const double *gw = el.GaussWeights();
int ne = el.Nodes();
int ni = el.GaussPoints();
for (int n = 0; n<ni; ++n)
{
// calculate jacobian
double detJt = dom.ShapeGradient(el, n, G);
// form the matrix
for (int i = 0; i<ne; ++i)
{
for (int j = 0; j<ne; ++j)
{
ke[i][j] += (G[i]*G[j])*(D*detJt*gw[n]);
}
}
}
}
//-----------------------------------------------------------------------------
void FECORE_API IntegrateBDB(FESolidDomain& dom, FESolidElement& el, const mat3ds& D, matrix& ke)
{
// vector to store global shape functions
const int EN = FEElement::MAX_NODES;
vec3d G[EN];
// loop over all integration points
const double *gw = el.GaussWeights();
int ne = el.Nodes();
int ni = el.GaussPoints();
for (int n = 0; n<ni; ++n)
{
// calculate jacobian
double detJt = dom.ShapeGradient(el, n, G);
// form the matrix
for (int i = 0; i<ne; ++i)
{
for (int j = 0; j<ne; ++j)
{
ke[i][j] += (G[i] * (D * G[j]))*(detJt*gw[n]);
}
}
}
}
//-----------------------------------------------------------------------------
FECORE_API void IntegrateBDB(FESolidDomain& dom, FESolidElement& el, std::function<mat3ds(const FEMaterialPoint& mp)> D, matrix& ke)
{
// vector to store global shape functions
const int EN = FEElement::MAX_NODES;
vec3d G[EN];
// loop over all integration points
const double *gw = el.GaussWeights();
int ne = el.Nodes();
int ni = el.GaussPoints();
for (int n = 0; n<ni; ++n)
{
// get the material point
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
// calculate jacobian
double detJt = dom.ShapeGradient(el, n, G);
// calculate D at this point
mat3ds Dn = D(mp);
// form the matrix
for (int i = 0; i<ne; ++i)
{
for (int j = 0; j<ne; ++j)
{
ke[i][j] += (G[i] * (Dn * G[j]))*(detJt*gw[n]);
}
}
}
}
//-----------------------------------------------------------------------------
void FECORE_API IntegrateNCN(FESolidDomain& dom, FESolidElement& el, double C, matrix& ke)
{
// number of nodes
int ne = el.Nodes();
// jacobian
double Ji[3][3];
// loop over all integration points
const double *gw = el.GaussWeights();
int ni = el.GaussPoints();
for (int n = 0; n<ni; ++n)
{
// calculate jacobian
double detJt = dom.invjact(el, Ji, n);
// shape function values at integration point n
double* H = el.H(n);
for (int i = 0; i<ne; ++i)
{
for (int j = 0; j<ne; ++j)
{
ke[i][j] += H[i] * H[j]*C*detJt*gw[n];
}
}
}
}
//-----------------------------------------------------------------------------
// Generice integrator class for solid domains
FECORE_API void AssembleSolidDomain(FESolidDomain& dom, FELinearSystem& ls, std::function<void(FESolidElement& el, matrix& ke)> elementIntegrand)
{
// loop over all elements in domain
int NE = dom.Elements();
#pragma omp parallel for shared (NE)
for (int i = 0; i<NE; ++i)
{
FESolidElement& el = dom.Element(i);
int ndofs = dom.GetElementDofs(el);
// build the element stiffness matrix
FEElementMatrix ke(ndofs, ndofs);
elementIntegrand(el, ke);
// set up the LM matrix
vector<int> lm;
dom.UnpackLM(el, lm);
// assemble into global matrix
ke.SetNodes(el.m_node);
ke.SetIndices(lm);
ls.Assemble(ke);
}
}
//-----------------------------------------------------------------------------
// Generic integrator class for solid domains
FECORE_API void AssembleSolidDomain(FESolidDomain& dom, FEGlobalVector& R, std::function<void(FESolidElement& el, vector<double>& fe)> elementIntegrand)
{
int NE = dom.Elements();
#pragma omp parallel for
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int ndofs = dom.GetElementDofs(el);
// get element contribution
vector<double> fe(ndofs, 0.0);
elementIntegrand(el, fe);
// assemble into RHS
vector<int> lm;
dom.UnpackLM(el, lm);
R.Assemble(lm, fe);
}
}
//-----------------------------------------------------------------------------
// Generice integrator class for solid domains
FECORE_API void IntegrateSolidDomain(FESolidDomain& dom, FELinearSystem& ls, std::function<void(FEMaterialPoint& mp, matrix& ke)> elementIntegrand)
{
// loop over all elements in domain
int NE = dom.Elements();
#pragma omp parallel for shared (NE)
for (int i = 0; i<NE; ++i)
{
FESolidElement& el = dom.Element(i);
int ndofs = dom.GetElementDofs(el);
// build the element stiffness matrix
FEElementMatrix ke(ndofs, ndofs);
ke.zero();
matrix kn(ndofs, ndofs);
// loop over all integration points
int nint = el.GaussPoints();
double* w = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
// evaluate the integration point's contribution
elementIntegrand(mp, kn);
// add it to the element matrix
ke.adds(kn, w[n]);
}
// set up the LM matrix
vector<int> lm;
dom.UnpackLM(el, lm);
// assemble into global matrix
ke.SetNodes(el.m_node);
ke.SetIndices(lm);
ls.Assemble(ke);
}
} | C++ |
3D | febiosoftware/FEBio | FECore/FEEdgeLoad.cpp | .cpp | 1,823 | 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.*/
#include "stdafx.h"
#include "FEEdgeLoad.h"
#include "FEEdge.h"
//-----------------------------------------------------------------------------
FEEdgeLoad::FEEdgeLoad(FEModel* pfem) : FEModelLoad(pfem)
{
m_pedge = nullptr;
}
FEEdgeLoad::~FEEdgeLoad(void)
{
}
//! Set the edge to apply the load to
void FEEdgeLoad::SetEdge(FEEdge* pe)
{
m_pedge = pe;
}
//! Get the edge
FEEdge& FEEdgeLoad::Edge()
{
return *m_pedge;
}
void FEEdgeLoad::Serialize(DumpStream& ar)
{
FEModelLoad::Serialize(ar);
FEEdge& e = Edge();
e.Serialize(ar);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEVec3dValuator.h | .h | 2,133 | 64 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEValuator.h"
#include "FEDataMap.h"
#include "MathObject.h"
//---------------------------------------------------------------------------------------
// Base class for evaluating vec3d parameters
class FECORE_API FEVec3dValuator : public FEValuator
{
FECORE_SUPER_CLASS(FEVEC3DVALUATOR_ID)
FECORE_BASE_CLASS(FEVec3dValuator)
public:
FEVec3dValuator(FEModel* fem);
public:
// evaluate value at a material point
virtual vec3d operator()(const FEMaterialPoint& pt) = 0;
// create a copy of the valuator
virtual FEVec3dValuator* copy() = 0;
// is the valuator constant
virtual bool isConst() { return false; }
// return the const value
virtual vec3d* constValue() { return nullptr; }
// return a unit vector
vec3d unitVector(const FEMaterialPoint& pt)
{
vec3d v = operator () (pt);
return v.Normalized();
}
};
| Unknown |
3D | febiosoftware/FEBio | FECore/ad2.h | .h | 8,456 | 400 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "tens4d.h"
#include "fecore_api.h"
#include <functional>
namespace ad2 {
struct number {
double r, d1, d2, dd;
number() : r(0.0), d1(0.0), d2(0.0), dd(0.0) {}
number(double v, double v1 = 0, double v2=0, double ddv = 0) : r(v), d1(v1), d2(v2), dd(ddv) {}
void operator = (const double& a) { r = a; d1 = d2 = dd = 0.0; }
};
// addition
inline number operator + (const number& a, const number& b)
{
return number(a.r + b.r, a.d1 + b.d1, a.d2 + b.d2, a.dd + b.dd);
}
inline number operator + (double a, const number& b)
{
return number(a + b.r, b.d1, b.d2, b.dd);
}
inline number operator + (const number& a, double b)
{
return number(a.r + b, a.d1, a.d2, a.dd);
}
// subtraction
inline number operator - (const number& a, const number& b)
{
return number(a.r - b.r, a.d1 - b.d1, a.d2 - b.d2, a.dd - b.dd);
}
inline number operator - (double a, const number& b)
{
return number(a - b.r, -b.d1, -b.d2, -b.dd);
}
inline number operator - (const number& a, double b)
{
return number(a.r - b, a.d1, a.d2, a.dd);
}
// multiplication
inline number operator * (const number& a, const number& b)
{
return number(
a.r * b.r,
a.d1 * b.r + a.r * b.d1,
a.d2 * b.r + a.r * b.d2,
a.dd * b.r + a.d1 * b.d2 + a.d2 * b.d1 + a.r * b.dd
);
}
inline number operator * (double a, const number& b)
{
return number(
a * b.r,
a * b.d1,
a * b.d2,
a * b.dd
);
}
inline number operator * (const number& a, double b)
{
return number(
a.r * b,
a.d1 * b,
a.d2 * b,
a.dd * b
);
}
// invert
inline number inv(const number& a)
{
return number(
1.0/a.r,
-a.d1/(a.r*a.r),
-a.d2/(a.r*a.r),
((2.0 * a.d1 * a.d2) / a.r - a.dd)/(a.r*a.r)
);
}
// division
inline number operator / (const number& a, const number& b)
{
return a*inv(b);
}
inline number operator / (double a, const number& b)
{
return a * inv(b);
}
inline number operator / (const number& a, double b)
{
return number(
a.r / b,
a.d1 / b,
a.d2 / b,
a.dd / b
);
}
// math functions
inline number log(const number& a)
{
return number(
::log(a.r),
a.d1 / a.r,
a.d2 / a.r,
(a.dd - a.d1*a.d2/a.r)/a.r
);
}
inline number sqrt(const number& a)
{
double s = ::sqrt(a.r);
return number(
s,
0.5 * a.d1 / s,
0.5 * a.d2 / s,
0.5 * a.dd / s - 0.25*a.d1*a.d2/(s*s*s)
);
}
inline number exp(const number& a)
{
double e = ::exp(a.r);
return number(
e,
e * a.d1,
e * a.d2,
e * (a.d1*a.d2 + a.dd)
);
}
inline number pow(const number& a, double e)
{
if (e == 0.0) return number(1.0);
double b = ::pow(a.r, e - 2.0);
return number(
b * a.r * a.r,
e * a.r * b * a.d1,
e * a.r * b * a.d2,
e * b * ((e - 1.0)* a.d1 * a.d2 + a.r * a.dd)
);
}
inline number sin(const number& a)
{
double sa = ::sin(a.r);
double ca = ::cos(a.r);
return number(
sa,
ca * a.d1,
ca * a.d2,
ca * a.dd - sa * a.d1 * a.d2
);
}
inline number cos(const number& a)
{
double sa = ::sin(a.r);
double ca = ::cos(a.r);
return number(
ca,
-sa*a.d1,
-sa*a.d2,
-sa*a.dd - ca*a.d1*a.d2
);
}
inline number cosh(const number& a)
{
double sa = ::sinh(a.r);
double ca = ::cosh(a.r);
return number(
ca,
sa * a.d1,
sa * a.d2,
ca * a.d1 * a.d2 + sa * a.dd
);
}
inline number sinh(const number& a)
{
double sa = ::sinh(a.r);
double ca = ::cosh(a.r);
return number(
sa,
ca * a.d1,
ca * a.d2,
sa * a.d1 * a.d2 + ca * a.dd
);
}
struct mat3ds
{
// This enumeration can be used to remember the order
// in which the components are stored.
enum {
XX = 0,
XY = 1,
YY = 2,
XZ = 3,
YZ = 4,
ZZ = 5
};
number m[6]; // {xx,xy,yy,xz,yz,zz}
number& operator [] (size_t n) { return m[n]; }
mat3ds() {}
mat3ds(
const number& xx,
const number& yy,
const number& zz,
const number& xy,
const number& yz,
const number& xz)
{
m[XX] = xx;
m[YY] = yy;
m[ZZ] = zz;
m[XY] = xy;
m[YZ] = yz;
m[XZ] = xz;
}
mat3ds(const ::mat3ds& C)
{
m[0] = C.xx();
m[1] = C.xy();
m[2] = C.yy();
m[3] = C.xz();
m[4] = C.yz();
m[5] = C.zz();
}
mat3ds(double d)
{
m[XX].r = d;
m[YY].r = d;
m[ZZ].r = d;
}
number& xx() { return m[XX]; }
number& yy() { return m[YY]; }
number& zz() { return m[ZZ]; }
number& xy() { return m[XY]; }
number& yz() { return m[YZ]; }
number& xz() { return m[XZ]; }
const number& xx() const { return m[XX]; }
const number& yy() const { return m[YY]; }
const number& zz() const { return m[ZZ]; }
const number& xy() const { return m[XY]; }
const number& yz() const { return m[YZ]; }
const number& xz() const { return m[XZ]; }
// functions
number tr() const { return m[XX] + m[YY] + m[ZZ]; }
number det() const {
return (m[XX] * (m[YY] * m[ZZ] - m[YZ] * m[YZ])
+ m[XY] * (m[YZ] * m[XZ] - m[ZZ] * m[XY])
+ m[XZ] * (m[XY] * m[YZ] - m[YY] * m[XZ]));
}
// double contraction
number dotdot(const mat3ds& B) const
{
const number* n = B.m;
return m[XX] * n[XX] + m[YY] * n[YY] + m[ZZ] * n[ZZ] + 2.0 * (m[XY] * n[XY] + m[YZ] * n[YZ] + m[XZ] * n[XZ]);
}
mat3ds inverse() const
{
number Di = 1.0 / det();
return mat3ds(
Di * (m[YY] * m[ZZ] - m[YZ] * m[YZ]),
Di * (m[XX] * m[ZZ] - m[XZ] * m[XZ]),
Di * (m[XX] * m[YY] - m[XY] * m[XY]),
Di * (m[XZ] * m[YZ] - m[XY] * m[ZZ]),
Di * (m[XY] * m[XZ] - m[XX] * m[YZ]),
Di * (m[XY] * m[YZ] - m[YY] * m[XZ]));
}
// return the square
mat3ds sqr() const
{
return mat3ds(
m[XX] * m[XX] + m[XY] * m[XY] + m[XZ] * m[XZ],
m[XY] * m[XY] + m[YY] * m[YY] + m[YZ] * m[YZ],
m[XZ] * m[XZ] + m[YZ] * m[YZ] + m[ZZ] * m[ZZ],
m[XX] * m[XY] + m[XY] * m[YY] + m[XZ] * m[YZ],
m[XY] * m[XZ] + m[YY] * m[YZ] + m[YZ] * m[ZZ],
m[XX] * m[XZ] + m[XY] * m[YZ] + m[XZ] * m[ZZ]
);
}
};
// arithmetic operations
inline mat3ds operator + (const mat3ds& A, const mat3ds& B)
{
return mat3ds(
A.xx() + B.xx(),
A.yy() + B.yy(),
A.zz() + B.zz(),
A.xy() + B.xy(),
A.yz() + B.yz(),
A.xz() + B.xz()
);
}
inline mat3ds operator - (const mat3ds& A, const mat3ds& B)
{
return mat3ds(
A.xx() - B.xx(),
A.yy() - B.yy(),
A.zz() - B.zz(),
A.xy() - B.xy(),
A.yz() - B.yz(),
A.xz() - B.xz()
);
}
inline mat3ds operator * (const mat3ds& A, double b)
{
return mat3ds(
A.xx() * b,
A.yy() * b,
A.zz() * b,
A.xy() * b,
A.yz() * b,
A.xz() * b
);
}
inline mat3ds operator * (double a, const mat3ds& B)
{
return mat3ds(
B.xx() * a,
B.yy() * a,
B.zz() * a,
B.xy() * a,
B.yz() * a,
B.xz() * a
);
}
inline mat3ds operator * (const mat3ds& A, const number& b)
{
return mat3ds(
A.xx() * b,
A.yy() * b,
A.zz() * b,
A.xy() * b,
A.yz() * b,
A.xz() * b
);
}
FECORE_API double Evaluate(std::function<number(mat3ds& C)> W, const ::mat3ds& C);
FECORE_API ::mat3ds Derive(std::function<number(mat3ds& C)> W, const ::mat3ds& C);
FECORE_API ::tens4ds Derive2(std::function<number(mat3ds& C)> W, const ::mat3ds& C);
}
| Unknown |
3D | febiosoftware/FEBio | FECore/tens3drs.hpp | .hpp | 10,232 | 276 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 tens3drs.h
// Users should not include this file manually!
#include "mat3d.h"
// access operator
inline double tens3drs::operator () (int i, int j, int k) const
{
const int m[3][3] = {{0,1,2},{1,3,4},{2,4,5}};
return d[6*i + m[j][k] ];
}
// access operator
inline double& tens3drs::operator () (int i, int j, int k)
{
const int m[3][3] = {{0,1,2},{1,3,4},{2,4,5}};
return d[6*i + m[j][k] ];
}
inline tens3drs::tens3drs(double a)
{
int nnz = tensor_traits<tens3drs>::NNZ;
for (int i = 0; i < nnz; ++i) d[i] = a;
}
// contract the right two legs by the dyad formed by a vector xi = Gijk*Xj*Xk
inline vec3d tens3drs::contractdyad1(const vec3d& v) const
{
vec3d x;
x.x = d[ 0]*v.x*v.x + 2*d[ 1]*v.x*v.y + 2*d[ 2]*v.x*v.z + d[ 3]*v.y*v.y + 2*d[ 4]*v.y*v.z + d[ 5]*v.z*v.z;
x.y = d[ 6]*v.x*v.x + 2*d[ 7]*v.x*v.y + 2*d[ 8]*v.x*v.z + d[ 9]*v.y*v.y + 2*d[10]*v.y*v.z + d[11]*v.z*v.z;
x.z = d[12]*v.x*v.x + 2*d[13]*v.x*v.y + 2*d[14]*v.x*v.z + d[15]*v.y*v.y + 2*d[16]*v.y*v.z + d[17]*v.z*v.z;
return x;
}
// contract the right two legs by a symmetric 2o tensor xi = Gijk*Sjk
inline vec3d tens3drs::contract2s(const mat3ds& s) const
{
vec3d x;
x.x = d[ 0]*s.xx() + 2*d[ 1]*s.xy() + 2*d[ 2]*s.xz() + d[ 3]*s.yy() + 2*d[ 4]*s.yz() + d[ 5]*s.zz();
x.y = d[ 6]*s.xx() + 2*d[ 7]*s.xy() + 2*d[ 8]*s.xz() + d[ 9]*s.yy() + 2*d[10]*s.yz() + d[11]*s.zz();
x.z = d[12]*s.xx() + 2*d[13]*s.xy() + 2*d[14]*s.xz() + d[15]*s.yy() + 2*d[16]*s.yz() + d[17]*s.zz();
return x;
}
// triple contraction by a similar 3o tensor m = Gijk*Hijk
inline double tens3drs::tripledot(const tens3drs& H) const
{
const double* h = H.d;
return d[ 0]*h[ 0] + 2*d[ 1]*h[ 1] + 2*d[ 2]*h[ 2] + d[ 3]*h[ 3] + 2*d[ 4]*h[ 4] + d[ 5]*h[ 5]
+ d[ 6]*h[ 6] + 2*d[ 7]*h[ 7] + 2*d[ 8]*h[ 8] + d[ 9]*h[ 9] + 2*d[10]*h[10] + d[11]*h[11]
+ d[12]*h[12] + 2*d[13]*h[13] + 2*d[14]*h[14] + d[15]*h[15] + 2*d[16]*h[16] + d[17]*h[17];
}
// contract the right two legs by the dyad formed by a vector xi = Gijk*Vj*Wk
inline vec3d tens3drs::contractdyad2(const vec3d& v, const vec3d& w)
{
vec3d x;
x.x = d[ 0]*v.x*w.x + d[ 1]*(v.x*w.y + v.y*w.x) + d[ 2]*(v.x*w.z + v.z*w.x) + d[ 3]*v.y*w.y + d[ 4]*(v.y*w.z + v.z*w.y) + d[ 5]*v.z*w.z;
x.y = d[ 6]*v.x*w.x + d[ 7]*(v.x*w.y + v.y*w.x) + d[ 8]*(v.x*w.z + v.z*w.x) + d[ 9]*v.y*w.y + d[10]*(v.y*w.z + v.z*w.y) + d[11]*v.z*w.z;
x.z = d[12]*v.x*w.x + d[13]*(v.x*w.y + v.y*w.x) + d[14]*(v.x*w.z + v.z*w.x) + d[15]*v.y*w.y + d[16]*(v.y*w.z + v.z*w.y) + d[17]*v.z*w.z;
return x;
}
// calculates the dyadic product T_ijk = l_i*r_j*r_k
inline tens3drs dyad3rs(const vec3d& l, const vec3d& r)
{
tens3drs a;
a.d[ 0] = l.x*r.x*r.x;
a.d[ 1] = l.x*r.x*r.y;
a.d[ 2] = l.x*r.x*r.z;
a.d[ 3] = l.x*r.y*r.y;
a.d[ 4] = l.x*r.y*r.z;
a.d[ 5] = l.x*r.z*r.z;
a.d[ 6] = l.y*r.x*r.x;
a.d[ 7] = l.y*r.x*r.y;
a.d[ 8] = l.y*r.x*r.z;
a.d[ 9] = l.y*r.y*r.y;
a.d[10] = l.y*r.y*r.z;
a.d[11] = l.y*r.z*r.z;
a.d[12] = l.z*r.x*r.x;
a.d[13] = l.z*r.x*r.y;
a.d[14] = l.z*r.x*r.z;
a.d[15] = l.z*r.y*r.y;
a.d[16] = l.z*r.y*r.z;
a.d[17] = l.z*r.z*r.z;
return a;
}
// calculates the dyadic product T_ijk = 1/2*(L_ij*r_k + L_ik*r_j)
inline tens3drs dyad3rs(const mat3d& L, const vec3d& r)
{
tens3drs a;
a.d[0] = L(0, 0)*r.x;
a.d[1] = (L(0, 0)*r.y + L(0, 1)*r.x)*0.5;
a.d[2] = (L(0, 0)*r.z + L(0, 2)*r.x)*0.5;
a.d[3] = L(0, 1)*r.y;
a.d[4] = (L(0, 1)*r.z + L(0, 2)*r.y)*0.5;
a.d[5] = L(0, 2)*r.z;
a.d[ 6] = L(1, 0)*r.x;
a.d[ 7] = (L(1, 0)*r.y + L(1, 1)*r.x)*0.5;
a.d[ 8] = (L(1, 0)*r.z + L(1, 2)*r.x)*0.5;
a.d[ 9] = L(1, 1)*r.y;
a.d[10] = (L(1, 1)*r.z + L(1, 2)*r.y)*0.5;
a.d[11] = L(1, 2)*r.z;
a.d[12] = L(2, 0)*r.x;
a.d[13] = (L(2, 0)*r.y + L(2, 1)*r.x)*0.5;
a.d[14] = (L(2, 0)*r.z + L(2, 2)*r.x)*0.5;
a.d[15] = L(2, 1)*r.y;
a.d[16] = (L(2, 1)*r.z + L(2, 2)*r.y)*0.5;
a.d[17] = L(2, 2)*r.z;
return a;
}
// calculate the transpose ((G_iJK)T = G_KJi)
inline tens3dls tens3drs::transpose()
{
tens3dls GLC;
GLC.d[ 0] = d[ 0];
GLC.d[ 3] = d[ 1];
GLC.d[ 6] = d[ 2];
GLC.d[ 9] = d[ 3];
GLC.d[12] = d[ 4];
GLC.d[15] = d[ 5];
GLC.d[ 1] = d[ 6];
GLC.d[ 4] = d[ 7];
GLC.d[ 7] = d[ 8];
GLC.d[10] = d[ 9];
GLC.d[13] = d[10];
GLC.d[16] = d[11];
GLC.d[ 2] = d[12];
GLC.d[ 5] = d[13];
GLC.d[ 8] = d[14];
GLC.d[11] = d[15];
GLC.d[14] = d[16];
GLC.d[17] = d[17];
return GLC;
}
// contract each leg by a 2o tensor (intended to calculate the inverse deformation hessian according to Finv_Ii * G_iJK * Finv_Jj * Fin_Kk)
inline void tens3drs::contractleg2(const mat3d& F, int leg)
{
tens3drs G = *this;
if (leg == 1)
{
d[0] = F(0,0)*G.d[0] + F(0,1)*G.d[6] + F(0,2)*G.d[12];
d[1] = F(0,0)*G.d[1] + F(0,1)*G.d[7] + F(0,2)*G.d[13];
d[2] = F(0,0)*G.d[2] + F(0,1)*G.d[8] + F(0,2)*G.d[14];
d[3] = F(0,0)*G.d[3] + F(0,1)*G.d[9] + F(0,2)*G.d[15];
d[4] = F(0,0)*G.d[4] + F(0,1)*G.d[10] + F(0,2)*G.d[16];
d[5] = F(0,0)*G.d[5] + F(0,1)*G.d[11] + F(0,2)*G.d[17];
d[6] = F(1,0)*G.d[0] + F(1,1)*G.d[6] + F(1,2)*G.d[12];
d[7] = F(1,0)*G.d[1] + F(1,1)*G.d[7] + F(1,2)*G.d[13];
d[8] = F(1,0)*G.d[2] + F(1,1)*G.d[8] + F(1,2)*G.d[14];
d[9] = F(1,0)*G.d[3] + F(1,1)*G.d[9] + F(1,2)*G.d[15];
d[10] = F(1,0)*G.d[4] + F(1,1)*G.d[10] + F(1,2)*G.d[16];
d[11] = F(1,0)*G.d[5] + F(1,1)*G.d[11] + F(1,2)*G.d[17];
d[12] = F(2,0)*G.d[0] + F(2,1)*G.d[6] + F(2,2)*G.d[12];
d[13] = F(2,0)*G.d[1] + F(2,1)*G.d[7] + F(2,2)*G.d[13];
d[14] = F(2,0)*G.d[2] + F(2,1)*G.d[8] + F(2,2)*G.d[14];
d[15] = F(2,0)*G.d[3] + F(2,1)*G.d[9] + F(2,2)*G.d[15];
d[16] = F(2,0)*G.d[4] + F(2,1)*G.d[10] + F(2,2)*G.d[16];
d[17] = F(2,0)*G.d[5] + F(2,1)*G.d[11] + F(2,2)*G.d[17];
}
else if (leg == 2)
{
d[0] = G.d[0]*F(0,0) + G.d[1]*F(1,0) + G.d[2]*F(2,0);
d[1] = G.d[1]*F(0,0) + G.d[3]*F(1,0) + G.d[4]*F(2,0);
d[2] = G.d[2]*F(0,0) + G.d[4]*F(1,0) + G.d[5]*F(2,0);
d[3] = G.d[1]*F(0,1) + G.d[3]*F(1,1) + G.d[4]*F(2,1);
d[4] = G.d[2]*F(0,1) + G.d[4]*F(1,1) + G.d[5]*F(2,1);
d[5] = G.d[2]*F(0,2) + G.d[4]*F(1,2) + G.d[5]*F(2,2);
d[6] = G.d[6]*F(0,0) + G.d[7]*F(1,0) + G.d[8]*F(2,0);
d[7] = G.d[7]*F(0,0) + G.d[9]*F(1,0) + G.d[10]*F(2,0);
d[8] = G.d[8]*F(0,0) + G.d[10]*F(1,0) + G.d[11]*F(2,0);
d[9] = G.d[7]*F(0,1) + G.d[9]*F(1,1) + G.d[10]*F(2,1);
d[10] = G.d[8]*F(0,1) + G.d[10]*F(1,1) + G.d[11]*F(2,1);
d[11] = G.d[8]*F(0,2) + G.d[10]*F(1,2) + G.d[11]*F(2,2);
d[12] = G.d[12]*F(0,0) + G.d[13]*F(1,0) + G.d[4]*F(2,0);
d[13] = G.d[13]*F(0,0) + G.d[14]*F(1,0) + G.d[16]*F(2,0);
d[14] = G.d[14]*F(0,0) + G.d[16]*F(1,0) + G.d[17]*F(2,0);
d[15] = G.d[13]*F(0,1) + G.d[15]*F(1,1) + G.d[16]*F(2,1);
d[16] = G.d[14]*F(0,1) + G.d[16]*F(1,1) + G.d[17]*F(2,1);
d[17] = G.d[14]*F(0,2) + G.d[16]*F(1,2) + G.d[17]*F(2,2);
}
else if (leg == 3)
{
d[0] = G.d[0]*F(0,0) + G.d[1]*F(1,0) + G.d[2]*F(2,0);
d[1] = G.d[0]*F(0,1) + G.d[1]*F(1,1) + G.d[2]*F(2,1);
d[2] = G.d[0]*F(0,2) + G.d[1]*F(1,2) + G.d[2]*F(2,2);
d[3] = G.d[1]*F(0,1) + G.d[3]*F(1,1) + G.d[4]*F(2,1);
d[4] = G.d[1]*F(0,2) + G.d[3]*F(1,2) + G.d[4]*F(2,2);
d[5] = G.d[2]*F(0,2) + G.d[4]*F(1,2) + G.d[5]*F(2,2);
d[6] = G.d[6]*F(0,0) + G.d[7]*F(1,0) + G.d[8]*F(2,0);
d[7] = G.d[6]*F(0,1) + G.d[7]*F(1,1) + G.d[8]*F(2,1);
d[8] = G.d[6]*F(0,2) + G.d[7]*F(1,2) + G.d[8]*F(2,2);
d[9] = G.d[7]*F(0,1) + G.d[9]*F(1,1) + G.d[10]*F(2,1);
d[10] = G.d[7]*F(0,2) + G.d[9]*F(1,2) + G.d[10]*F(2,2);
d[11] = G.d[8]*F(0,2) + G.d[10]*F(1,2) + G.d[11]*F(2,2);
d[12] = G.d[12]*F(0,0) + G.d[13]*F(1,0) + G.d[14]*F(2,0);
d[13] = G.d[12]*F(0,1) + G.d[13]*F(1,1) + G.d[14]*F(2,1);
d[14] = G.d[12]*F(0,2) + G.d[13]*F(1,2) + G.d[14]*F(2,2);
d[15] = G.d[13]*F(0,1) + G.d[15]*F(1,1) + G.d[16]*F(2,1);
d[16] = G.d[13]*F(0,2) + G.d[15]*F(1,2) + G.d[16]*F(2,2);
d[17] = G.d[14]*F(0,2) + G.d[16]*F(1,2) + G.d[17]*F(2,2);
}
}
// multiply by a 2o tensor on the left (F_Ii * G_iJK)
inline tens3drs operator * (const mat3d& F, const tens3drs& t)
{
tens3drs G;
const double* d = t.d;
G.d[ 0] = F(0,0)*d[0] + F(0,1)*d[ 6] + F(0,2)*d[12];
G.d[ 1] = F(0,0)*d[1] + F(0,1)*d[ 7] + F(0,2)*d[13];
G.d[ 2] = F(0,0)*d[2] + F(0,1)*d[ 8] + F(0,2)*d[14];
G.d[ 3] = F(0,0)*d[3] + F(0,1)*d[ 9] + F(0,2)*d[15];
G.d[ 4] = F(0,0)*d[4] + F(0,1)*d[10] + F(0,2)*d[16];
G.d[ 5] = F(0,0)*d[5] + F(0,1)*d[11] + F(0,2)*d[17];
G.d[ 6] = F(1,0)*d[0] + F(1,1)*d[ 6] + F(1,2)*d[12];
G.d[ 7] = F(1,0)*d[1] + F(1,1)*d[ 7] + F(1,2)*d[13];
G.d[ 8] = F(1,0)*d[2] + F(1,1)*d[ 8] + F(1,2)*d[14];
G.d[ 9] = F(1,0)*d[3] + F(1,1)*d[ 9] + F(1,2)*d[15];
G.d[10] = F(1,0)*d[4] + F(1,1)*d[10] + F(1,2)*d[16];
G.d[11] = F(1,0)*d[5] + F(1,1)*d[11] + F(1,2)*d[17];
G.d[12] = F(2,0)*d[0] + F(2,1)*d[ 6] + F(2,2)*d[12];
G.d[13] = F(2,0)*d[1] + F(2,1)*d[ 7] + F(2,2)*d[13];
G.d[14] = F(2,0)*d[2] + F(2,1)*d[ 8] + F(2,2)*d[14];
G.d[15] = F(2,0)*d[3] + F(2,1)*d[ 9] + F(2,2)*d[15];
G.d[16] = F(2,0)*d[4] + F(2,1)*d[10] + F(2,2)*d[16];
G.d[17] = F(2,0)*d[5] + F(2,1)*d[11] + F(2,2)*d[17];
return G;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMeshAdaptor.cpp | .cpp | 3,713 | 141 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMeshAdaptor.h"
#include "FESolidDomain.h"
#include "FEElementList.h"
#include "FEModel.h"
FEMeshAdaptor::FEMeshAdaptor(FEModel* fem) : FEStepComponent(fem)
{
m_elemSet = nullptr;
}
void FEMeshAdaptor::SetElementSet(FEElementSet* elemSet)
{
m_elemSet = elemSet;
}
FEElementSet* FEMeshAdaptor::GetElementSet()
{
return m_elemSet;
}
void FEMeshAdaptor::UpdateModel()
{
FEModel& fem = *GetFEModel();
fem.Reactivate();
}
// helper function for projecting integration point data to nodes
void projectToNodes(FEMesh& mesh, std::vector<double>& nodeVals, std::function<double(FEMaterialPoint& mp)> f)
{
// temp storage
double si[FEElement::MAX_INTPOINTS];
double sn[FEElement::MAX_NODES];
// allocate nodeVals and create valence array (tag)
int NN = mesh.Nodes();
vector<int> tag(NN, 0);
nodeVals.assign(NN, 0.0);
// loop over all elements
int NE = mesh.Elements();
FEElementList EL(mesh);
FEElementList::iterator it = EL.begin();
for (int i = 0; i < NE; ++i, ++it)
{
FEElement& e = *it;
int ne = e.Nodes();
int ni = e.GaussPoints();
// get the integration point values
for (int k = 0; k < ni; ++k)
{
FEMaterialPoint& mp = *e.GetMaterialPoint(k);
si[k] = f(mp);
}
// project to nodes
e.project_to_nodes(si, sn);
for (int j = 0; j < ne; ++j)
{
nodeVals[e.m_node[j]] += sn[j];
tag[e.m_node[j]]++;
}
}
for (int i = 0; i < NN; ++i)
{
if (tag[i] > 0) nodeVals[i] /= (double)tag[i];
}
}
// helper function for projecting integration point data to nodes
void projectToNodes(FEDomain& dom, std::vector<double>& nodeVals, std::function<double(FEMaterialPoint& mp)> f)
{
// temp storage
double si[FEElement::MAX_INTPOINTS];
double sn[FEElement::MAX_NODES];
// allocate nodeVals and create valence array (tag)
int NN = dom.Nodes();
vector<int> tag(NN, 0);
nodeVals.assign(NN, 0.0);
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
FEElement& e = dom.ElementRef(i);
int ne = e.Nodes();
int ni = e.GaussPoints();
// get the integration point values
for (int k = 0; k < ni; ++k)
{
FEMaterialPoint& mp = *e.GetMaterialPoint(k);
si[k] = f(mp);
}
// project to nodes
e.project_to_nodes(si, sn);
for (int j = 0; j < ne; ++j)
{
nodeVals[e.m_lnode[j]] += sn[j];
tag[e.m_node[j]]++;
}
}
for (int i = 0; i < NN; ++i)
{
if (tag[i] > 0) nodeVals[i] /= (double)tag[i];
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens6d.hpp | .hpp | 1,714 | 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.*/
#pragma once
// NOTE: This file is automatically included from tens5d.h
// Users should not include this file manually!
inline double tens6d::operator () (int i, int j, int k, int l, int m, int n) const
{
int R = 3*(3*i + j) + k;
int C = 3*(3*l + m) + n;
return d[27*C + R];
}
inline double& tens6d::operator () (int i, int j, int k, int l, int m, int n)
{
int R = 3*(3*i + j) + k;
int C = 3*(3*l + m) + n;
return d[27*C + R];
}
| Unknown |
3D | febiosoftware/FEBio | FECore/FEAnalysis.h | .h | 5,120 | 195 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "FECoreClass.h"
#include <vector>
//-----------------------------------------------------------------------------
class FEModel;
class FESolver;
class FEDomain;
class DumpStream;
class FEStepComponent;
class FETimeStepController;
//-----------------------------------------------------------------------------
//! Base class for finite element analysis
class FECORE_API FEAnalysis : public FECoreBase
{
FECORE_SUPER_CLASS(FEANALYSIS_ID)
FECORE_BASE_CLASS(FEAnalysis);
public:
//! constructor
FEAnalysis(FEModel* pfem);
//! destructor
virtual ~FEAnalysis();
//! Initialization
virtual bool Init() override;
//! Activation
virtual bool Activate();
//! See if this step is active
bool IsActive();
//! Reset analysis data
virtual void Reset();
//! Solve the analysis step
virtual bool Solve();
//! wrap it up
virtual void Deactivate();
//! Serialize data from and to a binary archive
virtual void Serialize(DumpStream& ar) override;
//! copy data from another analysis
void CopyFrom(FEAnalysis* step);
public:
void SetFESolver(FESolver* psolver);
FESolver* GetFESolver();
public:
//! Get active domains
int Domains() { return (int)m_Dom.size(); }
//! Get active domain
FEDomain* Domain(int i);
//! Add a domain
void AddDomain(int i) { m_Dom.push_back(i); }
//! clear all domains
void ClearDomains() { m_Dom.clear(); }
public:
//! add a step component
void AddStepComponent(FEStepComponent* pmc);
//! return number of model components
int StepComponents() const;
//! get a step component
FEStepComponent* GetStepComponent(int i);
public:
//! sets the plot level
void SetPlotLevel(int n);
//! sets the plot stride
void SetPlotStride(int n);
//! sets the plot range
void SetPlotRange(int n0, int n1);
//! sets the zero-state plot flag
void SetPlotZeroState(bool b);
//! sets the plot hint
void SetPlotHint(int plotHint);
//! get the plot hint
int GetPlotHint() const;
//! get the plot level
int GetPlotLevel();
//! Set the output level
void SetOutputLevel(int n);
//! Get the output level
int GetOutputLevel();
// initialize the solver
bool InitSolver();
// Call the FE Solver to solve the time step
// Returns an error code
// 0 = all is well, continue
// 1 = solver has failed, but try auto-time step
// 2 = abort
int SolveTimeStep();
public:
// --- Control Data ---
//{
int m_nanalysis; //!< analysis type
bool m_badaptorReSolve; //!< resolve analysis after mesh adaptor phase
//}
// --- Time Step Data ---
//{
int m_ntime; //!< nr of timesteps
double m_final_time; //!< end time for this time step
double m_dt; //!< current time step
double m_dt0; //!< initial time step size
double m_tstart; //!< start time
double m_tend; //!< end time
FETimeStepController* m_timeController;
//}
// --- Quasi-Newton Solver Variables ---
//{
int m_ntotrhs; //!< total nr of right hand side evaluations
int m_ntotref; //!< total nr of stiffness reformations
int m_ntotiter; //!< total nr of non-linear iterations
int m_ntimesteps; //!< time steps completed
//}
// --- I/O Data ---
//{
int m_nplot; //!< plot level
int m_noutput; //!< data output level
int m_nplot_stride; //!< stride for plotting
int m_noutput_stride; //!< stride for data output
int m_nplotRange[2]; //!< plot range
bool m_bplotZero; //!< Force plotting of time step "zero"
int m_plotHint; //!< the plot mode
//}
private:
// the FE solver
FESolver* m_psolver; //!< pointer to solver class that will solve this step.
bool m_bactive; //!< activation flag
protected:
std::vector<int> m_Dom; //!< list of active domains for this analysis
std::vector<FEStepComponent*> m_MC; //!< array of model components active during this step
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/Timer.cpp | .cpp | 4,415 | 178 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "Timer.h"
#include <stdio.h>
#include <string>
#include <chrono>
#include "FEModel.h"
using namespace std::chrono;
using dseconds = duration<double>;
// data storing timing info
struct Timer::Imp {
time_point<steady_clock> start; //!< time at start
time_point<steady_clock> stop; //!< time at last stop
time_point<steady_clock> pause; //!< time when paused
bool isRunning = false; //!< flag indicating whether start was called
dseconds total; //!< total accumulated time (between start and stop)
bool isPaused = false;
dseconds paused; //!< accumulated time while paused
Timer* parent = nullptr; // the timer that was active when this timer starts
static Timer* activeTimer;
};
Timer* Timer::Imp::activeTimer = nullptr;
Timer::Timer()
{
m = new Imp;
reset();
}
Timer::~Timer()
{
if (Imp::activeTimer == this) Imp::activeTimer = nullptr;
delete m;
}
Timer* Timer::activeTimer()
{
return Imp::activeTimer;
}
void Timer::start()
{
m->parent = m->activeTimer;
if (m->parent) m->parent->pause();
m->activeTimer = this;
m->start = steady_clock::now();
assert(m->isRunning == false);
m->isRunning = true;
}
void Timer::stop()
{
m->stop = steady_clock::now();
assert(m->isRunning == true);
m->isRunning = false;
m->total += m->stop - m->start;
assert(m->activeTimer == this);
m->activeTimer = m->parent;
if (m->parent) m->parent->unpause();
}
void Timer::pause()
{
assert(!m->isPaused);
m->pause = steady_clock::now();
m->isPaused = true;
}
void Timer::unpause()
{
assert(m->isPaused);
auto tmp = steady_clock::now();
m->paused += tmp - m->pause;
m->isPaused = false;
}
void Timer::reset()
{
m->total = dseconds(0);
m->paused = dseconds(0);
m->isRunning = false;
m->isPaused = false;
m->parent = nullptr;
if (m->activeTimer == this) m->activeTimer = nullptr;
}
bool Timer::isRunning() const { return m->isRunning; }
double Timer::peek()
{
if (m->isRunning)
{
time_point<steady_clock> tmp = steady_clock::now();
return duration_cast<dseconds>(m->total + (tmp - m->start)).count();
}
else
{
return m->total.count();
}
}
void Timer::GetTime(int& nhour, int& nmin, int& nsec)
{
double sec = peek();
GetTime(sec, nhour, nmin, nsec);
}
double Timer::GetExclusiveTime()
{
assert(!m->isPaused);
double sec = peek() - m->paused.count();
return sec;
}
void Timer::GetTime(double fsec, int& nhour, int& nmin, int& nsec)
{
nhour = (int) (fsec / 3600.0); fsec -= nhour*3600;
nmin = (int) (fsec / 60.0); fsec -= nmin*60;
nsec = (int) (fsec + 0.5);
}
double Timer::GetTime()
{
return (m->isRunning? peek() : m->total.count());
}
void Timer::time_str(char* sz)
{
int nhour, nmin, nsec;
GetTime(nhour, nmin, nsec);
snprintf(sz, 64, "%d:%02d:%02d", nhour, nmin, nsec);
}
void Timer::time_str(double fsec, char* sz)
{
int nhour, nmin, nsec;
GetTime(fsec, nhour, nmin, nsec);
snprintf(sz, 64, "%d:%02d:%02d", nhour, nmin, nsec);
}
//============================================================================
TimerTracker::TimerTracker(FEModel* fem, int timerId) : TimerTracker(fem->CollectTimings() ? fem->GetTimer(timerId) : nullptr) {}
| C++ |
3D | febiosoftware/FEBio | FECore/FETimeStepController.h | .h | 2,938 | 95 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
class FEAnalysis;
class DumpStream;
//-------------------------------------------------------------------
// Class to control the time step
class FECORE_API FETimeStepController : public FECoreBase
{
FECORE_SUPER_CLASS(FETIMECONTROLLER_ID)
FECORE_BASE_CLASS(FETimeStepController)
public:
FETimeStepController(FEModel* fem);
void SetAnalysis(FEAnalysis* step);
// initialization
bool Init() override;
//! reset
void Reset();
//! serialize
void Serialize(DumpStream& ar) override;
//! copy from
void CopyFrom(FETimeStepController* tc);
public:
//! Do a running restart
void Retry();
//! Update Time step
void AutoTimeStep(int niter);
//! Adjust for must points
double CheckMustPoints(double t, double dt);
private:
FEAnalysis* m_step;
public:
int m_nretries; //!< nr of retries tried so far
int m_maxretries; //!< max nr of retries allowed per time step
int m_naggr; //!< aggressivness parameter
int m_nmplc; //!< must point load curve number
int m_nmust; //!< current must-point
int m_next_must; //!< next must-point to visit
int m_iteopt; //!< optimum nr of iterations
double m_dtmin; //!< min time step size
double m_dtmax; //!< max time step size
double m_cutback; //!< cut back factor used in aggressive time stepping
std::vector<double> m_must_points; //!< the list of must-points
bool m_mp_repeat; //!< repeat must-points
double m_mp_toff; //!< offset for repeat must-points
private:
double m_ddt; //!< used by auto-time stepper
double m_dtp; //!< previous time step size
bool m_dtforce; //!< force max time step
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FENodeDataMap.cpp | .cpp | 3,575 | 158 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENodeDataMap.h"
#include "FENodeSet.h"
#include "FEMaterialPoint.h"
FENodeDataMap::FENodeDataMap() : FEDataMap(FE_NODE_DATA_MAP, FE_INVALID_TYPE)
{
m_nodeSet = nullptr;
}
FENodeDataMap::FENodeDataMap(FEDataType dataType) : FEDataMap(FE_NODE_DATA_MAP, dataType)
{
m_nodeSet = nullptr;
}
void FENodeDataMap::Create(const FENodeSet* nodeSet, double val)
{
m_nodeSet = nodeSet;
int nsize = nodeSet->Size();
resize(nsize, val);
}
const FENodeSet* FENodeDataMap::GetNodeSet() const
{
return m_nodeSet;
}
double FENodeDataMap::getValue(int n) const
{
return get<double>(n);
}
void FENodeDataMap::setValue(int n, double v)
{
set<double>(n, v);
}
void FENodeDataMap::setValue(int n, const vec2d& v)
{
set<vec2d>(n, v);
}
void FENodeDataMap::setValue(int n, const vec3d& v)
{
set<vec3d>(n, v);
}
void FENodeDataMap::setValue(int n, const mat3d& v)
{
set<mat3d>(n, v);
}
void FENodeDataMap::setValue(int n, const mat3ds& v)
{
set<mat3ds>(n, v);
}
void FENodeDataMap::fillValue(double v)
{
set<double>(v);
}
void FENodeDataMap::fillValue(const vec2d& v)
{
set<vec2d>(v);
}
void FENodeDataMap::fillValue(const vec3d& v)
{
set<vec3d>(v);
}
void FENodeDataMap::fillValue(const mat3d& v)
{
set<mat3d>(v);
}
void FENodeDataMap::fillValue(const mat3ds& v)
{
set<mat3ds>(v);
}
double FENodeDataMap::value(const FEMaterialPoint& mp)
{
assert(mp.m_elem == nullptr);
return get<double>(mp.m_index);
}
vec3d FENodeDataMap::valueVec3d(const FEMaterialPoint& mp)
{
assert(mp.m_elem == nullptr);
return get<vec3d>(mp.m_index);
}
mat3d FENodeDataMap::valueMat3d(const FEMaterialPoint& mp)
{
assert(mp.m_elem == nullptr);
return get<mat3d>(mp.m_index);
}
mat3ds FENodeDataMap::valueMat3ds(const FEMaterialPoint& mp)
{
assert(mp.m_elem == nullptr);
return get<mat3ds>(mp.m_index);
}
// return the item list associated with this map
FEItemList* FENodeDataMap::GetItemList()
{
return const_cast<FENodeSet*>(m_nodeSet);
}
void FENodeDataMap::Serialize(DumpStream& ar)
{
FEDataMap::Serialize(ar);
if (ar.IsShallow() == false)
{
if (ar.IsSaving())
{
// We have to cast the const away before serializing
FENodeSet* ns = const_cast<FENodeSet*>(m_nodeSet);
ar << ns;
}
else
{
FENodeSet* ns;
ar >> ns;
m_nodeSet = ns;
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/CompactSymmMatrix64.h | .h | 3,212 | 92 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "SparseMatrix.h"
#include "fecore_api.h"
//! This class stores a sparse matrix in Harwell-Boeing format (i.e. column major, lower triangular compact).
//! This class also assumes the matrix is symmetric and therefor only stores
//! the lower triangular matrix
class FECORE_API CompactSymmMatrix64 : public SparseMatrix
{
public:
//! class constructor
CompactSymmMatrix64(int offset = 0);
~CompactSymmMatrix64();
//! Create the matrix structure from the SparseMatrixProfile.
void Create(SparseMatrixProfile& mp) override;
//! Assemble an element matrix into the global matrix
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;
//! add a matrix item
void add(int i, int j, double v) override;
//! set matrix item
void set(int i, int j, double v) override;
//! get a matrix item
double get(int i, int j) override;
// alternative access
double operator ()(int i, int j) { return get(i, j); }
//! return the diagonal component
double diag(int i) override { return m_pvalues[m_ppointers[i] - m_offset]; }
//! multiply with vector
//! see if a matrix element is defined
bool check(int i, int j) override;
void Zero() override;
public:
double* Values() override { return m_pvalues; }
long long* Indices64() { return m_pindices; }
long long* Pointers64() { return m_ppointers; }
int Offset() const override { return (int)m_offset; }
private:
int* Indices() override { return nullptr; }
int* Pointers() override { return nullptr; }
bool mult_vector(double* x, double* r) override { return false; }
void Clear();
private:
double* m_pvalues; //!< matrix values
long long* m_pindices; //!< row indices
long long* m_ppointers; //!< pointers
long long m_offset; //!< adjust array indices for fortran arrays
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEConstValueVec3.h | .h | 5,402 | 199 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEVec3dValuator.h"
#include "FEModelParam.h"
//---------------------------------------------------------------------------------------
// A constant valuator
class FECORE_API FEConstValueVec3 : public FEVec3dValuator
{
public:
FEConstValueVec3(FEModel* fem);
FEVec3dValuator* copy() override;
vec3d operator()(const FEMaterialPoint& pt) override { return m_val; }
// is this a const value
bool isConst() override { return true; }
// get the const value (returns 0 if param is not const)
vec3d* constValue() override { return &m_val; }
vec3d& value() { return m_val; }
void setConstValue(const vec3d& v) { m_val = v; }
private:
vec3d m_val;
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
// The value is calculated using a mathematical expression
class FECORE_API FEMathValueVec3 : public FEVec3dValuator
{
public:
FEMathValueVec3(FEModel* fem);
vec3d operator()(const FEMaterialPoint& pt) override;
bool Init() override;
bool create(const std::string& sx, const std::string& sy, const std::string& sz);
FEVec3dValuator* copy() override;
bool UpdateParams() override;
void Serialize(DumpStream& ar) override;
private:
std::string m_expr;
FEMathExpression m_math[3];
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
// The value is determined by a data map
class FECORE_API FEMappedValueVec3 : public FEVec3dValuator
{
public:
FEMappedValueVec3(FEModel* fem);
void setDataMap(FEDataMap* val, vec3d scl = vec3d(1, 1, 1));
vec3d operator()(const FEMaterialPoint& pt) override;
FEVec3dValuator* copy() override;
void Serialize(DumpStream& ar) override;
bool Init() override;
private:
std::string m_mapName;
private:
FEDataMap* m_val;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// This class calculates a vector based on local element node numbering
class FECORE_API FELocalVectorGenerator : public FEVec3dValuator
{
public:
FELocalVectorGenerator(FEModel* fem);
bool Init() override;
vec3d operator () (const FEMaterialPoint& mp) override;
FEVec3dValuator* copy() override;
protected:
int m_n[2];
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FECylindricalVectorGenerator : public FEVec3dValuator
{
public:
FECylindricalVectorGenerator(FEModel* fem);
bool Init() override;
vec3d operator () (const FEMaterialPoint& mp) override;
FEVec3dValuator* copy() override;
protected:
vec3d m_center; // center of map
vec3d m_axis; // cylinder axis
vec3d m_vector; // reference direction
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FESphericalVectorGenerator : public FEVec3dValuator
{
public:
FESphericalVectorGenerator(FEModel* fem);
bool Init() override;
vec3d operator () (const FEMaterialPoint& mp) override;
FEVec3dValuator* copy() override;
protected:
vec3d m_center;
vec3d m_vector;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FESphericalAnglesVectorGenerator : public FEVec3dValuator
{
public:
FESphericalAnglesVectorGenerator(FEModel* fem);
vec3d operator () (const FEMaterialPoint& mp) override;
FEVec3dValuator* copy() override;
protected:
FEParamDouble m_theta; // in-plane (x,y) angle from x-axis
FEParamDouble m_phi; // angle from z-axis
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// This class is mostly to support some older formats that used the "user" fiber
// generator option. It actually doesn't generate any vectors and should not be used.
class FECORE_API FEUserVectorGenerator : public FEVec3dValuator
{
public:
FEUserVectorGenerator(FEModel* fem);
vec3d operator () (const FEMaterialPoint& mp) override;
FEVec3dValuator* copy() override;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEClosestPointProjection.cpp | .cpp | 15,398 | 555 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEClosestPointProjection.h"
#include "FEElemElemList.h"
#include "FEMesh.h"
//-----------------------------------------------------------------------------
// constructor
FEClosestPointProjection::FEClosestPointProjection(FESurface& s) : m_surf(s)
{
// set default options
m_tol = 0.01;
m_rad = 0.0; // 0 means don't use search radius
m_bspecial = false;
m_projectBoundary = false;
// calculate node-element list
m_NEL.Create(m_surf);
m_EEL.Create(&m_surf);
}
//-----------------------------------------------------------------------------
//! Initialization of data structures
bool FEClosestPointProjection::Init()
{
// initialize the nearest neighbor search
m_SNQ.Attach(&m_surf);
m_SNQ.Init();
return true;
}
//-----------------------------------------------------------------------------
// helper function for projecting a point onto an edge
bool Project2Edge(const vec3d& p0, const vec3d& p1, const vec3d& x, vec3d& q)
{
vec3d e = p1 - p0;
double D = e*e;
if (D == 0.0) return false;
double l = (e*(x - p0))/D;
q = p0 + e*l;
return (l>=0.0)&&(l<=1.0);
}
//-----------------------------------------------------------------------------
class FEPatch
{
public:
FEPatch(FESurface* surf, FEElement** ppe, int n)
{
m_surf = surf;
m_ppe = ppe;
m_nval = n;
}
bool HasNode(int n)
{
for (int i = 0; i < m_nval; ++i)
{
// get the element
FESurfaceElement& el = static_cast<FESurfaceElement&> (*m_ppe[i]);
if (el.HasNode(n))
{
return true;
}
}
return false;
}
bool Contains(FESurfaceElement& el)
{
for (int j = 0; j < m_nval; ++j)
{
FESurfaceElement& ei = *Element(j);
if ((el.Type() == ei.Type()) && (el.Nodes() == ei.Nodes()))
{
if (ei.HasNodes(&(el.m_node)[0], el.Nodes()) != 0)
{
return true;
}
}
}
return false;
}
FESurface* GetSurface() { return m_surf; }
int Size() const { return m_nval; }
FESurfaceElement* Element(int n) { return dynamic_cast<FESurfaceElement*>(m_ppe[n]); }
private:
FESurface* m_surf;
FEElement** m_ppe;
int m_nval;
};
// project a point to a patch
FESurfaceElement* projectToPatch(FEPatch& patch, const vec3d& x, vec3d& q, double& r, double& s, double tol)
{
FESurfaceElement* pemin = nullptr;
int nval = patch.Size();
FESurface* surf = patch.GetSurface();
double d2min = 0;
for (int j = 0; j < nval; ++j)
{
// get the element
FESurfaceElement& el = *patch.Element(j);
if (el.isActive())
{
int N = el.Nodes();
// project the node on the element
double p[2] = { 0, 0 };
vec3d qj = surf->ProjectToSurface(el, x, p[0], p[1]);
double d2 = (qj - x).norm2();
if (surf->IsInsideElement(el, p[0], p[1], tol))
{
if ((pemin == nullptr) || (d2 < d2min))
{
d2min = d2;
q = qj;
r = p[0];
s = p[1];
pemin = ⪙
}
}
}
}
return pemin;
}
//-----------------------------------------------------------------------------
//! Project the node on the surface. This function returns a pointer to the
//! surface element if the projection is succesful, otherwise null. The natural
//! coordinates of the projection is return in r and the spatial coordinates in q.
//!
FESurfaceElement* FEClosestPointProjection::Project(const vec3d& x, vec3d& q, vec2d& r)
{
// get the mesh
FEMesh& mesh = *m_surf.GetMesh();
// let's find the closest node
int mn = m_SNQ.Find(x);
if (mn < 0) return nullptr;
// make sure it is within the search radius
vec3d rm = m_surf.Node(mn).m_rt;
double d2 = (x - rm)*(x - rm);
if ((m_rad > 0) && (d2 > m_rad))
{
return nullptr;
}
// now that we found the closest node, lets see if we can find
// the best element
FEPatch patch(&m_surf, m_NEL.ElementList(mn), m_NEL.Valence(mn));
FESurfaceElement* pe = projectToPatch(patch, x, q, r[0], r[1], m_tol);
if (pe) return pe;
// If we get here, we did not find a facet.
// There are a couple of reasons why the search could fail:
// -1. the point cannot be projected onto the surface. For contact this implies the node is not in contact.
// -2. the projection falls outside the set of elements surrounding the closest point.
// -3. the projection falls on an edge of two faces whos normals are pointing away.
// -4. the closest node is in fact the closest point and no closer projection on face or edge can be found
//
if (m_bspecial)
{
return ProjectSpecial(mn, x, q, r);
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! This is slightly modified version of the ClosestPointProjection where the
//! node to be projected is part of this surface. This is used in some contact algorithms
//! that support self-contact. The algorithm is modified in two ways. First, a search_radius
//! limits the max distance for consideration of closest point. Second, the search point cannot
//! be part of the star of the closest point.
FESurfaceElement* FEClosestPointProjection::Project(int nodeIndex, vec3d& q, vec2d& r)
{
// get the mesh
FEMesh& mesh = *m_surf.GetMesh();
// get the node's position
vec3d x = mesh.Node(nodeIndex).m_rt;
// Find the closest surface node to x that:
// 1. is within the search radius
// 2. its star does not contain n
int mn = -1; // local index of closest node
double d2min; // min squared distance
int N = m_surf.Nodes();
double R2 = m_rad * m_rad;
for (int i = 0; i < N; ++i)
{
if (m_surf.NodeIndex(i) != nodeIndex)
{
vec3d r = m_surf.Node(i).m_rt;
double d2 = (r - x)*(r - x);
// make sure the node lies within the search radius
if ((m_rad == 0) || (d2 <= R2))
{
bool bok = true;
// The node cannot be part of the star of the closest point
FEPatch patch(&m_surf, m_NEL.ElementList(i), m_NEL.Valence(i));
if (patch.HasNode(nodeIndex))
{
bok = false;
}
// make sure the point is closer than the last one
if (bok && ((mn == -1) || (d2 < d2min)))
{
d2min = d2;
mn = i;
q = r;
}
}
}
}
if (mn == -1) return nullptr;
// now that we found the closest node, lets see if we can find
// the best element
FEPatch patch(&m_surf, m_NEL.ElementList(mn), m_NEL.Valence(mn));
FESurfaceElement* pemin = projectToPatch(patch, x, q, r[0], r[1], m_tol);
if (pemin) return pemin;
// If we get here, we did not find a facet.
// There are a couple of reasons why the search has failed:
// -1. the point cannot be projected onto the surface. For contact this implies the node is not in contact.
// -2. the projection falls outside the set of elements surrounding the closest point.
// -3. the projection falls on an edge of two faces whos normals are pointing away.
// -4. the closest node is in fact the closest point and no closer projection on face or edge can be found
//
if (m_bspecial)
{
return ProjectSpecial(mn, x, q, r);
}
return nullptr;
}
//! Project a point of a surface element onto a surface
FESurfaceElement* FEClosestPointProjection::Project(FESurfaceElement* pse, int intgrPoint, vec3d& q, vec2d& r)
{
assert(pse);
if (pse == nullptr) return nullptr;
// get the mesh
FEMesh& mesh = *m_surf.GetMesh();
// get the node's position
int nn = pse->Nodes();
vec3d re[FEElement::MAX_NODES];
for (int l = 0; l < nn; ++l) re[l] = mesh.Node(pse->m_node[l]).m_rt;
vec3d x = pse->eval(re, intgrPoint);
// if the element belongs to this surface
// we want to prevent this element and its immediate neigbors
// from being the closest.
bool check_self_projection = false;
if (ContainsElement(pse))
{
check_self_projection = true;
}
// find the closest point
int mn = -1;
double d2min;
double R2 = m_rad * m_rad;
int N = m_surf.Nodes();
for (int i = 0; i < N; ++i)
{
vec3d ri = m_surf.Node(i).m_rt;
double d2 = (ri - x)*(ri - x);
// make sure the node lies within the search radius
if ((R2 == 0) || (d2 <= R2))
{
bool bok = true;
if (check_self_projection)
{
// The pse element cannot be part of the star of the closest point
FEPatch patch(&m_surf, m_NEL.ElementList(i), m_NEL.Valence(i));
if (patch.Contains(*pse))
{
bok = false;
}
}
if (bok && ((mn == -1) || (d2 < d2min)))
{
d2min = d2;
mn = i;
q = ri;
}
}
}
if (mn == -1) return nullptr;
// mn is a local index, so get the global node number too
int m = m_surf.NodeIndex(mn);
// get the nodal position
vec3d r0 = mesh.Node(m).m_rt;
// check the distance
double D = (x - r0).norm();
if ((m_rad > 0) && (D > m_rad)) return 0;
// now that we found the closest node, lets see if we can find
// the best element
FEPatch patch(&m_surf, m_NEL.ElementList(mn), m_NEL.Valence(mn));
FESurfaceElement* pe = projectToPatch(patch, x, q, r[0], r[1], m_tol);
if (pe) return pe;
// If we get here, we did not find a facet.
// handle special cases
if (m_bspecial)
{
return ProjectSpecial(mn, x, q, r);
}
return nullptr;
}
bool FEClosestPointProjection::ContainsElement(FESurfaceElement* el)
{
if (el == nullptr) return false;
int n = el->m_lnode[0];
if ((n < 0) || (n >= m_surf.Nodes())) return false;
int nval = m_NEL.Valence(n);
FEElement** pe = m_NEL.ElementList(n);
for (int i = 0; i < nval; ++i)
{
FESurfaceElement& ei = dynamic_cast<FESurfaceElement&>(*(pe[i]));
int m = el->Nodes();
if ((el->Type() == ei.Type()) && (ei.Nodes() == m))
{
if (el->HasNodes(&ei.m_node[0], m) != 0)
{
return true;
}
}
}
return false;
}
//-------------------------------------------------------------------------------------------
// This function handles special cases for closest-point searches
// -1. the point cannot be projected onto the surface. For contact this implies the node is not in contact.
// -2. the projection falls outside the set of elements surrounding the closest point.
// -3. the projection falls on an edge of two faces whos normals are pointing away.
// -4. the closest node is in fact the closest point and no closer projection on face or edge can be found
//
FESurfaceElement* FEClosestPointProjection::ProjectSpecial(int closestPoint, const vec3d& x, vec3d& q, vec2d& r)
{
FEMesh& mesh = *m_surf.GetMesh();
int nval = m_NEL.Valence(closestPoint);
FEElement** pe = m_NEL.ElementList(closestPoint);
int* eil = m_NEL.ElementIndexList(closestPoint);
int m = m_surf.NodeIndex(closestPoint);
// get position of closest point
vec3d rm = m_surf.Node(closestPoint).m_rt;
FESurfaceElement* pemin = nullptr;
double D2min = (x - rm).norm2();
// First, let's redo the search but with a larger search radius
// NOTE: This is highly inefficient since multiple nodes and faces are visited multiple times
for (int i = 0; i < nval; ++i)
{
// get the element
FESurfaceElement& el = static_cast<FESurfaceElement&> (*pe[i]);
int N = el.Nodes();
for (int j = 0; j < N; ++j)
{
int mj = el.m_lnode[j];
int nj = m_NEL.Valence(mj);
FEElement** pej = m_NEL.ElementList(mj);
for (int k = 0; k < nj; ++k)
{
FESurfaceElement& ek = static_cast<FESurfaceElement&> (*pej[k]);
// project the node on the element
double p[2] = { 0, 0 };
vec3d qk = m_surf.ProjectToSurface(ek, x, p[0], p[1]);
if (m_surf.IsInsideElement(ek, p[0], p[1], m_tol))
{
double D2 = (x - qk).norm2();
if (D2 < D2min)
{
pemin = &ek;
q = qk;
r = vec2d(p[0], p[1]);
D2min = D2;
}
}
}
}
}
if (pemin) return pemin;
// This tries to handle some of the special cases.
// First we try to find an edge this point projects on
for (int j = 0; j < nval; ++j)
{
// get an element
FESurfaceElement& el = static_cast<FESurfaceElement&> (*pe[j]);
// loop over facet edges
int N = el.facet_edges();
for (int k = 0; k < N; ++k)
{
// if projection on boundary edges are not allowed
// make sure the element has a neighbor
if (m_projectBoundary || m_EEL.Neighbor(eil[j], k))
{
// get the two edge node indices
int en[3];
el.facet_edge(k, en);
int nk1 = en[0];
int nk2 = en[1];
// make sure one of them is our closest point
if ((nk1 == closestPoint) || (nk2 == closestPoint))
{
// try to project it on the edge
vec3d p0 = m_surf.Node(nk1).m_rt;
vec3d p1 = m_surf.Node(nk2).m_rt;
vec3d qk;
if (Project2Edge(p0, p1, x, qk))
{
double p[2] = { 0, 0 };
vec3d qp = m_surf.ProjectToSurface(el, qk, p[0], p[1]);
if (m_surf.IsInsideElement(el, p[0], p[1], m_tol))
{
// see if this is a closer projection
double D2 = (x - qp).norm2();
if (D2 < D2min)
{
pemin = ⪙
q = qp;
D2min = D2;
r = vec2d(p[0], p[1]);
}
}
}
}
}
}
}
if (pemin) return pemin;
// if we get here then no edge was found.
// This can imply that the projection is in fact the closest node
// first we want to make sure that the node does not lie on the boundary if
// boundary projects are not allowed
if (m_projectBoundary == false)
{
for (int j = 0; j < nval; ++j)
{
// get an element
FESurfaceElement& el = static_cast<FESurfaceElement&> (*pe[j]);
// make sure that the node does not lie on a boundary edge
int N = el.facet_edges();
for (int k = 0; k < N; ++k)
{
if (m_EEL.Neighbor(eil[j], k) == 0)
{
int n0 = el.m_node[k];
int n1 = el.m_node[(k + 1) % N];
if ((n0 == m) || (n1 == m)) return 0;
}
}
}
}
// Any element can now be used but just to be safe, we loop over all
// and make sure the element actually contains the closest point.
for (int j = 0; j < nval; ++j)
{
// get an element
FESurfaceElement& el = static_cast<FESurfaceElement&> (*pe[j]);
// make sure that the node does not lie on a boundary edge
int N = el.facet_edges();
if (m_projectBoundary == false)
{
for (int k = 0; k < N; ++k)
{
if (m_EEL.Neighbor(eil[j], k) == 0)
{
int n0 = el.m_node[k];
int n1 = el.m_node[(k + 1) % N];
if ((n0 == m) || (n1 == m)) return 0;
}
}
}
// make sure one of them is our closest point
if (el.HasNode(m))
{
q = rm;
return ⪙
}
}
return 0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECallback.cpp | .cpp | 1,614 | 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 "FECallBack.h"
#include "FEModel.h"
bool do_FECallBack_cb(FEModel* pfem, unsigned int nwhen, void* pd)
{
FECallBack* pCB = (FECallBack*) (pd);
return pCB->Execute(*pfem, nwhen);
}
FECallBack::FECallBack(FEModel* fem, int when) : FEModelComponent(fem)
{
fem->AddCallback(do_FECallBack_cb, when, this);
}
| C++ |
3D | febiosoftware/FEBio | FECore/Preconditioner.cpp | .cpp | 2,291 | 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.*/
#include "stdafx.h"
#include "Preconditioner.h"
//=================================================================================================
DiagonalPreconditioner::DiagonalPreconditioner(FEModel* fem) : Preconditioner(fem)
{
m_bsqr = false;
}
// take square root of diagonal entries
void DiagonalPreconditioner::CalculateSquareRoot(bool b)
{
m_bsqr = b;
}
// create a preconditioner for a sparse matrix
bool DiagonalPreconditioner::Factor()
{
SparseMatrix* A = GetSparseMatrix();
if (A == nullptr) return false;
int N = A->Rows();
if (A->Columns() != N) return false;
m_D.resize(N);
for (int i=0; i<N; ++i)
{
double dii = A->diag(i);
if (dii == 0.0) return false;
if (m_bsqr)
{
if (dii < 0) return false;
dii = sqrt(dii);
}
m_D[i] = 1.0 / dii;
}
return true;
}
// apply to vector P x = y
bool DiagonalPreconditioner::BackSolve(double* x, double* y)
{
int N = (int)m_D.size();
#pragma omp parallel for
for (int i=0; i<N; ++i)
{
x[i] = y[i]*m_D[i];
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELineSearch.cpp | .cpp | 4,830 | 199 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FELineSearch.h"
#include "FENewtonSolver.h"
#include "FEException.h"
#include "DumpStream.h"
#include "log.h"
#include <vector>
using namespace std;
FELineSearch::FELineSearch(FENewtonSolver* pns) : m_pns(pns)
{
m_LSmin = 0.01;
m_LStol = 0.9;
m_LSiter = 5;
m_checkJacobians = false;
}
// serialization
void FELineSearch::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_LSmin & m_LStol & m_LSiter & m_checkJacobians;
}
//! Performs a linesearch on a NR iteration
//! The description of this method can be found in:
//! "Nonlinear Continuum Mechanics for Finite Element Analysis", Bonet & Wood.
//
//! \todo Find a different way to update the deformation based on the ls.
//! For instance, define a di so that ui = s*di. Also, define the
//! position of the nodes at the previous iteration.
double FELineSearch::DoLineSearch(double s)
{
assert(m_pns);
double smin = s;
double a, A, B, D;
double r0, r1, r;
// max nr of line search iterations
int nmax = m_LSiter;
int n = 0;
// vectors
vector<double>& ui = m_pns->m_ui;
vector<double>& R0 = m_pns->m_R0;
vector<double>& R1 = m_pns->m_R1;
// initial energy
r0 = ui*R0;
double rmin = fabs(r0);
FENewtonStrategy* ns = m_pns->m_qnstrategy;
// ul = ls*ui
vector<double> ul(ui.size());
do
{
// Update geometry
s = UpdateModel(ul, ui, s);
// calculate residual at this point
ns->Residual(R1, false);
// make sure we are still in a valid range
// (When the check-jacobian flag is on, it's very possible that
// the current line search scale factor drops below the minimum,
// so we don't check the min value when the flag is on.)
if ((s < m_LSmin) && !m_checkJacobians)
{
// it appears that we are not converging
// I found in the NIKE3D code that when this happens,
// the line search step is simply set to 0.5.
// so let's try it here too
s = 0.5;
// reupdate
vcopys(ul, ui, s);
m_pns->Update(ul);
// recalculate residual at this point
ns->Residual(R1, false);
// return and hope for the best
break;
}
// calculate energies
r1 = ui*R1;
if ((n == 0) || (fabs(r1) < rmin))
{
smin = s;
rmin = fabs(r1);
}
// make sure that r1 does not happen to be really close to zero,
// since in that case we won't find any better solution.
if (fabs(r1) < 1.e-17) r = 0;
else r = fabs(r1 / r0);
if (r > m_LStol)
{
// calculate the line search step
a = r0 / r1;
A = 1 + a*(s - 1);
B = a*(s*s);
D = B*B - 4 * A*B;
// update the line step
if (D >= 0)
{
s = (B + sqrt(D)) / (2 * A);
if (s < 0) s = (B - sqrt(D)) / (2 * A);
if (s < 0) s = 0;
}
else
{
s = 0.5*B / A;
}
++n;
}
} while ((r > m_LStol) && (n < nmax));
if (n >= nmax)
{
// max nr of iterations reached.
// we choose the line step that reached the smallest energy
s = smin;
vcopys(ul, ui, s);
m_pns->Update(ul);
ns->Residual(R1, false);
}
return s;
}
double FELineSearch::UpdateModel(std::vector<double>& ul, std::vector<double>& ui, double s)
{
if (m_checkJacobians)
{
int nmax = m_LSiter;
int n = 0;
bool negJacFree = true;
do {
negJacFree = true;
vcopys(ul, ui, s);
try {
m_pns->Update(ul);
}
catch (NegativeJacobianDetected e)
{
negJacFree = false;
s *= 0.5;
feLogDebugEx(m_pns->GetFEModel(), "line search cutback : %lg", s);
n++;
if (n > nmax) throw;
}
} while (!negJacFree);
}
else
{
vcopys(ul, ui, s);
m_pns->Update(ul);
}
return s;
}
| C++ |
3D | febiosoftware/FEBio | FECore/SparseMatrix.h | .h | 3,736 | 115 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "MatrixProfile.h"
#include "MatrixOperator.h"
#include "matrix.h"
#include <vector>
//-----------------------------------------------------------------------------
//! Base class for sparse matrices
//! This is the base class for the sparse matrix classes and defines the interface
//! to the different matrix classes
class FECORE_API SparseMatrix : public MatrixOperator
{
public:
//! constructor
SparseMatrix();
//! destructor
virtual ~SparseMatrix();
public:
//! return number of rows
int Rows() const { return m_nrow; }
//! return number of columns
int Columns() const { return m_ncol; }
//! is the matrix square?
bool IsSquare() const { return (m_nrow == m_ncol); }
//! return number of nonzeros
size_t NonZeroes() const { return m_nsize; }
public: // functions to be overwritten in derived classes
//! set all matrix elements to zero
virtual void Zero() = 0;
//! Create a sparse matrix from a sparse-matrix profile
virtual void Create(SparseMatrixProfile& MP) = 0;
//! assemble a matrix into the sparse matrix
virtual void Assemble(const matrix& ke, const std::vector<int>& lm) = 0;
//! assemble a matrix into the sparse matrix
virtual void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) = 0;
//! check if an entry was allocated
virtual bool check(int i, int j) = 0;
//! set entry to value
virtual void set(int i, int j, double v) = 0;
//! add value to entry
virtual void add(int i, int j, double v) = 0;
//! retrieve value
virtual double get(int i, int j) { return 0; }
//! get the diagonal value
virtual double diag(int i) = 0;
//! release memory for storing data
virtual void Clear();
//! scale matrix
virtual void scale(const std::vector<double>& L, const std::vector<double>& R);
public:
//! multiply with vector
bool mult_vector(double* x, double* r) override { assert(false); return false; }
public:
// NOTE: The following functions are only used by the compact matrices, but I need to be able to override them
// for the JFNKMatrix so I've moved them here.
virtual double* Values() { return 0; }
virtual int* Indices() { return 0; }
virtual int* Pointers() { return 0; }
virtual int Offset() const { return 0; }
protected:
// NOTE: These values are set by derived classes
int m_nrow, m_ncol; //!< dimension of matrix
size_t m_nsize; //!< number of nonzeroes (i.e. matrix elements actually allocated)
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FENormalProjection.h | .h | 2,336 | 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 "FESurface.h"
#include "FEOctree.h"
//-----------------------------------------------------------------------------
//! This class calculates the normal projection on to a surface.
//! This is used by some contact algorithms.
class FECORE_API FENormalProjection
{
public:
//! constructor
FENormalProjection(FESurface& s);
// initialization
void Init();
void SetTolerance(double tol) { m_tol = tol; }
void SetSearchRadius(double srad) { m_rad = srad; }
public:
//! find the intersection of a ray with the surface
FESurfaceElement* Project(vec3d r, vec3d n, double rs[2]);
FESurfaceElement* Project2(vec3d r, vec3d n, double rs[2]);
FESurfaceElement* Project3(const vec3d& r, const vec3d& n, double rs[2], int* pei = 0);
vec3d Project(const vec3d& r, const vec3d& N);
vec3d Project2(const vec3d& r, const vec3d& N);
private:
double m_tol; //!< projection tolerance
double m_rad; //!< search radius
private:
FESurface& m_surf; //!< the target surface
FEOctree m_OT; //!< used to optimize ray-surface intersections
};
| Unknown |
3D | febiosoftware/FEBio | FECore/fecore_debug.cpp | .cpp | 6,412 | 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 "fecore_debug.h"
#include <string>
#include <iostream>
#include <stdarg.h>
#include "version.h"
#include <assert.h>
#include <iomanip>
using namespace std;
std::list<FECoreDebugger::Variable*> FECoreDebugger::m_var;
void FECoreDebugger::Break(FECoreBreakPoint* pbr)
{
string s;
do
{
if (pbr) cout << "#" << pbr->GetID();
cout << ">>";
cin >> s;
if (s == "cont" ) break;
else if (s == "print")
{
cin >> s;
list<Variable*>::iterator it;
bool bfound = false;
for (it = m_var.begin(); it != m_var.end(); ++it)
{
if (s == (*it)->m_szname)
{
(*it)->print();
cout << endl;
bfound = true;
break;
}
}
if (bfound == false) cout << "Error: unknown variable\n";
}
else if (s == "list")
{
list<Variable*>::iterator it;
for (it = m_var.begin(); it != m_var.end(); ++it)
{
cout << (*it)->m_szname << endl;
}
}
else if (s == "remove")
{
if (pbr) { pbr->Deactivate(); break; }
else cout << "No active breakpoint\n";
}
else if (s == "help")
{
cout << "cont = continue\n";
cout << "list = list all watch variables\n";
cout << "print var = print variable\n";
cout << "remove = remove breakpoint and continue\n";
cout << "help = show this information\n";
}
else cout << "Error: Unknown command\n";
}
while (1);
}
void FECoreDebugger::Clear()
{
list<Variable*>::iterator it;
for (it = m_var.begin(); it != m_var.end(); ++it) delete (*it);
m_var.clear();
}
void FECoreDebugger::Add(FECoreDebugger::Variable* pvar)
{
m_var.push_back(pvar);
}
void FECoreDebugger::Remove(FECoreDebugger::Variable* pvar)
{
list<Variable*>::iterator it;
for (it = m_var.begin(); it != m_var.end(); ++it)
{
if ((*it)==pvar)
{
delete *it;
m_var.erase(it);
break;
}
}
}
FILE* FECoreDebugger::m_fp = nullptr;
void FECoreDebugger::Print(const char* szformat, ...)
{
if (m_fp == nullptr)
{
char fileName[256] = { 0 };
snprintf(fileName, sizeof(fileName), "febio_%d.%d.%d_debug.log", FE_SDK_MAJOR_VERSION, FE_SDK_SUB_VERSION, FE_SDK_SUBSUB_VERSION);
m_fp = fopen(fileName, "wt"); assert(m_fp);
}
if (m_fp)
{
va_list args;
va_start(args, szformat);
vfprintf(m_fp, szformat, args);
va_end(args);
fflush(m_fp);
}
}
template <> void fecore_print_T<matrix>(matrix* pd)
{
matrix& m = *pd;
int nr = m.rows();
int nc = m.columns();
for (int i=0; i<nr; ++i)
{
for (int j=0; j<nc; ++j)
{
cout << std::setw(8) << std::setprecision(4) << m(i,j);
}
cout << endl;
}
}
template <> void fecore_print_T<mat3d>(mat3d* pd)
{
mat3d& m = *pd;
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j) cout << m(i,j) << " ";
cout << endl;
}
}
template <> void fecore_print_T<mat3ds>(mat3ds* pd)
{
mat3ds& m = *pd;
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j) cout << m(i,j) << " ";
cout << endl;
}
}
template <> void fecore_print_T<mat3da>(mat3da* pd)
{
mat3da& m = *pd;
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j) cout << m(i,j) << " ";
cout << endl;
}
}
template <> void fecore_print_T<mat3dd>(mat3dd* pd)
{
mat3dd& m = *pd;
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j) cout << m(i,j) << " ";
cout << endl;
}
}
template <> void fecore_print_T<vec3d>(vec3d* pd)
{
vec3d& v = *pd;
cout << v.x << endl;
cout << v.y << endl;
cout << v.z << endl;
}
template <> void fecore_print_T<tens4ds>(tens4ds* pd)
{
tens4ds& m = *pd;
for (int i=0; i<6; ++i)
{
for (int j=0; j<6; ++j)
{
cout << m(i,j) <<" ";
}
cout << endl;
}
}
template <> void fecore_print_T<std::vector<double> >(std::vector<double>* pv)
{
vector<double>& v = *pv;
int n = (int)v.size();
for (int i=0; i<n; ++i) cout << v[i] << endl;
}
template <> void fecore_print_T<std::vector<int> >(std::vector<int>* pv)
{
vector<int>& v = *pv;
int n = (int)v.size();
for (int i=0; i<n; ++i) cout << v[i] << endl;
}
//=============================================================================
FECoreDebugStream::FECoreDebugStream()
{
m_mode = STREAM_MODE::WRITING_MODE;
m_fp = nullptr;
m_counter = 0;
}
FECoreDebugStream::FECoreDebugStream(const char* szfilename, STREAM_MODE mode)
{
m_mode = mode;
m_fp = nullptr;
m_counter = 0;
Open(szfilename, mode);
}
FECoreDebugStream::~FECoreDebugStream()
{
if (m_fp) fclose(m_fp);
m_fp = nullptr;
}
bool FECoreDebugStream::Open(const char* szfilename, FECoreDebugStream::STREAM_MODE mode)
{
m_counter = 0;
m_filename = szfilename;
m_mode = mode;
if (mode == WRITING_MODE)
m_fp = fopen(szfilename, "wb");
else
m_fp = fopen(szfilename, "rb");
return (m_fp != nullptr);
}
bool FECoreDebugStream::ReopenForReading()
{
if (is_reading()) return true;
if (m_fp) fclose(m_fp);
m_mode = READING_MODE;
m_fp = fopen(m_filename.c_str(), "rb");
return (m_fp != nullptr);
}
size_t FECoreDebugStream::write(const void* pd, size_t size, size_t count)
{
m_counter++;
assert(is_writing());
return fwrite(pd, size, count, m_fp);
}
size_t FECoreDebugStream::read(void* pd, size_t size, size_t count)
{
m_counter++;
assert(is_reading());
return fread(pd, size, count, m_fp);
}
| C++ |
3D | febiosoftware/FEBio | FECore/besselIK.cpp | .cpp | 6,284 | 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) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "gamma.h"
#include <limits>
#include <math.h>
#include "besselIK.h"
// modified Bessel function of the first kind I0(x) (real x)
double i0(double x)
{
double ax,ans;
double y;
if ((ax=fabs(x)) < 3.75) {
y=x/3.75;
y*=y;
ans=1.0+y*(3.5156229+y*(3.0899424+y*
(1.2067492+y*
(0.2659732+y*(0.360768e-1+y*0.45813e-2))
)
)
);
}
else {
y=3.75/ax;
ans=(exp(ax)/sqrt(ax))*(0.39894228+y*
(0.1328592e-1+y*
(0.225319e-2+y*
(-0.157565e-2+y*(0.916281e-2 +y*
(-0.2057706e-1+y*
(0.2635537e-1+y*
(-0.1647633e-1 +y*0.392377e-2)
)
)
)
)
)
)
);
}
return ans;
}
// modified Bessel function of the first kind I1(x) (real x)
double i1(double x)
{
double ax,ans;
double y;
if ((ax=fabs(x)) < 3.75) {
y=x/3.75;
y*=y;
ans=ax*(0.5+y*(0.87890594+y*
(0.51498869+y*(0.15084934+y*
(0.2658733e-1+y*
(0.301532e-2+y*0.32411e-3)
)
)
)
)
);
}
else {
y=3.75/ax;
ans=0.2282967e-1+y*(-0.2895312e-1+y*
(0.1787654e-1-y*0.420059e-2));
ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2+y*
(0.163801e-2+y*(-0.1031555e-1+y*ans)
)
)
);
ans *= (exp(ax)/sqrt(ax));
}
return (x < 0.0) ? -ans : ans;
}
// modified Bessel function of the second kind K0(x) (real x)
double k0(double x)
{
double y,ans;
if (x <= 2.0) {
y=x*x/4.0;
ans=(-log(x/2.0)*i0(x))+(-0.57721566+y*
(0.42278420 +y*
(0.23069756+y*
(0.3488590e-1+y*
(0.262698e-2 +y*
(0.10750e-3+y*0.74e-5)
)
)
)
)
);
}
else {
y=2.0/x;
ans=(exp(-x)/sqrt(x))*(1.25331414+y*
(-0.7832358e-1 +y*
(0.2189568e-1+y*(-0.1062446e-1+y*
(0.587872e-2 +y*
(-0.251540e-2+y*0.53208e-3)
)
)
)
)
);
}
return ans;
}
// modified Bessel function of the second kind K1(x) (real x)
double k1(double x)
{
double y,ans;
if (x <= 2.0) {
y=x*x/4.0;
ans=(log(x/2.0)*i1(x))+(1.0/x)*(1.0+y*
(0.15443144 +y*
(-0.67278579+y*
(-0.18156897+y*
(-0.1919402e-1 +y*
(-0.110404e-2+y*
(-0.4686e-4)
)
)
)
)
)
);
}
else {
y=2.0/x;
ans=(exp(-x)/sqrt(x))*(1.25331414+y*
(0.23498619 +y*
(-0.3655620e-1+y*
(0.1504268e-1+y*
(-0.780353e-2 +y*
(0.325614e-2+y*
(-0.68245e-3)
)
)
)
)
)
);
}
return ans;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMeshAdaptorCriterion.h | .h | 3,579 | 97 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEModelComponent.h"
#include <FECore/FEMaterialPoint.h>
class FEElementSet;
class FEElement;
//-----------------------------------------------------------------------------
class FECORE_API FEMeshAdaptorSelection
{
public:
enum SortFlag
{
SORT_INCREASING,
SORT_DECREASING
};
public:
struct Item {
int m_elementId;
double m_elemValue;
};
public:
FEMeshAdaptorSelection() {}
FEMeshAdaptorSelection(size_t size) : m_itemList(size) {}
void resize(size_t newSize) { m_itemList.resize(newSize); }
Item& operator [] (size_t item) { return m_itemList[item]; }
const Item& operator [] (size_t item) const { return m_itemList[item]; }
bool empty() const { return m_itemList.empty(); }
size_t size() const { return m_itemList.size(); }
void push_back(int elemIndex, double scale) { m_itemList.push_back(Item{ elemIndex, scale }); }
void push_back(const Item& item) { m_itemList.push_back(item); }
public:
void Sort(SortFlag sortFlag);
private:
std::vector<Item> m_itemList;
};
//-----------------------------------------------------------------------------
// This class is a helper class for use in the mesh adaptors. Its purpose is to assign
// values based on some criterion. This element list is then usually passed to the
// mesh adaptor for further processing.
class FECORE_API FEMeshAdaptorCriterion : public FEModelComponent
{
FECORE_SUPER_CLASS(FEMESHADAPTORCRITERION_ID)
FECORE_BASE_CLASS(FEMeshAdaptorCriterion)
public:
// Constructor
FEMeshAdaptorCriterion(FEModel* fem);
// return a list of elements and associated values.
// The elements will be taken from the element set. If nullptr is passed
// for the element set, the entire mesh will be processed
virtual FEMeshAdaptorSelection GetElementSelection(FEElementSet* elset);
// evaluate an element. This can be overriden by derived classes. By default,
// it will evaluate the integration point average by calling GetMaterialPointValue
virtual bool GetElementValue(FEElement& el, double& value);
// This function needs to be overridden in order to set the element's value.
// Return false if the element cannot be evaluated. Otherwise return true.
virtual bool GetMaterialPointValue(FEMaterialPoint& mp, double& value);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogElemData.h | .h | 1,600 | 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 "FELogData.h"
class FEElement;
//! Base class for element log data
class FECORE_API FELogElemData : public FELogData
{
FECORE_SUPER_CLASS(FELOGELEMDATA_ID)
FECORE_BASE_CLASS(FELogElemData)
public:
FELogElemData(FEModel* fem);
virtual ~FELogElemData();
virtual double value(FEElement& el) = 0;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFunction1D.cpp | .cpp | 6,794 | 269 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFunction1D.h"
#include "FEModel.h"
#include "DumpStream.h"
#include "MMath.h"
#include "MObj2String.h"
#include "log.h"
FEFunction1D::FEFunction1D(FEModel* fem) : FECoreBase(fem)
{
}
double FEFunction1D::derive(double x) const
{
const double eps = 1e-6;
return (value(x + eps) - value(x))/eps;
}
double FEFunction1D::integrate(double a, double b) const
{
return (b-a)*((value(a) + value(b))/2);
}
void FEFunction1D::Serialize(DumpStream& ar)
{
FECoreBase::Serialize(ar);
if (ar.IsSaving())
{
}
else
{
}
}
// Invert the function f(x) = f0: given f0, return x.
// On input, x is the initial guess.
// On output, x is the solution.
// Function returns true if solution has converged, false otherwise.
// Uses Newton's method.
bool FEFunction1D::invert(const double f0, double &x)
{
const int maxiter = 100;
const double errabs = 1e-15;
const double errrel = 1e-6;
bool cnvgd = false;
bool done = false;
int iter = 0;
double dx;
while (!done) {
double f = value(x) - f0;
double df = derive(x);
// check if slope is zero
if (fabs(df) <= errabs) {
if (fabs(f) > errabs) {
// if function not zero, this is a local minimum
done = true;
}
else {
// if function is zero, this is a valid solution
done = cnvgd = true;
}
}
// if slope is not zero proceed with iterative scheme
else {
dx = -f/df;
x += dx;
// check for relative or absolute convergence
if ((fabs(dx) <= errrel*fabs(x)) || (fabs(f) <= errabs)) {
done = cnvgd = true;
}
}
++iter;
if (iter > maxiter) done = true;
}
return cnvgd;
}
//=============================================================================
BEGIN_FECORE_CLASS(FEConstFunction, FEFunction1D)
ADD_PARAMETER(m_value, "value");
END_FECORE_CLASS();
//=============================================================================
BEGIN_FECORE_CLASS(FEScaleFunction, FEFunction1D)
ADD_PARAMETER(m_scale, "scale");
END_FECORE_CLASS();
//=============================================================================
BEGIN_FECORE_CLASS(FELinearFunction, FEFunction1D)
ADD_PARAMETER(m_slope, "slope");
ADD_PARAMETER(m_intercept, "intercept");
END_FECORE_CLASS();
//=============================================================================
BEGIN_FECORE_CLASS(FEStepFunction, FEFunction1D)
ADD_PARAMETER(m_x0, "x0");
ADD_PARAMETER(m_leftVal , "left_val");
ADD_PARAMETER(m_rightVal, "right_val");
END_FECORE_CLASS();
//=============================================================================
BEGIN_FECORE_CLASS(FEMathFunction, FEFunction1D)
ADD_PARAMETER(m_s, "math");
END_FECORE_CLASS();
FEMathFunction::FEMathFunction(FEModel* fem) : FEFunction1D(fem)
{
m_s = "0";
}
void FEMathFunction::SetMathString(const std::string& s)
{
m_s = s;
}
bool FEMathFunction::Init()
{
if (BuildMathExpressions() == false) return false;
return FEFunction1D::Init();
}
bool FEMathFunction::BuildMathExpressions()
{
// process the string
m_exp.Clear();
if (m_exp.Create(m_s, true) == false) return false;
// match variables to model parameters.
m_var.clear();
m_ix = -1;
FEModel* fem = GetFEModel();
for (int i=0; i<m_exp.Variables(); ++i)
{
MVariable* v = m_exp.Variable(i);
ParamString ps(v->Name().c_str());
FEParamValue param = fem->GetParameterValue(ps);
if (param.isValid() == false)
{
// let's assume this is the independent parameter
if (m_ix == -1)
{
// push a dummy param value
m_var.push_back(FEParamValue());
m_ix = i;
}
else return false;
}
else
{
if (param.type() != FE_PARAM_DOUBLE) return false;
m_var.push_back(param);
}
}
// copy variables to derived expressions
m_dexp.Clear();
m_d2exp.Clear();
for (int i = 0; i < m_exp.Variables(); ++i)
{
m_dexp.AddVariable(m_exp.Variable(i)->Name());
m_d2exp.AddVariable(m_exp.Variable(i)->Name());
}
// evaluate first derivative
if (m_ix != -1) {
MITEM mi = MDerive(m_exp.GetExpression(), *m_exp.Variable(m_ix));
m_dexp.SetExpression(mi);
}
else
m_dexp.Create("0");
// evaluate second derivative
if (m_ix != -1) {
MITEM mi = MDerive(m_dexp.GetExpression(), *m_dexp.Variable(m_ix));
m_d2exp.SetExpression(mi);
}
else
m_d2exp.Create("0");
return true;
}
void FEMathFunction::Serialize(DumpStream& ar)
{
FEFunction1D::Serialize(ar);
if ((ar.IsShallow() == false) && (ar.IsLoading()))
{
bool b = BuildMathExpressions();
assert(b);
}
}
FEFunction1D* FEMathFunction::copy()
{
FEMathFunction* m = new FEMathFunction(GetFEModel());
m->m_s = m_s;
m->m_ix = m_ix;
m->m_var = m_var;
m->m_exp = m_exp;
m->m_dexp = m_dexp;
m->m_d2exp = m_d2exp;
return m;
}
void FEMathFunction::evalParams(std::vector<double>& val, double t) const
{
val.resize(m_var.size());
for (int i = 0; i < m_var.size(); ++i)
{
if (i == m_ix) val[i] = t;
else val[i] = m_var[i].value<double>();
}
}
double FEMathFunction::value(double t) const
{
vector<double> v;
evalParams(v, t);
return m_exp.value_s(v);
}
double FEMathFunction::derive(double t) const
{
vector<double> v;
evalParams(v, t);
return m_dexp.value_s(v);
}
double FEMathFunction::deriv2(double t) const
{
vector<double> v;
evalParams(v, t);
return m_d2exp.value_s(v);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEGlobalVector.h | .h | 2,580 | 73 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
class FEModel;
//-----------------------------------------------------------------------------
//! This class represents a global system array. It provides functions to assemble
//! local (element) vectors into this array
//! TODO: remove FEModel dependency!
class FECORE_API FEGlobalVector
{
public:
//! constructor
FEGlobalVector(FEModel& fem, std::vector<double>& R, std::vector<double>& Fr);
//! destructor
virtual ~FEGlobalVector();
//! Assemble the element vector into this global vector
virtual void Assemble(std::vector<int>& en, std::vector<int>& elm, std::vector<double>& fe, bool bdom = false);
//! Assemble into this global vector
virtual void Assemble(std::vector<int>& lm, std::vector<double>& fe);
//! assemble a nodel value
virtual void Assemble(int node, int dof, double f);
//! access operator
double& operator [] (int i) { return m_R[i]; }
//! Get the FE model
FEModel& GetFEModel() { return m_fem; }
//! get the size of the vector
int Size() const { return (int) m_R.size(); }
operator std::vector<double>& () { return m_R; }
protected:
FEModel& m_fem; //!< model
std::vector<double>& m_R; //!< residual
std::vector<double>& m_Fr; //!< nodal reaction forces \todo I want to remove this
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEOctree.cpp | .cpp | 9,592 | 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 "FEOctree.h"
#include "FESurface.h"
#include "FEMesh.h"
OTnode::OTnode()
{
m_ps = nullptr;
level = 0;
}
OTnode::~OTnode()
{
}
void OTnode::Clear()
{
children.clear();
}
//-----------------------------------------------------------------------------
// Create the eight children of an octree node and find their contents
void OTnode::CreateChildren(const int max_level, const int max_elem)
{
vec3d dc = (cmax - cmin)/2;
for (int i=0; i<=1; ++i) {
for (int j=0; j<=1; ++j) {
for (int k=0; k<=1; ++k) {
OTnode node;
node.m_ps = m_ps;
// evaluate bounding box by subdividing parent node box
node.cmin = vec3d(cmin.x+i*dc.x,
cmin.y+j*dc.y,
cmin.z+k*dc.z);
node.cmax = vec3d(cmax.x-(1-i)*dc.x,
cmax.y-(1-j)*dc.y,
cmax.z-(1-k)*dc.z);
// update octree level
node.level = level + 1;
// find all surface elements in this child node
node.FillNode(selist);
if (node.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.level < max_level) &&
(node.selist.size() > max_elem))
node.CreateChildren(max_level, max_elem);
}
// store this node
children.push_back(node);
}
}
}
}
//-----------------------------------------------------------------------------
// Find all surface elements that fall inside a node
void OTnode::FillNode(const vector<int>& parent_selist)
{
// Loop over all surface elements in the parent node
int nsize = (int)parent_selist.size();
for (int i=0; i<nsize; ++i) {
int j = parent_selist[i];
if (ElementIntersectsNode(j)) {
// add this surface element to the current node
selist.push_back(j);
}
}
}
//-----------------------------------------------------------------------------
// Determine whether a surface element intersects a node
bool OTnode::ElementIntersectsNode(const int iel)
{
// Extract FE node coordinates from surface element
// and determine bounding box of surface element
FEMesh& mesh = *(m_ps->GetMesh());
FESurfaceElement& el = m_ps->Element(iel);
vec3d rn = mesh.Node(el.m_node[0]).m_rt;
vec3d fmin = rn;
vec3d fmax = rn;
int N = el.Nodes();
for (int i=1; i<N; ++i) {
rn = mesh.Node(el.m_node[i]).m_rt;
if (rn.x < fmin.x) fmin.x = rn.x;
if (rn.x > fmax.x) fmax.x = rn.x;
if (rn.y < fmin.y) fmin.y = rn.y;
if (rn.y > fmax.y) fmax.y = rn.y;
if (rn.z < fmin.z) fmin.z = rn.z;
if (rn.z > fmax.z) fmax.z = rn.z;
}
// Check if bounding boxes of OT node and surface element overlap
if ((fmax.x < cmin.x) || (fmin.x > cmax.x)) return false;
if ((fmax.y < cmin.y) || (fmin.y > cmax.y)) return false;
if ((fmax.z < cmin.z) || (fmin.z > 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;
}
//-----------------------------------------------------------------------------
// Determine if a ray intersects any of the faces of this node.
// The ray originates at p and is directed along the unit vector n
bool OTnode::RayIntersectsNode(const vec3d& p, const vec3d& n)
{
// check intersection with x-faces
if (n.x) {
// face passing through cmin
double t = (cmin.x - p.x)/n.x;
double y = p.y + t*n.y;
double z = p.z + t*n.z;
if ((y >= cmin.y) && (y <= cmax.y)
&& (z >= cmin.z) && (z <= cmax.z))
return true;
// face passing through cmax
t = (cmax.x - p.x)/n.x;
y = p.y + t*n.y;
z = p.z + t*n.z;
if ((y >= cmin.y) && (y <= cmax.y)
&& (z >= cmin.z) && (z <= cmax.z))
return true;
}
// check intersection with y-faces
if (n.y) {
// face passing through cmin
double t = (cmin.y - p.y)/n.y;
double x = p.x + t*n.x;
double z = p.z + t*n.z;
if ((x >= cmin.x) && (x <= cmax.x)
&& (z >= cmin.z) && (z <= cmax.z))
return true;
// face passing through cmax
t = (cmax.y - p.y)/n.y;
x = p.x + t*n.x;
z = p.z + t*n.z;
if ((x >= cmin.x) && (x <= cmax.x)
&& (z >= cmin.z) && (z <= cmax.z))
return true;
}
// check intersection with z-faces
if (n.z) {
// face passing through cmin
double t = (cmin.z - p.z)/n.z;
double x = p.x + t*n.x;
double y = p.y + t*n.y;
if ((x >= cmin.x) && (x <= cmax.x)
&& (y >= cmin.y) && (y <= cmax.y))
return true;
// face passing through cmax
t = (cmax.z - p.z)/n.z;
x = p.x + t*n.x;
y = p.y + t*n.y;
if ((x >= cmin.x) && (x <= cmax.x)
&& (y >= cmin.y) && (y <= cmax.y))
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Find intersected octree leaves and return a set of their surface elements
void OTnode::FindIntersectedLeaves(const vec3d& p, const vec3d& n, set<int>& sel, double srad)
{
// Check if octree node is within search radius from p.
bool bNodeWithinSRad = ( (cmin.x - srad <= p.x) && (cmax.x + srad >= p.x) &&
(cmin.y - srad <= p.y) && (cmax.y + srad >= p.y) &&
(cmin.z - srad <= p.z) && (cmax.z + srad >= p.z) );
if (bNodeWithinSRad && RayIntersectsNode(p, n)) {
int nc = (int)children.size();
// if this node has children, search them for intersections
if (nc) {
for (int ic=0; ic<nc; ++ic) {
children[ic].FindIntersectedLeaves(p, n, sel, srad);
}
}
// otherwise we have reached the smallest intersected node in this
// branch, return its surface element list
else {
// using a 'set' container avoids duplication of surface
// elements shared by multiple octree nodes
sel.insert(selist.begin(), selist.end());
}
}
}
//-----------------------------------------------------------------------------
// Print node content (for debugging purposes)
void OTnode::PrintNodeContent()
{
int nel = (int)selist.size();
printf("Level = %d\n", level);
for (int i=0; i<nel; ++i)
printf("%d\n",selist[i]);
printf("-----------------------------------------------------\n");
int nc = (int)children.size();
for (int i=0; i<nc; ++i) {
printf("Child = %d\n", i);
children[i].PrintNodeContent();
}
}
//-----------------------------------------------------------------------------
// Count nodes (for debugging purposes)
void OTnode::CountNodes(int& nnode, int& nlevel)
{
int nc = (int)children.size();
nnode += nc;
nlevel = (level > nlevel) ? level : nlevel;
for (int i=0; i<nc; ++i) {
children[i].CountNodes(nnode, nlevel);
}
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FEOctree::FEOctree(FESurface* ps)
{
m_ps = ps;
max_level = 6;
max_elem = 9;
assert(max_level && max_elem);
}
FEOctree::~FEOctree()
{
}
//-----------------------------------------------------------------------------
void FEOctree::Init(const double stol)
{
assert(m_ps);
root.Clear();
// Set up the root node in the octree
root.m_ps = m_ps;
root.level = 0;
// Create the list of all surface elements in the root node
int nel = m_ps->Elements();
root.selist.resize(nel);
for (int i=0; i<nel; ++i)
root.selist[i] = i;
// Find the bounding box of the surface
vec3d fenode = (m_ps->Node(0)).m_rt;
root.cmin = fenode;
root.cmax = fenode;
for (int i=1; i<m_ps->Nodes(); ++i) {
fenode = (m_ps->Node(i)).m_rt;
if (fenode.x < root.cmin.x) root.cmin.x = fenode.x;
if (fenode.x > root.cmax.x) root.cmax.x = fenode.x;
if (fenode.y < root.cmin.y) root.cmin.y = fenode.y;
if (fenode.y > root.cmax.y) root.cmax.y = fenode.y;
if (fenode.z < root.cmin.z) root.cmin.z = fenode.z;
if (fenode.z > root.cmax.z) root.cmax.z = fenode.z;
}
// expand bounding box by search tolerance stol
double d = (root.cmax - root.cmin).norm()*stol;
root.cmin -= vec3d(d, d, d);
root.cmax += vec3d(d, d, d);
// Recursively create children of this root
if (root.selist.size()) {
if ((root.level < max_level) &&
(root.selist.size() > max_elem))
root.CreateChildren(max_level, max_elem);
}
return;
}
void FEOctree::FindCandidateSurfaceElements(vec3d p, vec3d n, set<int>& sel, double srad)
{
root.FindIntersectedLeaves(p, n, sel, srad);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEOctreeSearch.h | .h | 2,772 | 82 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include "vector.h"
#include <set>
class FEElement;
class FEMesh;
class FEDomain;
//-----------------------------------------------------------------------------
//! This class is a helper class to find ray intersection with a surface
class FECORE_API FEOctreeSearch
{
class Block
{
public:
Block(FEMesh* mesh, int level);
Block(Block* parent, int level);
~Block();
void Clear();
void CreateChildren(int max_level, int max_elem);
void FillBlock();
bool ElementIntersectsNode(FEElement* pe);
FEElement* FindElement(const vec3d& y, double r[3]);
bool IsInside(const vec3d& r) const;
public:
int m_level; //!< node level
vec3d m_cmin, m_cmax; //!< node bounding box
std::vector<FEElement*> m_selist; //!< list of surface elements inside this node
std::vector<Block*> m_children; //!< children of this node
FEMesh* m_mesh; //!< the mesh to search
Block* m_parent;
};
public:
FEOctreeSearch(FEMesh* mesh);
FEOctreeSearch(FEDomain* domain);
~FEOctreeSearch();
//! initialize search structures
bool Init(double inflate = 0.005);
FEElement* FindElement(const vec3d& x, double r[3]);
protected:
FEMesh* m_mesh; //!< the mesh
FEDomain* m_dom; //!< the domain to search (if null whole mesh will be searched)
Block* m_root; //!< root node in octree
int m_max_level; //!< maximum allowable number of levels in octree
int m_max_elem; //!< maximum allowable number of elements in any node
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBodyLoad.cpp | .cpp | 3,255 | 114 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBodyLoad.h"
#include "FEMesh.h"
#include "FEModelParam.h"
//-----------------------------------------------------------------------------
FEBodyLoad::FEBodyLoad(FEModel* pfem) : FEModelLoad(pfem)
{
}
//-----------------------------------------------------------------------------
FEBodyLoad::~FEBodyLoad()
{
}
//-----------------------------------------------------------------------------
//! initialization
bool FEBodyLoad::Init()
{
// If the domain list is empty, add all the domains
if (m_dom.IsEmpty())
{
FEMesh& mesh = GetMesh();
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain* dom = &mesh.Domain(i);
m_dom.AddDomain(dom);
}
}
return FEModelLoad::Init();
}
//-----------------------------------------------------------------------------
int FEBodyLoad::Domains() const
{
return m_dom.Domains();
}
//-----------------------------------------------------------------------------
FEDomain* FEBodyLoad::Domain(int i)
{
return m_dom.GetDomain(i);
}
//-----------------------------------------------------------------------------
void FEBodyLoad::SetDomainList(FEElementSet* elset)
{
m_dom = elset->GetDomainList();
// add it to all the mapped parameters
FEParameterList& PL = GetParameterList();
FEParamIterator it = PL.first();
for (int i = 0; i < PL.Parameters(); ++i, ++it)
{
FEParam& pi = *it;
if (pi.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& param = pi.value<FEParamDouble>();
param.SetItemList(elset);
}
else if (pi.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& param = pi.value<FEParamVec3>();
param.SetItemList(elset);
}
else if (pi.type() == FE_PARAM_MAT3D_MAPPED)
{
FEParamMat3d& param = pi.value<FEParamMat3d>();
param.SetItemList(elset);
}
}
}
// get the domain list
FEDomainList& FEBodyLoad::GetDomainList()
{
return m_dom;
}
//! Serialization
void FEBodyLoad::Serialize(DumpStream& ar)
{
FEModelLoad::Serialize(ar);
m_dom.Serialize(ar);
}
| C++ |
3D | febiosoftware/FEBio | FECore/tools.cpp | .cpp | 20,787 | 948 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "tools.h"
#include <math.h>
#include <limits>
#include <assert.h>
#include <float.h>
#include "matrix.h"
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
#define FMAX(a,b) ((a)>(b) ? (a) : (b))
//=============================================================================
// powell's method
// from Numerical Recipes in C, section 10.5, page 417-419
// modified for this application
//
void powell(double* p, double* xi, int n, double ftol, int* iter, double* fret, double(*fnc)(double[]))
{
int i, j, ibig;
double fp, fptt, del, t;
const int ITMAX = 200;
const double TINY = 1.0e-25;
double* pt = new double[n];
double* ptt = new double[n];
double* xit = new double[n];
*fret = (*fnc)(p);
for (i = 0; i<n; i++) pt[i] = p[i]; // save the initial point
for (*iter = 1;; ++(*iter))
{
fp = *fret;
ibig = 0;
del = 0.0; // will be biggest function decrease
for (i = 0; i<n; i++) // in each iteration loop over all directions in the set
{
for (j = 0; j<n; j++) xit[j] = xi[i*n + j]; // copy the direction
fptt = (*fret);
linmin(p, xit, n, fret, fnc); // minimize along it
if (fptt - (*fret) > del) // and record it as the largets decrease so far
{
del = fptt - (*fret);
ibig = i;
}
}
// termination criterion
if (2.0*(fp - (*fret)) <= ftol*(fabs(fp) + fabs(*fret)) + TINY)
{
delete[] pt;
delete[] ptt;
delete[] xit;
return;
}
// check we are not exceeding max number of iterations
if (*iter == ITMAX)
{
printf("FATAL ERROR : Max iterations reached\n");
exit(0);
}
for (j = 0; j<n; j++)
{
ptt[j] = 2.0*p[j] - pt[j];
xit[j] = p[j] - pt[j];
pt[j] = p[j];
}
fptt = (*fnc)(ptt);
if (fptt < fp)
{
t = 2.0*(fp - 2.0*(*fret) + fptt)*SQR(fp - (*fret) - del) - del*SQR(fp - fptt);
if (t < 0.0)
{
linmin(p, xit, n, fret, fnc);
for (j = 0; j<n; j++)
{
xi[ibig *n + j] = xi[(n - 1)*n + j];
xi[(n - 1)*n + j] = xit[j];
}
}
}
}
}
//--------------------------------------------------------------------------------
// line minimization routine
// from Numerical Recipes in C, section 10.5, page 419-420
// modified for this application
//
int ncom;
double *pcom, *xicom, *xt;
double(*nrfunc)(double[]);
double f1dim(double x)
{
int j;
double f;
for (j = 0; j<ncom; j++) xt[j] = pcom[j] + x*xicom[j];
f = (*nrfunc)(xt);
return f;
}
void linmin(double* p, double* xi, int n, double* fret, double(*fnc)(double[]))
{
int j;
double xx, xmin, fx, fb, fa, bx, ax;
const double TOL = 2.0e-4;
ncom = n;
pcom = new double[n];
xicom = new double[n];
xt = new double[n];
nrfunc = fnc;
for (j = 0; j<n; j++)
{
pcom[j] = p[j];
xicom[j] = xi[j];
}
ax = 0.0;
xx = 1.0e-4;
mnbrak(&ax, &xx, &bx, &fa, &fx, &fb, f1dim);
*fret = brent(ax, xx, bx, f1dim, TOL, &xmin);
for (j = 0; j<n; j++)
{
xi[j] *= xmin;
p[j] += xi[j];
}
delete[] xt;
delete[] pcom;
delete[] xicom;
}
//--------------------------------------------------------------------------------
// routine to find 1D minimum
// from Numerical Recipes in C, section 10.3, page 404-405
// modified for this application
//
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d);
#define SIGN(a,b) ((b)>=0.0 ? (a) : (-(a)))
double brent(double ax, double bx, double cx, double(*f)(double), double tol, double* xmin)
{
const int ITMAX = 100;
const double CGOLD = 0.3819660;
const double ZEPS = 1.0e-10;
int iter;
double a, b, d, etemp, fu, fv, fw, fx, p, q, r, tol1, tol2, u, v, w, x, xm;
double e = 0.0;
a = (ax < cx ? ax : cx);
b = (ax > cx ? ax : cx);
x = w = v = bx;
fw = fv = fx = (*f)(x);
for (iter = 1; iter <= ITMAX; iter++)
{
xm = 0.5*(a + b);
tol2 = 2.0*(tol1 = tol*fabs(x) + ZEPS);
if (fabs(x - xm) <= (tol2 - 0.5*(b - a)))
{
*xmin = x;
return fx;
}
if (fabs(e) > tol1)
{
r = (x - w)*(fx - fv);
q = (x - v)*(fx - fw);
p = (x - v)*q - (x - w)*r;
q = 2.0*(q - r);
if (q > 0.0) p = -p;
q = fabs(q);
etemp = e;
e = d;
if (fabs(p) >= fabs(0.5*q*etemp) || p <= q*(a - x) || p >= q*(b - x))
d = CGOLD*(e = (x >= xm ? a - x : b - x));
else
{
d = p / q;
u = x + d;
if (u - a < tol2 || b - u < tol2) d = SIGN(tol1, xm - x);
}
}
else d = CGOLD*(e = (x >= xm ? a - x : b - x));
u = (fabs(d) >= tol1 ? x + d : x + SIGN(tol1, d));
fu = (*f)(u);
if (fu <= fx)
{
if (u >= x) a = x; else b = x;
SHFT(v, w, x, u);
SHFT(fv, fw, fx, fu);
}
else
{
if (u<x) a = u; else b = u;
if (fu <= fw || w == x)
{
v = w;
w = u;
fv = fw;
fw = fu;
}
else if (fu <= fv || v == x || v == w)
{
v = u;
fv = fu;
}
}
}
fprintf(stderr, "ERROR : Too many iterations in brent routine\n");
*xmin = x;
return fx;
}
#define SHFT2(a, b, c) (a)=(b);(b)=(c);
#define SHFT(a, b, c, d) (a)=(b);(b)=(c);(c)=(d);
#define SIGN2(a, b) ((b)>=0?fabs(a):(-fabs(a)))
void mnbrak(double* pa, double* pb, double* pc, double* pfa, double* pfb, double* pfc, double(*func)(double))
{
const double GOLD = 1.618034;
const double TINY = 1.0e-20;
const double GLIMIT = 100;
double& a = *pa;
double& b = *pb;
double& c = *pc;
double& fa = *pfa;
double& fb = *pfb;
double& fc = *pfc;
double ulim, u, r, q, fu, dum;
fa = func(a);
fb = func(b);
if (fb>fa)
{
SHFT(dum, a, b, dum);
SHFT(dum, fb, fa, dum);
}
c = b + GOLD*(b - a);
fc = func(c);
while (fb > fc)
{
r = (b - a)*(fb - fc);
q = (b - c)*(fb - fa);
u = b - ((b - c)*q - (b - a)*r) / (2.0*SIGN2(FMAX(fabs(q - r), TINY), q - r));
ulim = b + GLIMIT*(c - b);
if ((b - u)*(u - c) > 0)
{
fu = func(u);
if (fu < fc)
{
a = b;
b = u;
fa = fb;
fb = fu;
return;
}
else if (fu > fb)
{
c = u;
fc = fu;
return;
}
u = c + GOLD*(c - b);
fu = func(u);
}
else if ((c - u)*(u - ulim) > 0)
{
fu = func(u);
if (fu < fc)
{
SHFT(b, c, u, c + GOLD*(c - b));
SHFT(fb, fc, fu, func(u));
}
}
else if ((u - ulim)*(ulim - c) >= 0)
{
u = ulim;
fu = func(u);
}
else
{
u = c + GOLD*(c - b);
fu = func(u);
}
SHFT(a, b, c, u);
SHFT(fa, fb, fc, fu);
}
}
double golden(double ax, double bx, double cx, double(*f)(double), double tol, double* xmin)
{
const double R = 0.61803399;
const double C = 1 - R;
double f1, f2, x0, x1, x2, x3;
x0 = ax;
x3 = cx;
if (fabs(cx - bx) > fabs(bx - ax))
{
x1 = bx;
x2 = bx + C*(cx - bx);
}
else
{
x2 = bx;
x1 = bx - C*(bx - ax);
}
f1 = f(x1);
f2 = f(x2);
while (fabs(x3 - x0) > tol*(fabs(x1) + fabs(x2)))
{
if (f2 < f1)
{
SHFT(x0, x1, x2, R*x1 + C*x3);
SHFT2(f1, f2, f(x2));
}
else
{
SHFT(x3, x2, x1, R*x2 + C*x0);
SHFT2(f2, f1, f(x1));
}
}
if (f1 < f2)
{
*xmin = x1;
return f1;
}
else
{
*xmin = x2;
return f2;
}
}
//-----------------------------------------------------------------------------
double zbrent(double func(double, void*), double x1, double x2, double tol, void* data)
{
const int ITMAX = 100;
const double EPS = DBL_EPSILON;
int iter;
double a=x1, b=x2, c=x2, d, e, min1, min2;
double fa=func(a, data), fb = func(b, data), fc, p, q, r, s, tol1, xm;
if ((fa > 0.0 && fb > 00) || (fa < 0.0 && fb < 0.0))
{
assert(false);
return 0.0;
}
fc = fb;
for (iter = 0; iter<ITMAX; iter++) {
if ((fb > 0.0 && fc > 0.0) || (fb < 0.0 && fc < 0.0)) {
c = a;
fc = fa;
e = d = b - a;
}
if (fabs(fc) < fabs(fb)) {
a = b;
b = c;
c = a;
fa = fb;
fb = fc;
fc = fa;
}
tol1 = 2.0*EPS*fabs(b) + 0.5*tol;
xm = 0.5*(c - b);
if (fabs(xm) <= tol1 || fb == 0.0) return b;
if (fabs(e) >= tol1 && fabs(fa) > fabs(fb)) {
s = fb / fa;
if (a == c) {
p = 2.0*xm*s;
q = 1.0 - s;
} else {
q = fa/fc;
r = fb/fc;
p = s*(2.0*xm*q*(q-r)-(b-a)*(r - 1.0));
q = (q - 1.0)*(r - 1.0)*(s - 1.0);
}
if (p > 0.0) q = -q;
p = fabs(p);
min1 = 3.0*xm*q - fabs(tol1*q);
min2 = fabs(e*q);
if (2.0*p < (min1 < min2 ? min1 : min2)) {
e = d;
d = p/q;
} else {
d = xm;
e = d;
}
} else {
d = xm;
e = d;
}
a = b;
fa = fb;
if (fabs(d) > tol1)
b += d;
else
b += SIGN(tol1, xm);
fb = func(b, data);
}
assert(false);
return 0.0;
}
//-----------------------------------------------------------------------------
bool zbrac(double f(double, void*), double& x1, double& x2, void* data)
{
const int MAXTRY = 50;
const double FACTOR = 1.6;
if (x1 == x2)
{
assert(false);
return false;
}
double f1 = f(x1, data);
double f2 = f(x2, data);
for (int j=0; j<MAXTRY; ++j)
{
if (f1*f2 < 0.0) return true;
if (fabs(f1) < fabs(f2))
f1 = f(x1 += FACTOR*(x1 - x2), data);
else
f2 = f(x2 += FACTOR*(x2 - x1), data);
}
return false;
}
//-----------------------------------------------------------------------------
void solve_3x3(double A[3][3], double b[3], double x[3])
{
double D = A[0][0] * A[1][1] * A[2][2] + A[0][1] * A[1][2] * A[2][0] + A[1][0] * A[2][1] * A[0][2] \
- A[1][1] * A[2][0] * A[0][2] - A[2][2] * A[1][0] * A[0][1] - A[0][0] * A[2][1] * A[1][2];
assert(D != 0);
double Ai[3][3];
Ai[0][0] = A[1][1] * A[2][2] - A[2][1] * A[1][2];
Ai[0][1] = A[2][1] * A[0][2] - A[0][1] * A[2][2];
Ai[0][2] = A[0][1] * A[1][2] - A[1][1] * A[0][2];
Ai[1][0] = A[2][0] * A[1][2] - A[1][0] * A[2][2];
Ai[1][1] = A[0][0] * A[2][2] - A[2][0] * A[0][2];
Ai[1][2] = A[1][0] * A[0][2] - A[0][0] * A[1][2];
Ai[2][0] = A[1][0] * A[2][1] - A[2][0] * A[1][1];
Ai[2][1] = A[2][0] * A[0][1] - A[0][0] * A[2][1];
Ai[2][2] = A[0][0] * A[1][1] - A[0][1] * A[1][0];
x[0] = (Ai[0][0] * b[0] + Ai[0][1] * b[1] + Ai[0][2] * b[2]) / D;
x[1] = (Ai[1][0] * b[0] + Ai[1][1] * b[1] + Ai[1][2] * b[2]) / D;
x[2] = (Ai[2][0] * b[0] + Ai[2][1] * b[1] + Ai[2][2] * b[2]) / D;
#ifndef NDEBUG
double r[3];
r[0] = b[0] - (A[0][0] * x[0] + A[0][1] * x[1] + A[0][2] * x[2]);
r[1] = b[1] - (A[1][0] * x[0] + A[1][1] * x[1] + A[1][2] * x[2]);
r[2] = b[2] - (A[2][0] * x[0] + A[2][1] * x[1] + A[2][2] * x[2]);
double nr = sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]);
#endif
}
//=============================================================================
bool LinearRegression(const std::vector<std::pair<double, double> >& data, std::pair<double, double>& res)
{
res.first = 0.0;
res.second = 0.0;
int n = (int)data.size();
if (n == 0) return false;
double mx = 0.0, my = 0.0;
double sxx = 0.0, sxy = 0.0;
for (int i = 0; i < n; ++i)
{
double xi = data[i].first;
double yi = data[i].second;
mx += xi;
my += yi;
sxx += xi * xi;
sxy += xi * yi;
}
mx /= (double)n;
my /= (double)n;
sxx /= (double)n;
sxy /= (double)n;
double D = sxx - mx * mx;
if (D == 0.0) return false;
double a = (sxy - mx * my) / D;
double b = my - a * mx;
res.first = a;
res.second = b;
return true;
}
class Func
{
public:
Func() {}
virtual ~Func() {}
virtual void setParams(const std::vector<double>& v) = 0;
virtual double value(double x) = 0;
virtual double derive1(double x, int n) = 0;
virtual double derive2(double x, int n1, int n2) = 0;
};
class Quadratic : public Func
{
public:
Quadratic() : m_a(0.0), m_b(0.0), m_c(0.0) {}
void setParams(const std::vector<double>& v) override { m_a = v[0]; m_b = v[1]; m_c = v[2]; }
double value(double x) override { return m_a * x * x + m_b * x + m_c; }
double derive1(double x, int n) override
{
switch (n)
{
case 0: return x * x; break;
case 1: return x; break;
case 2: return 1; break;
default:
assert(false);
return 0.0;
}
}
double derive2(double x, int n1, int n2) override
{
return 0.0;
}
private:
double m_a, m_b, m_c;
};
class Exponential : public Func
{
public:
Exponential() : m_a(0.0), m_b(0.0) {}
void setParams(const std::vector<double>& v) override { m_a = v[0]; m_b = v[1]; }
double value(double x) override { return m_a * exp(x * m_b); }
double derive1(double x, int n) override
{
switch (n)
{
case 0: return exp(x * m_b); break;
case 1: return m_a * x * exp(x * m_b); break;
default:
assert(false);
return 0.0;
}
}
double derive2(double x, int n1, int n2) override
{
if ((n1 == 0) && (n2 == 0)) return 0;
else if ((n1 == 0) && (n2 == 1)) return x * exp(x * m_b);
else if ((n1 == 1) && (n2 == 0)) return x * exp(x * m_b);
else if ((n1 == 1) && (n2 == 1)) return m_a * x * x * exp(x * m_b);
else return 0.0;
}
private:
double m_a, m_b;
};
bool NonlinearRegression(const std::vector<std::pair<double, double> >& data, std::vector<double>& res, int func)
{
int MAX_ITER = 10;
int niter = 0;
int n = (int)data.size();
int m = (int)res.size();
Func* f = 0;
switch (func)
{
case 1: f = new Quadratic; break;
case 2: f = new Exponential; break;
}
if (f == 0) return false;
std::vector<double> R(m, 0.0), da(m, 0.0);
matrix K(m, m); K.zero();
const double absTol = 1e-15;
const double relTol = 1e-3;
double norm0 = 0.0;
do
{
f->setParams(res);
// evaluate residual (and norm)
double norm = 0.0;
for (int i = 0; i < m; ++i)
{
R[i] = 0.0;
for (int j = 0; j < n; ++j)
{
double xj = data[j].first;
double yj = data[j].second;
double fj = f->value(xj);
double Dfi = f->derive1(xj, i);
R[i] -= (fj - yj) * Dfi;
}
norm += R[i] * R[i];
}
norm = sqrt(norm / n);
if (norm < absTol) break;
if (niter == 0) norm0 = norm;
else
{
double rel = norm / norm0;
if (rel < relTol) break;
}
// evaluate Jacobian
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < m; ++j)
{
double Kij = 0.0;
for (int k = 0; k < n; ++k)
{
double xk = data[k].first;
double yk = data[k].second;
double fk = f->value(xk);
double Dfi = f->derive1(xk, i);
double Dfj = f->derive1(xk, j);
double Dfij = f->derive2(xk, i, j);
Kij += Dfi * Dfj + (fk - yk) * Dfij;
}
K[i][j] = Kij;
}
}
// solve linear system
K.solve(da, R);
for (int i = 0; i < m; ++i) res[i] += da[i];
niter++;
} while (niter < MAX_ITER);
delete f;
return (niter < MAX_ITER);
}
//=============================================================================
//! Polynomial root solver
// function whose roots needs to be evaluated
void fn(std::complex<double>& z, std::complex<double>& fz, std::vector<double> a)
{
int n = (int)a.size() - 1;
fz = a[0];
std::complex<double> x(1, 0);
for (int i = 1; i <= n; ++i) {
x *= z;
fz += a[i] * x;
}
return;
}
//-----------------------------------------------------------------------------
// deflation
bool dflate(std::complex<double> zero, const int i, int& kount,
std::complex<double>& fzero, std::complex<double>& fzrdfl,
std::complex<double>* zeros, std::vector<double> a)
{
std::complex<double> den;
++kount;
fn(zero, fzero, a);
fzrdfl = fzero;
if (i < 1) return false;
for (int j = 0; j < i; ++j) {
den = zero - zeros[j];
if (abs(den) == 0) {
zeros[i] = zero * 1.001;
return true;
}
else {
fzrdfl = fzrdfl / den;
}
}
return false;
}
//-----------------------------------------------------------------------------
// Muller's method for solving roots of a function
bool muller(bool fnreal, std::complex<double>* zeros, const int n, const int nprev,
const int maxit, const double ep1, const double ep2, std::vector<double> a)
{
int kount;
std::complex<double> dvdf1p, fzrprv, fzrdfl, divdf1, divdf2;
std::complex<double> fzr, zero, c, den, sqr, z;
// initialization
double eps1 = (ep1 > 1e-12) ? ep1 : 1e-12;
double eps2 = (ep2 > 1e-20) ? ep2 : 1e-20;
for (int i = nprev; i < n; ++i) {
kount = 0;
eloop:
zero = zeros[i];
std::complex<double> h = 0.5;
std::complex<double> hprev = -1.0;
// compute first three estimates for zero as
// zero+0.5, zero-0.5, zero
z = zero + 0.5;
if (dflate(z, i, kount, fzr, dvdf1p, zeros, a)) goto eloop;
z = zero - 0.5;
if (dflate(z, i, kount, fzr, fzrprv, zeros, a)) goto eloop;
dvdf1p = (fzrprv - dvdf1p) / hprev;
if (dflate(zero, i, kount, fzr, fzrdfl, zeros, a)) goto eloop;
do {
divdf1 = (fzrdfl - fzrprv) / h;
divdf2 = (divdf1 - dvdf1p) / (h + hprev);
hprev = h;
dvdf1p = divdf1;
c = divdf1 + h * divdf2;
sqr = c * c - 4. * fzrdfl * divdf2;
if (fnreal && (sqr.real() < 0)) sqr = 0;
sqr = sqrt(sqr);
if (c.real() * sqr.real() + c.imag() * sqr.imag() < 0) {
den = c - sqr;
}
else {
den = c + sqr;
}
if (abs(den) <= 0.) den = 1.;
h = -2. * fzrdfl / den;
fzrprv = fzrdfl;
zero = zero + h;
dloop:
fn(zero, fzrdfl, a);
// check for convergence
if (abs(h) < eps1 * abs(zero)) break;
if (abs(fzrdfl) < eps2) break;
// check for divergence
if (abs(fzrdfl) >= 10. * abs(fzrprv)) {
h /= 2.;
zero -= h;
goto dloop;
}
} while (kount < maxit);
zeros[i] = zero;
}
return true;
}
//-----------------------------------------------------------------------------
// Newton's method for finding nearest root of a polynomial
bool newton(double& zero, const int n, const int maxit,
const double ep1, const double ep2, std::vector<double> a)
{
bool done = false;
bool conv = false;
int it = 0;
double f, df, x, dx, xi;
x = zero;
while (!done) {
// Evaluate function and its derivative
xi = x;
f = a[0] + a[1] * xi;
df = a[1];
for (int i = 2; i <= n; ++i) {
df += i * a[i] * xi;
xi *= x;
f += a[i] * xi;
}
if (df == 0) break;
// check absolute convergence and don't update x if met
if (abs(f) < ep2) {
done = true;
conv = true;
zero = x;
break;
}
// evaluate increment in x
dx = -f / df;
x += dx;
++it;
// check relative convergence
if (abs(dx) < ep1 * abs(x)) {
done = true;
conv = true;
zero = x;
}
// check iteration count
else if (it > maxit) {
done = true;
zero = x;
}
}
return conv;
}
//-----------------------------------------------------------------------------
// linear
bool poly1(std::vector<double> a, double& x)
{
if (a[1]) {
x = -a[0] / a[1];
return true;
}
else {
return false;
}
}
//-----------------------------------------------------------------------------
// quadratic
bool poly2(std::vector<double> a, double& x)
{
if (a[2]) {
x = (-a[1] + sqrt(SQR(a[1]) - 4 * a[0] * a[2])) / (2 * a[2]);
return true;
}
else {
return poly1(a, x);
}
}
//-----------------------------------------------------------------------------
// higher order
bool polyn(int n, std::vector<double> a, double& x)
{
// bool fnreal = true;
// vector< complex<double> > zeros(n,complex<double>(1,0));
int maxit = 100;
double ep1 = 1e-6;
double ep2 = 1e-12;
return newton(x, n, maxit, ep1, ep2, a);
}
//-----------------------------------------------------------------------------
// higher order
bool polym(int n, std::vector<double> a, double& x)
{
bool fnreal = true;
std::vector< std::complex<double> > zeros(n, std::complex<double>(1, 0));
int maxit = 100;
double ep1 = 1e-6;
double ep2 = 1e-12;
muller(fnreal, &zeros[0], n, 0, maxit, ep1, ep2, a);
for (int i = 0; i < n; ++i) {
if (fabs(zeros[i].imag()) < ep2) {
x = zeros[i].real();
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
bool solvepoly(int n, std::vector<double> a, double& x, bool nwt)
{
switch (n) {
case 1:
return poly1(a, x);
break;
case 2:
return poly2(a, x);
default:
if (a[n]) {
return nwt ? polyn(n, a, x) : polym(n, a, x);
}
else {
return solvepoly(n - 1, a, x);
}
break;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDomain2D.h | .h | 4,222 | 107 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDomain.h"
//-----------------------------------------------------------------------------
//! Abstract base class for shell elements
class FECORE_API FEDomain2D : public FEDomain
{
FECORE_SUPER_CLASS(FEDOMAIN2D_ID)
FECORE_BASE_CLASS(FEDomain2D)
public:
//! constructor
FEDomain2D(FEModel* fem) : FEDomain(FE_DOMAIN_2D, fem) {}
//! create storage for elements
bool Create(int nsize, FE_Element_Spec espec) override;
//! return nr of elements
int Elements() const override { return (int)m_Elem.size(); }
//! element access
FEElement2D& Element(int n) { return m_Elem[n]; }
FEElement& ElementRef(int n) override { return m_Elem[n]; }
const FEElement& ElementRef(int n) const override { return m_Elem[n]; }
int GetElementType() { return m_Elem[0].Type(); }
//! Initialize elements
void PreSolveUpdate(const FETimeInfo& timeInfo) override;
//! Reset element data
void Reset() override;
// inverse jacobian with respect to reference frame
double invjac0(FEElement2D& el, double J[2][2], int n);
// inverse jacobian with respect to current frame
double invjact(FEElement2D& el, double J[2][2], int n);
//! calculate in-plane gradient of function at integration points
vec2d gradient(FEElement2D& el, double* fn, int n);
//! calculate in-plane gradient of function at integration points
vec2d gradient(FEElement2D& el, vector<double>& fn, int n);
//! calculate in-plane gradient of vector function at integration points
mat2d gradient(FEElement2D& el, vec2d* fn, int n);
//! calculate in-plane gradient of vector function at integration points
mat3d gradient(FEElement2D& el, vec3d* fn, int n);
// jacobian with respect to reference frame
double detJ0(FEElement2D& el, int n);
//! calculate jacobian in current frame
double detJt(FEElement2D& el, int n);
//! calculates covariant basis vectors at an integration point
void CoBaseVectors(FEElement2D& el, int j, vec2d g[2]);
//! calculates contravariant basis vectors at an integration point
void ContraBaseVectors(FEElement2D& el, int j, vec2d g[2]);
//! calculates parametric derivatives of covariant basis vectors at an integration point
void CoBaseVectorDerivatives(FEElement2D& el, int j, vec2d dg[2][2]);
//! calculates parametric derivatives of contravariant basis vectors at an integration point
void ContraBaseVectorDerivatives(FEElement2D& el, int j, vec2d dg[2][2]);
//! calculate the laplacian of a vector function at an integration point
vec2d lapvec(FEElement2D& el, vec2d* fn, int n);
//! calculate the gradient of the divergence of a vector function at an integration point
vec2d gradivec(FEElement2D& el, vec2d* fn, int n);
protected:
vector<FEElement2D> m_Elem; //!< array of elements
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEPropertyT.h | .h | 7,617 | 324 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "DumpStream.h"
//-----------------------------------------------------------------------------
template <class T>
class FEPropertyT : public FEProperty
{
private:
T** m_pc; //!< pointer to pointer of property
public:
FEPropertyT(T** ppc) : FEProperty(T::superClassID())
{
m_pc = ppc;
m_className = T::BaseClassName();
}
bool IsArray() const override { return false; }
bool IsType(FECoreBase* pc) const override { return (dynamic_cast<T*>(pc) != nullptr); }
void SetProperty(FECoreBase* pc) override
{
*m_pc = dynamic_cast<T*>(pc);
pc->SetParent(GetParent());
}
int size() const override { return ((*m_pc) == 0 ? 0 : 1); }
FECoreBase* get(int i) override { return *m_pc; }
FECoreBase* get(const char* szname) override
{
if ((*m_pc)->GetName() == std::string(szname))
return *m_pc;
else
return 0;
}
FECoreBase* getFromID(int nid) override
{
if (m_pc && (*m_pc) && ((*m_pc)->GetID() == nid)) return *m_pc; else return 0;
}
void Serialize(DumpStream& ar) override
{
ar & (*m_pc);
}
bool Init() override
{
if (m_pc && (*m_pc)) { return (*m_pc)->Init(); }
return (IsRequired() == false);
}
bool Validate() override
{
if (m_pc && (*m_pc)) return (*m_pc)->Validate();
return true;
}
};
//-----------------------------------------------------------------------------
template <class T>
class FEFixedPropertyT : public FEProperty
{
private:
T* m_pc; //!< pointer to property
public:
FEFixedPropertyT(T* ppc) : FEProperty(T::superClassID())
{
m_pc = ppc;
m_className = T::BaseClassName();
}
bool IsArray() const override { return false; }
bool IsType(FECoreBase* pc) const override { return (dynamic_cast<T*>(pc) != nullptr); }
void SetProperty(FECoreBase* pc) override
{
assert(m_pc == nullptr);
m_pc = dynamic_cast<T*>(pc);
pc->SetParent(GetParent());
}
int size() const override { return (m_pc == 0 ? 0 : 1); }
FECoreBase* get(int i) override { return m_pc; }
FECoreBase* get(const char* szname) override
{
if (m_pc->GetName() == std::string(szname))
return m_pc;
else
return 0;
}
FECoreBase* getFromID(int nid) override
{
if (m_pc && (m_pc->GetID() == nid)) return m_pc; else return nullptr;
}
void Serialize(DumpStream& ar) override
{
assert(m_pc);
ar & (*m_pc);
}
bool Init() override
{
if (m_pc) { return m_pc->Init(); }
else return false;
}
bool Validate() override
{
if (m_pc) return m_pc->Validate();
return true;
}
};
template <class T>
class FEFixedVecPropertyT : public FEProperty
{
private:
std::vector<T>* m_pc; //!< pointer to property list
public:
FEFixedVecPropertyT(std::vector<T>* ppc) : FEProperty(T::superClassID())
{
m_pc = ppc;
m_className = T::BaseClassName();
}
bool IsArray() const override { return true; }
bool IsType(FECoreBase* pc) const override { return (dynamic_cast<T*>(pc) != nullptr); }
void SetProperty(FECoreBase* pc) override
{
T* p = dynamic_cast<T*>(pc); assert(p);
if (p == nullptr) return;
m_pc->push_back(*p);
}
int size() const override { return (int)(m_pc == 0 ? 0 : m_pc->size()); }
FECoreBase* get(int i) override
{
if ((i >= 0) && (i < (int)m_pc->size())) return &(*m_pc)[i];
if (i == m_pc->size())
{
m_pc->emplace_back(T());
return &m_pc->back();
}
return nullptr;
}
FECoreBase* get(const char* szname) override
{
// This requires that T has a GetName() member function, which may not be the case.
return nullptr;
}
FECoreBase* getFromID(int nid) override
{
// This assumes that T has a GetID() member, which may not be the case.
// I don't think I can implement this.
return nullptr;
}
void Serialize(DumpStream& ar) override
{
// TODO: implement serialization
}
bool Init() override
{
// TODO: implement initialization
return true;
}
bool Validate() override
{
// TODO: implement validation
return true;
}
};
//-----------------------------------------------------------------------------
//! Use this class to define array material properties
template<class T> class FEVecPropertyT : public FEProperty
{
private:
typedef std::vector<T*> Y;
Y* m_pmp; //!< pointer to actual material property
public:
FEVecPropertyT(Y* p) : FEProperty(T::superClassID())
{
m_pmp = p;
m_className = T::BaseClassName();
}
T* operator [] (int i) { return (*m_pmp)[i]; }
const T* operator [] (int i) const { return (*m_pmp)[i]; }
virtual bool IsArray() const { return true; }
virtual bool IsType(FECoreBase* pc) const { return (dynamic_cast<T*>(pc) != 0); }
virtual void SetProperty(FECoreBase* pc) {
T* pt = dynamic_cast<T*>(pc); assert(pt != nullptr);
m_pmp->push_back(pt);
pt->SetParent(GetParent());
}
virtual int size() const { return (int)m_pmp->size(); }
virtual FECoreBase* get(int i) { return (*m_pmp)[i]; }
virtual FECoreBase* get(const char* szname)
{
std::string name(szname);
for (int i=0; i<(int) m_pmp->size(); ++i)
{
T* p = (*m_pmp)[i];
if (p->GetName() == name) return p;
}
return 0;
}
virtual FECoreBase* getFromID(int nid)
{
for (int i = 0; i<(int)m_pmp->size(); ++i)
{
T* p = (*m_pmp)[i];
if (p && (p->GetID() == nid)) return p;
}
return 0;
}
void AddProperty(FECoreBase* pc) {
m_pmp->push_back(dynamic_cast<T*>(pc));
pc->SetParent(GetParent());
}
void Clear()
{
for (int i=0; i<(int) m_pmp->size(); ++i) delete (*m_pmp)[i];
m_pmp->clear();
}
void Insert(int n, T* pc)
{
m_pmp->insert(m_pmp->begin()+n, pc);
pc->SetParent(GetParent());
}
void Serialize(DumpStream& ar)
{
if (ar.IsSaving())
{
int n = size();
ar << n;
for (int i = 0; i<n; ++i)
{
T* pm = (*m_pmp)[i];
ar << pm;
}
}
else
{
int n = 0;
ar >> n;
if (ar.IsShallow() == false) m_pmp->assign(n, nullptr);
assert(m_pmp->size() == n);
for (int i = 0; i<n; ++i)
{
ar >> (*m_pmp)[i];
}
}
}
bool Init() {
if (m_pmp->empty() && IsRequired()) return false;
for (size_t i = 0; i<m_pmp->size(); ++i)
{
if ((*m_pmp)[i])
{
if ((*m_pmp)[i]->Init() == false) return false;
}
else return false;
}
return true;
}
bool Validate() {
if (m_pmp->empty()) return true;
for (size_t i = 0; i<m_pmp->size(); ++i)
{
if ((*m_pmp)[i])
{
if ((*m_pmp)[i]->Validate() == false) return false;
}
}
return true;
}
};
| Unknown |
3D | febiosoftware/FEBio | FECore/mathalg.cpp | .cpp | 2,907 | 119 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "mathalg.h"
mat3ds Log(const mat3ds& p, const mat3ds& X)
{
double l[3], s[3];
vec3d u[3], v[3];
// evaluate eigen-decomposition of p
p.eigen(l, u);
mat3d U(u[0], u[1], u[2]);
mat3dd L(l[0], l[1], l[2]);
mat3dd rootL(sqrt(l[0]), sqrt(l[1]), sqrt(l[2]));
mat3d G = U * rootL;
mat3d Gi = G.inverse();
mat3ds Y = (Gi * X*Gi.transpose()).sym();
Y.eigen(s, v);
mat3d V = mat3d(v[0], v[1], v[2]);
mat3d GV = G * V;
mat3dd logS(log(s[0]), log(s[1]), log(s[2]));
mat3d LogX = (GV)*logS*(GV.transpose());
return LogX.sym();
}
mat3ds Exp(const mat3ds& p, const mat3ds& X)
{
double l[3], s[3];
vec3d u[3], v[3];
// evaluate eigen-decomposition of p
p.eigen(l, u);
mat3d U(u[0], u[1], u[2]);
mat3dd L(l[0], l[1], l[2]);
mat3dd rootL(sqrt(l[0]), sqrt(l[1]), sqrt(l[2]));
mat3d G = U * rootL;
mat3d Gi = G.inverse();
mat3ds Y = (Gi * X*Gi.transpose()).sym();
Y.eigen(s, v);
mat3d V = mat3d(v[0], v[1], v[2]);
mat3d GV = G * V;
mat3dd expS(exp(s[0]), exp(s[1]), exp(s[2]));
mat3d ExpX = (GV)*expS*(GV.transpose());
return ExpX.sym();
}
mat3ds weightedAverageStructureTensor(mat3ds* d, double* w, int n)
{
const double eps = 1.0e-9;
mat3ds mu(1.0, 1.0, 1.0, 0.0, 0.0, 0.0);
double tau = 1.0;
double normXi = 0.0, normXip = 0.0;
mat3ds Xi, Xip;
int nc = 0;
do
{
Xip = Xi;
normXip = normXi;
Xi = weightedAverage<mat3ds>(d, w, n, [&](const mat3ds& a) {
return Log(mu, a);
});
mu = Exp(mu*tau, Xi);
normXi = Xi.norm();
if ((nc != 0) && (normXi > normXip))
{
Xi = Xip;
tau *= 0.5;
}
nc++;
}
while (normXi > eps);
return mu;
}
| C++ |
3D | febiosoftware/FEBio | FECore/MDerive.cpp | .cpp | 6,680 | 250 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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;
#ifndef PI
#define PI 3.141592653589793
#endif
//-----------------------------------------------------------------------------
MITEM MDerive(const MITEM& a, const MVariable& x)
{
MITEM e = MEvaluate(a);
if (is_dependent(e, x) == false) return 0.0;
switch (e.Type())
{
case MCONST:
case MFRAC:
case MNAMED: return 0.0;
case MVAR: if (e == x) return 1.0; else return 0.0;
case MNEG: return -MDerive(-e, x);
case MADD: return (MDerive(e.Left(), x) + MDerive(e.Right(), x));
case MSUB:
{
MITEM l = MDerive(e.Left(), x);
MITEM r = MDerive(e.Right(), x);
return l - r;
}
case MMUL:
{
MITEM l = e.Left();
MITEM dl = MDerive(l, x);
MITEM r = e.Right();
MITEM dr = MDerive(r, x);
return (dl*r + l*dr);
}
case MDIV:
{
MITEM l = e.Left();
MITEM r = e.Right();
MITEM dl = MDerive(l, x)*r;
MITEM dr = l*MDerive(r, x);
// be careful here that we are not subtracting two pointers
MITEM a = dl/(r^2.0);
MITEM b = dr/(r^2.0);
return (a-b);
}
case MPOW:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(r, x) == false) return (r*(l^(r-1.0)))*MDerive(l, x);
else if (is_dependent(l, x) == false) return (Log(l)*e)*MDerive(r, x);
else
{
MITEM dl = MDerive(l, x);
MITEM dr = MDerive(r, x);
return (e*(dr*Log(l) + (r*dl)/l));
}
}
case MF1D:
{
const string& s = mfnc1d(e)->Name();
MITEM p = mfnc1d(e)->Item()->copy();
MITEM dp = MDerive(p,x);
if (s.compare("cos") == 0) return -Sin(p)*dp;
if (s.compare("sin") == 0) return Cos(p)*dp;
if (s.compare("tan") == 0) return (Sec(p)^2.0)*dp;
if (s.compare("sec") == 0) return (Sec(p)*Tan(p))*dp;
if (s.compare("csc") == 0) return (-Csc(p)*Cot(p))*dp;
if (s.compare("cot") == 0) return -((Csc(p)^2.0)*dp);
if (s.compare("abs") == 0) return Sgn(p)*dp;
if (s.compare("ln" ) == 0) return (dp/p);
if (s.compare("log") == 0) return (dp/p)/Log(MITEM(10.0));
if (s.compare("asin") == 0) return (dp/Sqrt(1.0 - (p^2)));
if (s.compare("acos") == 0) return (-dp/Sqrt(1.0 - (p^2)));
if (s.compare("atan") == 0) return (dp/((p^2) + 1.0));
if (s.compare("cosh") == 0) return (dp*Sinh(p));
if (s.compare("sinh") == 0) return (dp*Cosh(p));
if (s.compare("sqrt") == 0) return (dp/(2.0*Sqrt(p)));
if (s.compare("acosh") == 0) return (dp/Sqrt((p^2) - 1.0));
#ifdef WIN32
if (s.compare("J0" ) == 0) return (-J1(p))*dp;
if (s.compare("J1" ) == 0) return dp*(J0(p) - Jn(2, p))/2.0;
if (s.compare("Y0" ) == 0) return (-Y1(p))*dp;
if (s.compare("Y1" ) == 0) return dp*(Y0(p) - Yn(2, p))/2.0;
#endif
if (s.compare("erf" ) == 0)
{
MITEM Pi = new MNamedCt(PI, "pi");
return 2/Sqrt(Pi)*Exp(-(p^2))*dp;
}
if (s.compare("erfc") == 0)
{
MITEM Pi = new MNamedCt(PI, "pi");
return -(2/Sqrt(Pi))*Exp(-(p^2))*dp;
}
if (s.compare("H") == 0)
{
return 0.0;
}
assert(false);
}
break;
case MF2D:
{
const string& s = mfnc2d(e)->Name();
MITEM l = e.Left();
MITEM r = e.Right();
if (s.compare("pow") == 0)
{
if (isConst(r) || is_named(r) || is_frac(r)) return (r * (l ^ (r - 1.0))) * MDerive(l, x);
else if (isConst(l) || is_named(l) || is_frac(l)) return (Log(l) * e) * MDerive(r, x);
else
{
MITEM dl = MDerive(l, x);
MITEM dr = MDerive(r, x);
return (e * (dr * Log(l) + (r * dl) / l));
}
}
#ifdef WIN32
else if (s.compare("Jn") == 0)
{
MITEM dr = MDerive(r, x);
if (is_int(l))
{
int n = (int) l.value();
if (n==0) return (-J1(r))*dr;
else return ((Jn(n-1, r) - Jn(n+1, r))/2.0)*dr;
}
}
else if (s.compare("Yn") == 0)
{
MITEM dr = MDerive(r, x);
if (is_int(l))
{
int n = (int) l.value();
if (n==0) return (-Y1(r))*dr;
else return ((Yn(n-1, r) - Yn(n+1, r))/2.0)*dr;
}
}
#endif
}
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 dmij = MDerive(mij, x);
(*pdm)[i][j] = dmij.copy();
}
return MITEM(pdm);
}
break;
case MSFNC:
{
const MSFuncND& f = *msfncnd(e);
MITEM v(f.Value()->copy());
return MDerive(v, x);
}
break;
}
assert(false);
return e;
}
//-----------------------------------------------------------------------------
MITEM MDerive(const MITEM& e, const MVariable& x, int n)
{
MITEM d = e;
for (int i=0; i<n; ++i) d = MDerive(d, x);
return d;
}
//-----------------------------------------------------------------------------
MITEM MDerive(const MITEM& e, const MSequence& x)
{
MITEM d = e;
for (int i=0; i<(int) x.size(); ++i)
{
const MVariable& xi = *(mvar(x[i])->GetVariable());
d = MDerive(d, xi);
}
return d;
}
//-----------------------------------------------------------------------------
MITEM MTaylor(const MITEM& e, const MVariable& v, double z, int n)
{
MITEM a(z);
MITEM x(v);
MITEM dx = x - a;
MITEM s = MReplace(e, v, a);
MITEM t(e);
double d = 1;
for (int i=1; i<=n; ++i)
{
t = MDerive(t /d, v);
d = (double) i;
MITEM f = MReplace(t, v, a);
MITEM Di = dx^d;
MITEM ds = ((f/d)*Di);
s = s + ds;
}
return s;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FETimeStepController.cpp | .cpp | 9,570 | 353 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FETimeStepController.h"
#include "FELoadCurve.h"
#include "FEAnalysis.h"
#include "FEPointFunction.h"
#include "DumpStream.h"
#include "FEModel.h"
#include "log.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FETimeStepController, FEParamContainer)
ADD_PARAMETER(m_maxretries, "max_retries")->setLongName("max retries");
ADD_PARAMETER(m_iteopt , "opt_iter")->setLongName("optimal iterations");
ADD_PARAMETER(m_dtmin , "dtmin")->setLongName("min stepsize");
ADD_PARAMETER(m_dtmax , "dtmax")->setLongName("max stepsize");
ADD_PARAMETER(m_naggr , "aggressiveness");
ADD_PARAMETER(m_cutback , "cutback");
ADD_PARAMETER(m_dtforce , "dtforce");
// ADD_PARAMETER(m_must_points, "must_points");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FETimeStepController::FETimeStepController(FEModel* fem) : FECoreBase(fem)
{
m_step = nullptr; // must be set with SetAnalysis
m_nretries = 0;
m_maxretries = 5;
m_naggr = 0;
m_cutback = 0.5;
m_nmust = -1;
m_next_must = -1;
m_nmplc = -1;
m_iteopt = 11;
m_dtmin = 0;
m_dtmax = 0.1;
m_ddt = 0;
m_dtp = 0;
m_mp_repeat = false;
m_mp_toff = 0.0;
m_dtforce = false;
}
//-----------------------------------------------------------------------------
void FETimeStepController::SetAnalysis(FEAnalysis* step)
{
m_step = step;
}
//-----------------------------------------------------------------------------
//! copy from
void FETimeStepController::CopyFrom(FETimeStepController* tc)
{
assert(m_step);
m_naggr = tc->m_naggr;
m_nmplc = tc->m_nmplc;
m_iteopt = tc->m_iteopt;
m_dtmin = tc->m_dtmin;
m_dtmax = tc->m_dtmax;
m_cutback = tc->m_cutback;
m_ddt = tc->m_ddt;
m_dtp = tc->m_dtp;
m_must_points = tc->m_must_points;
}
//-----------------------------------------------------------------------------
// initialization
bool FETimeStepController::Init()
{
// make sure we have a step assigned
if (m_step == 0) return false;
// steal the load curve param from the dtmax parameter
FEParam* p = FindParameterFromData((void*) &m_dtmax); assert(p);
FEModel* fem = GetFEModel();
FELoadController* plc = fem->GetLoadController(p);
if (plc)
{
m_nmplc = plc->GetID();
fem->DetachLoadController(p);
// print a warning that dtmax is ignored
if (m_dtmax != 0)
{
feLogWarning("dtmax is ignored when specifying must points.");
}
// if a must-point curve is defined and the must-points are empty,
// we copy the load curve points to the must-points
if (m_must_points.empty())
{
FELoadCurve* lc = dynamic_cast<FELoadCurve*>(plc);
if (lc)
{
PointCurve& f = lc->GetFunction();
// make sure we have at least two points
if (f.Points() < 2) return false;
for (int i = 0; i < f.Points(); ++i)
{
double ti = f.Point(i).x();
m_must_points.push_back(ti);
}
// check for repeat setting
if (f.GetExtendMode() == PointCurve::REPEAT) m_mp_repeat = true;
}
}
}
// initialize "previous" time step
m_dtp = m_step->m_dt0;
return true;
}
//-----------------------------------------------------------------------------
//! reset
void FETimeStepController::Reset()
{
m_dtp = m_step->m_dt0;
m_nmust = -1;
m_next_must = -1;
m_mp_toff = 0.0;
}
//-----------------------------------------------------------------------------
//! Restores data for a running restart
void FETimeStepController::Retry()
{
FEModel* fem = m_step->GetFEModel();
feLogEx(fem, "Retrying time step. Retry attempt %d of max %d\n\n", m_nretries + 1, m_maxretries);
// adjust time step
double dt = m_step->m_dt;
if (m_nretries == 0) m_ddt = (dt) / (m_maxretries + 1);
double dtn;
if (m_naggr == 0) dtn = dt - m_ddt;
else dtn = dt*m_cutback;
feLogEx(fem, "\nAUTO STEPPER: retry step, dt = %lg\n\n", dtn);
// increase retry counter
m_nretries++;
// the new time step cannot be a must-point
if (m_nmust != -1)
{
// if we were at a must-point, make sure we can hit this must-point again
m_next_must--;
m_nmust = -1;
}
m_dtp = dtn;
m_step->m_dt = dtn;
}
//-----------------------------------------------------------------------------
//! Adjusts the time step size based on the convergence information.
//! If the previous time step was able to converge in less than
//! m_fem.m_iteopt iterations the step size is increased, else it
//! is decreased.
void FETimeStepController::AutoTimeStep(int niter)
{
FEModel* fem = m_step->GetFEModel();
double dt = m_step->m_dt;
double dtn = m_dtp;
double told = fem->GetCurrentTime();
// make sure the timestep size is at least the minimum
if (dtn < m_dtmin) dtn = m_dtmin;
// get the max time step
double dtmax = m_dtmax;
// If we have a must-point load curve
// we take the max step size from the lc
if (m_nmplc >= 0)
{
FELoadCurve& mpc = *(dynamic_cast<FELoadCurve*>(fem->GetLoadController(m_nmplc)));
PointCurve& lc = mpc.GetFunction();
dtmax = lc.value(told);
}
// adjust time step size
if (m_dtforce)
{
// if the force flag is set, we just set the time step to the max value
dtn = dtmax;
}
else if (niter > 0)
{
double scale = sqrt((double)m_iteopt / (double)niter);
// Adjust time step size
if (scale >= 1)
{
dtn = dtn + (dtmax - dtn) * MIN(.20, scale - 1);
dtn = MIN(dtn, 5.0 * m_dtp);
if (dtmax > 0) dtn = MIN(dtn, dtmax);
}
else
{
dtn = dtn - (dtn - m_dtmin) * (1 - scale);
if (m_dtmin > 0) dtn = MAX(dtn, m_dtmin);
if (dtmax > 0) dtn = MIN(dtn, dtmax);
}
}
else if (niter == 0)
{
if (m_dtmin > 0) dtn = MAX(dtn, m_dtmin);
if (dtmax > 0) dtn = MIN(dtn, dtmax);
}
// Report new time step size
if (dtn > dt)
feLogEx(fem, "\nAUTO STEPPER: increasing time step, dt = %lg\n\n", dtn);
else if (dtn < dt)
feLogEx(fem, "\nAUTO STEPPER: decreasing time step, dt = %lg\n\n", dtn);
// Store this time step value. This is the value that will be used to evaluate
// the next time step increment. This will not include adjustments due to the must-point
// controller since this could create really small time steps that may be difficult to
// recover from.
m_dtp = dtn;
// check for mustpoints
if (m_must_points.empty() == false) dtn = CheckMustPoints(told, dtn);
// make sure we are not exceeding the final time
if (told + dtn > m_step->m_tend)
{
dtn = m_step->m_tend - told;
feLogEx(fem, "MUST POINT CONTROLLER: adjusting time step. dt = %lg\n\n", dtn);
}
// store time step size
assert(dtn > 0);
m_step->m_dt = dtn;
}
//-----------------------------------------------------------------------------
//! This function makes sure that no must points are passed. It returns an
//! updated value (less than dt) if t + dt would pass a must point. Otherwise
//! it returns dt.
//! \param t current time
//! \param dt current time step
//! \return updated time step.
double FETimeStepController::CheckMustPoints(double t, double dt)
{
FEModel* fem = m_step->GetFEModel();
const double eps = m_step->m_tend * 1e-12;
m_nmust = -1;
const int points = (int)m_must_points.size();
if (m_next_must >= points)
{
if (m_mp_repeat)
{
m_mp_toff += m_must_points.back();
m_next_must = -1;
}
else return dt;
}
// set the first must-point if it has not been set
if (m_next_must < 0)
{
m_next_must = 0;
while ((m_next_must < points) && (m_must_points[m_next_must] + m_mp_toff < t + eps))
{
m_next_must++;
if (m_next_must >= points)
{
if (m_mp_repeat)
{
m_next_must = 0;
m_mp_toff += m_must_points.back();
}
else return dt;
}
}
}
assert(m_next_must < points);
double tmust = m_must_points[m_next_must] + m_mp_toff;
assert(tmust + eps > t);
double dtnew = dt;
double tnew = t + dt;
if (tmust < tnew + eps)
{
dtnew = tmust - t;
feLogEx(fem, "MUST POINT CONTROLLER: adjusting time step. dt = %lg\n\n", dtnew);
m_nmust = m_next_must++;
}
return dtnew;
}
//-----------------------------------------------------------------------------
//! serialize
void FETimeStepController::Serialize(DumpStream& ar)
{
FECoreBase::Serialize(ar);
ar & m_nretries;
ar & m_nmplc;
ar & m_nmust;
ar & m_next_must;
ar & m_mp_toff;
ar & m_mp_repeat;
ar & m_ddt & m_dtp;
ar & m_step;
ar & m_must_points;
}
| C++ |
3D | febiosoftware/FEBio | FECore/PointCurve.h | .h | 3,774 | 131 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
#include "vec2d.h"
#include <vector>
class FECORE_API PointCurve
{
class Imp;
public:
//! Interpolation functions
enum INTFUNC { LINEAR = 0, STEP = 1, SMOOTH = 2, CSPLINE = 3, CPOINTS = 4, APPROX = 5, SMOOTH_STEP = 6, C2SMOOTH = 7 };
//! Extend mode
enum EXTMODE { CONSTANT, EXTRAPOLATE, REPEAT, REPEAT_OFFSET };
public:
//! default constructor
PointCurve();
//! copy constructor
PointCurve(const PointCurve& pc);
//! assignment operator
void operator = (const PointCurve& pc);
//! destructor
~PointCurve();
//! call this to update internal data structures
bool Update();
//! adds a point to the point curve
int Add(double x, double y);
//! adds a point to the point curve
int Add(const vec2d& p);
//! Clears the loadcurve data
void Clear();
//! set the x and y value of point i
void SetPoint(int i, double x, double y);
void SetPoint(int i, const vec2d& p);
//! set all points at once
void SetPoints(const std::vector<vec2d>& points);
//! return all points
std::vector<vec2d> GetPoints() const;
//! remove a point
void Delete(int n);
//! remove several points at once
void Delete(const std::vector<int>& indexList);
//! Set the type of interpolation
void SetInterpolator(int fnc);
//! return current interpolator
int GetInterpolator() const;
//! Set the extend mode
void SetExtendMode(int mode);
//! Get the extend mode
int GetExtendMode() const;
//! get a point
vec2d Point(int i) const;
//! finds closest load point
int FindPoint(double t, double& tval, int startIndex = 0);
//! return nr of points
int Points() const;
//! see if there is a point at time t
bool HasPoint(double t) const;
public: // operations
// scale all y points by s
void Scale(double s);
public:
//! returns the value of the load curve at time
double value(double x) const;
//! returns the derivative value at time
double derive(double x) const;
//! returns the second derivative value at time
double deriv2(double x) const;
//! returns the definite integral value between a and b
double integrate(double a, double b) const;
protected:
double ExtendValue(double t) const;
private:
Imp* im;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELoadController.cpp | .cpp | 1,671 | 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 "FELoadController.h"
#include "DumpStream.h"
FELoadController::FELoadController(FEModel* fem) : FEModelComponent(fem)
{
m_value = 0.0;
}
void FELoadController::Evaluate(double time)
{
m_value = GetValue(time);
}
void FELoadController::Serialize(DumpStream& ar)
{
FECoreBase::Serialize(ar);
ar & m_value;
}
void FELoadController::Reset()
{
m_value = 0.0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FESurfaceToSurfaceMap.h | .h | 1,875 | 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 "FEDataGenerator.h"
#include "FEFunction1D.h"
#include "FEClosestPointProjection.h"
#include "FENormalProjection.h"
class FEModel;
class FESurface;
class FESurfaceToSurfaceMap : public FEElemDataGenerator
{
public:
FESurfaceToSurfaceMap(FEModel* fem);
~FESurfaceToSurfaceMap();
bool Init() override;
FEDataMap* Generate() override;
private:
double value(const vec3d& x);
private:
FEFunction1D* m_func;
FESurface* m_surf1;
FESurface* m_surf2;
FEClosestPointProjection* m_ccp1;
FEClosestPointProjection* m_ccp2;
bool m_binverted;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESolidElementShape.h | .h | 9,146 | 247 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 FESolidElementShape : public FEElementShape
{
public:
FESolidElementShape(FE_Element_Shape shape, int nodes) : FEElementShape(shape, nodes) {}
//! values of shape functions
virtual void shape_fnc(double* H, double r, double s, double t) = 0;
//! values of shape function derivatives
virtual void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t) = 0;
//! values of shape function second derivatives
virtual void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t) = 0;
};
//=============================================================================
class FETet4 : public FESolidElementShape
{
public:
FETet4() : FESolidElementShape(ET_TET4, 4) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FETet5 : public FESolidElementShape
{
public:
FETet5() : FESolidElementShape(ET_TET5, 5) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEHex8 : public FESolidElementShape
{
public:
FEHex8() : FESolidElementShape(ET_HEX8, 8) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEPenta6 : public FESolidElementShape
{
public:
FEPenta6() : FESolidElementShape(ET_PENTA6, 6) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEPenta15 : public FESolidElementShape
{
public:
FEPenta15() : FESolidElementShape(ET_PENTA15, 15) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FETet10 : public FESolidElementShape
{
public:
FETet10() : FESolidElementShape(ET_TET10, 10) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FETet15 : public FESolidElementShape
{
public:
FETet15() : FESolidElementShape(ET_TET15, 15) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FETet20 : public FESolidElementShape
{
public:
FETet20() : FESolidElementShape(ET_TET20, 20) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEHex20 : public FESolidElementShape
{
public:
FEHex20() : FESolidElementShape(ET_HEX20, 20) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
//! Base class for 27-node quadratic hexahedral element
class FEHex27 : public FESolidElementShape
{
public:
FEHex27() : FESolidElementShape(ET_HEX27, 27) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEPyra5 : public FESolidElementShape
{
public:
FEPyra5() : FESolidElementShape(ET_PYRA5, 5) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
//=============================================================================
class FEPyra13 : public FESolidElementShape
{
public:
FEPyra13() : FESolidElementShape(ET_PYRA13, 13) {}
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBodyConstraint.cpp | .cpp | 2,811 | 101 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBodyConstraint.h"
#include "FEElementSet.h"
#include "FEModelParam.h"
#include "FEMesh.h"
FEBodyConstraint::FEBodyConstraint(FEModel* fem) : FENLConstraint(fem)
{
}
bool FEBodyConstraint::Init()
{
// If the domain list is empty, add all the domains
if (m_dom.IsEmpty())
{
FEMesh& mesh = GetMesh();
for (int i = 0; i < mesh.Domains(); ++i)
{
FEDomain* dom = &mesh.Domain(i);
m_dom.AddDomain(dom);
}
}
return FENLConstraint::Init();
}
int FEBodyConstraint::Domains() const
{
return m_dom.Domains();
}
FEDomain* FEBodyConstraint::Domain(int i)
{
return m_dom.GetDomain(i);
}
void FEBodyConstraint::SetDomainList(FEElementSet* elset)
{
m_dom = elset->GetDomainList();
// add it to all the mapped parameters
FEParameterList& PL = GetParameterList();
FEParamIterator it = PL.first();
for (int i = 0; i < PL.Parameters(); ++i, ++it)
{
FEParam& pi = *it;
if (pi.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& param = pi.value<FEParamDouble>();
param.SetItemList(elset);
}
else if (pi.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& param = pi.value<FEParamVec3>();
param.SetItemList(elset);
}
else if (pi.type() == FE_PARAM_MAT3D_MAPPED)
{
FEParamMat3d& param = pi.value<FEParamMat3d>();
param.SetItemList(elset);
}
}
}
// get the domain list
FEDomainList& FEBodyConstraint::GetDomainList()
{
return m_dom;
}
//! Serialization
void FEBodyConstraint::Serialize(DumpStream& ar)
{
FENLConstraint::Serialize(ar);
m_dom.Serialize(ar);
}
| C++ |
3D | febiosoftware/FEBio | FECore/MatrixProfile.cpp | .cpp | 8,794 | 361 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "MatrixProfile.h"
#include <assert.h>
using namespace std;
SparseMatrixProfile::ColumnProfile::ColumnProfile(const SparseMatrixProfile::ColumnProfile& a)
{
m_data = a.m_data;
}
void SparseMatrixProfile::ColumnProfile::insertRow(int row)
{
// first, check if empty
if (m_data.empty()) { push_back(row, row); return; }
int N = size();
// check some easy cases first
if (row + 1 < m_data[0].start) { push_front(row, row); return; }
if (row + 1 == m_data[0].start) { m_data[0].start--; return; }
if (row - 1 > m_data[N-1].end) { push_back(row, row); return; }
if (row - 1 == m_data[N-1].end) { m_data[N-1].end++; return; }
// general case, find via bisection
int N0 = 0, N1 = N-1;
int n = N/2, m = 0;
while (true)
{
RowEntry& rn = m_data[n];
// see if row falls inside the interval
if ((row >= rn.start) && (row <= rn.end))
{
// no need to do anything
return;
}
if (row < rn.start)
{
assert(n>0); // this should always be the case due to the easy case handling above
// get the previous entry
RowEntry& r0 = m_data[n-1];
if (row > r0.end)
{
if (row + 1 == rn.start)
{
if (r0.end == row - 1)
{
// merge entries
r0.end = rn.end;
m_data.erase(m_data.begin() + n);
return;
}
else
{
rn.start--;
return;
}
}
else if (row - 1 == r0.end)
{
r0.end++;
return;
}
else
{
RowEntry re = {row, row};
m_data.insert(m_data.begin() + n, re);
return;
}
}
else
{
N1 = n;
n = (N0 + N1) / 2;
}
}
else
{
assert(row > rn.end);
// get the next entry
RowEntry& r1 = m_data[n + 1];
if (row < r1.start)
{
if (row - 1 == rn.end)
{
if (r1.start == row + 1)
{
// merge entries
r1.start = rn.start;
m_data.erase(m_data.begin() + n);
return;
}
else
{
rn.end++;
return;
}
}
else if (row + 1 == r1.start)
{
r1.start--;
return;
}
else
{
RowEntry re = { row, row };
m_data.insert(m_data.begin() + n + 1, re);
return;
}
}
else
{
N0 = n;
n = (N0 + N1 + 1) / 2;
}
}
++m;
assert(m <= N);
}
}
//-----------------------------------------------------------------------------
//! MatrixProfile constructor. Takes the nr of equations as input argument.
//! If n is larger than zero a default profile is constructor for a diagonal
//! matrix.
SparseMatrixProfile::SparseMatrixProfile(int nrow, int ncol)
{
m_nrow = nrow;
m_ncol = ncol;
// allocate storage profile
if (ncol > 0)
{
int nres = (m_ncol < 100 ? m_ncol : 100);
m_prof.resize(ncol);
for (int i=0; i<ncol; ++i) m_prof[i].reserve(nres);
}
}
//-----------------------------------------------------------------------------
//! allocate storage for profile
void SparseMatrixProfile::Create(int nrow, int ncol)
{
m_nrow = nrow;
m_ncol = ncol;
int nres = (m_ncol < 100 ? m_ncol : 100);
m_prof.resize(ncol);
for (int i = 0; i<ncol; ++i) m_prof[i].reserve(nres);
}
//-----------------------------------------------------------------------------
//! Copy constructor. Simply copies the profile
SparseMatrixProfile::SparseMatrixProfile(const SparseMatrixProfile& mp)
{
m_nrow = mp.m_nrow;
m_ncol = mp.m_ncol;
m_prof = mp.m_prof;
}
//-----------------------------------------------------------------------------
//! Assignment operator. Copies the profile.
SparseMatrixProfile& SparseMatrixProfile::operator =(const SparseMatrixProfile& mp)
{
m_nrow = mp.m_nrow;
m_ncol = mp.m_ncol;
m_prof = mp.m_prof;
return (*this);
}
//-----------------------------------------------------------------------------
//! Create the profile of a diagonal matrix
void SparseMatrixProfile::CreateDiagonal()
{
int n = min(m_nrow, m_ncol);
// initialize the profile to a diagonal matrix
for (int i = 0; i<n; ++i)
{
ColumnProfile& a = m_prof[i];
a.insertRow(i);
}
}
//-----------------------------------------------------------------------------
void SparseMatrixProfile::Clear()
{
m_prof.clear();
}
//-----------------------------------------------------------------------------
//! Updates the profile. The LM array contains a list of elements that contribute
//! to the sparse matrix. Each "element" defines a set of degrees of freedom that
//! are somehow connected. Each pair of dofs that are connected contributes to
//! the global stiffness matrix and therefor also to the matrix profile.
void SparseMatrixProfile::UpdateProfile(vector< vector<int> >& LM, int M)
{
// get the dimensions of the matrix
int nr = m_nrow;
int nc = m_ncol;
// make sure there is work to do
if (nr*nc == 0) return;
// Count the number of elements that contribute to a certain column
// The pval array stores this number (which I also call the valence
// of the column)
vector<int> pval(nc, 0);
// fill the valence array
int Ntot = 0;
for (int i = 0; i<M; ++i)
{
int* lm = &(LM[i])[0];
int N = (int)LM[i].size();
Ntot += N;
for (int j = 0; j<N; ++j)
{
if (lm[j] >= 0) pval[lm[j]]++;
}
}
// create a "compact" 2D array that stores for each column the element
// numbers that contribute to that column. The compact array consists
// of two arrays. The first one (pelc) contains all element numbers, sorted
// by column. The second array stores for each column a pointer to the first
// element in the pelc array that contributes to that column.
vector<int> pelc(Ntot);
vector<int*> ppelc(nc);
// set the column pointers
ppelc[0] = &pelc[0];
for (int i = 1; i<nc; ++i) ppelc[i] = ppelc[i - 1] + pval[i - 1];
// fill the pelc array
for (int i = 0; i<M; ++i)
{
int* lm = &(LM[i])[0];
int N = (int)LM[i].size();
for (int j = 0; j<N; ++j)
{
if (lm[j] >= 0) *(ppelc[lm[j]])++ = i;
}
}
// reset pelc pointers
ppelc[0] = &pelc[0];
for (int i = 1; i<nc; ++i) ppelc[i] = ppelc[i - 1] + pval[i - 1];
// loop over all columns
#pragma omp parallel for schedule(dynamic)
for (int i = 0; i<nc; ++i)
{
if (pval[i] > 0)
{
// get the column
ColumnProfile& a = m_prof[i];
// loop over all elements in the plec
for (int j = 0; j<pval[i]; ++j)
{
int iel = (ppelc[i])[j];
int* lm = &(LM[iel])[0];
int N = (int)LM[iel].size();
for (int k = 0; k<N; ++k)
{
if (lm[k] >= 0)
{
a.insertRow(lm[k]);
}
}
}
}
}
}
//-----------------------------------------------------------------------------
//! inserts an entry into the profile
void SparseMatrixProfile::Insert(int i, int j)
{
ColumnProfile& a = m_prof[j];
a.insertRow(i);
}
//-----------------------------------------------------------------------------
// extract the matrix profile of a block
SparseMatrixProfile SparseMatrixProfile::GetBlockProfile(int nrow0, int ncol0, int nrow1, int ncol1) const
{
int nrows = nrow1 - nrow0 + 1;
int ncols = ncol1 - ncol0 + 1;
assert(nrows > 0);
assert(ncols > 0);
// This will store the block profile
SparseMatrixProfile bMP(nrows, ncols);
for (int j=0; j<ncols; ++j)
{
const ColumnProfile& sj = m_prof[ncol0+j];
ColumnProfile& dj = bMP.m_prof[j];
int nr = sj.size();
for (int i=0; i<nr; i++)
{
const RowEntry& ri = sj[i];
int n0 = ri.start;
int n1 = ri.end;
if ((n1 >= nrow0)&&(n0 <= nrow1))
{
if (n0 < nrow0) n0 = nrow0;
if (n1 > nrow1) n1 = nrow1;
n0 -= nrow0;
n1 -= nrow0;
dj.push_back(n0, n1);
}
}
}
return bMP;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDataStream.h | .h | 4,302 | 124 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include "mat3d.h"
#include "tens4d.h"
//-----------------------------------------------------------------------------
// This class can be used to serialize data.
// This is part of a new experimental feature that allows domain classes to define
// data exports. This in turn will eliminate the need for many of the plot classes.
// TODO: This looks a lot like a FEDataArray. Perhaps combine?
class FEDataStream
{
public:
FEDataStream(){}
void clear() { m_a.clear(); }
FEDataStream& operator << (const double& f) { m_a.push_back((float) f); return *this; }
FEDataStream& operator << (const vec3d& v)
{
m_a.push_back((float) v.x);
m_a.push_back((float) v.y);
m_a.push_back((float) v.z);
return *this;
}
FEDataStream& operator << (const mat3ds& m)
{
m_a.push_back((float) m.xx());
m_a.push_back((float) m.yy());
m_a.push_back((float) m.zz());
m_a.push_back((float) m.xy());
m_a.push_back((float) m.yz());
m_a.push_back((float) m.xz());
return *this;
}
FEDataStream& operator << (const mat3d& m)
{
m_a.push_back((float)m(0, 0));
m_a.push_back((float)m(0, 1));
m_a.push_back((float)m(0, 2));
m_a.push_back((float)m(1, 0));
m_a.push_back((float)m(1, 1));
m_a.push_back((float)m(1, 2));
m_a.push_back((float)m(2, 0));
m_a.push_back((float)m(2, 1));
m_a.push_back((float)m(2, 2));
return *this;
}
FEDataStream& operator << (const tens4ds& a)
{
for (int k=0; k<21; ++k) m_a.push_back((float) a.d[k]);
return *this;
}
FEDataStream& operator << (const std::vector<double>& a)
{
for (double ai : a) m_a.push_back((float)ai);
return *this;
}
FEDataStream& operator << (const std::vector<vec3d>& a)
{
for (vec3d ai : a)
{
m_a.push_back((float)ai.x);
m_a.push_back((float)ai.y);
m_a.push_back((float)ai.z);
}
return *this;
}
void assign(size_t count, float f) { m_a.assign(count, f); }
void resize(size_t count, float f) { m_a.resize(count, f); }
void reserve(size_t count) { m_a.reserve(count); }
void push_back(const float& f) { m_a.push_back(f); }
size_t size() const { return m_a.size(); }
float& operator [] (int i) { return m_a[i]; }
std::vector<float>& data() { return m_a; }
template <class T> T get(int i);
private:
std::vector<float> m_a;
};
template <class T> inline T FEDataStream::get(int i) { return T(0.0); }
template <> inline float FEDataStream::get<float >(int i) { return m_a[i]; }
template <> inline double FEDataStream::get<double>(int i) { return (double) m_a[i]; }
template <> inline vec3d FEDataStream::get<vec3d >(int i) { return vec3d(m_a[3*i], m_a[3*i+1], m_a[3*i+2]); }
template <> inline vec3f FEDataStream::get<vec3f >(int i) { return vec3f(m_a[3*i], m_a[3*i+1], m_a[3*i+2]); }
template <> inline mat3fs FEDataStream::get<mat3fs>(int i) { float* v = &m_a[6*i]; return mat3fs(v[0],v[1],v[2],v[3],v[4],v[5]); }
template <> inline mat3f FEDataStream::get<mat3f >(int i) { float* v = &m_a[9*i]; return mat3f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]); }
| Unknown |
3D | febiosoftware/FEBio | FECore/FELevelStructure.h | .h | 3,857 | 117 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENodeNodeList.h"
#include <vector>
//-----------------------------------------------------------------------------
//! This class implements the idea of a level structure
//! A level structures groups the nodes per level. The basic notion is that
//! (1) each node in level 1 is adjacent to a node in level 1 and/or level 2.
//! (2) each node in level k is adjacent to a node in level k and/or level k-1
//! (3) each node in level 1<i<k is adjacent to a node in level i-1, i, or i+1
//! The width of the level structure is the largest width of any level.
//!
//! The level structure is used by the node - reorder algorithm implemented in
//! the FENodeReorder class.
class FECORE_API FELevelStructure
{
public:
//! default constructor
FELevelStructure();
//! destructor
virtual ~FELevelStructure();
//! copy constructor
FELevelStructure(FELevelStructure& L)
{
m_lval = L.m_lval;
m_nref = L.m_nref;
m_pl = L.m_pl;
m_node = L.m_node;
m_nwidth = L.m_nwidth;
m_pNL = L.m_pNL;
}
//! assignment operator
FELevelStructure& operator = (FELevelStructure& L)
{
m_lval = L.m_lval;
m_nref = L.m_nref;
m_pl = L.m_pl;
m_node = L.m_node;
m_nwidth = L.m_nwidth;
m_pNL = L.m_pNL;
return (*this);
}
//! Combine level structures L1 and L2 into one level structure
void Merge(FELevelStructure& L1, FELevelStructure& L2, bool& bswap);
//! Create a rooted level structure, starting at node nroot
void Create(FENodeNodeList& L, int nroot);
//! return the depth, ie. the number of levels.
int Depth() const { return (int) m_lval.size(); }
//! return the width of the level structure
int Width() { return m_nwidth; }
//! return the number of nodes in level l
int Valence(int l) { return m_lval[l]; }
//! return a list of nodes in level l
int* NodeList(int l) { return &m_nref[0] + m_pl[l]; }
//! return the level that node n is in
int NodeLevel(int n) { return m_node[n]; }
//! sort all nodes in levels l0 to l1 in order of increasing degree
void SortLevels(int l0, int l1);
protected:
std::vector<int> m_lval; //!< the level valence
std::vector<int> m_nref; //!< the nodes in the level
std::vector<int> m_pl; //!< start of each level
std::vector<int> m_node; //!< the levels to which a nodes belongs
FENodeNodeList* m_pNL; //!< The nodelist that generated the level structure
int m_nwidth; //!< width of level structure
static FELevelStructure* m_pthis; //!< this pointer used in static compare function
//!< used in sorting the nodes of a level
static int compare(const void*, const void*);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tens3ds.hpp | .hpp | 3,065 | 78 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// NOTE: This file is automatically included from tens3drs.h
// Users should not include this file manually!
// access operator
inline double tens3ds::operator()(int i, int j, int k) const
{
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}}};
return d[LUT[i][j][k]];
}
// contract the right two legs by the dyad formed by a vector xi = Tijk*Xi*Xk
inline vec3d tens3ds::contractdyad1(const vec3d& v)
{
vec3d x;
x.x = d[0]*v.x*v.x + 2*d[1]*v.x*v.y + 2*d[2]*v.x*v.z + d[3]*v.y*v.y + 2*d[4]*v.y*v.z + d[5]*v.z*v.z;
x.y = d[1]*v.x*v.x + 2*d[3]*v.x*v.y + 2*d[4]*v.x*v.z + d[6]*v.y*v.y + 2*d[7]*v.y*v.z + d[8]*v.z*v.z;
x.z = d[2]*v.x*v.x + 2*d[4]*v.x*v.y + 2*d[5]*v.x*v.z + d[7]*v.y*v.y + 2*d[8]*v.y*v.z + d[9]*v.z*v.z;
return x;
}
// triple contraction by a similar 3o tensor m = Tijk*Hijk
inline double tens3ds::tripledot(const tens3ds& H)
{
const double* h = H.d;
return d[0]*h[0] + 3*d[1]*h[1] + 3*d[2]*h[2] + 3*d[3]*h[3] + 6*d[4]*h[4] + 3*d[5]*h[5] + d[6]*h[6] + 3*d[7]*h[7] + 3*d[8]*h[8] + d[9]*h[9];
}
// calculates the symmetric tensor A_ijk = (l_i*m_j*r_k + perm(i,j,k))/6
inline tens3ds dyad3s(const vec3d& l, const vec3d& m, const vec3d& r)
{
tens3ds a;
a.d[0] = (l.x*m.x*r.x);
a.d[1] = (l.x*m.x*r.y + l.x*m.y*r.x + l.y*m.x*r.x)/3.0;
a.d[2] = (l.x*m.x*r.z + l.x*m.z*r.x + l.z*m.x*r.x)/3.0;
a.d[3] = (l.x*m.y*r.y + l.y*m.x*r.y + l.y*m.y*r.x)/3.0;
a.d[4] = (l.x*m.y*r.z + l.y*m.x*r.z + l.z*m.y*r.x + l.x*m.z*r.y + l.z*m.x*r.y + l.y*m.z*r.x)/6.0;
a.d[5] = (l.x*m.z*r.z + l.z*m.x*r.z + l.z*m.z*r.x)/3.0;
a.d[6] = (l.y*m.y*r.y);
a.d[7] = (l.y*m.y*r.z + l.y*m.z*r.y + l.z*m.y*r.y)/3.0;
a.d[8] = (l.y*m.z*r.z + l.z*m.y*r.z + l.z*m.z*r.y)/3.0;
a.d[9] = (l.z*m.z*r.z);
return a;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/CompactUnSymmMatrix.h | .h | 5,200 | 180 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "CompactMatrix.h"
#include "fecore_api.h"
struct MatrixItem
{
int row, col;
double val;
};
//=============================================================================
//! This class stores a general, sparse matrix in Compact Row Storage format
class FECORE_API CRSSparseMatrix : public CompactMatrix
{
public:
class Iterator
{
public:
Iterator(CRSSparseMatrix* A);
bool valid();
void next();
void reset();
MatrixItem get();
void set(double v);
private:
int r, n;
CRSSparseMatrix* m_A;
};
public:
//! constructor
CRSSparseMatrix(int offset = 0);
//! copy constructor
CRSSparseMatrix(const CRSSparseMatrix& A);
//! Create the matrix structure from the SparseMatrixProfile
void Create(SparseMatrixProfile& mp) override;
//! Assemble the element matrix into the global matrix
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;
//! add a value to the matrix item
void add(int i, int j, double v) override;
//! set the matrix item
void set(int i, int j, double v) override;
//! get a matrix item
double get(int i, int j) override;
//! return the diagonal value
double diag(int i) override;
//! multiply with vector
bool mult_vector(double* x, double* r) override;
//! see if a matrix element is defined
bool check(int i, int j) override;
// scale matrix
void scale(double s);
void scale(const std::vector<double>& L, const std::vector<double>& R) override;
//! extract a block of this matrix
void get(int i0, int j0, int nr, int nc, CSRMatrix& M);
//! is the matrix symmetric or not
bool isSymmetric() override { return false; }
//! is this a row-based format or not
bool isRowBased() override { return true; }
//! calculate the inf norm
double infNorm() const override;
//! calculate the one norm
double oneNorm() const override;
//! make the matrix a unit matrix (retains sparsity pattern)
void makeUnit();
//! Create a copy of the matrix (does not copy values)
CRSSparseMatrix* Copy(int offset);
//! Copy the values from another matrix
void CopyValues(CompactMatrix* A);
//! convert to another format (currently only offset can be changed)
bool Convert(int newOffset);
};
//=============================================================================
//! This class stores a sparse matrix in Compact Column Storage format
class FECORE_API CCSSparseMatrix : public CompactMatrix
{
public:
//! constructor
CCSSparseMatrix(int offset = 0);
//! copy constructor
CCSSparseMatrix(const CCSSparseMatrix& A);
//! Create the matrix structure from the SparseMatrixProfile
void Create(SparseMatrixProfile& mp) override;
//! Assemble the element matrix into the global matrix
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;
//! add a value to the matrix item
void add(int i, int j, double v) override;
//! set the matrix item
void set(int i, int j, double v) override;
//! get a matrix item
double get(int i, int j) override;
//! return the diagonal value
double diag(int i) override;
//! multiply with vector
bool mult_vector(double* x, double* r) override;
//! see if a matrix element is defined
bool check(int i, int j) override;
//! is the matrix symmetric or not
bool isSymmetric() override { return false; }
//! is this a row-based format or not
bool isRowBased() override { return false; }
//! calculate the inf norm
double infNorm() const override;
//! calculate the one norm
double oneNorm() const override;
//! do row (L) and column (R) scaling
void scale(const std::vector<double>& L, const std::vector<double>& R) override;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfaceBC.h | .h | 1,619 | 49 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBoundaryCondition.h"
#include "fecore_api.h"
class FESurface;
class FECORE_API FESurfaceBC : public FEBoundaryCondition
{
FECORE_BASE_CLASS(FESurfaceBC)
public:
FESurfaceBC(FEModel* fem);
bool Init() override;
void SetSurface(FESurface* surface);
FESurface* GetSurface();
private:
FESurface* m_surface;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataValue.cpp | .cpp | 2,790 | 96 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEDataValue.h"
#include "FELogNodeData.h"
#include "FELogElemData.h"
#include "FEModel.h"
#include "FEMesh.h"
FEDataValue::FEDataValue()
{
}
bool FEDataValue::IsValid() const
{
return (m_logData != nullptr);
}
void FEDataValue::SetLogData(FELogData* logData)
{
m_logData = logData;
}
bool FEDataValue::GetValues(const FEItemList* itemList, std::vector<double>& val)
{
if (m_logData == nullptr) return false;
if (itemList == nullptr) return false;
FELogNodeData* nodeData = dynamic_cast<FELogNodeData*>(m_logData);
if (nodeData)
{
const FENodeSet* nset = dynamic_cast<const FENodeSet*>(itemList);
if (nset == nullptr) return false;
FEModel* fem = nodeData->GetFEModel();
FEMesh& mesh = fem->GetMesh();
int n = nset->Size();
val.resize(n);
for (int i = 0; i < n; ++i)
{
int nid = (*nset)[i];
FENode* node = mesh.FindNodeFromID(nid);
if (node == nullptr) return false;
val[i] = nodeData->value(*node);
}
return true;
}
FELogElemData* elemData = dynamic_cast<FELogElemData*>(m_logData);
if (elemData)
{
const FEElementSet* eset = dynamic_cast<const FEElementSet*>(itemList);
if (eset == nullptr) return false;
FEModel* fem = elemData->GetFEModel();
FEMesh& mesh = fem->GetMesh();
int n = eset->Elements();
val.resize(n);
for (int i = 0; i < n; ++i)
{
int eid = (*eset)[i];
FEElement* elem = mesh.FindElementFromID(eid);
if (elem == nullptr) return false;
val[i] = elemData->value(*elem);
}
return true;
}
return false;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECore.cpp | .cpp | 8,046 | 213 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FECore.h"
#include "FECoreKernel.h"
#include "FEPrescribedDOF.h"
#include "FENodalLoad.h"
#include "FEFixedBC.h"
#include "FELinearConstraint.h"
#include "FEInitialCondition.h"
#include "FECorePlot.h"
#include "FESurfaceToSurfaceMap.h"
#include "FESurfaceToSurfaceVectorMap.h"
#include "FEParabolicMap.h"
#include "FEDataMathGenerator.h"
#include "FEPointFunction.h"
#include "FELoadCurve.h"
#include "FEMathController.h"
#include "FEMathIntervalController.h"
#include "FEPIDController.h"
#include "Preconditioner.h"
#include "FEMat3dValuator.h"
#include "FEMat3dSphericalAngleMap.h"
#include "FEAnalysis.h"
#include "BFGSSolver.h"
#include "FEBroydenStrategy.h"
#include "JFNKStrategy.h"
#include "FENodeSet.h"
#include "FEFacetSet.h"
#include "FEElementSet.h"
#include "FEConstValueVec3.h"
#include "NodeDataRecord.h"
#include "FaceDataRecord.h"
#include "ElementDataRecord.h"
#include "NLConstraintDataRecord.h"
#include "FEAugLagLinearConstraint.h"
#include "SurfaceDataRecord.h"
#include "FELogEnclosedVolume.h"
#include "FELogElementVolume.h"
#include "FELogDomainVolume.h"
#include "FELogSolutionNorm.h"
#include "FELogElemMath.h"
#include "LUSolver.h"
#include "FETimeStepController.h"
#include "FEModifiedNewtonStrategy.h"
#include "FEFullNewtonStrategy.h"
#include "SkylineSolver.h"
#define FECORE_VERSION 0
#define FECORE_SUBVERSION 1
//-----------------------------------------------------------------------------
// Get the version info
void FECore::get_version(int& version, int& subversion)
{
version = FECORE_VERSION;
subversion = FECORE_SUBVERSION;
}
//-----------------------------------------------------------------------------
// get the version string
const char* FECore::get_version_string()
{
static const char fecore_str[4] = {'0'+FECORE_VERSION, '.', '0'+FECORE_SUBVERSION };
return fecore_str;
}
//-----------------------------------------------------------------------------
void FECore::InitModule()
{
// initialize the element librar
FEElementLibrary::Initialize();
// analysis class
//REGISTER_FECORE_CLASS(FEAnalysis, "analysis");
// time controller
REGISTER_FECORE_CLASS(FETimeStepController, "default");
// boundary conditions
REGISTER_FECORE_CLASS(FEFixedDOF , "fix" , 0x300); // obsolete in 4.0
REGISTER_FECORE_CLASS(FEPrescribedDOF, "prescribe", 0x300); // obsolete in 4.0
REGISTER_FECORE_CLASS(FELinearConstraint, "linear constraint");
REGISTER_FECORE_CLASS(FELinearConstraintDOF, "child_dof");
// nodal loads
REGISTER_FECORE_CLASS(FENodalDOFLoad, "nodal_load");
// initial conditions
REGISTER_FECORE_CLASS(FEInitialDOF , "init_dof" , 0x300); // obsolete in 4.0
// (augmented lagrangian) linear constraints
REGISTER_FECORE_CLASS(FELinearConstraintSet, "linear constraint");
REGISTER_FECORE_CLASS(FEAugLagLinearConstraint, "linear_constraint");
REGISTER_FECORE_CLASS(FEAugLagLinearConstraintDOF, "node");
// plot field
REGISTER_FECORE_CLASS(FEPlotParameter, "parameter");
REGISTER_FECORE_CLASS(FEPlotPIDController, "pid controller");
REGISTER_FECORE_CLASS(FEPlotMeshData, "mesh_data");
REGISTER_FECORE_CLASS(FEPlotFieldVariable, "field");
// 1D functions
REGISTER_FECORE_CLASS(FEPointFunction , "point");
REGISTER_FECORE_CLASS(FEConstFunction, "const");
REGISTER_FECORE_CLASS(FEScaleFunction, "scale");
REGISTER_FECORE_CLASS(FELinearFunction, "linear ramp");
REGISTER_FECORE_CLASS(FEStepFunction , "step");
REGISTER_FECORE_CLASS(FEMathFunction , "math");
// data generators
REGISTER_FECORE_CLASS(FEDataMathGenerator , "math");
REGISTER_FECORE_CLASS(FESurfaceToSurfaceMap, "surface-to-surface map");
REGISTER_FECORE_CLASS(FESurfaceToSurfaceVectorMap, "surface-to-surface vector");
REGISTER_FECORE_CLASS(FEParabolicMap , "parabolic map");
// scalar valuators
REGISTER_FECORE_CLASS(FEConstValue , "const");
REGISTER_FECORE_CLASS(FEMathValue , "math" );
REGISTER_FECORE_CLASS(FEMappedValue, "map" );
// vector generators
REGISTER_FECORE_CLASS(FELocalVectorGenerator , "local");
REGISTER_FECORE_CLASS(FEConstValueVec3 , "vector");
REGISTER_FECORE_CLASS(FEMathValueVec3 , "math");
REGISTER_FECORE_CLASS(FESphericalVectorGenerator , "spherical");
REGISTER_FECORE_CLASS(FECylindricalVectorGenerator , "cylindrical");
REGISTER_FECORE_CLASS(FESphericalAnglesVectorGenerator, "angles");
REGISTER_FECORE_CLASS(FEMappedValueVec3 , "map");
REGISTER_FECORE_CLASS(FEUserVectorGenerator , "user");
// mat3d generators
REGISTER_FECORE_CLASS(FEConstValueMat3d , "const" );
REGISTER_FECORE_CLASS(FEMat3dLocalElementMap , "local" );
REGISTER_FECORE_CLASS(FEMat3dSphericalMap , "spherical" );
REGISTER_FECORE_CLASS(FEMat3dCylindricalMap , "cylindrical");
REGISTER_FECORE_CLASS(FEMat3dVectorMap , "vector" );
REGISTER_FECORE_CLASS(FEMat3dSphericalAngleMap, "angles" );
REGISTER_FECORE_CLASS(FEMat3dPolarMap , "polar" );
REGISTER_FECORE_CLASS(FEMappedValueMat3d , "map" );
// mat3ds generators
REGISTER_FECORE_CLASS(FEConstValueMat3ds , "const");
REGISTER_FECORE_CLASS(FEMappedValueMat3ds, "map");
// load controllers
REGISTER_FECORE_CLASS(FELoadCurve , "loadcurve");
REGISTER_FECORE_CLASS(FEMathController , "math");
REGISTER_FECORE_CLASS(FEMathIntervalController, "math-interval");
REGISTER_FECORE_CLASS(FEPIDController , "PID");
// Newton strategies
REGISTER_FECORE_CLASS(BFGSSolver , "BFGS");
REGISTER_FECORE_CLASS(FEBroydenStrategy, "Broyden");
REGISTER_FECORE_CLASS(JFNKStrategy , "JFNK");
REGISTER_FECORE_CLASS(FEModifiedNewtonStrategy, "modified Newton");
REGISTER_FECORE_CLASS(FEFullNewtonStrategy , "full Newton");
// preconditioners
REGISTER_FECORE_CLASS(DiagonalPreconditioner, "diagonal");
REGISTER_FECORE_CLASS(FESurface, "surface");
// data records
REGISTER_FECORE_CLASS(NodeDataRecord, "node_data");
REGISTER_FECORE_CLASS(FaceDataRecord, "face_data");
REGISTER_FECORE_CLASS(ElementDataRecord, "element_data");
REGISTER_FECORE_CLASS(NLConstraintDataRecord, "rigid_connector_data");
// log classes
REGISTER_FECORE_CLASS(FELogEnclosedVolume, "volume");
REGISTER_FECORE_CLASS(FELogEnclosedVolumeChange, "volume change");
REGISTER_FECORE_CLASS(FELogElementVolume, "V");
REGISTER_FECORE_CLASS(FELogDomainVolume, "volume");
REGISTER_FECORE_CLASS(FELogAvgDomainData, "avg");
REGISTER_FECORE_CLASS(FELogPctDomainData, "pct");
REGISTER_FECORE_CLASS(FELogIntegralDomainData, "integrate");
REGISTER_FECORE_CLASS(FELogSolutionNorm, "solution_norm");
REGISTER_FECORE_CLASS(FELogFaceArea , "facet area");
REGISTER_FECORE_CLASS(FELogElemMath , "_math", FECORE_EXPERIMENTAL);
// linear solvers
REGISTER_FECORE_CLASS(LUSolver, "LU");
REGISTER_FECORE_CLASS(SkylineSolver, "skyline");
}
| C++ |
3D | febiosoftware/FEBio | FECore/MEvaluate.h | .h | 3,174 | 103 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "MathObject.h"
#include "MMatrix.h"
#include <list>
//-----------------------------------------------------------------------------
void MEvaluate(MathObject* po);
//-----------------------------------------------------------------------------
MITEM MEvaluate(const MITEM& e);
//-----------------------------------------------------------------------------
MITEM MEvaluate(const MMatrix& A);
//-----------------------------------------------------------------------------
MITEM MMultiply(const MITEM& l, const MITEM& r);
//-----------------------------------------------------------------------------
MITEM MDivide(const MITEM& n, const MITEM& d);
//-----------------------------------------------------------------------------
MITEM MAddition(const MITEM& l, const MITEM& r);
//-----------------------------------------------------------------------------
// This class describes a multi-factor product. It is used to simplify
// expressions involving factors for which the binary operations might be
// too difficult to process
class MProduct
{
public:
MProduct(const MITEM& a);
public:
void Multiply(const MITEM& a);
MITEM operator / (const MProduct& D);
MITEM Item();
bool operator == (const MProduct& a);
bool contains(const MITEM& i) const;
protected:
std::list<MITEM> m_p;
};
//-----------------------------------------------------------------------------
// This class describes a general sum
class MSum
{
class MTerm
{
public:
MITEM m_a; // term
FRACTION m_s; // multiplier (can be negative!)
public:
MTerm(const MITEM& i);
MTerm(const MTerm& i) { m_a = i.m_a; m_s = i.m_s; }
void operator = (const MTerm& i) { m_a = i.m_a; m_s = i.m_s; }
};
public:
MSum(const MITEM& a);
void Add(const MITEM& a);
void Sub(const MITEM& a);
MITEM Item();
protected:
std::list<MTerm> m_t;
FRACTION m_c; // accumulator for constants
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MCollect.cpp | .cpp | 3,634 | 160 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
//---------------------------------------------------
void MCollect(const MITEM& e, const MITEM& x, MITEM& a, MITEM& b);
//---------------------------------------------------
// collect terms in x
MITEM MCollect(const MITEM& e, const MITEM& x)
{
MITEM a(0.0);
MITEM b(0.0);
MCollect(e, x, a, b);
return MEvaluate(a*x + b);
}
//---------------------------------------------------
void MCollect(const MITEM& e, const MITEM& x, MITEM& a, MITEM& b)
{
// check for equality
if (e == x)
{
a = a + 1.0;
return;
}
// check for dependancy
if (is_dependent(e, x) == false)
{
b = MEvaluate(b + e);
return;
}
// process operators
switch (e.Type())
{
case MNEG:
{
MITEM c(0.0), d(0.0);
MCollect(e.Item(), x, c, d);
a = a - c;
b = b - d;
}
break;
case MADD:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(l, x) == false)
{
b = MEvaluate(b + l);
MCollect(r, x, a, b);
}
else if (is_dependent(r, x) == false)
{
b = MEvaluate(b + r);
MCollect(l, x, a, b);
}
else
{
MITEM al(0.0), ar(0.0), bl(0.0), br(0.0);
MCollect(l, x, al, bl);
MCollect(r, x, ar, br);
a = a + al + ar;
b = b + bl + br;
}
}
break;
case MSUB:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(l, x) == false)
{
b = MEvaluate(b + l);
MCollect(-r, x, a, b);
}
else if (is_dependent(r, x) == false)
{
b = MEvaluate(b - r);
MCollect(l, x, a, b);
}
else
{
MITEM al(0.0), ar(0.0), bl(0.0), br(0.0);
MCollect(l, x, al, bl);
MCollect(r, x, ar, br);
a = a + al - ar;
b = b + bl - br;
}
}
break;
case MMUL:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (l == x) a = a + r;
else if (r == x) a = a + l;
else if (is_dependent(l, x) == false)
{
MCollect(r, x, a, b);
a = MEvaluate(l*a);
b = MEvaluate(l*b);
}
else if (is_dependent(r, x) == false)
{
MCollect(l, x, a, b);
a = MEvaluate(r*a);
b = MEvaluate(r*b);
}
else b = b + e;
}
break;
case MDIV:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(l, x))
{
MCollect(l, x, a, b);
a = MEvaluate(a/r);
b = MEvaluate(b/r);
}
else b = b + e;
}
break;
default:
b = b + e;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEParabolicMap.cpp | .cpp | 7,524 | 294 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEParabolicMap.h"
#include "FESurfaceMap.h"
#include "FESurface.h"
#include "FEElemElemList.h"
#include "log.h"
#include "SparseMatrix.h"
#include "LinearSolver.h"
#include "FEGlobalMatrix.h"
#include "FEModel.h"
BEGIN_FECORE_CLASS(FEParabolicMap, FEFaceDataGenerator)
ADD_PARAMETER(m_scale, "value");
END_FECORE_CLASS();
FEParabolicMap::FEParabolicMap(FEModel* fem) : FEFaceDataGenerator(fem), m_dofs(fem)
{
m_scale = 1.0;
}
FEParabolicMap::~FEParabolicMap()
{
}
void FEParabolicMap::SetDOFConstraint(const FEDofList& dofs)
{
m_dofs = dofs;
}
FEDataMap* FEParabolicMap::Generate()
{
const FEFacetSet& facetSet = *GetFacetSet();
FESurfaceMap* map = new FESurfaceMap(FEDataType::FE_DOUBLE);
map->Create(&facetSet, 0.0, FMT_NODE);
// create temporary surface
FESurface surf(GetFEModel());
surf.Create(facetSet);
surf.InitSurface();
// find surface boundary nodes
FEElemElemList EEL;
EEL.Create(&surf);
vector<bool> boundary(surf.Nodes(), false);
for (int i = 0; i<surf.Elements(); ++i) {
FESurfaceElement& el = surf.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;
}
}
}
// Apply dof constraints
if (m_dofs.IsEmpty() == false)
{
// only consider nodes with fixed dofs as boundary nodes
for (int i = 0; i < surf.Nodes(); ++i)
if (boundary[i]) {
FENode& node = surf.Node(i);
bool b = false;
for (int j = 0; j < m_dofs.Size(); ++j)
{
if (node.get_bc(m_dofs[j]) != DOF_FIXED) b = true;
}
if (b) boundary[i] = false;
}
}
// count number of non-boundary nodes
int neq = 0;
vector<int> glm(surf.Nodes(), -1);
for (int i = 0; i< surf.Nodes(); ++i)
if (!boundary[i]) glm[i] = neq++;
if (neq == 0)
{
feLogError("Unable to set parabolic map\n");
return nullptr;
}
// create a linear solver
LinearSolver* plinsolve; //!< the linear solver
FEGlobalMatrix* pK; //!< stiffness matrix
FECoreKernel& fecore = FECoreKernel::GetInstance();
plinsolve = fecore_new<LinearSolver>("skyline", nullptr);
if (plinsolve == 0)
{
feLogError("Unknown solver type selected\n");
return nullptr;
}
SparseMatrix* pS = plinsolve->CreateSparseMatrix(REAL_SYMMETRIC);
pK = new FEGlobalMatrix(pS);
if (pK == 0)
{
feLogError("Failed allocating stiffness matrix\n\n");
return nullptr;
}
// build matrix profile for normal velocity at non-boundary nodes
pK->build_begin(neq);
for (int i = 0; i< surf.Elements(); ++i) {
FESurfaceElement& el = surf.Element(i);
vector<int> elm(el.Nodes(), -1);
for (int j = 0; j<el.Nodes(); ++j)
elm[j] = glm[el.m_lnode[j]];
pK->build_add(elm);
}
pK->build_end();
pS->Zero();
// create global vector
vector<double> v; //!< solution
vector<double> rhs; //!< right-hand-side
vector<double> Fr; //!< reaction forces
v.assign(neq, 0);
rhs.assign(neq, 0);
Fr.assign(neq, 0);
FEModel pfem;
FEGlobalVector pR(pfem, rhs, Fr);
// calculate the global matrix and vector
FEElementMatrix ke;
vector<double> fe;
vector<int> lm;
for (int m = 0; m< surf.Elements(); ++m)
{
// get the surface element
FESurfaceElement& el = surf.Element(m);
int neln = el.Nodes();
// get the element stiffness matrix
ke.resize(neln, neln);
lm.resize(neln);
fe.resize(neln);
vector<vec3d> gradN(neln);
// calculate stiffness
int nint = el.GaussPoints();
// gauss weights
double* w = el.GaussWeights();
// nodal coordinates
FEMesh& mesh = *surf.GetMesh();
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();
zero(fe);
vec3d gcnt[2];
for (int n = 0; n<nint; ++n)
{
double* N = el.H(n);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
surf.ContraBaseVectors(el, n, gcnt);
vec3d dxr(0, 0, 0), dxs(0, 0, 0);
for (int i = 0; i<neln; ++i)
{
dxr += rt[i] * Gr[i];
dxs += rt[i] * Gs[i];
gradN[i] = gcnt[0] * Gr[i] + gcnt[1] * Gs[i];
}
double da = (dxr ^ dxs).norm();
// calculate stiffness component
for (int i = 0; i<neln; ++i) {
fe[i] += N[i] * w[n] * da;
for (int j = 0; j<neln; ++j)
ke[i][j] += (gradN[i] * gradN[j])*w[n] * da;
}
}
// get the element's LM vector
for (int j = 0; j<el.Nodes(); ++j)
lm[j] = glm[el.m_lnode[j]];
// assemble element matrix in global stiffness matrix
ke.SetIndices(lm);
pK->Assemble(ke);
pR.Assemble(lm, fe);
}
// solve linear system
plinsolve->PreProcess();
plinsolve->Factor();
if (plinsolve->BackSolve(v, rhs) == false)
{
feLogError("Unable to solve for parabolic field\n");
return nullptr;
}
plinsolve->Destroy();
// set the nodal normal velocity scale factors
vector<double> VN(surf.Nodes(), 0.0);
for (int i = 0; i< surf.Nodes(); ++i) {
if (glm[i] == -1) VN[i] = 0;
else VN[i] = v[glm[i]];
}
// evaluate net area and volumetric flow rate
double A = 0, Q = 0;
for (int m = 0; m< surf.Elements(); ++m)
{
// get the surface element
FESurfaceElement& el = surf.Element(m);
int neln = el.Nodes();
int nint = el.GaussPoints();
double* w = el.GaussWeights();
// nodal coordinates
FEMesh& mesh = *surf.GetMesh();
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
for (int n = 0; n<nint; ++n)
{
double* N = el.H(n);
double* Gr = el.Gr(n);
double* Gs = el.Gs(n);
double vn = 0;
vec3d dxr(0, 0, 0), dxs(0, 0, 0);
for (int i = 0; i<neln; ++i)
{
vn += N[i] * VN[el.m_lnode[i]];
dxr += rt[i] * Gr[i];
dxs += rt[i] * Gs[i];
}
double da = (dxr ^ dxs).norm();
for (int i = 0; i<neln; ++i) {
A += N[i] * w[n] * da;
Q += N[i] * vn*w[n] * da;
}
}
}
// normalize nodal velocity cards
double vbar = Q / A;
for (int i = 0; i< surf.Nodes(); ++i) VN[i] /= vbar;
// assign nodal values to surface map
map->set<double>(0.0);
for (int i = 0; i < surf.Nodes(); ++i)
{
map->set<double>(i, VN[i] * m_scale);
}
return map;
}
| C++ |
3D | febiosoftware/FEBio | FECore/DomainDataRecord.h | .h | 3,437 | 105 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "DataRecord.h"
#include "ElementDataRecord.h"
class FEDomain;
//-----------------------------------------------------------------------------
//! Base class for domain log data
class FECORE_API FELogDomainData : public FELogData
{
FECORE_SUPER_CLASS(FELOGDOMAINDATA_ID)
FECORE_BASE_CLASS(FELogDomainData)
public:
FELogDomainData(FEModel* fem) : FELogData(fem) {}
virtual ~FELogDomainData() {}
virtual double value(FEDomain& rc) = 0;
virtual bool SetParameters(std::vector<std::string>& params) { return false; }
};
//-----------------------------------------------------------------------------
class FECORE_API FEDomainDataRecord : public DataRecord
{
public:
FEDomainDataRecord(FEModel* pfem);
double Evaluate(int item, int ndata) override;
void SetData(const char* sz) override;
void SelectAllItems() override;
void SetDomain(int domainIndex);
int Size() const override;
private:
vector<FELogDomainData*> m_Data;
};
//-----------------------------------------------------------------------------
class FECORE_API FELogAvgDomainData : public FELogDomainData
{
public:
FELogAvgDomainData(FEModel* pfem);
~FELogAvgDomainData();
double value(FEDomain& rc) override;
bool SetParameters(std::vector<std::string>& params) override;
private:
FELogElemData* m_elemData;
};
//-----------------------------------------------------------------------------
class FECORE_API FELogPctDomainData : public FELogDomainData
{
public:
FELogPctDomainData(FEModel* pfem);
~FELogPctDomainData();
double value(FEDomain& rc) override;
bool SetParameters(std::vector<std::string>& params) override;
private:
double m_pct;
FELogElemData* m_elemData;
};
//-----------------------------------------------------------------------------
class FECORE_API FELogIntegralDomainData : public FELogDomainData
{
public:
FELogIntegralDomainData(FEModel* pfem);
~FELogIntegralDomainData();
double value(FEDomain& rc) override;
bool SetParameters(std::vector<std::string>& params) override;
private:
FELogElemData* m_elemData;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/DumpStream.cpp | .cpp | 10,404 | 355 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "DumpStream.h"
#include "matrix.h"
//-----------------------------------------------------------------------------
DumpStream::DumpStream(FEModel& fem) : m_fem(fem)
{
m_bsave = false;
m_bshallow = false;
m_bytes_serialized = 0;
m_ptr_lock = false;
#ifndef NDEBUG
m_btypeInfo = false;
#else
m_btypeInfo = false;
#endif
}
//-----------------------------------------------------------------------------
//! See if the stream is used for input or output
bool DumpStream::IsSaving() const { return m_bsave; }
//-----------------------------------------------------------------------------
//! See if the stream is used for input
bool DumpStream::IsLoading() const { return !m_bsave; }
//-----------------------------------------------------------------------------
//! See if shallow flag is set
bool DumpStream::IsShallow() const { return m_bshallow; }
//-----------------------------------------------------------------------------
DumpStream::~DumpStream()
{
m_ptrOut.clear();
m_ptrIn.clear();
m_bytes_serialized = 0;
}
//-----------------------------------------------------------------------------
// set the write type info flag
void DumpStream::WriteTypeInfo(bool b)
{
m_btypeInfo = b;
}
//-----------------------------------------------------------------------------
// see if the stream has type info
bool DumpStream::HasTypeInfo() const
{
return m_btypeInfo;
}
//-----------------------------------------------------------------------------
void DumpStream::Open(bool bsave, bool bshallow)
{
m_bsave = bsave;
m_bshallow = bshallow;
m_bytes_serialized = 0;
m_ptr_lock = false;
// add the "null" pointer
if (bsave)
{
m_ptrOut.clear();
m_ptrOut[nullptr] = 0;
}
else
{
m_ptrIn.clear();
m_ptrIn.push_back(nullptr);
}
}
//-----------------------------------------------------------------------------
void DumpStream::check()
{
if (IsSaving())
{
m_bytes_serialized += write(&m_bytes_serialized, sizeof(m_bytes_serialized), 1);
}
else
{
size_t nsize;
size_t tmp = read(&nsize, sizeof(m_bytes_serialized), 1);
assert(m_bytes_serialized == nsize);
if (m_bytes_serialized != nsize) throw DumpStream::ReadError();
m_bytes_serialized += tmp;
}
}
//-----------------------------------------------------------------------------
void DumpStream::LockPointerTable()
{
m_ptr_lock = true;
}
//-----------------------------------------------------------------------------
void DumpStream::UnlockPointerTable()
{
m_ptr_lock = false;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator << (const char* sz)
{
int n = (sz ? (int)strlen(sz) : 0);
m_bytes_serialized += write(&n, sizeof(int), 1);
if (sz && (n > 0)) m_bytes_serialized += write(sz, sizeof(char), n);
return (*this);
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator << (char* sz)
{
int n = (sz ? (int)strlen(sz) : 0);
m_bytes_serialized += write(&n, sizeof(int), 1);
if (sz && (n > 0)) m_bytes_serialized += write(sz, sizeof(char), n);
return (*this);
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator<<(std::string& s)
{
const char* sz = s.c_str();
this->operator<<(sz);
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator<<(const std::string& s)
{
const char* sz = s.c_str();
this->operator<<(sz);
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator << (bool b)
{
int n = (b ? 1 : 0);
m_bytes_serialized += write(&n, sizeof(n), 1);
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator << (int n)
{
if (m_btypeInfo) writeType(TypeID::TYPE_INT);
m_bytes_serialized += write(&n, sizeof(int), 1);
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator << (const double a[3][3])
{
m_bytes_serialized += write(a, sizeof(double), 9);
return (*this);
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator >> (char* sz)
{
int n;
m_bytes_serialized += read(&n, sizeof(int), 1);
if (n>0) m_bytes_serialized += read(sz, sizeof(char), n);
sz[n] = 0;
return (*this);
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator >> (std::string& s)
{
int n;
m_bytes_serialized += read(&n, sizeof(int), 1);
char* tmp = new char[n + 1];
if (n > 0) m_bytes_serialized += read(tmp, sizeof(char), n);
tmp[n] = 0;
s = std::string(tmp);
delete [] tmp;
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator >> (bool& b)
{
int n;
m_bytes_serialized += read(&n, sizeof(int), 1);
b = (n == 1);
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::operator >> (double a[3][3])
{
m_bytes_serialized += read(a, sizeof(double), 9);
return (*this);
}
//-----------------------------------------------------------------------------
int DumpStream::FindPointer(void* p)
{
assert(IsSaving());
auto it = m_ptrOut.find(p);
if (it != m_ptrOut.end()) return it->second;
return -1;
}
//-----------------------------------------------------------------------------
void DumpStream::AddPointer(void* p)
{
if (m_ptr_lock) return;
if (p == nullptr) { assert(false); return; }
if (IsSaving())
{
assert(FindPointer(p) == -1);
int id = (int)m_ptrOut.size();
m_ptrOut[p] = id;
}
else
{
m_ptrIn.push_back(p);
}
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::write_matrix(matrix& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_MATRIX);
// don't write type info for all components
bool oldTypeFlag = m_btypeInfo;
m_btypeInfo = false;
DumpStream& ar = *this;
int nr = o.rows();
int nc = o.columns();
ar << nr << nc;
int nsize = nr*nc;
if (nsize > 0)
{
vector<double> data;
data.reserve(nr*nc);
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j) data.push_back(o(i, j));
ar << data;
}
m_btypeInfo = oldTypeFlag;
return *this;
}
//-----------------------------------------------------------------------------
DumpStream& DumpStream::read_matrix(matrix& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_MATRIX);
// don't read type info for all components
bool oldTypeFlag = m_btypeInfo;
m_btypeInfo = false;
DumpStream& ar = *this;
int nr = 0, nc = 0;
ar >> nr >> nc;
int nsize = nr*nc;
if (nsize > 0)
{
o.resize(nr, nc);
vector<double> data;
ar >> data;
int n = 0;
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j) o(i, j) = data[n++];
}
m_btypeInfo = oldTypeFlag;
return *this;
}
//-----------------------------------------------------------------------------
// read the next block
bool DumpStream::readBlock(DataBlock& d)
{
// make sure we have type info
if (m_btypeInfo == false) return false;
// see if we have reached the end of the stream
if (EndOfStream()) return false;
// read the data type
d.m_type = readType();
// turn off type flag since we already read it
m_btypeInfo = false;
// read/allocate data
switch (d.m_type)
{
case TypeID::TYPE_INT : { int v; read_raw(v); d.m_pd = new int (v); } break;
case TypeID::TYPE_UINT : { unsigned int v; read_raw(v); d.m_pd = new unsigned int(v); } break;
case TypeID::TYPE_FLOAT : { float v; read_raw(v); d.m_pd = new float (v); } break;
case TypeID::TYPE_DOUBLE : { double v; read_raw(v); d.m_pd = new double (v); } break;
case TypeID::TYPE_VEC2D : { vec2d v; read_raw(v); d.m_pd = new vec2d (v); } break;
case TypeID::TYPE_VEC3D : { vec3d v; read_raw(v); d.m_pd = new vec3d (v); } break;
case TypeID::TYPE_MAT2D : { mat2d v; read_raw(v); d.m_pd = new mat2d (v); } break;
case TypeID::TYPE_MAT3D : { mat3d v; read_raw(v); d.m_pd = new mat3d (v); } break;
case TypeID::TYPE_MAT3DD : { mat3dd v; read_raw(v); d.m_pd = new mat3dd (v); } break;
case TypeID::TYPE_MAT3DS : { mat3ds v; read_raw(v); d.m_pd = new mat3ds (v); } break;
case TypeID::TYPE_MAT3DA : { mat3da v; read_raw(v); d.m_pd = new mat3da (v); } break;
case TypeID::TYPE_QUATD : { quatd v; read_raw(v); d.m_pd = new quatd (v); } break;
case TypeID::TYPE_TENS3DS : { tens3ds v; read_raw(v); d.m_pd = new tens3ds (v); } break;
case TypeID::TYPE_TENS3DRS: { tens3drs v; read_raw(v); d.m_pd = new tens3drs (v); } break;
case TypeID::TYPE_MATRIX : { matrix v; read_raw(v); d.m_pd = new matrix (v); } break;
default:
assert(false);
m_btypeInfo = true;
return false;
}
// turn the type info flag back on
m_btypeInfo = true;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELoadCurve.h | .h | 2,436 | 82 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FELoadController.h"
#include "PointCurve.h"
//-----------------------------------------------------------------------------
// Base class for load curves.
// Load curves are used to manipulate the time dependency of model parameters.
class FECORE_API FELoadCurve : public FELoadController
{
public:
// constructor
FELoadCurve(FEModel* fem);
FELoadCurve(const FELoadCurve& lc);
void operator = (const FELoadCurve& lc);
// destructor
virtual ~FELoadCurve();
void Serialize(DumpStream& ar) override;
bool CopyFrom(FELoadCurve* lc);
void Add(double time, double value);
void Clear();
bool Init() override;
void Reset() override;
PointCurve& GetFunction() { return m_fnc; }
int GetInterpolation() const { return m_int; }
void SetInterpolation(PointCurve::INTFUNC f);
int GetExtendMode() const { return m_ext; }
void SetExtendMode(PointCurve::EXTMODE f);
std::vector<vec2d> GetPoints() const { return m_points; }
double GetValue(double time) override;
private:
int m_int;
int m_ext;
std::vector<vec2d> m_points;
private:
PointCurve m_fnc; //!< function to evaluate
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MatrixProfile.h | .h | 3,980 | 133 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vector.h"
//-----------------------------------------------------------------------------
//! This class stores the profile of a sparse matrix. A profile is defined by the
//! column and row indices of the non-zero elements of a matrix.
//! These elements are stored in a condensed format.
//! This means that for each column, an array of pairs is stored where each pair
//! identifies the start and end row index of the nonzero elements in that column.
//! The matrix profile is used to build the sparse matrix structure
//! in an efficient way.
class FECORE_API SparseMatrixProfile
{
public:
struct RowEntry
{
int start, end;
};
class ColumnProfile
{
public:
ColumnProfile() {}
ColumnProfile(const ColumnProfile& a);
// get the number of row entries
int size() const { return (int) m_data.size(); }
// access
RowEntry& operator [] (int i) { return m_data[i]; }
const RowEntry& operator [] (int i) const { return m_data[i]; }
// make room
void clear() { m_data.clear(); }
// reserve some storage
void reserve(int n)
{
m_data.reserve(n);
}
// add to the end
void push_back(int n0, int n1)
{
RowEntry re = { n0, n1 };
m_data.push_back(re);
}
void push_front(int n0, int n1)
{
RowEntry re = {n0, n1};
m_data.insert(m_data.begin(), re);
}
// add row index to column profile
void insertRow(int row);
private:
std::vector<RowEntry> m_data; // the column profile data
};
public:
//! Constructor. Takes the nr of equations as the input argument
SparseMatrixProfile(int nrow = 0, int ncol = 0);
//! allocate storage for profile
void Create(int nrow, int ncol);
//! copy constructor
SparseMatrixProfile(const SparseMatrixProfile& mp);
//! assignment operator
SparseMatrixProfile& operator = (const SparseMatrixProfile& mp);
//! Create the profile of a diagonal matrix
void CreateDiagonal();
//! clears the matrix profile
void Clear();
//! updates the profile for an array of elements
void UpdateProfile(std::vector< std::vector<int> >& LM, int N);
//! inserts an entry into the profile (This is an expensive operation!)
void Insert(int i, int j);
//! returns the number of rows
int Rows() const { return m_nrow; }
//! returns the number of columns
int Columns() const { return m_ncol; }
//! returns the non-zero row indices (in condensed format) for a column
ColumnProfile& Column(int i) { return m_prof[i]; }
// Extracts a block profile
SparseMatrixProfile GetBlockProfile(int nrow0, int ncol0, int nrow1, int ncol1) const;
private:
int m_nrow, m_ncol; //!< dimensions of matrix
std::vector<ColumnProfile> m_prof; //!< the actual profile in condensed format
};
| Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.