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/FECorePlot.h | .h | 3,447 | 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 "FEPlotData.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class FEMaterial;
class FEDomainList;
class FEFacetSet;
class FEDataMap;
//-----------------------------------------------------------------------------
// class for exporting element specific material parameters to plot file
class FECORE_API FEPlotParameter : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotParameter)
public:
FEPlotParameter(FEModel* pfem);
bool Save(FEDomain& dom, FEDataStream& a) override;
bool Save(FESurface& dom, FEDataStream& a) override;
bool Save(FEMesh& mesh, FEDataStream& a) override;
bool SetFilter(const char* sz) override;
void Serialize(DumpStream& ar) override;
protected:
FEParamValue m_param; //!< parameter
int m_index; //!< index for array parameters
private:
FEMaterial* m_mat;
FEDomainList* m_dom;
FEFacetSet* m_surf;
std::string m_filter;
};
//-----------------------------------------------------------------------------
class FEPIDController;
class FECORE_API FEPlotPIDController : public FEPlotGlobalData
{
public:
FEPlotPIDController(FEModel* pfem);
bool SetFilter(const char* sz) override;
bool Save(FEDataStream& a) override;
private:
FEPIDController* m_pid;
};
//-----------------------------------------------------------------------------
class FECORE_API FEPlotMeshData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotMeshData)
public:
FEPlotMeshData(FEModel* pfem);
bool Save(FEDomain& dom, FEDataStream& a) override;
bool Save(FESurface& dom, FEDataStream& a) override;
bool Save(FEMesh& mesh, FEDataStream& a) override;
bool SetFilter(const char* sz) override;
void Serialize(DumpStream& ar) override;
protected:
FEDataMap* m_map; //!< parameter
const FEDomainList* m_dom;
std::string m_filter;
};
//! Plot variable for field variables
class FECORE_API FEPlotFieldVariable : public FEPlotNodeData
{
public:
FEPlotFieldVariable(FEModel* pfem);
bool Save(FEMesh& mesh, FEDataStream& a) override;
bool SetFilter(const char* sz) override;
void Serialize(DumpStream& ar) override;
protected:
std::vector<int> m_dofs;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/AkimaSpline.h | .h | 1,961 | 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) 2023 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
#include "vec2d.h"
#include <vector>
class FECORE_API AkimaSpline
{
struct Impl;
public:
// constructor
AkimaSpline();
// copy constructor
AkimaSpline(const AkimaSpline& as);
// destructor
~AkimaSpline();
// assignment operator
void operator = (const AkimaSpline& as);
public:
// Akima spline function evaluations
double eval(double x) const;
double eval_deriv(double x) const;
double eval_deriv2(double x) const;
public:
// initializations
// use given points p as control points
bool init(const std::vector<vec2d>& p);
private:
Impl* im;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDomain2D.cpp | .cpp | 13,976 | 465 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEDomain2D.h"
#include "FEMesh.h"
#include "FEMaterial.h"
//-----------------------------------------------------------------------------
bool FEDomain2D::Create(int nelems, FE_Element_Spec espec)
{
m_Elem.resize(nelems);
for (int i = 0; i < nelems; ++i)
{
FEElement2D& el = m_Elem[i];
el.SetLocalID(i);
el.SetMeshPartition(this);
}
if (espec.etype != FE_ELEM_INVALID_TYPE)
for (int i=0; i<nelems; ++i) m_Elem[i].SetType(espec.etype);
return true;
}
//-----------------------------------------------------------------------------
void FEDomain2D::PreSolveUpdate(const FETimeInfo& timeInfo)
{
ForEachMaterialPoint([&](FEMaterialPoint& mp) {
mp.Update(timeInfo);
});
}
//-----------------------------------------------------------------------------
void FEDomain2D::Reset()
{
ForEachMaterialPoint([](FEMaterialPoint& mp) {
mp.Init();
});
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the reference frame at
//! integration point n. The inverse jacobian is return in Ji. The return value
//! is the determinant of the jacobian (not the inverse!)
double FEDomain2D::invjac0(FEElement2D& el, double Ji[2][2], int n)
{
// initial nodal coordinates
int neln = el.Nodes();
double x[FEElement::MAX_NODES];
double y[FEElement::MAX_NODES];
for (int i=0; i<neln; ++i)
{
vec3d& ri = m_pMesh->Node(el.m_node[i]).m_r0;
x[i] = ri.x;
y[i] = ri.y;
}
// calculate Jacobian
double J[2][2] = {0};
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Hr(n)[i];
const double& Gsi = el.Hs(n)[i];
J[0][0] += Gri*x[i]; J[0][1] += Gsi*x[i];
J[1][0] += Gri*y[i]; J[1][1] += Gsi*y[i];
}
// calculate the determinant
double det = J[0][0]*J[1][1] - J[0][1]*J[1][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];
Ji[1][0] = -deti*J[1][0];
Ji[0][1] = -deti*J[0][1];
Ji[1][1] = deti*J[0][0];
return det;
}
//-----------------------------------------------------------------------------
//! Calculate the inverse jacobian with respect to the reference frame at
//! integration point n. The inverse jacobian is return in Ji. The return value
//! is the determinant of the jacobian (not the inverse!)
double FEDomain2D::invjact(FEElement2D& el, double Ji[2][2], int n)
{
// number of nodes
int neln = el.Nodes();
// nodal coordinates
double x[FEElement::MAX_NODES];
double y[FEElement::MAX_NODES];
for (int i=0; i<neln; ++i)
{
vec3d& ri = m_pMesh->Node(el.m_node[i]).m_rt;
x[i] = ri.x;
y[i] = ri.y;
}
// calculate Jacobian
double J[2][2] = {0};
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Hr(n)[i];
const double& Gsi = el.Hs(n)[i];
J[0][0] += Gri*x[i]; J[0][1] += Gsi*x[i];
J[1][0] += Gri*y[i]; J[1][1] += Gsi*y[i];
}
// calculate the determinant
double det = J[0][0]*J[1][1] - J[0][1]*J[1][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];
Ji[1][0] = -deti*J[1][0];
Ji[0][1] = -deti*J[0][1];
Ji[1][1] = deti*J[0][0];
return det;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points
//! A 2D element is assumed to have no variation through the thickness.
vec2d FEDomain2D::gradient(FEElement2D& el, double* fn, int n)
{
double Ji[2][2];
invjact(el, Ji, n);
double* Grn = el.Hr(n);
double* Gsn = el.Hs(n);
double Gx, Gy;
vec2d gradf(0,0);
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];
Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i];
// calculate gradient
gradf.x() += Gx*fn[i];
gradf.y() += Gy*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate gradient of function at integration points
//! A 2D element is assumed to have no variation through the thickness.
vec2d FEDomain2D::gradient(FEElement2D& el, vector<double>& fn, int n)
{
double Ji[2][2];
invjact(el, Ji, n);
double* Grn = el.Hr(n);
double* Gsn = el.Hs(n);
vec2d gradf(0,0);
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 !
double Gx = Ji[0][0]*Grn[i]+Ji[1][0]*Gsn[i];
double Gy = Ji[0][1]*Grn[i]+Ji[1][1]*Gsn[i];
// calculate pressure gradient
gradf.x() += Gx*fn[i];
gradf.y() += Gy*fn[i];
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
mat2d FEDomain2D::gradient(FEElement2D& el, vec2d* fn, int n)
{
double Ji[2][2];
invjact(el, Ji, n);
vec2d g1(Ji[0][0],Ji[0][1]);
vec2d g2(Ji[1][0],Ji[1][1]);
double* Gr = el.Hr(n);
double* Gs = el.Hs(n);
mat2d gradf;
gradf.zero();
int N = el.Nodes();
for (int i=0; i<N; ++i)
{
vec2d tmp = g1*Gr[i] + g2*Gs[i];
gradf += dyad(fn[i], tmp);
}
return gradf;
}
//-----------------------------------------------------------------------------
//! calculate spatial gradient of function at integration points
//! A 2D element is assumed to have no variation through the thickness.
mat3d FEDomain2D::gradient(FEElement2D& el, vec3d* fn, int n)
{
double Ji[2][2];
invjact(el, Ji, n);
vec3d g1(Ji[0][0],Ji[0][1],0.0);
vec3d g2(Ji[1][0],Ji[1][1],0.0);
double* Gr = el.Hr(n);
double* Gs = el.Hs(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]);
return gradf;
}
//-----------------------------------------------------------------------------
//! Calculate jacobian with respect to reference frame
double FEDomain2D::detJ0(FEElement2D &el, int n)
{
// initial nodal coordinates
int neln = el.Nodes();
double x[FEElement::MAX_NODES];
double y[FEElement::MAX_NODES];
for (int i=0; i<neln; ++i)
{
vec3d& ri = m_pMesh->Node(el.m_node[i]).m_r0;
x[i] = ri.x;
y[i] = ri.y;
}
// calculate Jacobian
double J[2][2] = {0};
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Hr(n)[i];
const double& Gsi = el.Hs(n)[i];
J[0][0] += Gri*x[i]; J[0][1] += Gsi*x[i];
J[1][0] += Gri*y[i]; J[1][1] += Gsi*y[i];
}
// calculate the determinant
double det = J[0][0]*J[1][1] - J[0][1]*J[1][0];
return det;
}
//-----------------------------------------------------------------------------
//! Calculate jacobian with respect to current frame
double FEDomain2D::detJt(FEElement2D &el, int n)
{
// initial nodal coordinates
int neln = el.Nodes();
double x[FEElement::MAX_NODES];
double y[FEElement::MAX_NODES];
for (int i=0; i<neln; ++i)
{
vec3d& ri = m_pMesh->Node(el.m_node[i]).m_rt;
x[i] = ri.x;
y[i] = ri.y;
}
// calculate Jacobian
double J[2][2] = {0};
for (int i=0; i<neln; ++i)
{
const double& Gri = el.Hr(n)[i];
const double& Gsi = el.Hs(n)[i];
J[0][0] += Gri*x[i]; J[0][1] += Gsi*x[i];
J[1][0] += Gri*y[i]; J[1][1] += Gsi*y[i];
}
// calculate the determinant
double det = J[0][0]*J[1][1] - J[0][1]*J[1][0];
return det;
}
//-----------------------------------------------------------------------------
//! This function calculates the covariant basis vectors of a 2D element
//! at an integration point
void FEDomain2D::CoBaseVectors(FEElement2D& el, int j, vec2d g[2])
{
FEMesh& m = *m_pMesh;
// get the nr of nodes
int n = el.Nodes();
// get the shape function derivatives
double* Hr = el.Hr(j);
double* Hs = el.Hs(j);
g[0] = g[1] = vec2d(0,0);
for (int i=0; i<n; ++i)
{
vec2d rt = vec2d(m.Node(el.m_node[i]).m_rt.x,m.Node(el.m_node[i]).m_rt.y);
g[0] += rt*Hr[i];
g[1] += rt*Hs[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the contravariant basis vectors of a 2D element
//! at an integration point
void FEDomain2D::ContraBaseVectors(FEElement2D& el, int j, vec2d gcnt[2])
{
vec2d gcov[2];
CoBaseVectors(el, j, gcov);
mat2d J = mat2d(gcov[0].x(), gcov[1].x(),
gcov[0].y(), gcov[1].y());
mat3d Ji = J.inverse();
gcnt[0] = vec2d(Ji(0,0),Ji(0,1));
gcnt[1] = vec2d(Ji(1,0),Ji(1,1));
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of covariant basis
//! vectors of a 2D element at an integration point
void FEDomain2D::CoBaseVectorDerivatives(FEElement2D& el, int j, vec2d dg[2][2])
{
FEMesh& m = *m_pMesh;
// get the nr of nodes
int n = el.Nodes();
// get the shape function derivatives
double* Hrr = el.Hrr(j); double* Hrs = el.Hrs(j);
double* Hsr = el.Hsr(j); double* Hss = el.Hss(j);
dg[0][0] = dg[0][1] = vec2d(0,0); // derivatives of g[0]
dg[1][0] = dg[1][1] = vec2d(0,0); // derivatives of g[1]
for (int i=0; i<n; ++i)
{
vec2d rt = vec2d(m.Node(el.m_node[i]).m_rt.x,m.Node(el.m_node[i]).m_rt.y);
dg[0][0] += rt*Hrr[i]; dg[0][1] += rt*Hsr[i];
dg[1][0] += rt*Hrs[i]; dg[1][1] += rt*Hss[i];
}
}
//-----------------------------------------------------------------------------
//! This function calculates the parametric derivatives of contravariant basis
//! vectors of a solid element at an integration point
void FEDomain2D::ContraBaseVectorDerivatives(FEElement2D& el, int j, vec2d dgcnt[2][2])
{
vec2d gcnt[2];
vec2d dgcov[2][2];
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]);
dgcnt[0][1] = -gcnt[0]*(gcnt[0]*dgcov[0][1])-gcnt[1]*(gcnt[0]*dgcov[1][1]);
// derivatives of gcnt[1]
dgcnt[1][0] = -gcnt[0]*(gcnt[1]*dgcov[0][0])-gcnt[1]*(gcnt[1]*dgcov[1][0]);
dgcnt[1][1] = -gcnt[0]*(gcnt[1]*dgcov[0][1])-gcnt[1]*(gcnt[1]*dgcov[1][1]);
}
//-----------------------------------------------------------------------------
//! calculate the laplacian of a vector function at an integration point
vec2d FEDomain2D::lapvec(FEElement2D& el, vec2d* fn, int n)
{
vec2d gcnt[2];
vec2d dgcnt[2][2];
ContraBaseVectors(el, n, gcnt);
ContraBaseVectorDerivatives(el, n, dgcnt);
double* Gr = el.Hr(n);
double* Gs = el.Hs(n);
// get the shape function derivatives
double* Hrr = el.Hrr(n); double* Hrs = el.Hrs(n);
double* Hsr = el.Hsr(n); double* Hss = el.Hss(n);
vec2d lapv(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[1]*Hsr[i]+dgcnt[1][0]*Gs[i])*gcnt[0]+
(gcnt[1]*Hss[i]+dgcnt[1][1]*Gs[i])*gcnt[1]);
return lapv;
}
//-----------------------------------------------------------------------------
//! calculate the gradient of the divergence of a vector function at an integration point
vec2d FEDomain2D::gradivec(FEElement2D& el, vec2d* fn, int n)
{
vec2d gcnt[2];
vec2d dgcnt[2][2];
ContraBaseVectors(el, n, gcnt);
ContraBaseVectorDerivatives(el, n, dgcnt);
double* Gr = el.Hr(n);
double* Gs = el.Hs(n);
// get the shape function derivatives
double* Hrr = el.Hrr(n); double* Hrs = el.Hrs(n);
double* Hsr = el.Hsr(n); double* Hss = el.Hss(n);
vec2d gdv(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[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]);
return gdv;
}
| C++ |
3D | febiosoftware/FEBio | FECore/MMath.h | .h | 2,990 | 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 "MItem.h"
#include "fecore_api.h"
// Take the derivative with respect of x
MITEM FECORE_API MDerive(const MITEM& e, const MVariable& x);
// Take the nth-derivative with respect of x
MITEM FECORE_API MDerive(const MITEM& e, const MVariable& x, int n);
// Take the partial derivative with respect to x, y, z, ...
MITEM FECORE_API MDerive(const MITEM& e, const MSequence& x);
// Replace an expression with an expression
MITEM FECORE_API MReplace(const MITEM& e, const MVariable& x, const MITEM& s);
// Replace an expression with an expression (assuming x is an equality)
MITEM FECORE_API MReplace(const MITEM& e, const MITEM& x);
// Replace an expression with an expression
MITEM FECORE_API MReplace(const MITEM& e, const MITEM& x, const MITEM& s);
// replace multiple expressions with other expressions
MITEM FECORE_API MReplace(const MITEM& e, const MSequence& x, const MSequence& s);
// Calculate the taylor expansion of an expression
MITEM FECORE_API MTaylor(const MITEM& e, const MVariable& x, double z, int n);
// Calculate the indefinite integral (without constant)
MITEM FECORE_API MIntegral(const MITEM& e, const MVariable& x);
// Calculate the definite integral
MITEM FECORE_API MIntegral(const MITEM& e, const MVariable& x, const MITEM& a, const MITEM& b);
// Expand an expression
MITEM FECORE_API MExpand(const MITEM& e);
// Expand an expression but don't expand the second argument
MITEM FECORE_API MExpand(const MITEM& e, const MITEM& s);
// solve an expression
MITEM FECORE_API MSolve(const MITEM& e, const MITEM& v);
// collect terms
MITEM FECORE_API MCollect(const MITEM& e, const MITEM& x);
// simplify an expression
MITEM FECORE_API MSimplify(const MITEM& e);
| Unknown |
3D | febiosoftware/FEBio | FECore/besselIK.h | .h | 1,715 | 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) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
// modified Bessel function of the first kind I0(x) (real x)
FECORE_API double i0(double x);
// modified Bessel function of the first kind I1(x) (real x)
FECORE_API double i1(double x);
// modified Bessel function of the second kind I0(x) (real x)
FECORE_API double k0(double x);
// modified Bessel function of the second kind I1(x) (real x)
FECORE_API double k1(double x);
| Unknown |
3D | febiosoftware/FEBio | FECore/FECoreKernel.h | .h | 12,354 | 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.*/
#pragma once
#include "FECoreFactory.h"
#include "ClassDescriptor.h"
#include <vector>
#include <map>
#include <string.h>
#include <stdio.h>
#include "version.h"
//-----------------------------------------------------------------------------
// Forward declarations
class FEModel;
class LinearSolver;
class FEModule;
//-----------------------------------------------------------------------------
//! This is the FECore kernel class that manages the interactions between the
//! different modules. In particular, it manages the factory classes
//! which are responsible for the creation of different classes that are registered
//! with the kernel.
class FECORE_API FECoreKernel
{
public:
// Do not call this function from a plugin as it will not return the correct
// instance. Instead, use the FECoreKernel object that is passed in the PluginInitialize method
static FECoreKernel& GetInstance();
// set the instance of the kernel
static void SetInstance(FECoreKernel* pkernel);
public:
static const char* SuperClassString(unsigned int sid);
static std::map<unsigned int, const char*> GetSuperClassMap();
public:
//! Register a class with the framework
void RegisterFactory(FECoreFactory* ptf);
//! Create a specific using a superclass ID and an alias
FECoreBase* Create(int superClassID, const char* szalias, FEModel* pfem);
//! Creat a specific class using a superclass ID, an alias and a module name
FECoreBase* Create(int superClassID, const char* szalias, const char* szmod, FEModel* pfem);
//! Create a class from its base class name and type string
FECoreBase* Create(const char* baseClassName, const char* typeStr, FEModel* pfem);
//! Create a specific class
FECoreBase* CreateClass(const char* szclassName, FEModel* fem);
//! Create a class from a class descriptor
FECoreBase* Create(int superClassID, FEModel* pfem, const FEClassDescriptor& cd);
//! count the number of registered classes with a given super-class id
int Count(SUPER_CLASS_ID sid);
//! List the registered classes with a given super-class id
void List(SUPER_CLASS_ID sid);
//! Get the number of registered factory classes
int FactoryClasses();
//! return a factory class
const FECoreFactory* GetFactoryClass(int i);
//! return a factory class
const FECoreFactory* GetFactoryClass(int superClassID, int i);
//! Get the index of a class factory (NOTE: this is a slow function!)
int GetFactoryIndex(int superClassId, const char* sztype);
//! find a factory class
FECoreFactory* FindFactoryClass(int classID, const char* sztype);
//! find a factory class (also match module name)
FECoreFactory* FindFactoryClass(int classID, const char* sztype, const char* szmod);
//! remove a factory class
bool UnregisterFactory(FECoreFactory* ptf);
//! unregister factories from allocator
void UnregisterFactories(int alloc_id);
//! unregister modules from allocator
void UnregisterModules(int alloc_id);
//! set the current allocator ID
void SetAllocatorID(int alloc_id);
//! generate a allocator ID
int GenerateAllocatorID();
FECoreBase* CreateInstance(const FECoreFactory* fac, FEModel* fem);
bool IsModuleActive(int moduleID);
public: // Modules
//! count modules
int Modules() const;
//! Create a module (also makes it the active module)
bool CreateModule(const char* szmodule, const char* description = nullptr);
bool CreateModule(FEModule* pmodule, const char* szmodule, const char* description = nullptr);
//! set the active module
bool SetActiveModule(const char* szmodule);
bool SetActiveModule(int moduleId);
// return the active module's ID
int GetActiveModuleID();
FEModule* GetActiveModule();
//! add module dependency to the active module
bool AddModuleDependency(const char* szdep);
//! Get a module's name
const char* GetModuleName(int i) const;
const char* GetModuleNameFromId(int id) const;
const char* GetModuleDescription(int i) const;
int GetModuleStatus(int i) const;
int GetModuleAllocatorID(int i) const;
int FindModuleID(const char* szmodule) const;
//! Get a module's dependencies
vector<int> GetModuleDependencies(int i) const;
//! set the spec ID. Features with a matching spec ID will be preferred
//! set spec ID to -1 to stop caring
void SetSpecID(int nspec);
public:
//! Register a new domain class
void RegisterDomain(FEDomainFactory* pf, bool pushFront = false);
//! Create a domain of a certain type (this uses the domain factories)
FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat);
//! Create a domain of a certain type (this does not use the domain factories)
FEDomain* CreateDomainExplicit(int superClass, const char* sztype, FEModel* fem);
public:
//! set the default linear solver
FECoreFactory* SetDefaultSolverType(const char* sztype);
void SetDefaultSolver(FEClassDescriptor* linsolve);
//! get the linear solver type
const char* GetLinearSolverType() const;
//! Get a linear solver
LinearSolver* CreateDefaultLinearSolver(FEModel* fem);
public:
void ShowDeprecationWarnings(bool b);
private:
std::vector<FECoreFactory*> m_Fac; // list of registered factory classes
std::vector<FEDomainFactory*> m_Dom; // list of domain factory classes
bool m_bshowDeprecationWarning;
std::map<unsigned int, const char*> m_sidMap; // super class ID map
std::string m_default_solver_type; // default linear solver
FEClassDescriptor* m_default_solver;
// module list
vector<FEModule*> m_modules;
int m_activeModule;
int m_nspec;
int m_alloc_id; //!< current allocator ID
int m_next_alloc_id; //!< next allocator ID
private: // make singleton
FECoreKernel();
FECoreKernel(const FECoreKernel&){}
void operator = (const FECoreKernel&){}
private:
static FECoreKernel* m_pKernel; // the one-and-only kernel object
};
//-----------------------------------------------------------------------------
//! This class helps with the registration of a class with the framework
template <typename T> class FERegisterClass_T : public FECoreFactory
{
public:
FERegisterClass_T(SUPER_CLASS_ID sid, const char* szclass, const char* szbase, const char* szalias, int spec = -1) : FECoreFactory(sid, szclass, szbase, szalias, spec)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
fecore.RegisterFactory(this);
}
FECoreBase* Create(FEModel* pfem) const { return new T(pfem); }
};
//-----------------------------------------------------------------------------
// Register a factory class
#define REGISTER_FECORE_FACTORY(theFactory) \
static theFactory _##theFactory##_rc;
//-----------------------------------------------------------------------------
// Register a class using default creation parameters
#define REGISTER_FECORE_CLASS(theClass, ...) \
static FERegisterClass_T<theClass> _##theClass##_rc(theClass::superClassID(), #theClass, theClass::BaseClassName(), __VA_ARGS__);
//-----------------------------------------------------------------------------
// Register a class using default creation parameters
#define REGISTER_FECORE_CLASS_EXPLICIT(theClass, theID, ...) \
static FERegisterClass_T<theClass> _##theClass##_rc(theID, #theClass, theClass::BaseClassName(), __VA_ARGS__);
//-----------------------------------------------------------------------------
// version for classes that require template arguments
#define REGISTER_FECORE_CLASS_T(theClass, theArg, theName) \
static FERegisterClass_T<theClass<theArg> > _##theClass##theArg##_rc(theClass<theArg>::superClassID(), #theClass, theClass<theArg>::BaseClassName(), theName);
//-----------------------------------------------------------------------------
// version for classes that require template arguments
#define REGISTER_FECORE_CLASS_T2(theClass, theArg1, theArg2, theName) \
static FERegisterClass_T<theClass<theArg1, theArg2> > _##theClass##theArg1##theArg2##_rc(theClass<theArg1, theArg2>::superClassID(), #theClass, theClass<theArg1, theArg2>::BaseClassName(), theName);
//-----------------------------------------------------------------------------
// Create an instance of a class.
// This assumes that TBase is derived from FECoreBase and defines a class ID.
template <typename TBase> inline TBase* fecore_new(const char* sztype, FEModel* pfem)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
return static_cast<TBase*>(fecore.Create(TBase::superClassID(), sztype, pfem));
// return static_cast<TBase*>(fecore.Create(TBase::BaseClassName(), sztype, pfem));
}
//-----------------------------------------------------------------------------
// Create an instance of a class in a particulare module.
// This assumes that TBase is derived from FECoreBase and defines a class ID.
template <typename TBase> inline TBase* fecore_new_ex(const char* sztype, const char* szmod, FEModel* pfem)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
return static_cast<TBase*>(fecore.Create(TBase::superClassID(), sztype, szmod, pfem));
}
//-----------------------------------------------------------------------------
// Create an instance of a class.
// This assumes that TBase is derived from FECoreBase and defines a class ID.
template <typename TBase> inline TBase* fecore_new(int classIndex, FEModel* pfem)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
const FECoreFactory* f = fecore.GetFactoryClass(TBase::superClassID(), classIndex);
if (f) return static_cast<TBase*>(f->Create(pfem));
else return nullptr;
}
//-----------------------------------------------------------------------------
template <typename TClass> inline TClass* fecore_new_class(const char* szclass, FEModel* fem)
{
int superId = TClass::superClassID();
FECoreKernel& fecore = FECoreKernel::GetInstance();
return static_cast<TClass*>(fecore.CreateClass(szclass, fem));
}
//-----------------------------------------------------------------------------
#define fecore_alloc(theClass, fem) fecore_new_class<theClass>(#theClass, fem)
//-----------------------------------------------------------------------------
// Three-parameter form of the fecore_new function for situations where the base class does not
// define the classID value.
template <typename TBase> inline TBase* fecore_new(int sid, const char* sztype, FEModel* pfem)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
return static_cast<TBase*>(fecore.Create(sid, sztype, pfem));
}
//=============================================================================
// TODO: Move all this stuff to sdk.h
//-----------------------------------------------------------------------------
// Template class for factory classes for plugins
template <typename T, SUPER_CLASS_ID sid> class FEPluginFactory_T : public FECoreFactory
{
public:
FEPluginFactory_T(const char* sz) : FECoreFactory(sid, nullptr, sz, nullptr){}
FECoreBase* Create(FEModel* pfem) const { return new T(pfem); }
};
//------------------------------------------------------------------------------
// This is for functions exported from a plugin
#ifdef WIN32
#define FECORE_EXPORT extern "C" __declspec(dllexport)
#else
#define FECORE_EXPORT extern "C"
#endif
| Unknown |
3D | febiosoftware/FEBio | FECore/sdk.h | .h | 2,171 | 51 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreKernel.h"
//------------------------------------------------------------------------------
// This macro should be used to start the definition of the plugin classes
#define BEGIN_PLUGIN_DEFINITION static std::vector<FECoreFactory*> _facs; \
FECORE_API void PluginInitialize(FECoreKernel& febio) { FECoreKernel::SetInstance(&febio);
//------------------------------------------------------------------------------
// Use this macro to define each new plugin class
#define REGISTER_PLUGIN(theClass, theID, theName) \
_facs.push_back(new FEPluginFactory_T<theClass, theID>(theName));
//------------------------------------------------------------------------------
// This macro ends the plugin definition section
#define END_PLUGIN_DEFINITION
#ifdef WIN32
#define FECORE_PLUGIN extern "C" __declspec(dllexport)
#else
#define FECORE_PLUGIN extern "C"
#endif
| Unknown |
3D | febiosoftware/FEBio | FECore/FEElementLibrary.cpp | .cpp | 10,766 | 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 "FEElementLibrary.h"
#include "FEElement.h"
#include "FESolidElementShape.h"
#include "FESurfaceElementShape.h"
FEElementLibrary* FEElementLibrary::m_pThis = 0;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//! initialize library
void FEElementLibrary::Initialize()
{
// Calling GetInstance will initialize the static pointer
if (m_pThis == 0) GetInstance();
}
FEElementLibrary* FEElementLibrary::GetInstance()
{
if (m_pThis == 0)
{
m_pThis = new FEElementLibrary;
int n;
// register element shapes (must be done before types!)
n = m_pThis->RegisterShape(new FETet4 ); assert(n == ET_TET4 );
n = m_pThis->RegisterShape(new FETet5 ); assert(n == ET_TET5 );
n = m_pThis->RegisterShape(new FETet10 ); assert(n == ET_TET10 );
n = m_pThis->RegisterShape(new FETet15 ); assert(n == ET_TET15 );
n = m_pThis->RegisterShape(new FETet20 ); assert(n == ET_TET20 );
n = m_pThis->RegisterShape(new FEPenta6 ); assert(n == ET_PENTA6 );
n = m_pThis->RegisterShape(new FEPenta15); assert(n == ET_PENTA15);
n = m_pThis->RegisterShape(new FEHex8 ); assert(n == ET_HEX8 );
n = m_pThis->RegisterShape(new FEHex20 ); assert(n == ET_HEX20 );
n = m_pThis->RegisterShape(new FEHex27 ); assert(n == ET_HEX27 );
n = m_pThis->RegisterShape(new FEPyra5 ); assert(n == ET_PYRA5 );
n = m_pThis->RegisterShape(new FEPyra13 ); assert(n == ET_PYRA13 );
n = m_pThis->RegisterShape(new FEQuad4 ); assert(n == ET_QUAD4 );
n = m_pThis->RegisterShape(new FEQuad8 ); assert(n == ET_QUAD8 );
n = m_pThis->RegisterShape(new FEQuad9 ); assert(n == ET_QUAD9 );
n = m_pThis->RegisterShape(new FETri3 ); assert(n == ET_TRI3 );
n = m_pThis->RegisterShape(new FETri6 ); assert(n == ET_TRI6 );
n = m_pThis->RegisterShape(new FETri7 ); assert(n == ET_TRI7 );
n = m_pThis->RegisterShape(new FETri10 ); assert(n == ET_TRI10 );
// register element types
n = m_pThis->RegisterTraits(new FEHex8G8 ); assert(n==FE_HEX8G8 );
n = m_pThis->RegisterTraits(new FEHex8RI ); assert(n==FE_HEX8RI );
n = m_pThis->RegisterTraits(new FEHex8G1 ); assert(n==FE_HEX8G1 );
n = m_pThis->RegisterTraits(new FETet4G1 ); assert(n==FE_TET4G1 );
n = m_pThis->RegisterTraits(new FETet4G4 ); assert(n==FE_TET4G4 );
n = m_pThis->RegisterTraits(new FETet5G4 ); assert(n==FE_TET5G4 );
n = m_pThis->RegisterTraits(new FEPenta6G6 ); assert(n==FE_PENTA6G6 );
n = m_pThis->RegisterTraits(new FETet10G1 ); assert(n==FE_TET10G1 );
n = m_pThis->RegisterTraits(new FETet10G4 ); assert(n==FE_TET10G4 );
n = m_pThis->RegisterTraits(new FETet10G8 ); assert(n==FE_TET10G8 );
n = m_pThis->RegisterTraits(new FETet10GL11 ); assert(n==FE_TET10GL11);
n = m_pThis->RegisterTraits(new FETet10G4RI1); assert(n==FE_TET10G4RI1);
n = m_pThis->RegisterTraits(new FETet10G8RI4); assert(n==FE_TET10G8RI4);
n = m_pThis->RegisterTraits(new FETet15G4 ); assert(n==FE_TET15G4 );
n = m_pThis->RegisterTraits(new FETet15G8 ); assert(n==FE_TET15G8 );
n = m_pThis->RegisterTraits(new FETet15G11 ); assert(n==FE_TET15G11 );
n = m_pThis->RegisterTraits(new FETet15G15 ); assert(n==FE_TET15G15 );
n = m_pThis->RegisterTraits(new FETet15G15RI4); assert(n==FE_TET15G15RI4);
n = m_pThis->RegisterTraits(new FETet20G15 ); assert(n==FE_TET20G15 );
n = m_pThis->RegisterTraits(new FEHex20G8 ); assert(n==FE_HEX20G8 );
n = m_pThis->RegisterTraits(new FEHex20G27 ); assert(n==FE_HEX20G27 );
n = m_pThis->RegisterTraits(new FEHex27G27 ); assert(n==FE_HEX27G27 );
n = m_pThis->RegisterTraits(new FEPenta15G8 ); assert(n==FE_PENTA15G8);
n = m_pThis->RegisterTraits(new FEPenta15G21); assert(n==FE_PENTA15G21);
n = m_pThis->RegisterTraits(new FEPyra5G8 ); assert(n==FE_PYRA5G8 );
n = m_pThis->RegisterTraits(new FEPyra13G8 ); assert(n==FE_PYRA13G8 );
n = m_pThis->RegisterTraits(new FEQuad4G4 ); assert(n==FE_QUAD4G4 );
n = m_pThis->RegisterTraits(new FEQuad4G16 ); assert(n==FE_QUAD4G16 );
n = m_pThis->RegisterTraits(new FEQuad4NI ); assert(n==FE_QUAD4NI );
n = m_pThis->RegisterTraits(new FETri3G1 ); assert(n==FE_TRI3G1 );
n = m_pThis->RegisterTraits(new FETri3G3 ); assert(n==FE_TRI3G3 );
n = m_pThis->RegisterTraits(new FETri3G7 ); assert(n==FE_TRI3G7 );
n = m_pThis->RegisterTraits(new FETri3NI ); assert(n==FE_TRI3NI );
n = m_pThis->RegisterTraits(new FETri6G3 ); assert(n==FE_TRI6G3 );
n = m_pThis->RegisterTraits(new FETri6G4 ); assert(n==FE_TRI6G4 );
n = m_pThis->RegisterTraits(new FETri6G7 ); assert(n==FE_TRI6G7 );
// n = m_pThis->RegisterTraits(new FETri6mG7 ); assert(n==FE_TRI6MG7 );
n = m_pThis->RegisterTraits(new FETri6GL7 ); assert(n==FE_TRI6GL7 );
n = m_pThis->RegisterTraits(new FETri6NI ); assert(n==FE_TRI6NI );
n = m_pThis->RegisterTraits(new FETri7G3 ); assert(n==FE_TRI7G3 );
n = m_pThis->RegisterTraits(new FETri7G4 ); assert(n==FE_TRI7G4 );
n = m_pThis->RegisterTraits(new FETri7G7 ); assert(n==FE_TRI7G7 );
n = m_pThis->RegisterTraits(new FETri7GL7 ); assert(n==FE_TRI7GL7 );
n = m_pThis->RegisterTraits(new FETri10G7 ); assert(n==FE_TRI10G7 );
n = m_pThis->RegisterTraits(new FETri10G12 ); assert(n==FE_TRI10G12 );
n = m_pThis->RegisterTraits(new FEQuad8G9 ); assert(n==FE_QUAD8G9 );
n = m_pThis->RegisterTraits(new FEQuad8NI ); assert(n==FE_QUAD8NI );
n = m_pThis->RegisterTraits(new FEQuad9G9 ); assert(n==FE_QUAD9G9 );
n = m_pThis->RegisterTraits(new FEQuad9NI ); assert(n==FE_QUAD9NI );
n = m_pThis->RegisterTraits(new FEShellQuad4G4 ); assert(n==FE_SHELL_QUAD4G4 );
n = m_pThis->RegisterTraits(new FEShellQuad4G8 ); assert(n==FE_SHELL_QUAD4G8 );
n = m_pThis->RegisterTraits(new FEShellQuad4G12 ); assert(n==FE_SHELL_QUAD4G12);
n = m_pThis->RegisterTraits(new FEShellQuad8G18 ); assert(n==FE_SHELL_QUAD8G18);
n = m_pThis->RegisterTraits(new FEShellQuad8G27 ); assert(n==FE_SHELL_QUAD8G27);
n = m_pThis->RegisterTraits(new FEShellTri3G3 ); assert(n==FE_SHELL_TRI3G3);
n = m_pThis->RegisterTraits(new FEShellTri3G6 ); assert(n==FE_SHELL_TRI3G6);
n = m_pThis->RegisterTraits(new FEShellTri3G9 ); assert(n==FE_SHELL_TRI3G9);
n = m_pThis->RegisterTraits(new FEShellTri6G14 ); assert(n==FE_SHELL_TRI6G14);
n = m_pThis->RegisterTraits(new FEShellTri6G21 ); assert(n==FE_SHELL_TRI6G21);
n = m_pThis->RegisterTraits(new FETrussElementTraits ); assert(n==FE_TRUSS);
n = m_pThis->RegisterTraits(new FEDiscreteElementTraits ); assert(n==FE_DISCRETE);
n = m_pThis->RegisterTraits(new FE2DTri3G1 ); assert(n==FE2D_TRI3G1 );
n = m_pThis->RegisterTraits(new FE2DTri6G3 ); assert(n==FE2D_TRI6G3 );
n = m_pThis->RegisterTraits(new FE2DQuad4G4 ); assert(n==FE2D_QUAD4G4);
n = m_pThis->RegisterTraits(new FE2DQuad8G9 ); assert(n==FE2D_QUAD8G9);
n = m_pThis->RegisterTraits(new FE2DQuad9G9 ); assert(n==FE2D_QUAD9G9);
n = m_pThis->RegisterTraits(new FELine2G1 ); assert(n==FE_LINE2G1);
n = m_pThis->RegisterTraits(new FELine2NI ); assert(n==FE_LINE2NI);
n = m_pThis->RegisterTraits(new FEBeam2G1 ); assert(n==FE_BEAM2G1);
n = m_pThis->RegisterTraits(new FEBeam2G2 ); assert(n==FE_BEAM2G2);
n = m_pThis->RegisterTraits(new FEBeam3G2 ); assert(n==FE_BEAM3G2);
}
return m_pThis;
}
FEElementLibrary::~FEElementLibrary()
{
for (size_t i=0; i<m_Traits.size(); ++i) delete m_Traits[i];
m_Traits.clear();
}
int FEElementLibrary::RegisterShape(FEElementShape* pshape)
{
m_Shape.push_back(pshape);
return ((int)m_Shape.size() - 1);
}
int FEElementLibrary::RegisterTraits(FEElementTraits* ptrait)
{
m_Traits.push_back(ptrait);
return ((int)m_Traits.size()-1);
}
void FEElementLibrary::SetElementTraits(FEElement& el, int nid)
{
el.SetTraits( GetInstance()->m_Traits[nid] );
}
//! return element shape class
FEElementShape* FEElementLibrary::GetElementShapeClass(FE_Element_Shape eshape)
{
return GetInstance()->m_Shape[eshape];
}
FEElementTraits* FEElementLibrary::GetElementTraits(int ntype)
{
return GetInstance()->m_Traits[ntype];
}
FE_Element_Shape FEElementLibrary::GetElementShape(int ntype)
{
FEElementLibrary* p = GetInstance();
if ((ntype < 0)||(ntype >= p->m_Traits.size())) return FE_ELEM_INVALID_SHAPE;
return p->m_Traits[ntype]->Shape();
}
//! return the element class of a given element type
FE_Element_Class FEElementLibrary::GetElementClass(int ntype)
{
FEElementLibrary* p = GetInstance();
if ((ntype < 0) || (ntype >= p->m_Traits.size())) return FE_ELEM_INVALID_CLASS;
return p->m_Traits[ntype]->Class();
}
bool FEElementLibrary::IsValid(const FE_Element_Spec& c)
{
if (c.eclass == FE_ELEM_INVALID_CLASS) return false;
if (c.eshape == FE_ELEM_INVALID_SHAPE) return false;
if (c.etype == FE_ELEM_INVALID_TYPE ) return false;
if (c.eclass != GetElementClass(c.etype)) return false;
if (c.eshape != GetElementShape(c.etype)) return false;
return true;
}
//! get the element spec from the type
FE_Element_Spec FEElementLibrary::GetElementSpecFromType(FE_Element_Type elemType)
{
FE_Element_Spec espec;
espec.etype = elemType;
if (elemType != FE_ELEM_INVALID_TYPE)
{
espec.eclass = GetElementClass(elemType);
espec.eshape = GetElementShape(elemType);
}
return espec;
}
| C++ |
3D | febiosoftware/FEBio | FECore/quatd.cpp | .cpp | 5,910 | 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 "quatd.h"
#include <math.h>
//-----------------------------------------------------------------------------
//! Spherical linear interpolation between two quaternions.
quatd quatd::slerp(quatd &q1, quatd &q2, const double t)
{
quatd q3;
double dot = quatd::dot(q1, q2);
/* dot = cos(theta)
if (dot < 0), q1 and q2 are more than 90 degrees apart,
so we can invert one to reduce spinning */
if (dot < 0)
{
dot = -dot;
q3 = -q2;
} else q3 = q2;
if (dot < 0.95f)
{
double angle = acos(dot);
return (q1*sin(angle*(1-t)) + q3*sin(angle*t))/sin(angle);
} else // if the angle is small, use linear interpolation
return quatd::lerp(q1,q3,t);
}
//-----------------------------------------------------------------------------
quatd::quatd(const mat3d & m)
{
// find max(tr(m), m00,m11,m22)
double M = m.trace();
if ((M >= m(0, 0)) && (M >= m(1, 1)) && (M >= m(2, 2)))
{
w = 0.5*sqrt(1.0 + M);
x = 0.25 * (m(2, 1) - m(1, 2)) / w;
y = 0.25 * (m(0, 2) - m(2, 0)) / w;
z = 0.25 * (m(1, 0) - m(0, 1)) / w;
}
else
{
int i = 0;
if (m(1, 1) > m(0, 0)) i = 1;
if (m(2, 2) > m(i, i)) i = 2;
int j = (i + 1) % 3;
int k = (j + 1) % 3;
double q[3];
q[i] = sqrt(0.5 * m(i, i) + 0.25 * (1.0 - M));
w = 0.25 * (m(k, j) - m(j, k)) / q[i];
q[j] = 0.25 * (m(j, i) + m(i, j)) / q[i];
q[k] = 0.25 * (m(k, i) + m(i, k)) / q[i];
x = q[0];
y = q[1];
z = q[2];
}
}
// TODO: This looks like it calculates the opposite rotation
/*
quatd::quatd(const mat3d& m)
{
quatd& q = *this;
double t;
if (m(2, 2) < 0)
{
if (m(0, 0) > m(1, 1))
{
t = 1 + m(0, 0) - m(1, 1) - m(2, 2);
q = quatd(t, m(0, 1) + m(1, 0), m(2, 0) + m(0, 2), m(1, 2) - m(2, 1));
}
else
{
t = 1 - m(0, 0) + m(1, 1) - m(2, 2);
q = quatd(m(0, 1) + m(1, 0), t, m(1, 2) + m(2, 1), m(2, 0) - m(0, 2));
}
}
else
{
if (m(0, 0) < -m(1, 1))
{
t = 1 - m(0, 0) - m(1, 1) + m(2, 2);
q = quatd(m(2, 0) + m(0, 2), m(1, 2) + m(2, 1), t, m(0, 1) - m(1, 0));
}
else
{
t = 1 + m(0, 0) + m(1, 1) + m(2, 2);
q = quatd(m(1, 2) - m(2, 1), m(2, 0) - m(0, 2), m(0, 1) - m(1, 0), t);
}
}
double s = 0.5 / sqrt(t);
q.x *= s;
q.y *= s;
q.z *= s;
q.w *= s;
}
*/
//-----------------------------------------------------------------------------
void quatd::SetEuler(double X, double Y, double Z)
{
// calculate cos and sin of angles
double cz = cos(Z*0.5);
double sz = sin(Z*0.5);
double cx = cos(X*0.5);
double sx = sin(X*0.5);
double cy = cos(Y*0.5);
double sy = sin(Y*0.5);
// define quaternion
w = cz * cx * cy + sz * sx * sy;
x = cz * sx * cy - sz * cx * sy;
y = cz * cx * sy + sz * sx * cy;
z = sz * cx * cy - cz * sx * sy;
}
//-----------------------------------------------------------------------------
void quatd::GetEuler(double& X, double& Y, double& Z) const
{
// roll (x-axis rotation)
double t0 = +2.0 * (w * x + y * z);
double t1 = +1.0 - 2.0 * (x*x + y*y);
X = atan2(t0, t1);
// pitch (y-axis rotation)
double t2 = +2.0 * (w*y - z*x);
t2 = t2 > 1.0 ? 1.0 : t2;
t2 = t2 < -1.0 ? -1.0 : t2;
Y = asin(t2);
// yaw (z-axis rotation)
double t3 = +2.0 * (w * z + x * y);
double t4 = +1.0 - 2.0 * (y*y + z*z);
Z = atan2(t3, t4);
}
//-----------------------------------------------------------------------------
// convert euler angles to a rotation matrix
// l[0] = psi (x-rotation)
// l[1] = theta (y-rotation)
// l[2] = phi (z-rotation)
mat3d euler2rot(double l[3])
{
double c0 = cos(l[0]), s0 = sin(l[0]);
double c1 = cos(l[1]), s1 = sin(l[1]);
double c2 = cos(l[2]), s2 = sin(l[2]);
mat3d Rx(1.0, 0.0, 0.0, 0.0, c0, -s0, 0.0, s0, c0);
mat3d Ry(c1, 0.0, s1, 0.0, 1.0, 0.0, -s1, 0.0, c1);
mat3d Rz(c2, -s2, 0.0, s2, c2, 0.0, 0.0, 0.0, 1.0);
return Rz*Ry*Rx;
}
//-----------------------------------------------------------------------------
// convert a rotation matrix to euler angles
// l[0] = psi (x-rotation)
// l[1] = theta (y-rotation)
// l[2] = phi (z-rotation)
void rot2euler(const mat3d& m, double l[3])
{
const double e = 1e-12;
if (fabs(m(2,0) - 1.0) < e)
{
if (m(2,0) < 0.0)
{
l[2] = 0.0;
l[1] = PI/2.0;
l[0] = atan2(m(0,1),m(0,2));
}
else
{
l[2] = 0.0;
l[1] = -PI/2.0;
l[0] = atan2(-m(0,1),-m(0,2));
}
}
else
{
l[1] = -asin(m(2,0));
double c1 = cos(l[1]);
l[0] = atan2(m(2,1)/c1, m(2,2)/c1);
l[2] = atan2(m(1,0)/c1, m(0,0)/c1);
}
}
//-----------------------------------------------------------------------------
// convert a quaternion to Euler angles
void quat2euler(const quatd& q, double l[3])
{
mat3d Q = q.RotationMatrix();
rot2euler(Q, l);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEModel.cpp | .cpp | 72,125 | 2,681 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEModel.h"
#include "FELoadController.h"
#include "FEMaterial.h"
#include "FEModelLoad.h"
#include "FEBoundaryCondition.h"
#include "FENodalLoad.h"
#include "FESurfaceLoad.h"
#include "FEEdgeLoad.h"
#include "FEBodyLoad.h"
#include "FEInitialCondition.h"
#include "FESurfacePairConstraint.h"
#include "FENLConstraint.h"
#include "FEAnalysis.h"
#include "FEGlobalData.h"
#include "FECoreKernel.h"
#include "FELinearConstraintManager.h"
#include "log.h"
#include "FEDataArray.h"
#include "FESurfaceConstraint.h"
#include "FEModelParam.h"
#include "FEEdge.h"
#include "FEMeshAdaptor.h"
#include <string>
#include <map>
#include "DumpStream.h"
#include "LinearSolver.h"
#include "FETimeStepController.h"
#include "Timer.h"
#include "DumpMemStream.h"
#include "FEPlotDataStore.h"
#include "FESolidDomain.h"
#include "FEShellDomain.h"
#include "FETrussDomain.h"
#include "FEDomain2D.h"
#include "FEDiscreteDomain.h"
#include "FEDataGenerator.h"
#include "FEModule.h"
#include "FELogNodeData.h"
#include "FELogElemData.h"
#include "log.h"
#include <stdarg.h>
#include <sstream>
using namespace std;
template <class T> int findComponentInVector(std::vector<T*>& v, FECoreBase* item)
{
for (size_t i = 0; i < v.size(); ++i)
{
if (v[i] == item) return (int) i;
}
return -1;
}
//-----------------------------------------------------------------------------
// Implementation class for the FEModel class
class FEModel::Implementation
{
public:
struct LoadParam
{
FEParam* param;
int lc;
double m_scl;
vec3d m_vscl;
LoadParam()
{
m_scl = 1.0;
m_vscl = vec3d(0, 0, 0);
}
void Serialize(DumpStream& ar)
{
ar & lc;
ar & m_scl & m_vscl;
if (ar.IsShallow() == false)
{
// we can't save the FEParam* directly, so we need to store meta data and try to find it on loading
if (ar.IsSaving())
{
FECoreBase* pc = dynamic_cast<FECoreBase*>(param->parent()); assert(pc);
ar << pc;
ar << param->name();
}
else
{
FECoreBase* pc = nullptr;
ar >> pc; assert(pc);
char name[256] = { 0 };
ar >> name;
param = pc->FindParameter(name); assert(param);
}
}
else param = nullptr;
}
};
public:
Implementation(FEModel* fem) : m_fem(fem), m_mesh(fem), m_dmp(*fem)
{
// --- Analysis Data ---
m_pStep = 0;
m_nStep = -1;
m_ftime0 = 0;
m_nupdates = 0;
m_bsolved = false;
m_block_log = false;
m_printParams = false;
m_meshUpdate = false;
// create the linear constraint manager
m_LCM = new FELinearConstraintManager(fem);
// allocate timers
// Make sure enough timers are allocated for all the TimerIds!
m_timers.resize(TIMER_COUNT);
}
~Implementation()
{
for (auto p : m_logData) delete p;
m_logData.clear();
}
void Serialize(DumpStream& ar);
void PushState()
{
DumpMemStream& ar = m_dmp;
ar.clear(); // this also prepares the stream for writing
m_fem->Serialize(ar);
}
bool PopState()
{
// get the dump stream
DumpMemStream& ar = m_dmp;
// make sure we have data to rewind
if (ar.size() == 0) return false;
// prepare the archive for reading
ar.Open(false, true);
// restore the previous state
m_fem->Serialize(m_dmp);
return true;
}
std::pair<int, int> FindComponent(FECoreBase* pc)
{
int n = -1;
n = findComponentInVector<FEMaterial >(m_MAT , pc); if (n >= 0) return { FEMATERIAL_ID, n };
n = findComponentInVector<FEBoundaryCondition >(m_BC , pc); if (n >= 0) return { FEBC_ID, n };
n = findComponentInVector<FEModelLoad >(m_ML , pc); if (n >= 0) return { FELOAD_ID, n };
n = findComponentInVector<FEInitialCondition >(m_IC , pc); if (n >= 0) return { FEIC_ID, n };
n = findComponentInVector<FESurfacePairConstraint>(m_CI , pc); if (n >= 0) return { FESURFACEINTERFACE_ID, n };
n = findComponentInVector<FENLConstraint >(m_NLC , pc); if (n >= 0) return { FENLCONSTRAINT_ID, n };
n = findComponentInVector<FELoadController >(m_LC , pc); if (n >= 0) return { FELOADCONTROLLER_ID, n };
n = findComponentInVector<FEAnalysis >(m_Step, pc); if (n >= 0) return { FEANALYSIS_ID, n };
n = findComponentInVector<FEMeshAdaptor >(m_MA , pc); if (n >= 0) return { FEMESHADAPTOR_ID, n };
n = findComponentInVector<FEMeshDataGenerator >(m_MD , pc); if (n >= 0) return { FEMESHDATAGENERATOR_ID, n };
return { -1,-1 };
}
public: // TODO: Find a better place for these parameters
FETimeInfo m_timeInfo; //!< current time value
double m_ftime0; //!< start time of current step
bool m_block_log;
bool m_log_verbose = false;
int m_nupdates; //!< number of calls to FEModel::Update
public:
std::vector<FEMaterial*> m_MAT; //!< array of materials
std::vector<FEBoundaryCondition*> m_BC; //!< boundary conditions
std::vector<FEModelLoad*> m_ML; //!< model loads
std::vector<FEInitialCondition*> m_IC; //!< initial conditions
std::vector<FESurfacePairConstraint*> m_CI; //!< contact interface array
std::vector<FENLConstraint*> m_NLC; //!< nonlinear constraints
std::vector<FELoadController*> m_LC; //!< load controller data
std::vector<FEAnalysis*> m_Step; //!< array of analysis steps
std::vector<FEMeshAdaptor*> m_MA; //!< mesh adaptors
std::vector<FEMeshDataGenerator*> m_MD; //!< mesh data generators
std::vector<LoadParam> m_Param; //!< list of parameters controller by load controllers
bool m_dotiming = true; // flag to enable/disable timings
std::vector<Timer> m_timers; // list of timers
public:
FEAnalysis* m_pStep; //!< pointer to current analysis step
int m_nStep; //!< current index of analysis step
bool m_printParams; //!< print parameters
bool m_meshUpdate; //!< mesh update flag
std::string m_units; // units string
public:
// The model
FEModel* m_fem;
// module name
std::string m_moduleName;
bool m_bsolved; // solved flag
// DOFS data
DOFS m_dofs; //!< list of degree of freedoms in this model
// Geometry data
FEMesh m_mesh; //!< the one and only FE mesh
// linear constraint data
FELinearConstraintManager* m_LCM;
DataStore m_dataStore; //!< the data store used for data logging
FEPlotDataStore m_plotData; //!< Output request for plot file
DumpMemStream m_dmp; // only used by incremental solver
// user-requested log data (via GetDataValue)
vector<FELogData*> m_logData;
public: // Global Data
std::map<string, double> m_Const; //!< Global model constants
vector<FEGlobalData*> m_GD; //!< global data structures
std::vector<FEGlobalVariable*> m_Var;
FEMODEL_MEMORY_STATS m_memstats;
};
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEModel, FECoreBase)
// model parameters
ADD_PARAMETER(m_imp->m_timeInfo.currentTime, "time");
// model properties
ADD_PROPERTY(m_imp->m_MAT , "material" );
ADD_PROPERTY(m_imp->m_BC , "bc" );
ADD_PROPERTY(m_imp->m_ML , "load" );
ADD_PROPERTY(m_imp->m_IC , "initial" );
ADD_PROPERTY(m_imp->m_CI , "contact" );
ADD_PROPERTY(m_imp->m_NLC , "constraint" );
ADD_PROPERTY(m_imp->m_MA , "mesh_adaptor" );
ADD_PROPERTY(m_imp->m_LC , "load_controller");
ADD_PROPERTY(m_imp->m_MD , "mesh_data" );
ADD_PROPERTY(m_imp->m_Step, "step" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEModel::FEModel(void) : FECoreBase(this), m_imp(new FEModel::Implementation(this))
{
// set the name
SetName("fem");
// reset all timers
ResetAllTimers();
}
//-----------------------------------------------------------------------------
//! Delete all dynamically allocated data
FEModel::~FEModel(void)
{
Clear();
delete m_imp;
}
void FEModel::SetVerboseMode(bool b)
{
m_imp->m_log_verbose = b;
}
//-----------------------------------------------------------------------------
//! return the data store
DataStore& FEModel::GetDataStore()
{
return m_imp->m_dataStore;
}
//-----------------------------------------------------------------------------
FEPlotDataStore& FEModel::GetPlotDataStore() { return m_imp->m_plotData; }
//-----------------------------------------------------------------------------
const FEPlotDataStore& FEModel::GetPlotDataStore() const { return m_imp->m_plotData; }
//-----------------------------------------------------------------------------
//! will return true if the model solved succussfully
bool FEModel::IsSolved() const
{
return m_imp->m_bsolved;
}
//-----------------------------------------------------------------------------
// call this function to set the mesh's update flag
void FEModel::SetMeshUpdateFlag(bool b)
{
m_imp->m_meshUpdate = b;
}
//-----------------------------------------------------------------------------
void FEModel::Clear()
{
// clear dofs
m_imp->m_dofs.Reset();
// clear all properties
for (FEMaterial* mat : m_imp->m_MAT ) delete mat; m_imp->m_MAT.clear();
for (FEBoundaryCondition* bc : m_imp->m_BC ) delete bc; m_imp->m_BC.clear();
for (FEModelLoad* ml : m_imp->m_ML ) delete ml; m_imp->m_ML.clear();
for (FEInitialCondition* ic : m_imp->m_IC ) delete ic; m_imp->m_IC.clear();
for (FESurfacePairConstraint* ci : m_imp->m_CI ) delete ci; m_imp->m_CI.clear();
for (FENLConstraint* nlc : m_imp->m_NLC ) delete nlc; m_imp->m_NLC.clear();
for (FELoadController* lc : m_imp->m_LC ) delete lc; m_imp->m_LC.clear();
for (FEMeshDataGenerator* md : m_imp->m_MD ) delete md; m_imp->m_MD.clear();
for (FEAnalysis* step : m_imp->m_Step) delete step; m_imp->m_Step.clear();
// global data
for (size_t i = 0; i<m_imp->m_GD.size(); ++i) delete m_imp->m_GD[i]; m_imp->m_GD.clear();
m_imp->m_Const.clear();
// global variables (TODO: Should I delete the corresponding parameters?)
for (size_t i = 0; i < m_imp->m_Var.size(); ++i) delete m_imp->m_Var[i];
m_imp->m_Var.clear();
// clear the linear constraints
if (m_imp->m_LCM) m_imp->m_LCM->Clear();
// clear the mesh
m_imp->m_mesh.Clear();
// clear load parameters
m_imp->m_Param.clear();
}
//-----------------------------------------------------------------------------
//! set the module name
void FEModel::SetActiveModule(const std::string& moduleName)
{
m_imp->m_moduleName = moduleName;
FECoreKernel& fecore = FECoreKernel::GetInstance();
fecore.SetActiveModule(moduleName.c_str());
FEModule* pmod = fecore.GetActiveModule();
pmod->InitModel(this);
}
//-----------------------------------------------------------------------------
//! get the module name
string FEModel::GetModuleName() const
{
return m_imp->m_moduleName;
}
//-----------------------------------------------------------------------------
int FEModel::BoundaryConditions() const { return (int)m_imp->m_BC.size(); }
//-----------------------------------------------------------------------------
FEBoundaryCondition* FEModel::BoundaryCondition(int i) { return m_imp->m_BC[i]; }
//-----------------------------------------------------------------------------
void FEModel::AddBoundaryCondition(FEBoundaryCondition* pbc) { m_imp->m_BC.push_back(pbc); }
//-----------------------------------------------------------------------------
void FEModel::ClearBoundaryConditions() { m_imp->m_BC.clear(); }
//-----------------------------------------------------------------------------
int FEModel::InitialConditions() { return (int)m_imp->m_IC.size(); }
//-----------------------------------------------------------------------------
FEInitialCondition* FEModel::InitialCondition(int i) { return m_imp->m_IC[i]; }
//-----------------------------------------------------------------------------
void FEModel::AddInitialCondition(FEInitialCondition* pbc) { m_imp->m_IC.push_back(pbc); }
//-----------------------------------------------------------------------------
//! retrieve the number of steps
int FEModel::Steps() const { return (int)m_imp->m_Step.size(); }
//-----------------------------------------------------------------------------
//! clear the steps
void FEModel::ClearSteps() { m_imp->m_Step.clear(); }
//-----------------------------------------------------------------------------
//! Add an analysis step
void FEModel::AddStep(FEAnalysis* pstep) { m_imp->m_Step.push_back(pstep); }
//-----------------------------------------------------------------------------
//! Get a particular step
FEAnalysis* FEModel::GetStep(int i) { return m_imp->m_Step[i]; }
//-----------------------------------------------------------------------------
//! Get the current step
FEAnalysis* FEModel::GetCurrentStep() { return m_imp->m_pStep; }
const FEAnalysis* FEModel::GetCurrentStep() const { return m_imp->m_pStep; }
//-----------------------------------------------------------------------------
//! Set the current step
void FEModel::SetCurrentStep(FEAnalysis* pstep) { m_imp->m_pStep = pstep; }
//-----------------------------------------------------------------------------
//! Set the current step index
int FEModel::GetCurrentStepIndex() const
{
return m_imp->m_nStep;
}
//-----------------------------------------------------------------------------
//! Set the current step index
void FEModel::SetCurrentStepIndex(int n)
{
m_imp->m_nStep = n;
}
//-----------------------------------------------------------------------------
//! return number of surface pair interactions
int FEModel::SurfacePairConstraints() { return (int)m_imp->m_CI.size(); }
//-----------------------------------------------------------------------------
//! retrive a surface pair interaction
FESurfacePairConstraint* FEModel::SurfacePairConstraint(int i) { return m_imp->m_CI[i]; }
//-----------------------------------------------------------------------------
//! Add a surface pair interaction
void FEModel::AddSurfacePairConstraint(FESurfacePairConstraint* pci) { m_imp->m_CI.push_back(pci); }
//-----------------------------------------------------------------------------
//! return number of nonlinear constraints
int FEModel::NonlinearConstraints() { return (int)m_imp->m_NLC.size(); }
//-----------------------------------------------------------------------------
//! retrieve a nonlinear constraint
FENLConstraint* FEModel::NonlinearConstraint(int i) { return m_imp->m_NLC[i]; }
//-----------------------------------------------------------------------------
//! add a nonlinear constraint
void FEModel::AddNonlinearConstraint(FENLConstraint* pnlc) { m_imp->m_NLC.push_back(pnlc); }
//-----------------------------------------------------------------------------
//! return the number of model loads
int FEModel::ModelLoads() { return (int)m_imp->m_ML.size(); }
//-----------------------------------------------------------------------------
//! retrieve a model load
FEModelLoad* FEModel::ModelLoad(int i) { return m_imp->m_ML[i]; }
//-----------------------------------------------------------------------------
//! Add a model load
void FEModel::AddModelLoad(FEModelLoad* pml) { m_imp->m_ML.push_back(pml); }
//-----------------------------------------------------------------------------
// get the FE mesh
FEMesh& FEModel::GetMesh() { return m_imp->m_mesh; }
//-----------------------------------------------------------------------------
FELinearConstraintManager& FEModel::GetLinearConstraintManager() { return *m_imp->m_LCM; }
//-----------------------------------------------------------------------------
bool FEModel::Init()
{
// make sure there is something to do
if (m_imp->m_Step.size() == 0) return false;
// intitialize time
FETimeInfo& tp = GetTime();
tp.currentTime = 0;
tp.timeIncrement = m_imp->m_Step[0]->m_dt0;
m_imp->m_ftime0 = 0;
// initialize global data
// TODO: I'd like to do this here for consistency, but
// the problem is that solute dofs (i.e. concentration dofs) have
// to be allocated before the materials are read in.
// So right now the Init function is called when the solute data is created.
/* for (int i=0; i<(int) m_GD.size(); ++i)
{
FEGlobalData* pd = m_GD[i]; assert(pd);
if (pd->Init() == false) return false;
}
*/
// Initialize all load controllers and evaluate at the initial time
if (InitLoadControllers() == false) return false;
// Initialize and evaluate all mesh data generators
if (InitMeshDataGenerators() == false) return false;
// initialize step data
if (InitSteps() == false) return false;
// validate BC's
if (InitBCs() == false) return false;
// initialize material data
// NOTE: This must be called after the rigid system is initialiazed since the rigid materials will
// reference the rigid bodies
if (InitMaterials() == false) return false;
// Validate the materials
if (ValidateMaterials() == false) return false;
// initialize mesh data
// NOTE: this must be done AFTER the elements have been assigned material point data !
// this is because the mesh data is reset
// TODO: perhaps I should not reset the mesh data during the initialization
if (InitMesh() == false) return false;
// initialize model loads
// NOTE: This must be called after the InitMaterials since the COM of the rigid bodies
// are set in that function.
if (InitModelLoads() == false) return false;
// initialize contact data
if (InitContact() == false) return false;
// initialize nonlinear constraints
if (InitConstraints() == false) return false;
// initialize mesh adaptors
if (InitMeshAdaptors() == false) return false;
// evaluate all load parameters
// Do this last in case any model components redefined their load curves.
if (EvaluateLoadParameters() == false) return false;
// activate all permanent dofs
Activate();
// check if all load curves are being used
int NLC = LoadControllers();
vector<int> tag(NLC, 0);
for (int i = 0; i < m_imp->m_Param.size(); ++i)
{
int lc = m_imp->m_Param[i].lc;
tag[lc]++;
}
for (int i = 0; i < m_imp->m_Step.size(); ++i)
{
FEAnalysis* step = m_imp->m_Step[i];
if (step->m_timeController)
{
int lc = step->m_timeController->m_nmplc;
if (lc >= 0) tag[lc]++;
}
}
int unused = 0;
for (int i = 0; i < NLC; ++i) if (tag[i] == 0) unused++;
if (unused != 0)
{
feLogWarning("Model has %d unreferenced load controllers.", unused);
}
bool ret = false;
try
{
ret = DoCallback(CB_INIT);
}
catch (std::exception c)
{
ret = false;
feLogError(c.what());
}
// do the callback
return ret;
}
//-----------------------------------------------------------------------------
//! initialization of load controllers
bool FEModel::InitLoadControllers()
{
for (int i = 0; i < LoadControllers(); ++i)
{
FELoadController* plc = m_imp->m_LC[i];
if (plc->Init() == false)
{
std::string s = plc->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Load controller %d (%s) failed to initialize", i + 1, sz);
return false;
}
plc->Evaluate(0);
}
return true;
}
//-----------------------------------------------------------------------------
//! initialize mesh data generators
bool FEModel::InitMeshDataGenerators()
{
for (int i = 0; i < MeshDataGenerators(); ++i)
{
FEMeshDataGenerator* pmd = m_imp->m_MD[i];
if (pmd->Init() == false)
{
std::string s = pmd->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Node data generator %d (%s) failed to initialize", i + 1, sz);
return false;
}
pmd->Evaluate(0);
}
return true;
}
//-----------------------------------------------------------------------------
//! initialize steps
bool FEModel::InitSteps()
{
for (int i = 0; i < (int)m_imp->m_Step.size(); ++i)
{
FEAnalysis& step = *m_imp->m_Step[i];
if (step.Init() == false)
{
std::string s = step.GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Step %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
bool FEModel::InitMeshAdaptors()
{
for (int i = 0; i < MeshAdaptors(); ++i)
{
FEMeshAdaptor* ma = MeshAdaptor(i);
if (ma->Init() == false)
{
std::string s = ma->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Mesh adaptor %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
// get the number of calls to Update()
int FEModel::UpdateCounter() const
{
return m_imp->m_nupdates;
}
//-----------------------------------------------------------------------------
void FEModel::IncrementUpdateCounter()
{
m_imp->m_nupdates++;
}
//-----------------------------------------------------------------------------
void FEModel::Update()
{
// update model counter
m_imp->m_nupdates++;
// update mesh
FEMesh& mesh = GetMesh();
const FETimeInfo& tp = GetTime();
try {
TRACK_TIME(TimerID::Timer_Update);
mesh.Update(tp);
}
catch (NegativeJacobianDetected e)
{
// for debug modes we do want to see inverted elements on the post side
DoCallback(CB_MODEL_UPDATE);
throw;
}
// update model components
{
TRACK_TIME(TimerID::Timer_Update);
// set the mesh update flag to false
// If any load sets this to true, the
// mesh will also be update after the loads are updated
m_imp->m_meshUpdate = false;
int nvel = BoundaryConditions();
for (int i = 0; i < nvel; ++i)
{
FEBoundaryCondition& bc = *BoundaryCondition(i);
if (bc.IsActive()) bc.UpdateModel();
}
// update all model loads
for (int i = 0; i < ModelLoads(); ++i)
{
FEModelLoad* pml = ModelLoad(i);
if (pml && pml->IsActive()) pml->Update();
}
// update all paired-interfaces
for (int i = 0; i < SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* psc = SurfacePairConstraint(i);
if (psc && psc->IsActive()) psc->Update();
}
// update all constraints
for (int i = 0; i < NonlinearConstraints(); ++i)
{
FENLConstraint* pc = NonlinearConstraint(i);
if (pc && pc->IsActive()) pc->Update();
}
// some of the loads may alter the prescribed dofs, so we update the mesh again
if (m_imp->m_meshUpdate)
{
mesh.Update(tp);
m_imp->m_meshUpdate = false;
}
}
// do the callback
DoCallback(CB_MODEL_UPDATE);
}
//-----------------------------------------------------------------------------
//! See if the BC's are setup correctly.
bool FEModel::InitBCs()
{
// check the IC's
int NIC = InitialConditions();
for (int i = 0; i<NIC; ++i)
{
FEInitialCondition* pic = InitialCondition(i);
if (pic->Init() == false)
{
std::string s = pic->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Initial condition %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
// check the BC's
int NBC = BoundaryConditions();
for (int i=0; i<NBC; ++i)
{
FEBoundaryCondition* pbc = BoundaryCondition(i);
if (pbc->Init() == false)
{
std::string s = pbc->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Boundary condition %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
// check the linear constraints
if (GetLinearConstraintManager().Initialize() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FEModel::AddMaterial(FEMaterial* pm)
{
m_imp->m_MAT.push_back(pm);
}
//-----------------------------------------------------------------------------
//! get the number of materials
int FEModel::Materials() { return (int)m_imp->m_MAT.size(); }
//-----------------------------------------------------------------------------
//! return a pointer to a material
FEMaterial* FEModel::GetMaterial(int i) { return m_imp->m_MAT[i]; }
//-----------------------------------------------------------------------------
FEMaterial* FEModel::FindMaterial(int nid)
{
for (int i = 0; i<Materials(); ++i)
{
FEMaterial* pm = GetMaterial(i);
if (pm->GetID() == nid) return pm;
}
return 0;
}
//-----------------------------------------------------------------------------
FEMaterial* FEModel::FindMaterial(const std::string& matName)
{
for (int i = 0; i<Materials(); ++i)
{
FEMaterial* mat = GetMaterial(i);
if (mat->GetName() == matName) return mat;
}
return 0;
}
//-----------------------------------------------------------------------------
//! Initialize material data (This also does an initial validation).
bool FEModel::InitMaterials()
{
// initialize material data
for (int i=0; i<Materials(); ++i)
{
// get the material
FEMaterial* pmat = GetMaterial(i);
// initialize material data
if (pmat->Init() == false)
{
feLogError("Failed initializing material %d (name=\"%s\")", i+1, pmat->GetName().c_str());
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! validate material data
bool FEModel::ValidateMaterials()
{
// initialize material data
for (int i=0; i<Materials(); ++i)
{
// get the material
FEMaterial* pmat = GetMaterial(i);
// initialize material data
if (pmat->Validate() == false)
{
feLogError("Failed validating material %d (name=\"%s\")", i+1, pmat->GetName().c_str());
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! Add a loadcurve to the model
void FEModel::AddLoadController(FELoadController* plc)
{
m_imp->m_LC.push_back(plc) ;
}
//-----------------------------------------------------------------------------
void FEModel::ReplaceLoadController(int n, FELoadController* plc)
{
assert((n >= 0) && (n < LoadControllers()));
delete m_imp->m_LC[n];
m_imp->m_LC[n] = plc;
}
//-----------------------------------------------------------------------------
//! get a loadcurve
FELoadController* FEModel::GetLoadController(int i)
{
return m_imp->m_LC[i];
}
//-----------------------------------------------------------------------------
//! get the number of loadcurves
int FEModel::LoadControllers() const
{
return (int)m_imp->m_LC.size();
}
//-----------------------------------------------------------------------------
//! Attach a load controller to a parameter
void FEModel::AttachLoadController(FEParam* param, int lc)
{
Implementation::LoadParam lp;
lp.param = param;
lp.lc = lc;
switch (param->type())
{
case FE_PARAM_DOUBLE: lp.m_scl = param->value<double>(); break;
case FE_PARAM_VEC3D : lp.m_vscl = param->value<vec3d >(); break;
}
m_imp->m_Param.push_back(lp);
}
//! return the number of load-controlled parameters
int FEModel::LoadParams() const
{
return (int)m_imp->m_Param.size();
}
//! return a load-controlled parameter
FEParam* FEModel::GetLoadParam(int n)
{
if ((n < 0) || (n >= LoadParams())) return nullptr;
return m_imp->m_Param[n].param;
}
//-----------------------------------------------------------------------------
void FEModel::AttachLoadController(FEParam* p, FELoadController* plc)
{
AttachLoadController(p, plc->GetID());
}
//-----------------------------------------------------------------------------
//! Detach a load controller from a parameter
bool FEModel::DetachLoadController(FEParam* p)
{
for (int i = 0; i < (int)m_imp->m_Param.size(); ++i)
{
Implementation::LoadParam& pi = m_imp->m_Param[i];
if (pi.param == p)
{
m_imp->m_Param.erase(m_imp->m_Param.begin() + i);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
//! Get a load controller for a parameter (returns null if the param is not under load control)
FELoadController* FEModel::GetLoadController(FEParam* p)
{
for (int i = 0; i < (int)m_imp->m_Param.size(); ++i)
{
Implementation::LoadParam& pi = m_imp->m_Param[i];
if (pi.param == p)
{
return (pi.lc >= 0 ? GetLoadController(pi.lc) : nullptr);
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! Add a mesh data generator to the model
void FEModel::AddMeshDataGenerator(FEMeshDataGenerator* pmd)
{
m_imp->m_MD.push_back(pmd);
}
//-----------------------------------------------------------------------------
FEMeshDataGenerator* FEModel::GetMeshDataGenerator(int i)
{
return m_imp->m_MD[i];
}
//-----------------------------------------------------------------------------
//! get the number of mesh data generators
int FEModel::MeshDataGenerators() const
{
return (int)m_imp->m_MD.size();
}
//-----------------------------------------------------------------------------
//! Initialize rigid force data
bool FEModel::InitModelLoads()
{
// call the Init() function of all rigid forces
for (int i=0; i<ModelLoads(); ++i)
{
FEModelLoad& FC = *ModelLoad(i);
if (FC.Init() == false)
{
std::string s = FC.GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Load %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! Does one-time initialization of the Mesh data. Call FEMesh::Reset for resetting
//! the mesh data.
bool FEModel::InitMesh()
{
FEMesh& mesh = GetMesh();
// find and remove isolated vertices
int ni = mesh.RemoveIsolatedVertices();
if (ni != 0)
{
if (ni == 1)
feLogWarning("%d isolated vertex removed.", ni);
else
feLogWarning("%d isolated vertices removed.", ni);
}
// Initialize shell data
// This has to be done before the domains are initialized below
if (!InitShells())
{
feLogError("Errors found during initialization of shells.");
return false;
}
// reset data
// TODO: Not sure why this is here
try {
mesh.Reset();
}
catch (NegativeJacobian e)
{
feLogError("Negative jacobian detected during mesh initialization.");
return false;
}
// initialize all domains
// Initialize shell domains first (in order to establish SSI)
// TODO: I'd like to move the initialization of the SSI to InitShells, but I can't
// do that because FESSIShellDomain::FindSSI depends on the FEDomain::m_Node array which is
// initialized in FEDomain::Init.
for (int i = 0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.Class() == FE_DOMAIN_SHELL)
if (dom.Init() == false) return false;
}
for (int i = 0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.Class() != FE_DOMAIN_SHELL)
if (dom.Init() == false) return false;
}
// initialize surfaces
for (int i = 0; i < mesh.Surfaces(); ++i)
{
if (mesh.Surface(i).Init() == false) return false;
}
// do some additional mesh validation
ValidateMesh();
// All done
return true;
}
void FEModel::ValidateMesh()
{
FEMesh& mesh = GetMesh();
for (int i = 0; i < mesh.NodeSets(); ++i)
{
FENodeSet* ns = mesh.NodeSet(i);
if (ns->Size() == 0)
{
std::string name = ns->GetName();
feLogWarning("The nodeset \"%s\" is empty!", name.c_str());
}
}
for (int i = 0; i < mesh.Surfaces(); ++i)
{
FESurface& surf = mesh.Surface(i);
if (surf.Elements() == 0)
{
std::string name = surf.GetName();
feLogWarning("The surface \"%s\" is empty!", name.c_str());
}
}
}
//-----------------------------------------------------------------------------
bool FEModel::InitShells()
{
FEMesh& mesh = GetMesh();
// calculate initial directors for shell nodes
int NN = mesh.Nodes();
vector<vec3d> D(NN, vec3d(0, 0, 0));
vector<int> ND(NN, 0);
// loop over all domains
for (int nd = 0; nd < mesh.Domains(); ++nd)
{
// Calculate the shell directors as the local node normals
if (mesh.Domain(nd).Class() == FE_DOMAIN_SHELL)
{
FEShellDomain& sd = static_cast<FEShellDomain&>(mesh.Domain(nd));
vec3d r0[FEElement::MAX_NODES];
for (int i = 0; i<sd.Elements(); ++i)
{
FEShellElement& el = sd.Element(i);
int n = el.Nodes();
int* en = &el.m_node[0];
// get the nodes
for (int j = 0; j<n; ++j) r0[j] = mesh.Node(en[j]).m_r0;
for (int j = 0; j<n; ++j)
{
int m0 = j;
int m1 = (j + 1) % n;
int m2 = (j == 0 ? n - 1 : j - 1);
vec3d a = r0[m0];
vec3d b = r0[m1];
vec3d c = r0[m2];
vec3d d = (b - a) ^ (c - a); d.unit();
D[en[m0]] += d*el.m_h0[j];
++ND[en[m0]];
}
}
}
}
// assign initial directors to shell nodes
// make sure we average the directors
for (int i = 0; i<NN; ++i)
if (ND[i] > 0) mesh.Node(i).m_d0 = D[i] / ND[i];
// do any other shell initialization
for (int nd = 0; nd<mesh.Domains(); ++nd)
{
FEDomain& dom = mesh.Domain(nd);
if (dom.Class() == FE_DOMAIN_SHELL)
{
FEShellDomain& shellDom = static_cast<FEShellDomain&>(dom);
if (!shellDom.InitShells()) return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! Initializes contact data
bool FEModel::InitContact()
{
// loop over all contact interfaces
for (int i=0; i<SurfacePairConstraints(); ++i)
{
// get the contact interface
FESurfacePairConstraint& ci = *SurfacePairConstraint(i);
// initializes contact interface data
if (ci.Init() == false)
{
std::string s = ci.GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Contact %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! Initialize the nonlinear constraints.
//! This function is called during model initialization (\sa FEModel::Init)
bool FEModel::InitConstraints()
{
for (int i=0; i<NonlinearConstraints(); ++i)
{
FENLConstraint* plc = NonlinearConstraint(i);
// initialize
if (plc->Init() == false)
{
std::string s = plc->GetName();
const char* sz = (s.empty() ? "<unnamed>" : s.c_str());
feLogError("Nonlinear constraint %d (%s) failed to initialize", i + 1, sz);
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! This function solves the FE problem by calling the solve method for each step.
bool FEModel::Solve()
{
// error flag
bool bok = true;
{
TRACK_TIME(Timer_ModelSolve);
// loop over all analysis steps
// Note that we don't necessarily from step 0.
// This is because the user could have restarted
// the analysis.
for (size_t nstep = m_imp->m_nStep; nstep < Steps(); ++nstep)
{
// set the current analysis step
m_imp->m_nStep = (int)nstep;
m_imp->m_pStep = m_imp->m_Step[(int)nstep];
// In the case we restarted, the current step can already be active
// so don't activate it again.
if (m_imp->m_pStep->IsActive() == false)
{
if (m_imp->m_pStep->Activate() == false)
{
bok = false;
break;
}
// do callback
DoCallback(CB_STEP_ACTIVE);
}
// solve the analaysis step
bok = m_imp->m_pStep->Solve();
// do callbacks
DoCallback(CB_STEP_SOLVED);
if (nstep + 1 == Steps())
{
// set the solved flag
m_imp->m_bsolved = bok;
}
// wrap it up
m_imp->m_pStep->Deactivate();
// break if the step has failed
if (bok == false) break;
}
// do the callbacks
DoCallback(CB_SOLVED);
}
return bok;
}
//-----------------------------------------------------------------------------
bool FEModel::RCI_Rewind()
{
return m_imp->PopState();
}
//-----------------------------------------------------------------------------
bool FEModel::RCI_ClearRewindStack()
{
if (m_imp->m_dmp.size() == 0) return false;
m_imp->m_dmp.clear();
return true;
}
//-----------------------------------------------------------------------------
bool FEModel::RCI_Init()
{
// start the timer
TRACK_TIME(Timer_ModelSolve);
// reset solver status flag
m_imp->m_bsolved = false;
// loop over all analysis steps
int nstep = m_imp->m_nStep;
m_imp->m_pStep = m_imp->m_Step[(int)nstep];
FEAnalysis* step = m_imp->m_pStep;
// intitialize step data
if (step->Activate() == false)
{
return false;
}
// do callback
DoCallback(CB_STEP_ACTIVE);
// initialize the step's solver
if (step->InitSolver() == false)
{
return false;
}
return true;
}
bool FEModel::RCI_Restart()
{
FEAnalysis* step = GetCurrentStep();
if (step == nullptr) return false;
return step->InitSolver();
}
bool FEModel::RCI_Advance()
{
// get the current step
FEAnalysis* step = m_imp->m_pStep;
if (step == nullptr) return false;
// first see if the step has finished
const double eps = step->m_tend * 1e-7;
double currentTime = GetCurrentTime();
if (step->m_tend - currentTime <= eps)
{
// TODO: not sure why this is needed.
SetStartTime(GetCurrentTime());
// wrap it up
DoCallback(CB_STEP_SOLVED);
step->Deactivate();
// go to the next step
int nstep = ++m_imp->m_nStep;
if (nstep >= m_imp->m_Step.size())
{
// we're done
m_imp->m_bsolved = true;
return true;
}
else
{
// go to the next step
step = m_imp->m_pStep = m_imp->m_Step[nstep];
if (step->Activate() == false) return false;
DoCallback(CB_STEP_ACTIVE);
if (step->InitSolver() == false) return false;
}
}
// store current state in case we need to rewind
m_imp->PushState();
// Inform that the time is about to change. (Plugins can use
// this callback to modify time step)
DoCallback(CB_UPDATE_TIME);
// update time
FETimeInfo& tp = GetTime();
double newTime = tp.currentTime + step->m_dt;
tp.currentTime = newTime;
tp.timeIncrement = step->m_dt;
feLog("\n===== beginning time step %d : %lg =====\n", step->m_ntimesteps + 1, newTime);
// initialize the solver step
// (This basically evaluates all the parameter lists, but let's the solver
// customize this process to the specific needs of the solver)
if (step->GetFESolver()->InitStep(newTime) == false) return false;
// Solve the time step
int ierr = step->SolveTimeStep();
if (ierr != 0) return false;
// update counters
FESolver* psolver = step->GetFESolver();
step->m_ntotref += psolver->m_ntotref;
step->m_ntotiter += psolver->m_niter;
step->m_ntotrhs += psolver->m_nrhs;
// Yes! We have converged!
feLog("\n------- converged at time : %lg\n\n", GetCurrentTime());
// update nr of completed timesteps
step->m_ntimesteps++;
// call callback function
if (DoCallback(CB_MAJOR_ITERS) == false)
{
feLogWarning("Early termination on user's request");
return false;
}
return true;
}
bool FEModel::RCI_Finish()
{
// stop the timer
GetTimer(Timer_ModelSolve)->stop();
// do the callbacks
DoCallback(CB_SOLVED);
return true;
}
//-----------------------------------------------------------------------------
// Model activation.
// BC's that are not assigned to a step will not have their Activate() member called
// so we do it here. This function is called in Init() and Reset()
void FEModel::Activate()
{
// initial conditions
// Must be activated before prescribed BC's
// since relative prescribed BC's use the initial values
for (int i=0; i<InitialConditions(); ++i)
{
FEInitialCondition& ic = *InitialCondition(i);
if (ic.IsActive()) ic.Activate();
}
// Boundary conditions
for (int i = 0; i<BoundaryConditions(); ++i)
{
FEBoundaryCondition& bc = *BoundaryCondition(i);
if (bc.IsActive()) bc.Activate();
}
// model loads
for (int i=0; i<ModelLoads(); ++i)
{
FEModelLoad& FC = *ModelLoad(i);
if (FC.IsActive()) FC.Activate();
}
// nonlinear constraints
for (int i=0; i<NonlinearConstraints(); ++i)
{
FENLConstraint* plc = NonlinearConstraint(i);
if (plc->IsActive()) plc->Activate();
}
// initialize material points before evaluating contact autopenalty
m_imp->m_mesh.InitMaterialPoints();
// contact interfaces
for (int i=0; i<SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint& ci = *SurfacePairConstraint(i);
if (ci.IsActive()) ci.Activate();
}
}
//-----------------------------------------------------------------------------
// TODO: temporary construction. Need to see if I can just use Activate().
// This is called after remeshed
void FEModel::Reactivate()
{
// reactivate BCs
for (int i = 0; i < BoundaryConditions(); ++i)
{
FEBoundaryCondition& bc = *BoundaryCondition(i);
if (bc.IsActive()) bc.Activate();
}
// reactivate model loads
for (int i = 0; i < ModelLoads(); ++i)
{
FEModelLoad& ml = *ModelLoad(i);
if (ml.IsActive()) ml.Activate();
}
// update surface interactions
for (int i = 0; i < SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint& ci = *SurfacePairConstraint(i);
if (ci.IsActive()) ci.Activate();
}
// reactivate the linear constraints
GetLinearConstraintManager().Activate();
}
//-----------------------------------------------------------------------------
//! \todo Do I really need this function. I think calling FEModel::Init achieves the
//! same effect.
bool FEModel::Reset()
{
// reset all timers
ResetAllTimers();
// reset solved flag
m_imp->m_bsolved = false;
// initialize materials
for (int i=0; i<Materials(); ++i)
{
FEMaterial* pmat = GetMaterial(i);
pmat->Init();
}
// reset mesh data
m_imp->m_mesh.Reset();
// set up rigid joints
if (m_imp->m_NLC.size() > 0)
{
int NC = (int)m_imp->m_NLC.size();
for (int i=0; i<NC; ++i)
{
FENLConstraint* plc = m_imp->m_NLC[i];
plc->Reset();
}
}
// set the start time
m_imp->m_timeInfo.currentTime = 0;
m_imp->m_timeInfo.timeIncrement = 0;
m_imp->m_ftime0 = 0;
// set first time step
m_imp->m_pStep = m_imp->m_Step[0];
m_imp->m_nStep = 0;
for (int i=0; i<Steps(); ++i) GetStep(i)->Reset();
// reset contact data
// TODO: I just call Init which I think is okay
InitContact();
// Call Activate() to activate all permanent BC's
Activate();
// Reevaluate load parameters
for (int i = 0; i < LoadControllers(); ++i)
{
FELoadController& lc = *GetLoadController(i);
lc.Reset();
}
EvaluateLoadParameters();
DoCallback(CB_RESET);
return true;
}
//-----------------------------------------------------------------------------
//! Get the current time information.
FETimeInfo& FEModel::GetTime()
{
return m_imp->m_timeInfo;
}
//-----------------------------------------------------------------------------
double FEModel::GetStartTime() const { return m_imp->m_ftime0; }
//-----------------------------------------------------------------------------
void FEModel::SetStartTime(double t) { m_imp->m_ftime0 = t; }
//-----------------------------------------------------------------------------
double FEModel::GetCurrentTime() const { return m_imp->m_timeInfo.currentTime; }
//-----------------------------------------------------------------------------
void FEModel::SetCurrentTime(double t) { m_imp->m_timeInfo.currentTime = t; }
//-----------------------------------------------------------------------------
void FEModel::SetCurrentTimeStep(double dt)
{
FEAnalysis* step = GetCurrentStep(); assert(step);
if (step) step->m_dt = dt;
}
//=============================================================================
// P A R A M E T E R F U N C T I O N S
//=============================================================================
//-----------------------------------------------------------------------------
FEParam* FEModel::FindParameter(const ParamString& s)
{
// make sure it starts with the name of this model
if (s != GetName()) return 0;
return FECoreBase::FindParameter(s.next());
}
//-----------------------------------------------------------------------------
FEParamValue GetComponent(FEParamValue& p, const ParamString& c)
{
switch (p.type())
{
case FE_PARAM_MAT3DS:
if (c == "xx") return p.component(0);
if (c == "xy") return p.component(1);
if (c == "yy") return p.component(2);
if (c == "xz") return p.component(3);
if (c == "yz") return p.component(4);
if (c == "zz") return p.component(5);
break;
}
return FEParamValue();
}
//-----------------------------------------------------------------------------
FEParamValue GetComponent(vec3d& r, const ParamString& c)
{
if (c == "x") return FEParamValue(0, &r.x, FE_PARAM_DOUBLE);
if (c == "y") return FEParamValue(0, &r.y, FE_PARAM_DOUBLE);
if (c == "z") return FEParamValue(0, &r.z, FE_PARAM_DOUBLE);
return FEParamValue();
}
//! return the parameter string for a parameter
std::string FEModel::GetParamString(FEParam* p)
{
if (p == nullptr) return string();
FECoreBase* pc = dynamic_cast<FECoreBase*>(p->parent());
if (pc == nullptr) return string();
string paramName = p->name();
while (pc->GetParent())
{
FECoreBase* parent = pc->GetParent();
FEProperty* prop = parent->FindProperty(pc);
if (prop == nullptr) return string();
if (prop->IsArray())
{
int n = -1;
for (int i = 0; i < prop->size(); ++i)
if (prop->get(i) == pc)
{
n = i;
break;
}
if (n == -1) return string();
stringstream ss;
ss << prop->GetName() << "[" << n << "].";
paramName = ss.str() + paramName;
}
else
{
paramName = string(prop->GetName()) + "." + paramName;
}
pc = parent;
}
if (paramName.empty()) return string();
std::pair<int, int> item = m_imp->FindComponent(pc);
int typeId = item.first;
int index = item.second;
if ((typeId == -1) || (index == -1)) return string();
string typeStr;
switch (typeId)
{
case FEMATERIAL_ID : typeStr = "material"; break;
case FEBC_ID : typeStr = "bc"; break;
case FELOAD_ID : typeStr = "load"; break;
case FEIC_ID : typeStr = "initial"; break;
case FESURFACEINTERFACE_ID : typeStr = "contact"; break;
case FENLCONSTRAINT_ID : typeStr = "constraint"; break;
case FEMESHADAPTOR_ID : typeStr = "mesh_adaptor"; break;
case FELOADCONTROLLER_ID : typeStr = "load_controller"; break;
case FEMESHDATAGENERATOR_ID: typeStr = "mesh_data"; break;
case FEANALYSIS_ID : typeStr = "step"; break;
default:
return string();
}
stringstream ss;
ss << "fem." << typeStr << "[" << index << "]." << paramName;
string s = ss.str();
return s;
}
//-----------------------------------------------------------------------------
// helper function for evaluating mesh data
FEParamValue FEModel::GetMeshParameter(const ParamString& paramString)
{
FEMesh& mesh = GetMesh();
ParamString next = paramString.next();
if (next == "node")
{
FENode* node = 0;
int nid = next.Index();
if (nid < 0)
{
ParamString fnc = next.next();
if (fnc == "fromId")
{
nid = fnc.Index();
node = mesh.FindNodeFromID(nid);
next = next.next();
}
}
else if ((nid >= 0) && (nid < mesh.Nodes()))
{
node = &mesh.Node(nid);
}
if (node)
{
ParamString paramString = next.next();
if (paramString == "position" ) return GetComponent(node->m_rt, paramString.next());
// TODO: the m_Fr is not a vec3d any more, so not sure what to do here.
// In any case, this should probably be handled by the FEMechModel
// else if (paramString == "reaction_force") return GetComponent(node->m_Fr, paramString.next());
else
{
// see if it corresponds to a solution variable
int n = GetDOFIndex(paramString.c_str());
if ((n >= 0) && (n < node->dofs()))
{
return FEParamValue(0, &node->get(n), FE_PARAM_DOUBLE);
}
}
}
}
else if (next == "elem")
{
FEElement* elem = 0;
int nid = next.Index();
if (nid < 0)
{
ParamString fnc = next.next();
if (fnc == "fromId")
{
nid = fnc.Index();
elem = mesh.FindElementFromID(nid);
next = next.next();
}
}
else if ((nid >= 0) && (nid < mesh.Elements()))
{
elem = mesh.Element(nid);
}
if (elem)
{
ParamString paramString = next.next();
FEDomain* dom = dynamic_cast<FEDomain*>(elem->GetMeshPartition());
if (dom == nullptr) return FEParamValue();
if (paramString == "var")
{
std::string varName = paramString.IDString();
FEMaterial* mat = dom->GetMaterial();
if (mat)
{
FEDomainParameter* var = mat->FindDomainParameter(varName);
if (var)
{
FEParamValue v = var->value(*elem->GetMaterialPoint(0));
if (v.isValid())
{
ParamString comp = paramString.next();
return GetComponent(v, comp);
}
}
}
}
}
}
else if (next == "domain")
{
int nid = next.Index();
if ((nid >= 0) && (nid < mesh.Domains()))
{
FEDomain& dom = mesh.Domain(nid);
ParamString paramName = next.next();
FEParam* param = dom.FindParameter(paramName);
if (param)
{
if (param->type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& v = param->value<FEParamDouble>();
if (v.isConst()) return FEParamValue(param, &v.constValue(), FE_PARAM_DOUBLE);
}
return FEParamValue(param, param->data_ptr(), param->type());
}
}
}
// if we get here, we did not find it
return FEParamValue();
}
//-----------------------------------------------------------------------------
//! Return a pointer to the named variable
//! This function returns a pointer to a named variable.
FEParamValue FEModel::GetParameterValue(const ParamString& paramString)
{
// make sure it starts with the name of this model
if (paramString != GetName()) return FEParamValue();
ParamString next = paramString.next();
FEParamValue val = FECoreBase::GetParameterValue(next);
if (!val.isValid())
{
if (next == "mesh") return GetMeshParameter(next);
}
return val;
}
FEDataValue FEModel::GetDataValue(const ParamString& s)
{
FEDataValue val;
if (s != GetName()) return val;
ParamString data = s.next();
if (data == "node_data")
{
string params = data.IDString();
FELogNodeData* pd = fecore_new<FELogNodeData>(params.c_str(), this);
if (pd == nullptr) { feLogError("Invalid data variable %s", params.c_str()); return val; }
m_imp->m_logData.push_back(pd);
val.SetLogData(pd);
}
else if (data == "elem_data")
{
string params = data.IDString();
FELogElemData* pd = fecore_new<FELogElemData>(params.c_str(), this);
if (pd == nullptr) { feLogError("Invalid data variable %s", params.c_str()); return val; }
m_imp->m_logData.push_back(pd);
val.SetLogData(pd);
}
return val;
}
//-----------------------------------------------------------------------------
FECoreBase* FEModel::FindComponent(const ParamString& prop)
{
// make sure it starts with the name of this model
if (prop != GetName()) return 0;
// see what the next reference is
ParamString next = prop.next();
// next, find the property
FECoreBase* pc = GetProperty(next);
return pc;
}
//-----------------------------------------------------------------------------
//! Evaluates all load curves at the specified time
void FEModel::EvaluateLoadControllers(double time)
{
const int NLC = LoadControllers();
for (int i=0; i<NLC; ++i) GetLoadController(i)->Evaluate(time);
}
//-----------------------------------------------------------------------------
//! Evaluates all load curves at the specified time
void FEModel::EvaluateDataGenerators(double time)
{
for (int i = 0; i < MeshDataGenerators(); ++i) GetMeshDataGenerator(i)->Evaluate(time);
}
//-----------------------------------------------------------------------------
//! Set the print parameters flag
void FEModel::SetPrintParametersFlag(bool b)
{
m_imp->m_printParams = b;
}
//-----------------------------------------------------------------------------
//! Get the print parameter flag
bool FEModel::GetPrintParametersFlag() const
{
return m_imp->m_printParams;
}
//-----------------------------------------------------------------------------
bool FEModel::EvaluateLoadParameters()
{
feLog("\n");
int NLC = LoadControllers();
for (int i = 0; i<(int)m_imp->m_Param.size(); ++i)
{
Implementation::LoadParam& pi = m_imp->m_Param[i];
int nlc = pi.lc;
if ((nlc >= 0) && (nlc < NLC))
{
double s = GetLoadController(nlc)->Value();
FEParam* p = pi.param;
FECoreBase* parent = dynamic_cast<FECoreBase*>(p->parent());
if (m_imp->m_printParams)
{
if (parent && (parent->GetName().empty() == false))
{
const char* pname = parent->GetName().c_str();
feLog("Setting parameter \"%s.%s\" to : ", pname, p->name());
}
else
feLog("Setting parameter \"%s\" to : ", p->name());
};
assert(p->IsVolatile());
switch (p->type())
{
case FE_PARAM_INT: {
p->value<int>() = (int)s;
if (m_imp->m_printParams) feLog("%d\n", p->value<int>());
}
break;
case FE_PARAM_DOUBLE: {
p->value<double>() = pi.m_scl*s;
if (m_imp->m_printParams) feLog("%lg\n", p->value<double>());
}
break;
case FE_PARAM_BOOL: {
p->value<bool>() = (s > 0 ? true : false);
if (m_imp->m_printParams) feLog("%s\n", (p->value<bool>() ? "true" : "false"));
}
break;
case FE_PARAM_VEC3D: {
vec3d& v = p->value<vec3d>();
p->value<vec3d>() = pi.m_vscl*s;
if (m_imp->m_printParams) feLog("%lg, %lg, %lg\n", v.x, v.y, v.z);
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble& v = p->value<FEParamDouble>();
double c = 1.0;
if (v.isConst()) c = v.constValue();
v.SetScaleFactor(s * pi.m_scl);
if (m_imp->m_printParams) feLog("%lg\n", c*p->value<FEParamDouble>().GetScaleFactor());
}
break;
case FE_PARAM_VEC3D_MAPPED :
{
FEParamVec3& v = p->value<FEParamVec3>();
v.SetScaleFactor(s * pi.m_scl);
if (m_imp->m_printParams) feLog("%lg\n", v.GetScaleFactor());
}
break;
default:
feLog("\n");
assert(false);
}
}
else
{
feLogError("Invalid load curve ID");
return false;
}
}
feLog("\n");
return true;
}
//-----------------------------------------------------------------------------
DOFS& FEModel::GetDOFS()
{
return m_imp->m_dofs;
}
//-----------------------------------------------------------------------------
int FEModel::GetDOFIndex(const char* sz) const
{
int n = m_imp->m_dofs.GetDOF(sz);
if (n < 0)
{
// NOTE: This is a hack so that concentration variables can
// also be referenced by the solute name
n = FindGlobalDataIndex(sz);
}
return n;
}
//-----------------------------------------------------------------------------
int FEModel::GetDOFIndex(const char* szvar, int n) const
{
return m_imp->m_dofs.GetDOF(szvar, n);
}
std::string CallbackId2String(unsigned int nevent)
{
switch (nevent)
{
case CB_INIT : return "CB_INIT" ; break;
case CB_STEP_ACTIVE : return "CB_STEP_ACTIVE" ; break;
case CB_MAJOR_ITERS : return "CB_MAJOR_ITERS" ; break;
case CB_MINOR_ITERS : return "CB_MINOR_ITERS" ; break;
case CB_SOLVED : return "CB_SOLVED" ; break;
case CB_UPDATE_TIME : return "CB_UPDATE_TIME" ; break;
case CB_AUGMENT : return "CB_AUGMENT" ; break;
case CB_STEP_SOLVED : return "CB_STEP_SOLVED" ; break;
case CB_MATRIX_REFORM : return "CB_MATRIX_REFORM" ; break;
case CB_REMESH : return "CB_REMESH" ; break;
case CB_PRE_MATRIX_SOLVE: return "CB_PRE_MATRIX_SOLVE"; break;
case CB_RESET : return "CB_RESET" ; break;
case CB_MODEL_UPDATE : return "CB_MODEL_UPDATE" ; break;
case CB_TIMESTEP_SOLVED : return "CB_TIMESTEP_SOLVED" ; break;
case CB_SERIALIZE_SAVE : return "CB_SERIALIZE_SAVE" ; break;
case CB_SERIALIZE_LOAD : return "CB_SERIALIZE_LOAD" ; break;
case CB_TIMESTEP_FAILED : return "CB_TIMESTEP_FAILED" ; break;
case CB_QUASIN_CONVERGED: return "CB_QUASIN_CONVERGED"; break;
case CB_USER1 : return "CB_USER1" ; break;
default:
return "<unknown>";
}
}
//-----------------------------------------------------------------------------
// Call the callback function if there is one defined
//
bool FEModel::DoCallback(unsigned int nevent)
{
TRACK_TIME(TimerID::Timer_Callback);
if (m_imp->m_log_verbose)
{
string name = GetName();
string cbname = CallbackId2String(nevent);
feLog("[%s.%s]===>\n", name.c_str(), cbname.c_str());
}
try
{
// do the callbacks
bool bret = CallbackHandler::DoCallback(this, nevent);
if (m_imp->m_log_verbose)
{
string name = GetName();
string cbname = CallbackId2String(nevent);
feLog("<===[%s.%s]\n", name.c_str(), cbname.c_str());
}
return bret;
}
catch (ForceConversion)
{
throw;
}
catch (IterationFailure)
{
throw;
}
catch (DoRunningRestart)
{
throw;
}
catch (std::exception e)
{
throw;
}
catch (...)
{
return false;
}
return true;
}
//-----------------------------------------------------------------------------
void FEModel::Log(int ntag, const char* msg)
{
}
//-----------------------------------------------------------------------------
void FEModel::Logf(int ntag, const char* msg, ...)
{
if (m_imp->m_block_log) return;
// get a pointer to the argument list
va_list args;
// make the message
char sztxt[2048] = { 0 };
va_start(args, msg);
vsnprintf(sztxt, sizeof(sztxt), msg, args);
va_end(args);
Log(ntag, sztxt);
}
//-----------------------------------------------------------------------------
void FEModel::BlockLog()
{
m_imp->m_block_log = true;
}
//-----------------------------------------------------------------------------
void FEModel::UnBlockLog()
{
m_imp->m_block_log = false;
}
//-----------------------------------------------------------------------------
bool FEModel::LogBlocked() const
{
return m_imp->m_block_log;
}
//-----------------------------------------------------------------------------
void FEModel::SetGlobalConstant(const string& s, double v)
{
m_imp->m_Const[s] = v;
return;
}
//-----------------------------------------------------------------------------
double FEModel::GetGlobalConstant(const string& s)
{
return (m_imp->m_Const.count(s) ? m_imp->m_Const.find(s)->second : 0);
}
//-----------------------------------------------------------------------------
int FEModel::GlobalVariables() const
{
return (int)m_imp->m_Var.size();
}
//-----------------------------------------------------------------------------
void FEModel::AddGlobalVariable(const string& s, double v)
{
FEGlobalVariable* var = new FEGlobalVariable;
var->v = v;
var->name = s;
AddParameter(var->v, var->name.c_str());
m_imp->m_Var.push_back(var);
}
const FEGlobalVariable& FEModel::GetGlobalVariable(int n)
{
return *m_imp->m_Var[n];
}
//-----------------------------------------------------------------------------
void FEModel::AddGlobalData(FEGlobalData* psd)
{
m_imp->m_GD.push_back(psd);
}
//-----------------------------------------------------------------------------
FEGlobalData* FEModel::GetGlobalData(int i)
{
return m_imp->m_GD[i];
}
//-----------------------------------------------------------------------------
FEGlobalData* FEModel::FindGlobalData(const char* szname)
{
for (int i = 0; i < m_imp->m_GD.size(); ++i)
{
if (m_imp->m_GD[i]->GetName() == szname) return m_imp->m_GD[i];
}
return nullptr;
}
//-----------------------------------------------------------------------------
int FEModel::FindGlobalDataIndex(const char* szname) const
{
for (int i = 0; i < m_imp->m_GD.size(); ++i)
{
if (m_imp->m_GD[i]->GetName() == szname) return i;
}
return -1;
}
//-----------------------------------------------------------------------------
int FEModel::GlobalDataItems()
{
return (int)m_imp->m_GD.size();
}
//-----------------------------------------------------------------------------
FECoreBase* CopyFEBioClass(FECoreBase* pc, FEModel* fem)
{
if ((pc == nullptr) || (fem == nullptr))
{
assert(false);
return nullptr;
}
const char* sztype = pc->GetTypeStr();
// create a new material
FECoreBase* pcnew = fecore_new<FECoreBase>(pc->GetSuperClassID(), sztype, fem);
assert(pcnew);
pcnew->SetID(pc->GetID());
// copy parameters
pcnew->GetParameterList() = pc->GetParameterList();
// copy properties
for (int i = 0; i < pc->PropertyClasses(); ++i)
{
FEProperty* prop = pc->PropertyClass(i);
if (prop->size() > 0)
{
for (int j = 0; j < prop->size(); ++j)
{
FECoreBase* pci = prop->get(j);
if (pc)
{
FECoreBase* pci_new = CopyFEBioClass(pci, fem); assert(pci_new);
bool b = pcnew->SetProperty(i, pci_new); assert(b);
}
}
}
}
return pcnew;
}
//-----------------------------------------------------------------------------
//! This function copies the model data from the fem object. Note that it only copies
//! the model definition, i.e. mesh, bc's, contact interfaces, etc..
void FEModel::CopyFrom(FEModel& fem)
{
// clear the current model data
Clear();
// copy the active module
SetActiveModule(fem.GetModuleName());
// --- Parameters ---
// copy parameters (not sure if I need/want to copy all of these)
m_imp->m_nStep = fem.m_imp->m_nStep;
m_imp->m_timeInfo = fem.m_imp->m_timeInfo;
m_imp->m_ftime0 = fem.m_imp->m_ftime0;
m_imp->m_pStep = 0;
// copy model variables
// we only copy the user created parameters, which presumably don't exist yet
// in this model.
int NS = fem.GlobalVariables();
if (NS > 0)
{
assert(GlobalVariables() == 0);
FEParameterList& PL = GetParameterList();
for (int i = 0; i < NS; ++i)
{
const FEGlobalVariable& var = fem.GetGlobalVariable(i);
AddGlobalVariable(var.name, var.v);
}
}
// --- Steps ---
// copy the steps
// NOTE: This does not copy the boundary conditions of the steps
int NSTEP = fem.Steps();
for (int i=0; i<NSTEP; ++i)
{
// get the type string
FEAnalysis* ps = fem.GetStep(i);
// create a new step
FEAnalysis* pnew = new FEAnalysis(this);
// copy additional info
pnew->CopyFrom(ps);
// copy the solver
FESolver* psolver = ps->GetFESolver();
const char* sztype = psolver->GetTypeStr();
// create a new solver
FESolver* pnew_solver = fecore_new<FESolver>(sztype, this);
assert(pnew_solver);
pnew->SetFESolver(pnew_solver);
// copy parameters
pnew_solver->GetParameterList() = psolver->GetParameterList();
// add the step
AddStep(pnew);
}
// --- Materials ---
// copy material data
int NMAT = fem.Materials();
for (int i=0; i<NMAT; ++i)
{
// get the type info from the old material
FEMaterial* pmat = fem.GetMaterial(i);
// copy the material
FEMaterial* pnew = dynamic_cast<FEMaterial*>(CopyFEBioClass(pmat, this));
assert(pnew);
// copy the name
pnew->SetName(pmat->GetName());
// add the material
AddMaterial(pnew);
}
assert(m_imp->m_MAT.size() == fem.m_imp->m_MAT.size());
// --- Mesh ---
// copy the mesh data
// NOTE: This will not assign materials to the new domains
// A. copy nodes
FEMesh& sourceMesh = fem.GetMesh();
FEMesh& mesh = GetMesh();
int N = sourceMesh.Nodes();
mesh.CreateNodes(N);
for (int i=0; i<N; ++i)
{
mesh.Node(i) = sourceMesh.Node(i);
}
// B. domains
// let's first create a table of material indices for the old domains
int NDOM = sourceMesh.Domains();
vector<int> LUT(NDOM);
for (int i=0; i<NDOM; ++i)
{
FEMaterial* pm = sourceMesh.Domain(i).GetMaterial();
for (int j=0; j<NMAT; ++j)
{
if (pm == fem.GetMaterial(j))
{
LUT[i] = j;
break;
}
}
}
// now allocate domains
for (int i=0; i<NDOM; ++i)
{
FEDomain& dom = sourceMesh.Domain(i);
const char* sz = dom.GetTypeStr();
// create a new domain
FEDomain* pd = nullptr;
switch (dom.Class())
{
case FE_DOMAIN_SOLID : pd = fecore_new<FESolidDomain >(sz, this); break;
case FE_DOMAIN_SHELL : pd = fecore_new<FEShellDomain >(sz, this); break;
case FE_DOMAIN_BEAM : pd = fecore_new<FEBeamDomain >(sz, this); break;
case FE_DOMAIN_2D : pd = fecore_new<FEDomain2D >(sz, this); break;
case FE_DOMAIN_DISCRETE: pd = fecore_new<FEDiscreteDomain>(sz, this); break;
}
assert(pd);
pd->SetMaterial(GetMaterial(LUT[i]));
// copy domain data
pd->CopyFrom(&dom);
// add it to the mesh
mesh.AddDomain(pd);
}
// --- boundary conditions ---
int NDC = fem.BoundaryConditions();
for (int i=0; i<NDC; ++i)
{
FEBoundaryCondition* pbc = fem.BoundaryCondition(i);
const char* sz = pbc->GetTypeStr();
FEBoundaryCondition* pnew = fecore_new<FEBoundaryCondition>(sz, this);
assert(pnew);
pnew->CopyFrom(pbc);
// add to model
AddBoundaryCondition(pnew);
}
// --- contact interfaces ---
int NCI = fem.SurfacePairConstraints();
for (int i=0; i<NCI; ++i)
{
// get the next interaction
FESurfacePairConstraint* pci = fem.SurfacePairConstraint(i);
const char* sztype = pci->GetTypeStr();
// create a new contact interface
FESurfacePairConstraint* pnew = fecore_new<FESurfacePairConstraint>(sztype, this);
assert(pnew);
// create a copy
pnew->CopyFrom(pci);
// add the new interface
AddSurfacePairConstraint(pnew);
// add the surfaces to the surface list
mesh.AddSurface(pnew->GetSecondarySurface());
mesh.AddSurface(pnew->GetPrimarySurface ());
}
// --- nonlinear constraints ---
int NLC = fem.NonlinearConstraints();
for (int i=0; i<NLC; ++i)
{
// get the next constraint
FENLConstraint* plc = fem.NonlinearConstraint(i);
const char* sztype = plc->GetTypeStr();
// create a new nonlinear constraint
FENLConstraint* plc_new = fecore_new<FENLConstraint>(sztype, this);
assert(plc_new);
// create a copy
plc_new->CopyFrom(plc);
// add the nonlinear constraint
AddNonlinearConstraint(plc_new);
// add the surface to the mesh (if any)
FESurfaceConstraint* psc = dynamic_cast<FESurfaceConstraint*>(plc_new);
if (psc)
{
FESurface* ps = psc->GetSurface();
if (ps) mesh.AddSurface(ps);
}
}
// --- Load curves ---
// copy load curves
int NLD = fem.LoadControllers();
for (int i = 0; i<NLD; ++i)
{
FELoadController* lc = fem.GetLoadController(i);
FELoadController* newlc = fecore_new<FELoadController>(lc->GetTypeStr(), this); assert(newlc);
AddLoadController(newlc);
}
// copy linear constraints
if (fem.m_imp->m_LCM)
{
if (m_imp->m_LCM) delete m_imp->m_LCM;
m_imp->m_LCM = new FELinearConstraintManager(this);
m_imp->m_LCM->CopyFrom(*fem.m_imp->m_LCM);
}
// copy output data
m_imp->m_plotData = fem.m_imp->m_plotData;
// TODO: copy all the properties
// assert(false);
}
//-----------------------------------------------------------------------------
// This function serializes data to a stream.
// This is used for running and cold restarts.
void FEModel::Implementation::Serialize(DumpStream& ar)
{
if (ar.IsShallow())
{
// stream model data
ar & m_timeInfo;
// stream mesh
ar & m_mesh;
// stream domains
m_fem->SerializeGeometry(ar);
// serialize contact
ar & m_CI;
// serialize nonlinear constraints
ar & m_NLC;
// serialize step and solver data
ar & m_Step;
}
else
{
if (ar.IsLoading()) m_fem->Clear();
ar & m_moduleName;
if (ar.IsLoading())
{
FECoreKernel::GetInstance().SetActiveModule(m_moduleName.c_str());
}
ar & m_timeInfo;
ar & m_dofs;
ar & m_Const;
ar & m_GD;
ar & m_ftime0;
ar & m_bsolved;
// serialize the mesh first
ar & m_mesh;
// we have to stream materials before we serialize the domains
ar & m_MAT;
// stream geometry (domains)
m_fem->SerializeGeometry(ar);
// stream all boundary conditions
ar & m_BC;
ar & m_ML;
ar & m_IC;
ar & m_CI;
ar & m_NLC;
// stream step data next
ar & m_nStep;
ar & m_Step;
ar & m_pStep; // This must be streamed after m_Step
// serialize linear constraints
if (m_LCM) m_LCM->Serialize(ar);
// serialize data generators
ar & m_MD;
// load controllers and load parameters are streamed last
// since they can depend on other model parameters.
ar & m_LC;
ar & m_Param;
// if the model was solved, then start at the next step
if (ar.IsLoading())
{
if (m_bsolved)
{
m_bsolved = false;
m_nStep++;
}
}
}
}
//-----------------------------------------------------------------------------
//! This is called to serialize geometry.
//! Derived classes can override this
void FEModel::SerializeGeometry(DumpStream& ar)
{
m_imp->m_mesh.SerializeDomains(ar);
}
//-----------------------------------------------------------------------------
// This function serializes data to a stream.
// This is used for running and cold restarts.
void FEModel::Serialize(DumpStream& ar)
{
TRACK_TIME(TimerID::Timer_Serialize);
m_imp->Serialize(ar);
DoCallback(ar.IsSaving() ? CB_SERIALIZE_SAVE : CB_SERIALIZE_LOAD);
}
//-----------------------------------------------------------------------------
void FEModel::BuildMatrixProfile(FEGlobalMatrix& G, bool breset)
{
FEAnalysis* pstep = GetCurrentStep();
FESolver* solver = pstep->GetFESolver();
solver->BuildMatrixProfile(G, breset);
}
//-----------------------------------------------------------------------------
bool FEModel::GetNodeData(int ndof, vector<double>& data)
{
// get the dofs
DOFS& dofs = GetDOFS();
// make sure the dof index is valid
if ((ndof < 0) || (ndof >= dofs.GetTotalDOFS())) return false;
// get the mesh and number of nodes
FEMesh& mesh = GetMesh();
int N = mesh.Nodes();
// make sure data is correct size
data.resize(N, 0.0);
// loop over all nodes
for (int i=0; i<N; ++i)
{
FENode& node = mesh.Node(i);
data[i] = node.get(ndof);
}
return true;
}
void FEModel::CollectTimings(bool b)
{
m_imp->m_dotiming = b;
}
bool FEModel::CollectTimings() const
{
return m_imp->m_dotiming;
}
//-----------------------------------------------------------------------------
// reset all the timers
void FEModel::ResetAllTimers()
{
for (size_t i = 0; i<m_imp->m_timers.size(); ++i)
{
Timer& ti = m_imp->m_timers[i];
ti.reset();
}
}
//-----------------------------------------------------------------------------
int FEModel::Timers()
{
return (int)m_imp->m_timers.size();
}
//-----------------------------------------------------------------------------
Timer* FEModel::GetTimer(int i)
{
return &(m_imp->m_timers[i]);
}
//-----------------------------------------------------------------------------
//! return number of mesh adaptors
int FEModel::MeshAdaptors()
{
return (int)m_imp->m_MA.size();
}
//-----------------------------------------------------------------------------
//! retrieve a mesh adaptors
FEMeshAdaptor* FEModel::MeshAdaptor(int i)
{
return m_imp->m_MA[i];
}
//-----------------------------------------------------------------------------
//! add a mesh adaptor
void FEModel::AddMeshAdaptor(FEMeshAdaptor* meshAdaptor)
{
m_imp->m_MA.push_back(meshAdaptor);
}
//-----------------------------------------------------------------------------
void FEModel::SetUnits(const char* szunits)
{
if (szunits)
m_imp->m_units = szunits;
else
m_imp->m_units.clear();
}
//-----------------------------------------------------------------------------
const char* FEModel::GetUnits() const
{
if (m_imp->m_units.empty()) return nullptr;
else return m_imp->m_units.c_str();
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDataMap.h | .h | 2,502 | 68 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDataArray.h"
class FEMaterialPoint;
class FEItemList;
//-----------------------------------------------------------------------------
// Base class for all data maps. A data map needs to be able to evaluate data across a domain
// TODO: This is a work in progress.
// This class was added to create a base for FESurfaceMap and FEDomainMap so that both could be used in
// FEMappedValue.
class FECORE_API FEDataMap : public FEDataArray
{
public:
FEDataMap(FEDataMapType mapType, FEDataType dataType = FE_INVALID_TYPE);
FEDataMap(const FEDataMap& map);
//! set the name
void SetName(const std::string& name);
//! get the name
const std::string& GetName() const;
public:
// This function needs to be overridden by derived classes
virtual double value(const FEMaterialPoint& mp) = 0;
virtual vec3d valueVec3d(const FEMaterialPoint& mp) = 0;
virtual mat3d valueMat3d(const FEMaterialPoint& mp) = 0;
virtual mat3ds valueMat3ds(const FEMaterialPoint& mp) = 0;
// return the item list associated with this map
virtual FEItemList* GetItemList() = 0;
public:
void Serialize(DumpStream& ar) override;
protected:
std::string m_name; // name of data map TODO: Move to base class?
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBodyLoad.h | .h | 2,276 | 72 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEModelLoad.h"
#include "FEDomain.h"
#include "FEDomainList.h"
#include "FESurface.h"
//-----------------------------------------------------------------------------
// forward declaration of FEModel class
class FEModel;
class FELinearSystem;
//-----------------------------------------------------------------------------
//! Base class for body-loads
class FECORE_API FEBodyLoad : public FEModelLoad
{
FECORE_BASE_CLASS(FEBodyLoad)
public:
FEBodyLoad(FEModel* pfem);
virtual ~FEBodyLoad();
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
public:
//! return number of domains this load is applied to
int Domains() const;
//! return a domain
FEDomain* Domain(int i);
//! add a domain to which to apply this load
void SetDomainList(FEElementSet* elset);
//! get the domain list
FEDomainList& GetDomainList();
private:
FEDomainList m_dom; //!< list of domains to which to apply the body load
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFullNewtonStrategy.cpp | .cpp | 2,353 | 63 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFullNewtonStrategy.h"
#include "FESolver.h"
#include "FEException.h"
#include "FENewtonSolver.h"
//-----------------------------------------------------------------------------
FEFullNewtonStrategy::FEFullNewtonStrategy(FEModel* fem) : FENewtonStrategy(fem)
{
m_plinsolve = nullptr;
m_maxups = 0;
}
//-----------------------------------------------------------------------------
bool FEFullNewtonStrategy::Init()
{
if (m_pns == nullptr) return false;
m_plinsolve = m_pns->GetLinearSolver();
return true;
}
//-----------------------------------------------------------------------------
bool FEFullNewtonStrategy::Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1)
{
// always return false to force a matrix reformation
return false;
}
//-----------------------------------------------------------------------------
void FEFullNewtonStrategy::SolveEquations(vector<double>& x, vector<double>& b)
{
// perform a backsubstitution
if (m_plinsolve->BackSolve(x, b) == false)
{
throw LinearSolverFailed();
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/fecore_debug.h | .h | 3,809 | 129 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// Load debugger template constructions.
// Don't use anything in this file directly.
// Instead use the functions and macros defined below
#include "fecore_debug_t.h"
//-----------------------------------------------------------------------------
// Set a break point. This will bring up the debugger prompt.
// (type help for a list of available debugger commands)
#define fecore_break() { \
static FECoreBreakPoint _br_##__LINE__; \
if (_br_##__LINE__.IsActive()) { \
cout << "breakpoint " << _br_##__LINE__.GetID() << " : " << __FILE__ << "(line " << __LINE__ << ")\n"; \
_br_##__LINE__.Break(); }}
//-----------------------------------------------------------------------------
// Add a variable to the watch list.
// A variable on the watch list can be inspected from the debugger
// (type print var on the debugger prompt, where var is the variable name)
#define fecore_watch(a) FECoreWatchVariable _##a(create_watch_variable(&a, #a));
//-----------------------------------------------------------------------------
// print the contents of a variable to the screen
#define fecore_print(a) { \
cout << #a << endl << typeid(a).name() << endl; \
fecore_print_T(&a); \
cout << endl; }
//-----------------------------------------------------------------------------
class FECORE_API FECoreDebugStream
{
public:
enum STREAM_MODE
{
WRITING_MODE,
READING_MODE
};
public:
FECoreDebugStream();
FECoreDebugStream(const char* szfilename, STREAM_MODE mode);
~FECoreDebugStream();
bool Open(const char* szfilename, STREAM_MODE mode);
bool is_writing() const { return m_mode == STREAM_MODE::WRITING_MODE; }
bool is_reading() const { return m_mode == STREAM_MODE::READING_MODE; }
bool ReopenForReading();
template <typename T> bool check(T& v)
{
if (is_writing())
{
write(&v, sizeof(T), 1);
return true;
}
else
{
T tmp;
read(&tmp, sizeof(T), 1);
assert(tmp == v);
return (tmp == v);
}
}
template <typename T> bool check(std::vector<T>& v)
{
size_t n = v.size();
if (is_writing())
{
write(v.data(), sizeof(T), n);
return true;
}
else
{
std::vector<T> tmp(n);
read(tmp.data(), sizeof(T), n);
for (size_t i = 0; i < n; ++i)
{
assert(tmp[i] == v[i]);
if (tmp[i] != v[i]) return false;
}
return true;
}
}
private:
size_t write(const void* pd, size_t size, size_t count);
size_t read(void* pd, size_t size, size_t count);
private:
STREAM_MODE m_mode;
FILE* m_fp;
std::string m_filename;
int m_counter;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBoundaryCondition.cpp | .cpp | 2,396 | 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.*/
#include "stdafx.h"
#include "FEBoundaryCondition.h"
#include "FEFacetSet.h"
//-----------------------------------------------------------------------------
FEBoundaryCondition::FEBoundaryCondition(FEModel* pfem) : FEStepComponent(pfem), m_dof(pfem)
{
}
//-----------------------------------------------------------------------------
FEBoundaryCondition::~FEBoundaryCondition()
{
}
//-----------------------------------------------------------------------------
//! fill the prescribed values
void FEBoundaryCondition::PrepStep(std::vector<double>& u, bool brel)
{
}
void FEBoundaryCondition::Serialize(DumpStream& ar)
{
FEStepComponent::Serialize(ar);
if (ar.IsShallow() == false) ar & m_dof;
}
//-----------------------------------------------------------------------------
void FEBoundaryCondition::SetDOFList(int ndof)
{
m_dof.Clear();
m_dof.AddDof(ndof);
}
//-----------------------------------------------------------------------------
void FEBoundaryCondition::SetDOFList(const std::vector<int>& dofs)
{
m_dof = dofs;
}
void FEBoundaryCondition::SetDOFList(const FEDofList& dofs)
{
m_dof = dofs;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENodeSet.h | .h | 2,336 | 74 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEItemList.h"
#include "FENodeList.h"
#include <vector>
#include <string>
//-----------------------------------------------------------------------------
// Forward declarations
class FEMesh;
class FENode;
class DumpStream;
//-----------------------------------------------------------------------------
//! Defines a node set of the model
//
class FECORE_API FENodeSet : public FEItemList
{
public:
FENodeSet(FEModel* fem);
void Add(int n);
void Add(const std::vector<int>& ns);
void Add(const FENodeList& nodeList);
void Clear();
int Size() const { return m_Node.Size(); }
int operator [] (int i) const { return m_Node[i]; }
FENodeList GetNodeList() { return m_Node; }
const FENodeList& GetNodeList() const { return m_Node; }
FENode* Node(int i);
const FENode* Node(int i) const;
public:
void Serialize(DumpStream& ar);
static void SaveClass(DumpStream& ar, FENodeSet* p);
static FENodeSet* LoadClass(DumpStream& ar, FENodeSet* p);
protected:
FENodeList m_Node; //!< list of nodes
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEEdgeList.cpp | .cpp | 12,269 | 494 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEEdgeList.h"
#include "FEMesh.h"
#include "FENodeNodeList.h"
#include "FEDomain.h"
#include "FEElementList.h"
#include <set>
using namespace std;
FEEdgeList::FEEdgeList() : m_mesh(nullptr)
{
}
int FEEdgeList::Edges() const
{
return (int) m_edgeList.size();
}
const FEEdgeList::EDGE& FEEdgeList::operator[] (int i)
{
return m_edgeList[i];
}
const FEEdgeList::EDGE& FEEdgeList::Edge(int i) const
{
return m_edgeList[i];
}
FEMesh* FEEdgeList::GetMesh()
{
return m_mesh;
}
struct edge_less
{
bool operator ()(const pair<int, int>& lhs, const pair<int, int>& rhs) const
{
int na0 = lhs.first;
int na1 = lhs.second;
if (na0 > na1) { int tmp = na0; na0 = na1; na1 = tmp; }
int nb0 = rhs.first;
int nb1 = rhs.second;
if (nb0 > nb1) { int tmp = nb0; nb0 = nb1; nb1 = tmp; }
if (na0 != nb0) return na0 < nb0;
else return na1 < nb1;
}
};
struct EDGE_less
{
bool operator ()(const FEEdgeList::EDGE& lhs, const FEEdgeList::EDGE& rhs) const
{
int na0 = lhs.node[0];
int na1 = lhs.node[1];
if (na0 > na1) { int tmp = na0; na0 = na1; na1 = tmp; }
int nb0 = rhs.node[0];
int nb1 = rhs.node[1];
if (nb0 > nb1) { int tmp = nb0; nb0 = nb1; nb1 = tmp; }
if (na0 != nb0) return na0 < nb0;
else return na1 < nb1;
}
};
bool FEEdgeList::Create(FEMesh* pmesh)
{
if (pmesh == nullptr) return false;
m_mesh = pmesh;
FEMesh& mesh = *pmesh;
// create the node-node list
FEElementList elemList(mesh);
set<pair<int, int>, edge_less> edgeSet;
const int ETET[ 6][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 0, 3 },{ 1, 3 },{ 2, 3 } };
const int EHEX[12][2] = { { 0, 1 },{ 1, 2 },{ 2, 3 },{ 3, 0 },{ 4, 5 },{ 5, 6 },{ 6, 7 },{ 7, 4 },{ 0, 4 },{ 1, 5 },{ 2, 6 },{ 3, 7 } };
const int EPEN[ 9][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 3, 4 },{ 4, 5 },{ 5, 3 },{ 0, 3 },{ 1, 4 },{ 2, 5 } };
for (FEElementList::iterator it = elemList.begin(); it != elemList.end(); ++it)
{
FEElement& el = *it;
if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5))
{
for (int i = 0; i < 6; ++i)
{
pair<int, int> edge;
edge.first = el.m_node[ETET[i][0]];
edge.second = el.m_node[ETET[i][1]];
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_HEX8)
{
for (int i = 0; i < 12; ++i)
{
pair<int, int> edge;
edge.first = el.m_node[EHEX[i][0]];
edge.second = el.m_node[EHEX[i][1]];
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_PENTA6)
{
for (int i = 0; i < 9; ++i)
{
pair<int, int> edge;
edge.first = el.m_node[EPEN[i][0]];
edge.second = el.m_node[EPEN[i][1]];
edgeSet.insert(edge);
}
}
}
// copy set into a vector
size_t edges = edgeSet.size();
m_edgeList.resize(edges);
set< pair<int, int>, edge_less>::iterator edgeIter = edgeSet.begin();
for (size_t i = 0; i < edges; ++i, ++edgeIter)
{
const pair<int, int>& edge = *edgeIter;
EDGE& Edge = m_edgeList[i];
Edge.ntype = 2;
int n0 = edge.first;
int n1 = edge.second;
if (n0 > n1) { int tmp = n0; n0 = n1; n1 = tmp; }
Edge.node[0] = n0;
Edge.node[1] = n1;
}
return true;
}
bool FEEdgeList::Create(FEDomain* dom)
{
if (dom == nullptr) return false;
m_mesh = dom->GetMesh();
FEMesh& mesh = *m_mesh;
set<EDGE, EDGE_less> edgeSet;
const int ETET[6][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 0, 3 },{ 1, 3 },{ 2, 3 } };
const int ETET10[6][3] = { { 0, 1, 4 },{ 1, 2, 5 },{ 2, 0, 6 },{ 0, 3, 7 },{ 1, 3, 8 },{ 2, 3, 9 } };
const int EHEX[12][2] = { { 0, 1 },{ 1, 2 },{ 2, 3 },{ 3, 0 },{ 4, 5 },{ 5, 6 },{ 6, 7 },{ 7, 4 },{ 0, 4 },{ 1, 5 },{ 2, 6 },{ 3, 7 } };
const int EHEX20[12][3] = { { 0, 1, 8 },{ 1, 2, 9 },{ 2, 3, 10 },{ 3, 0, 11 },{ 4, 5, 12 },{ 5, 6, 13 },{ 6, 7, 14 },{ 7, 4, 15 },{ 0, 4, 16 },{ 1, 5, 17 },{ 2, 6, 18 },{ 3, 7, 19 } };
const int EPEN[9][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 3, 4 },{ 4, 5 },{ 5, 3 },{ 0, 3 },{ 1, 4 },{ 2, 5 } };
for (int i = 0; i<dom->Elements(); ++i)
{
FEElement& el = dom->ElementRef(i);
if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5))
{
for (int i = 0; i < 6; ++i)
{
EDGE edge;
edge.ntype = 2;
edge.node[0] = el.m_lnode[ETET[i][0]];
edge.node[1] = el.m_lnode[ETET[i][1]];
edge.node[2] = -1;
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_PENTA6)
{
for (int i = 0; i < 9; ++i)
{
EDGE edge;
edge.ntype = 2;
edge.node[0] = el.m_lnode[EPEN[i][0]];
edge.node[1] = el.m_lnode[EPEN[i][1]];
edge.node[2] = -1;
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_HEX8)
{
for (int i = 0; i < 12; ++i)
{
EDGE edge;
edge.ntype = 2;
edge.node[0] = el.m_lnode[EHEX[i][0]];
edge.node[1] = el.m_lnode[EHEX[i][1]];
edge.node[2] = -1;
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_HEX20)
{
for (int i = 0; i < 12; ++i)
{
EDGE edge;
edge.ntype = 3;
edge.node[0] = el.m_lnode[EHEX20[i][0]];
edge.node[1] = el.m_lnode[EHEX20[i][1]];
edge.node[2] = el.m_lnode[EHEX20[i][2]];
edgeSet.insert(edge);
}
}
else if (el.Shape() == ET_TET10)
{
for (int i = 0; i < 6; ++i)
{
EDGE edge;
edge.ntype = 3;
edge.node[0] = el.m_lnode[ETET10[i][0]];
edge.node[1] = el.m_lnode[ETET10[i][1]];
edge.node[2] = el.m_lnode[ETET10[i][2]];
edgeSet.insert(edge);
}
}
}
// copy set into a vector
size_t edges = edgeSet.size();
m_edgeList.resize(edges);
set< EDGE, EDGE_less>::iterator edgeIter = edgeSet.begin();
for (size_t i = 0; i < edges; ++i, ++edgeIter)
{
m_edgeList[i] = *edgeIter;
}
return true;
}
int FEEdgeList::FindEdge(int a, int b)
{
for (int i = 0; i < (int)m_edgeList.size(); ++i)
{
EDGE& edge = m_edgeList[i];
if ((edge.node[0] == a) && (edge.node[1] == b)) return i;
if ((edge.node[0] == b) && (edge.node[1] == a)) return i;
}
return -1;
}
//=============================================================================
FEElementEdgeList::FEElementEdgeList()
{
}
int FEElementEdgeList::Edges(int elem) const
{
return (int)m_EEL[elem].size();
}
const std::vector<int>& FEElementEdgeList::EdgeList(int elem) const
{
return m_EEL[elem];
}
// NOTE: This only works for TET4 and HEX8 elements!
bool FEElementEdgeList::Create(FEElementList& elemList, FEEdgeList& edgeList)
{
FEMesh& mesh = *edgeList.GetMesh();
const int ETET[6][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 0, 3 },{ 1, 3 },{ 2, 3 } };
const int EHEX[12][2] = { { 0, 1 },{ 1, 2 },{ 2, 3 },{ 3, 0 },{ 4, 5 },{ 5, 6 },{ 6, 7 },{ 7, 4 },{ 0, 4 },{ 1, 5 },{ 2, 6 },{ 3, 7 } };
const int EPENTA[9][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 3, 4 },{ 4, 5 },{ 5, 3 },{ 0, 3 },{ 1, 4 },{ 2, 5 } };
int NN = mesh.Nodes();
vector<pair<int, int> > NI;
NI.resize(NN);
for (int i = 0; i<NN; ++i) NI[i].second = 0;
for (int i = edgeList.Edges() - 1; i >= 0; --i)
{
const FEEdgeList::EDGE& et = edgeList.Edge(i);
NI[et.node[0]].first = i;
NI[et.node[0]].second++;
}
int NE = mesh.Elements();
m_EEL.resize(NE);
int i = 0;
for (FEElementList::iterator it = elemList.begin(); it != elemList.end(); ++it, ++i)
{
const FEElement& el = *it;
vector<int>& EELi = m_EEL[i];
if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5))
{
EELi.resize(6);
for (int j = 0; j<6; ++j)
{
int n0 = el.m_node[ETET[j][0]];
int n1 = el.m_node[ETET[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l<ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_HEX8)
{
EELi.resize(12);
for (int j = 0; j<12; ++j)
{
int n0 = el.m_node[EHEX[j][0]];
int n1 = el.m_node[EHEX[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l<ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_PENTA6)
{
EELi.resize(9);
for (int j = 0; j < 9; ++j)
{
int n0 = el.m_node[EPENTA[j][0]];
int n1 = el.m_node[EPENTA[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l < ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
}
return true;
}
// NOTE: This only works for TET4 and HEX8 elements!
bool FEElementEdgeList::Create(FEDomain& domain, FEEdgeList& edgeList)
{
FEMesh& mesh = *edgeList.GetMesh();
const int ETET[6][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 0, 3 },{ 1, 3 },{ 2, 3 } };
const int EHEX[12][2] = { { 0, 1 },{ 1, 2 },{ 2, 3 },{ 3, 0 },{ 4, 5 },{ 5, 6 },{ 6, 7 },{ 7, 4 },{ 0, 4 },{ 1, 5 },{ 2, 6 },{ 3, 7 } };
const int EPEN[9][2] = { { 0, 1 },{ 1, 2 },{ 2, 0 },{ 3, 4 },{ 4, 5 },{ 5, 3 },{ 0, 3 },{ 1, 4 },{ 2, 5 } };
int NN = mesh.Nodes();
vector<pair<int, int> > NI;
NI.resize(NN);
for (int i = 0; i < NN; ++i) NI[i].second = 0;
for (int i = edgeList.Edges() - 1; i >= 0; --i)
{
const FEEdgeList::EDGE& et = edgeList.Edge(i);
NI[et.node[0]].first = i;
NI[et.node[0]].second++;
}
int NE = domain.Elements();
m_EEL.resize(NE);
for (int i=0; i < NE; ++i)
{
const FEElement& el = domain.ElementRef(i);
vector<int>& EELi = m_EEL[i];
if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5))
{
EELi.resize(6);
for (int j = 0; j < 6; ++j)
{
int n0 = el.m_node[ETET[j][0]];
int n1 = el.m_node[ETET[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l < ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_HEX8)
{
EELi.resize(12);
for (int j = 0; j < 12; ++j)
{
int n0 = el.m_node[EHEX[j][0]];
int n1 = el.m_node[EHEX[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l < ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_PENTA6)
{
EELi.resize(9);
for (int j = 0; j < 9; ++j)
{
int n0 = el.m_node[EPEN[j][0]];
int n1 = el.m_node[EPEN[j][1]];
if (n1 < n0) { int nt = n1; n1 = n0; n0 = nt; }
int l0 = NI[n0].first;
int ln = NI[n0].second;
for (int l = 0; l < ln; ++l)
{
assert(edgeList[l0 + l].node[0] == n0);
if (edgeList[l0 + l].node[1] == n1)
{
EELi[j] = l0 + l;
break;
}
}
}
}
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEPlotData.cpp | .cpp | 4,084 | 140 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEPlotData.h"
//-----------------------------------------------------------------------------
FEPlotData::FEPlotData(FEModel* fem) : FECoreBase(fem)
{
m_ntype = PLT_FLOAT;
m_sfmt = FMT_NODE;
m_nregion = FE_REGION_NODE;
m_arraySize = 0;
m_szdom[0] = 0;
m_szunit = nullptr;
}
//-----------------------------------------------------------------------------
FEPlotData::FEPlotData(FEModel* fem, Region_Type R, Var_Type t, Storage_Fmt s) : FECoreBase(fem)
{
m_ntype = t;
m_sfmt = s;
m_nregion = R;
m_arraySize = 0;
m_szdom[0] = 0;
m_szunit = nullptr;
}
//-----------------------------------------------------------------------------
void FEPlotData::SetArraySize(int n)
{
m_arraySize = n;
}
//-----------------------------------------------------------------------------
int FEPlotData::GetArraysize() const
{
return m_arraySize;
}
//-----------------------------------------------------------------------------
int FEPlotData::VarSize(Var_Type t)
{
int ndata = 0;
switch (DataType())
{
case PLT_FLOAT : ndata = 1; break;
case PLT_VEC3F : ndata = 3; break;
case PLT_MAT3FS : ndata = 6; break;
case PLT_MAT3FD : ndata = 3; break;
case PLT_TENS4FS: ndata = 21; break;
case PLT_MAT3F : ndata = 9; break;
case PLT_ARRAY : ndata = GetArraysize(); break;
case PLT_ARRAY_VEC3F: ndata = GetArraysize()*3; break;
}
assert(ndata);
return ndata;
}
//-----------------------------------------------------------------------------
void FEPlotData::SetDomainName(const char* szdom)
{
strcpy(m_szdom, szdom);
}
FEPlotFieldDescriptor::FEPlotFieldDescriptor(const std::string& typeString)
{
m_valid = false;
m_filterType = NO_FILTER;
numFilter = -1;
fieldName = typeString;
// see if there is an alias defined
size_t equalSign = fieldName.find('=');
if (equalSign != string::npos)
{
alias = fieldName.substr(equalSign + 1, string::npos);
fieldName.erase(equalSign, string::npos);
}
else alias = fieldName;
// see if there is a filter
size_t leftBracket = fieldName.find('[');
if (leftBracket != string::npos)
{
// find the right bracket
size_t rightBracket = fieldName.rfind(']');
if (rightBracket == string::npos) return;
string filter = fieldName.substr(leftBracket + 1, rightBracket - leftBracket - 1);
fieldName.erase(leftBracket, string::npos);
// see if the filter is a number or a string
size_t leftQuote = filter.find('\'');
if (leftQuote != string::npos)
{
size_t rightQuote = filter.rfind('\'');
if ((rightQuote == string::npos) || (rightQuote == leftQuote)) return;
m_filterType = STRING_FILTER;
strFilter = filter.substr(leftQuote + 1, rightQuote - leftQuote - 1);
}
else
{
m_filterType = NUMBER_FILTER;
numFilter = atoi(filter.c_str());
}
}
m_valid = true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEBeamDomain.cpp | .cpp | 1,499 | 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 "FEBeamDomain.h"
#include "FEMesh.h"
//-----------------------------------------------------------------------------
FEBeamDomain::FEBeamDomain(FEModel* fem) : FEDomain(FE_DOMAIN_BEAM, fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/vec3d.h | .h | 7,764 | 219 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "vec2d.h"
//! 3D vector class with double precision components
class vec3d
{
public:
//! Default constructor - initializes vector to (0, 0, 0)
vec3d() : x(0), y(0), z(0) {}
//! Constructor with single value - initializes all components to the same value
explicit vec3d(double a) : x(a), y(a), z(a) {}
//! Constructor with three components
vec3d(double X, double Y, double Z) : x(X), y(Y), z(Z) {}
//! Constructor from 2D vector - sets z component to 0
vec3d(const vec2d& v) { x = v.r[0]; y = v.r[1]; z = 0.0; }
//! Vector addition operator
vec3d operator + (const vec3d& r) const { return vec3d(x+r.x, y+r.y, z+r.z); }
//! Vector subtraction operator
vec3d operator - (const vec3d& r) const { return vec3d(x-r.x, y-r.y, z-r.z); }
//! Scalar multiplication operator
vec3d operator * (double a) const { return vec3d(x*a, y*a, z*a); }
//! Scalar division operator
vec3d operator / (double a) const { return vec3d(x/a, y/a, z/a); }
//! Vector addition assignment operator
vec3d& operator += (const vec3d& r) { x += r.x; y += r.y; z += r.z; return (*this); }
//! Vector subtraction assignment operator
vec3d& operator -= (const vec3d& r) { x -= r.x; y -= r.y; z -= r.z; return (*this); }
//! Scalar multiplication assignment operator
vec3d& operator *= (double a) { x*=a; y*=a; z*=a; return (*this); }
//! Scalar division assignment operator
vec3d& operator /= (double a) { x/=a; y/=a; z/=a; return (*this); }
//! Unary negation operator
vec3d operator - () const { return vec3d(-x, -y, -z); }
//! Component access operator (non-const)
double& operator() (int i)
{
switch(i)
{
case 0: {return x; break;}
case 1: {return y; break;}
case 2: {return z; break;}
default: {return x; break;}
}
}
//! Component access operator (const)
double operator() (int i) const
{
switch(i)
{
case 0: {return x; break;}
case 1: {return y; break;}
case 2: {return z; break;}
default: {return x; break;}
}
}
//! Dot product operator
double operator * (const vec3d& r) const { return (x*r.x + y*r.y + z*r.z); }
//! Cross product operator
vec3d operator ^ (const vec3d& r) const { return vec3d(y*r.z-z*r.y,z*r.x-x*r.z,x*r.y-y*r.x); }
//! Normalize the vector in place and return original length
double unit()
{
double d = sqrt(x*x+y*y+z*z);
if (d != 0) { x/=d; y/=d; z/=d; }
return d;
}
//! Return a normalized copy of this vector
vec3d normalized() const {
double d = sqrt(x*x + y*y + z*z);
d = (d == 0.0? d = 1.0 : d = 1.0/d);
return vec3d(x*d, y*d, z*d);
}
//! Return the length (magnitude) of the vector
double norm() const { return sqrt(x*x+y*y+z*z); }
//! Return the squared length of the vector
double norm2() const { return (x*x + y*y + z*z); }
public:
//! Normalize the vector in place (FEBio Studio compatibility)
vec3d Normalize() { unit(); return *this; }
//! Return a normalized copy of this vector (FEBio Studio compatibility)
vec3d Normalized() const { vec3d v(x, y, z); v.unit(); return v; }
//! Return the length of the vector (FEBio Studio compatibility)
double Length() const { return norm(); }
//! Return the squared length of the vector (FEBio Studio compatibility)
double SqrLength() const { return norm2(); }
//! Equality comparison operator
bool operator == (const vec3d& a) const { return ((a.x == x) && (a.y == y) && (a.z == z)); }
public:
//! X component of the vector
double x, y, z;
};
//-----------------------------------------------------------------------------
//! 3D vector class with single precision (float) components
class vec3f
{
public:
//! Default constructor - initializes vector to (0, 0, 0)
vec3f() { x = y = z = 0; }
//! Constructor with three float components
vec3f(float rx, float ry, float rz) { x = rx; y = ry; z = rz; }
//! Vector addition operator
vec3f operator + (const vec3f& v) const { return vec3f(x + v.x, y + v.y, z + v.z); }
//! Vector subtraction operator
vec3f operator - (const vec3f& v) const { return vec3f(x - v.x, y - v.y, z - v.z); }
//! Cross product operator
vec3f operator ^ (const vec3f& v) const
{
return vec3f(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
}
//! Dot product operator
float operator * (const vec3f& v) const { return (x * v.x + y * v.y + z * v.z); }
//! Scalar multiplication operator
vec3f operator * (const float g) const { return vec3f(x * g, y * g, z * g); }
//! Scalar division operator
vec3f operator / (const float g) const { return vec3f(x / g, y / g, z / g); }
//! Vector addition assignment operator
const vec3f& operator += (const vec3f& v) { x += v.x; y += v.y; z += v.z; return (*this); }
//! Vector subtraction assignment operator
const vec3f& operator -= (const vec3f& v) { x -= v.x; y -= v.y; z -= v.z; return (*this); }
//! Float division assignment operator
const vec3f& operator /= (const float& f) { x /= f; y /= f; z /= f; return (*this); }
//! Integer division assignment operator
const vec3f& operator /= (const int& n) { x /= n; y /= n; z /= n; return (*this); }
//! Float multiplication assignment operator
const vec3f& operator *= (const float& f) { x *= f; y *= f; z *= f; return (*this); }
//! Unary negation operator
vec3f operator - () { return vec3f(-x, -y, -z); }
//! Return the length (magnitude) of the vector
float Length() const { return (float)sqrt(x * x + y * y + z * z); }
//! Return the squared length of the vector
float SqrLength() const { return (float)(x * x + y * y + z * z); }
//! Normalize the vector in place
vec3f& Normalize()
{
float L = Length();
if (L != 0) { x /= L; y /= L; z /= L; }
return (*this);
}
public:
//! X component of the vector
float x, y, z;
};
//! Convert vec3f to vec3d
inline vec3d to_vec3d(const vec3f& r) { return vec3d((double)r.x, (double)r.y, (double)r.z); }
//! Convert vec3d to vec3f
inline vec3f to_vec3f(const vec3d& r) { return vec3f((float)r.x, (float)r.y, (float)r.z); }
//-----------------------------------------------------------------------------
//! 3D vector class with integer components
class vec3i
{
public:
//! Default constructor - initializes vector to (0, 0, 0)
vec3i() { x = y = z = 0; }
//! Constructor with three integer components
vec3i(int X, int Y, int Z) { x = X; y = Y; z = Z;}
public:
//! X component of the vector
int x, y, z;
}; | Unknown |
3D | febiosoftware/FEBio | FECore/FENLConstraint.h | .h | 3,249 | 91 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FESolver.h"
#include "FEStepComponent.h"
#include "FEGlobalVector.h"
#include "FEGlobalMatrix.h"
#include "FETimeInfo.h"
#include <vector>
//-----------------------------------------------------------------------------
// forward declaration of the model class
class FEModel;
class FELinearSystem;
//-----------------------------------------------------------------------------
//! Base class for nonlinear constraints enforced using an augmented Lagrangian method.
//! The constraint must provide a residual (force) contribution, its stiffness matrix,
//! and an augmentation function.
//!
class FECORE_API FENLConstraint : public FEStepComponent
{
FECORE_SUPER_CLASS(FENLCONSTRAINT_ID)
FECORE_BASE_CLASS(FENLConstraint);
public:
FENLConstraint(FEModel* pfem);
virtual ~FENLConstraint();
// clone the constraint
virtual void CopyFrom(FENLConstraint* plc) {}
// initialize equations
// Overridden by constraint classes that need to allocate more equations,
// e.g. for Lagrange Multipliers.
virtual int InitEquations(int neq) { return 0; }
public:
// The LoadVector function evaluates the "forces" that contribute to the residual of the system
virtual void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) = 0;
// Evaluates the contriubtion to the stiffness matrix
virtual void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) = 0;
// Performs an augmentation step
virtual bool Augment(int naug, const FETimeInfo& tp) { return true; }
// Build the matrix profile
virtual void BuildMatrixProfile(FEGlobalMatrix& M) = 0;
// reset the state data
virtual void Reset() {}
// called at start of time step
virtual void PrepStep() {}
// update
using FEModelComponent::Update;
// update for Lagrange Multiplier implementations
virtual void Update(const std::vector<double>& Ui, const std::vector<double>& ui) {}
virtual void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) {}
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEParamValidator.h | .h | 6,613 | 166 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class FEParam;
class DumpStream;
//-----------------------------------------------------------------------------
//! Range for parameters
//! Used only by parameters of type FE_PARAM_INT and FE_PARAM_DOUBLE
enum FEParamRange {
FE_DONT_CARE, // parameter can take on any value
FE_GREATER, // parameter must be greater than val (> val)
FE_GREATER_OR_EQUAL, // parameter must be greater or equal than val ( >= val)
FE_LESS, // parameter must be less than val ( < val)
FE_LESS_OR_EQUAL, // parameter must be less or equal than val ( <= val)
FE_OPEN, // parameter must be inside the open interval (min,max)
FE_CLOSED, // parameter must be inside the closed interval [min, max]
FE_LEFT_OPEN, // parameter must be inside the half-open interval (min, max]
FE_RIGHT_OPEN, // parameter must be inside the right-open interval [min, max)
FE_NOT_EQUAL, // parameter must not equal val ( != val)
};
//-----------------------------------------------------------------------------
// helper class for defining ranges
struct RANGE
{
public:
FEParamRange m_rt;
double m_fmin;
double m_fmax;
public:
RANGE(FEParamRange rt) { m_rt = rt; m_fmin = m_fmax = 0.0; }
RANGE(FEParamRange rt, double fval) { m_rt = rt; m_fmin = fval; m_fmax = 0.0; }
RANGE(FEParamRange rt, double fmin, double fmax) { m_rt = rt; m_fmin = fmin; m_fmax = fmax; }
};
//-----------------------------------------------------------------------------
//! Abstract base class for parameter validators.
class FECORE_API FEParamValidator
{
public:
FEParamValidator(){}
virtual ~FEParamValidator(){}
//! Function that is used to see if a parameter is valid
virtual bool is_valid(const FEParam& p) const = 0;
//! Creates a copy of the validator
virtual FEParamValidator* copy() const = 0;
//! Serialize validator data
virtual void Serialize(DumpStream& ar) = 0;
};
//-----------------------------------------------------------------------------
//! Base class for parameter validators that uses CRTP for implementing a copy method.
//! Deriving validators from this class automatically adds the copy method which simplifies
//! the implementation of new validators. It does assume that the derived class has a valid
//! copy constructor.
template <class T> class FEParamValidator_ : public FEParamValidator
{
public:
FEParamValidator* copy() const { return new T(static_cast<T const&>(*this)); }
};
//-----------------------------------------------------------------------------
//! Validator for FE_PARAM_INT parameters that does basic range checking.
class FEIntValidator : public FEParamValidator_<FEIntValidator>
{
public:
FEIntValidator(FEParamRange rng, int nmin, int nmax) : m_rng(rng), m_nmin(nmin), m_nmax(nmax) {}
//! See if the parameter is an FE_PARAM_INT and within the specified range
bool is_valid(const FEParam& p) const;
void Serialize(DumpStream& ar);
RANGE GetRange() { return { (FEParamRange)m_rng, (double)m_nmin, (double)m_nmax }; }
private:
int m_rng;
int m_nmin;
int m_nmax;
};
//-----------------------------------------------------------------------------
//! Validator for FE_PARAM_DOUBLE parameters that does basic range checking.
class FEDoubleValidator : public FEParamValidator_<FEDoubleValidator>
{
public:
FEDoubleValidator(FEParamRange rng, double fmin, double fmax) : m_rng(rng), m_fmin(fmin), m_fmax(fmax) {}
//! See if the parameter is an FE_PARAM_DOUBLE and within the specified range
bool is_valid(const FEParam& p) const;
void Serialize(DumpStream& ar);
RANGE GetRange() { return { (FEParamRange)m_rng, m_fmin, m_fmax }; }
private:
int m_rng;
double m_fmin;
double m_fmax;
};
//-----------------------------------------------------------------------------
//! Validator for FE_PARAM_DOUBLE parameters that does basic range checking.
class FEParamDoubleValidator : public FEParamValidator_<FEParamDoubleValidator>
{
public:
FEParamDoubleValidator(FEParamRange rng, double fmin, double fmax) : m_rng(rng), m_fmin(fmin), m_fmax(fmax) {}
//! See if the parameter is an FE_PARAM_DOUBLE and within the specified range
bool is_valid(const FEParam& p) const;
void Serialize(DumpStream& ar);
RANGE GetRange() { return { (FEParamRange)m_rng, m_fmin, m_fmax }; }
private:
int m_rng;
double m_fmin;
double m_fmax;
};
inline RANGE FE_RANGE_DONT_CARE() { return RANGE(FE_DONT_CARE); }
inline RANGE FE_RANGE_GREATER (double f) { return RANGE(FE_GREATER , f); }
inline RANGE FE_RANGE_GREATER_OR_EQUAL(double f) { return RANGE(FE_GREATER_OR_EQUAL, f); }
inline RANGE FE_RANGE_LESS (double f) { return RANGE(FE_LESS , f); }
inline RANGE FE_RANGE_LESS_OR_EQUAL (double f) { return RANGE(FE_LESS_OR_EQUAL , f); }
inline RANGE FE_RANGE_OPEN (double fmin, double fmax) {return RANGE(FE_OPEN , fmin, fmax); }
inline RANGE FE_RANGE_CLOSED (double fmin, double fmax) {return RANGE(FE_CLOSED , fmin, fmax); }
inline RANGE FE_RANGE_LEFT_OPEN (double fmin, double fmax) {return RANGE(FE_LEFT_OPEN , fmin, fmax); }
inline RANGE FE_RANGE_RIGHT_OPEN(double fmin, double fmax) {return RANGE(FE_RIGHT_OPEN, fmin, fmax); }
inline RANGE FE_RANGE_NOT_EQUAL (double f) { return RANGE(FE_NOT_EQUAL, f); }
| Unknown |
3D | febiosoftware/FEBio | FECore/FEInitialCondition.h | .h | 3,257 | 109 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEStepComponent.h"
#include <vector>
#include "FENodeDataMap.h"
#include "FENodeSet.h"
#include "FEDofList.h"
#include "FEModelParam.h"
//-----------------------------------------------------------------------------
//! Base class for defining initial conditions.
//! Initial conditions can be used to set the initial state of the model in an analysis.
class FECORE_API FEInitialCondition : public FEStepComponent
{
FECORE_SUPER_CLASS(FEIC_ID)
FECORE_BASE_CLASS(FEInitialCondition);
public:
FEInitialCondition(FEModel* pfem);
};
//-----------------------------------------------------------------------------
// Base class for initial conditions applied to node sets
class FECORE_API FENodalIC : public FEInitialCondition
{
public:
FENodalIC(FEModel* fem);
// set the nodeset for this component
void SetNodeSet(FENodeSet* nset);
// get the node set
FENodeSet* GetNodeSet();
// set the list of degrees of freedom
void SetDOFList(const FEDofList& dofList);
// serialization
void Serialize(DumpStream& ar) override;
// return the values for node i
virtual void GetNodalValues(int inode, std::vector<double>& values) = 0;
public:
void Activate() override;
bool Init() override;
protected:
FEDofList m_dofs;
FENodeSet* m_nodeSet;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// Class representing an initial condition on a degree of freedom
class FECORE_API FEInitialDOF : public FENodalIC
{
public:
FEInitialDOF(FEModel* pfem);
FEInitialDOF(FEModel* fem, int ndof, FENodeSet* nset);
void SetDOF(int ndof);
bool SetDOF(const char* szdof);
void Serialize(DumpStream& ar) override;
bool Init() override;
// return the values for node i
void GetNodalValues(int inode, std::vector<double>& values) override;
void SetValue(double v);
protected:
int m_dof; //!< degree of freedom
FEParamDouble m_data; //!< nodal values
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEScalarValuator.h | .h | 4,263 | 156 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEValuator.h"
#include "MathObject.h"
#include "FEDataMap.h"
#include "FENodeDataMap.h"
//---------------------------------------------------------------------------------------
// Base class for evaluating scalar parameters
class FECORE_API FEScalarValuator : public FEValuator
{
FECORE_SUPER_CLASS(FESCALARVALUATOR_ID)
FECORE_BASE_CLASS(FEScalarValuator)
public:
FEScalarValuator(FEModel* fem) : FEValuator(fem) {};
virtual double operator()(const FEMaterialPoint& pt) = 0;
virtual FEScalarValuator* copy() = 0;
virtual bool isConst() { return false; }
virtual double* constValue() { return nullptr; }
};
//---------------------------------------------------------------------------------------
class FECORE_API FEConstValue : public FEScalarValuator
{
public:
FEConstValue(FEModel* fem) : FEScalarValuator(fem), m_val(0.0) {};
double operator()(const FEMaterialPoint& pt) override { return m_val; }
bool isConst() override { return true; }
double* constValue() override { return &m_val; }
FEScalarValuator* copy() override;
private:
double m_val;
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
class FEMathExpression : public MSimpleExpression
{
struct MathParam
{
int type; // 0 = param, 1 = map
FEParam* pp;
FEDataMap* map;
};
public:
bool Init(const std::string& expr, FECoreBase* pc = nullptr);
void operator = (const FEMathExpression& me);
double value(FEModel* fem, const FEMaterialPoint& pt);
private:
std::vector<MathParam> m_vars;
};
//---------------------------------------------------------------------------------------
class FECORE_API FEMathValue : public FEScalarValuator
{
public:
FEMathValue(FEModel* fem);
~FEMathValue();
double operator()(const FEMaterialPoint& pt) override;
bool Init() override;
FEScalarValuator* copy() override;
void setMathString(const std::string& s);
bool create(FECoreBase* pc = 0);
void Serialize(DumpStream& ar) override;
private:
std::string m_expr;
FEMathExpression m_math;
FECoreBase* m_parent;
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
class FECORE_API FEMappedValue : public FEScalarValuator
{
public:
FEMappedValue(FEModel* fem);
void setDataMap(FEDataMap* val);
void setScaleFactor(double s);
FEDataMap* dataMap();
double operator()(const FEMaterialPoint& pt) override;
FEScalarValuator* copy() override;
void Serialize(DumpStream& dmp) override;
private:
double m_scale; // scale factor
FEDataMap* m_val;
};
//---------------------------------------------------------------------------------------
class FECORE_API FENodeMappedValue : public FEScalarValuator
{
public:
FENodeMappedValue(FEModel* fem);
void setDataMap(FENodeDataMap* val);
double operator()(const FEMaterialPoint& pt) override;
FEScalarValuator* copy() override;
private:
FENodeDataMap* m_val;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FECoreFactory.h | .h | 4,238 | 120 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEParameterList.h"
//-----------------------------------------------------------------------------
//! Forward declaration of the FEModel class. All classes that register
//! with the framework take a pointer to FEModel as their constructor parameter.
class FEModel;
class FECoreBase;
//-----------------------------------------------------------------------------
//! The factory class contains the mechanism for instantiating a class.
class FECORE_API FECoreFactory : public FEParamContainer
{
public:
//! constructor
FECoreFactory(SUPER_CLASS_ID scid, const char* szclass, const char* szbase, const char* szalias, int nspec = -1);
//! virtual constructor
virtual ~FECoreFactory();
//! This is the function that the kernel will use to intantiate an object
FECoreBase* CreateInstance(FEModel* pfem) const;
public:
// return the class name
const char* GetClassName() const { return m_szclass; }
// return the base class name
const char* GetBaseClassName() const { return m_szbase; }
// return the type string identifier
const char* GetTypeStr() const { return m_szalias; }
//! return the super-class ID
SUPER_CLASS_ID GetSuperClassID() const { return m_scid; }
//! return the module name
unsigned int GetModuleID() const { return m_module; }
//! set the module name
void SetModuleID(unsigned int nid);
//! Get the spec number
int GetSpecID() const { return m_spec; }
//! Set the allocator ID
void SetAllocatorID(int alloc) { m_alloc_id = alloc; }
//! Get the allocator ID
int GetAllocatorID() const { return m_alloc_id; }
public:
//! derived classes implement this to create an instance of a class
virtual FECoreBase* Create(FEModel*) const = 0;
private:
const char* m_szclass; //!< class name
const char* m_szbase; //!< base class name
const char* m_szalias; //!< class alias string
int m_spec; //!< The max spec number for which this feature is defined (-1 is don't care)
unsigned int m_module; //!< ID of module this class belongs to
SUPER_CLASS_ID m_scid; //!< the super-class ID
int m_alloc_id; //!< allocator ID
};
//-----------------------------------------------------------------------------
//! Forward declarations of classes used by the domain factory
class FEDomain;
class FEMesh;
class FEMaterial;
class FEModel;
//-----------------------------------------------------------------------------
//! Creation of domains are a little more elaborate and deviate from the usual
//! factory methods.
class FECORE_API FEDomainFactory
{
public:
FEDomainFactory(){}
virtual ~FEDomainFactory(){}
virtual FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat) = 0;
};
#define FECORE_SPEC(major, minor) ((major << 8) + minor)
#define FECORE_SPEC_MAJOR(n) ((n) >> 8)
#define FECORE_SPEC_MINOR(n) ((n) & 0x0F)
// macro for tagging a feature as experimental (i.e. in development)
#define FECORE_EXPERIMENTAL int(0xFFFF)
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogSolutionNorm.cpp | .cpp | 1,921 | 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.*/
#include "stdafx.h"
#include "FELogSolutionNorm.h"
#include "FEModel.h"
#include "FEAnalysis.h"
#include "FESolver.h"
//================================================================================
FELogSolutionNorm::FELogSolutionNorm(FEModel* fem) : FEModelLogData(fem) {}
double FELogSolutionNorm::value()
{
FEModel* fem = GetFEModel(); assert(fem);
if (fem == nullptr) return 0.0;
FEAnalysis* step = fem->GetCurrentStep();
if (step == nullptr) return 0.0;
FESolver* solver = step->GetFESolver();
if (solver == nullptr) return 0.0;
std::vector<double> u = solver->GetSolutionVector();
double unorm = l2_norm(u);
return unorm;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEBoundaryCondition.h | .h | 2,855 | 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 "FEStepComponent.h"
#include "FENodeSet.h"
#include "FEDofList.h"
//-----------------------------------------------------------------------------
class FEFacetSet;
//-----------------------------------------------------------------------------
//! This class is the base class of boundary conditions.
//! Boundary conditions set the "bc" state of nodes. The bc-state determines
//! whether or not the dofs of the node will be assigned an equation number.
//! Currently, there are two boundary conditions: a fixed (FEFixedBC) and a
//! prescribed (FEPrescribedBC) boundary condition.
class FECORE_API FEBoundaryCondition : public FEStepComponent
{
FECORE_SUPER_CLASS(FEBC_ID)
FECORE_BASE_CLASS(FEBoundaryCondition);
public:
//! constructor
FEBoundaryCondition(FEModel* pfem);
//! desctructor
~FEBoundaryCondition();
//! fill the prescribed values
virtual void PrepStep(std::vector<double>& u, bool brel = true);
// copy data from another class
virtual void CopyFrom(FEBoundaryCondition* pbc) = 0;
// repair BC if needed
virtual void Repair() {}
void Serialize(DumpStream& ar) override;
// TODO: Temporary construction to update some special boundary conditions in FEModel::Update
// Will likely remove this at some point.
virtual void UpdateModel() {}
public:
// set the dof list
void SetDOFList(int ndof);
void SetDOFList(const std::vector<int>& dofs);
void SetDOFList(const FEDofList& dofs);
const FEDofList& GetDofList() const { return m_dof; }
protected:
FEDofList m_dof; // the dof list for the BC
};
| Unknown |
3D | febiosoftware/FEBio | FECore/ElementDataRecord.cpp | .cpp | 5,068 | 187 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "ElementDataRecord.h"
#include "FECoreKernel.h"
#include "FEModel.h"
#include "FEDomain.h"
#include "FELogElemMath.h"
//-----------------------------------------------------------------------------
ElementDataRecord::ElementDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_ELEM)
{
m_offset = 0;
}
//-----------------------------------------------------------------------------
void ElementDataRecord::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;
FELogElemData* pdata = nullptr;
if (sz && sz[0] == '=')
{
FELogElemMath* logMath = fecore_alloc(FELogElemMath, GetFEModel());
if (logMath)
{
string smath(sz + 1);
if (logMath->SetExpression(smath))
{
pdata = logMath;
}
}
}
else
pdata = fecore_new<FELogElemData>(sz, GetFEModel());
if (pdata) m_Data.push_back(pdata);
else throw UnknownDataField(sz);
sz = ch;
}
while (ch);
}
//-----------------------------------------------------------------------------
double ElementDataRecord::Evaluate(int item, int ndata)
{
// make sure we have an ELT
if (m_ELT.empty()) BuildELT();
// find the element
FEMesh& mesh = GetFEModel()->GetMesh();
int index = item - m_offset;
if ((index >= 0) && (index < m_ELT.size()))
{
ELEMREF& e = m_ELT[index];
assert((e.ndom != -1) && (e.nid != -1));
FEElement* pe = &mesh.Domain(e.ndom).ElementRef(e.nid); assert(pe);
assert(pe->GetID() == item);
// get the element value
return m_Data[ndata]->value(*pe);
}
else return 0.0;
}
//-----------------------------------------------------------------------------
void ElementDataRecord::BuildELT()
{
m_ELT.clear();
FEMesh& m = GetFEModel()->GetMesh();
// find the min, max ID
int minID = -1, maxID = 0;
for (int i = 0; i<m.Domains(); ++i)
{
FEDomain& dom = m.Domain(i);
int NE = dom.Elements();
for (int j = 0; j<NE; ++j)
{
FEElement& el = dom.ElementRef(j);
int id = el.GetID(); assert(id > 0);
if ((minID < 0) || (id < minID)) minID = id;
if (id > maxID) maxID = id;
}
}
// allocate lookup table
int nsize = maxID - minID + 1;
m_ELT.resize(nsize);
for (int i=0; i<nsize; ++i)
{
m_ELT[i].ndom = -1;
m_ELT[i].nid = -1;
}
// build lookup table
m_offset = minID;
for (int i=0; i<m.Domains(); ++i)
{
FEDomain& d = m.Domain(i);
int ne = d.Elements();
for (int j=0; j<ne; ++j)
{
FEElement& el = d.ElementRef(j);
int id = el.GetID() - minID;
m_ELT[id].ndom = i;
m_ELT[id].nid = j;
}
}
}
//-----------------------------------------------------------------------------
int ElementDataRecord::Size() const
{
return (int)m_Data.size();
}
//-----------------------------------------------------------------------------
void ElementDataRecord::SelectAllItems()
{
FEMesh& m = GetFEModel()->GetMesh();
int n = m.Elements();
m_item.resize(n);
n = 0;
for (int i=0; i<m.Domains(); ++i)
{
FEDomain& dom = m.Domain(i);
int NE = dom.Elements();
for (int j=0; j<NE; ++j, n++)
{
FEElement& el = dom.ElementRef(j);
m_item[n] = el.GetID();
}
}
}
//-----------------------------------------------------------------------------
// This sets the item list based on a element set.
void ElementDataRecord::SetElementSet(FEElementSet* pg)
{
int n = pg->Elements();
assert(n);
m_item.resize(n);
for (int i=0; i<n; ++i) m_item[i] = (*pg)[i];
}
//-----------------------------------------------------------------------------
void ElementDataRecord::SetItemList(FEItemList* itemList, const vector<int>& selection)
{
FEElementSet* pg = dynamic_cast<FEElementSet*>(itemList);
assert(selection.empty());
SetElementSet(pg);
}
| C++ |
3D | febiosoftware/FEBio | FECore/qsort.cpp | .cpp | 2,657 | 100 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "fecore_api.h"
#define SWAP(a,b) { itemp = a; a = b; b = itemp; }
FECORE_API void qsort(int n, const int* arr, int* indx)
{
const int M = 7;
const int NSTACK = 50;
int i, indxt, ir=n-1, itemp, j, k, l=0;
int jstack = -1, istack[NSTACK];
int a;
for (j=0; j<n; ++j) indx[j] = j;
for (;;)
{
if (ir-l<M)
{
for (j=l+1; j<=ir; ++j)
{
indxt = indx[j];
a = arr[indxt];
for (i=j-1; i>=l; --i)
{
if (arr[indx[i]] <= a) break;
indx[i+1] = indx[i];
}
indx[i+1] = indxt;
}
if (jstack == -1) break;
ir = istack[jstack--];
l = istack[jstack--];
}
else
{
k = ((l+ir+2) >> 1) - 1;
SWAP(indx[k], indx[l+1]);
if (arr[indx[l]] > arr[indx[ir]]) SWAP(indx[l], indx[ir]);
if (arr[indx[l+1]] > arr[indx[ir]]) SWAP(indx[l+1], indx[ir]);
if (arr[indx[l]] > arr[indx[l+1]]) SWAP(indx[l], indx[l+1]);
i=l+1;
j=ir;
indxt=indx[l+1];
a = arr[indxt];
for(;;)
{
do i++; while (arr[indx[i]] < a);
do j--; while (arr[indx[j]] > a);
if (j<i) break;
SWAP(indx[i], indx[j]);
}
indx[l+1] = indx[j];
indx[j] = indxt;
jstack += 2;
// if (jstack < NSTACK) throw "a fit";
if (ir-i+1 >= j-l)
{
istack[jstack] = ir;
istack[jstack-1] = i;
ir = j-1;
}
else
{
istack[jstack] = j-1;
istack[jstack-1] = l;
l=i;
}
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEEdgeList.h | .h | 2,148 | 83 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
class FEMesh;
class FEElementList;
class FEDomain;
class FECORE_API FEEdgeList
{
public:
struct EDGE
{
int ntype; // 2 = linear, 3 = quadratic
int node[3];
};
public:
FEEdgeList();
bool Create(FEMesh* mesh);
bool Create(FEDomain* dom);
int Edges() const;
const EDGE& operator[] (int i);
const EDGE& Edge(int i) const;
FEMesh* GetMesh();
int FindEdge(int a, int b);
private:
FEMesh* m_mesh;
std::vector<EDGE> m_edgeList;
};
class FECORE_API FEElementEdgeList
{
public:
FEElementEdgeList();
bool Create(FEElementList& elemList, FEEdgeList& edgeList);
// Create the element edge list of a domain
bool Create(FEDomain& domain, FEEdgeList& edgeList);
int Edges(int elem) const;
const std::vector<int>& EdgeList(int elem) const;
private:
std::vector<std::vector<int> > m_EEL;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/mat3d.cpp | .cpp | 11,988 | 473 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "mat3d.h"
#include "eig3.h"
#include "sys.h"
#define ROTATE(a, i, j, k, l) g=a[i][j]; h=a[k][l];a[i][j]=g-s*(h+g*tau); a[k][l] = h + s*(g - h*tau);
void mat3ds::eigen(double l[3], vec3d r[3]) const
{
const int NMAX = 50;
double sm, tresh, g, h, t, c, tau, s, th;
int i, j, k;
// copy the matrix components since we will be overwriting them
double a[3][3] = {
{m[XX], m[XY], m[XZ]},
{m[XY], m[YY], m[YZ]},
{m[XZ], m[YZ], m[ZZ]}
};
// the v matrix contains the eigen vectors
// intialize to identity
double v[3][3] = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
};
// initialize b and d to the diagonal of a
double b[3] = {a[0][0], a[1][1], a[2][2]};
double d[3] = {a[0][0], a[1][1], a[2][2]};
double z[3] = {0};
const double eps = 0;//1.0e-15;
// loop
int n, nrot = 0;
for (n=0; n<NMAX; ++n)
{
// sum off-diagonal elements
sm = fabs(a[0][1]) + fabs(a[0][2]) + fabs(a[1][2]);
if (sm <= eps) break;
// set the treshold
if (n < 3) tresh = 0.2*sm/9.0; else tresh = 0.0;
// loop over off-diagonal elements
for (i=0; i<2; ++i)
{
for (j=i+1; j<3; ++j)
{
g = 100.0*fabs(a[i][j]);
// after four sweeps, skip the rotation if the off-diagonal element is small
if ((n > 3) && ((fabs(d[i])+g) == fabs(d[i]))
&& ((fabs(d[j])+g) == fabs(d[j])))
{
a[i][j] = 0.0;
}
else if (fabs(a[i][j]) > tresh)
{
h = d[j] - d[i];
if ((fabs(h)+g) == fabs(h))
t = a[i][j]/h;
else
{
th = 0.5*h/a[i][j];
t = 1.0/(fabs(th) + sqrt(1+th*th));
if (th < 0.0) t = -t;
}
c = 1.0/sqrt(1.0 + t*t);
s = t*c;
tau = s/(1.0+c);
h = t*a[i][j];
z[i] -= h;
z[j] += h;
d[i] -= h;
d[j] += h;
a[i][j] = 0;
for (k= 0; k<=i-1; ++k) { ROTATE(a, k, i, k, j) }
for (k=i+1; k<=j-1; ++k) { ROTATE(a, i, k, k, j) }
for (k=j+1; k< 3; ++k) { ROTATE(a, i, k, j, k) }
for (k= 0; k< 3; ++k) { ROTATE(v, k, i, k, j) }
++nrot;
}
}
}
for (i=0; i<3; ++i)
{
b[i] += z[i];
d[i] = b[i];
z[i] = 0.0;
}
}
// we sure we converged
assert(n < NMAX);
// copy eigenvalues
l[0] = d[0];
l[1] = d[1];
l[2] = d[2];
// copy eigenvectors
if (r)
{
r[0].x = v[0][0]; r[0].y = v[1][0]; r[0].z = v[2][0];
r[1].x = v[0][1]; r[1].y = v[1][1]; r[1].z = v[2][1];
r[2].x = v[0][2]; r[2].y = v[1][2]; r[2].z = v[2][2];
}
}
//-----------------------------------------------------------------------------
// Calculate the eigenvalues of A using an analytical expression for the
// eigen values.
void mat3ds::exact_eigen(double l[3]) const
{
const double S3 = sqrt(3.0);
const double S2 = sqrt(2.0);
mat3ds S = dev();
double nS = S.norm();
mat3ds T = (S.sqr()).dev();
double nT = T.norm();
double D = nS * nT;
if (D > 0.0)
{
double w = S.dotdot(T) / D; if (w > 1.0) w = 1.0; if (w < -1.0) w = -1.0;
double t = asin(w) / 3.0;
double r = S.norm();
double z = tr() / S3;
l[0] = z / S3 + (r / S2)*(sin(t) / S3 + cos(t));
l[1] = z / S3 - (S2 / S3)*r*sin(t);
l[2] = z / S3 + (r / S2)*(sin(t) / S3 - cos(t));
}
else
{
// check it matrix is exact diagonal
if ((m[1] == 0) && (m[3] == 0) && (m[4] == 0)) {
l[0] = m[0]; l[1] = m[2]; l[2] = m[5];
}
else {
l[0] = l[1] = l[2] = 0.0;
}
}
}
//-----------------------------------------------------------------------------
// Calculate the eigenvalues and eigenvectors of A using the method of
// Connelly Barnes ( http://barnesc.blogspot.com/2007/02/eigenvectors-of-3x3-symmetric-matrix.html )
void mat3ds::eigen2(double l[3], vec3d r[3]) const
{
double A[3][3] = {xx(), xy(), xz(), xy(), yy(), yz(), xz(), yz(), zz()};
double V[3][3];
if (ISNAN(tr())) return;
eigen_decomposition(A, V, l);
if (r) {
r[0] = vec3d(V[0][0],V[1][0],V[2][0]);
r[1] = vec3d(V[0][1],V[1][1],V[2][1]);
r[2] = vec3d(V[0][2],V[1][2],V[2][2]);
}
}
//-----------------------------------------------------------------------------
// calculates the unique right polar decomposition F = R*U
void mat3d::right_polar(mat3d& R, mat3ds& U) const
{
const mat3d& F = *this;
mat3ds C = (F.transpose()*F).sym();
double l[3];
vec3d v[3];
C.eigen2(l, v);
U = dyad(v[0])*sqrt(l[0]) + dyad(v[1])*sqrt(l[1]) + dyad(v[2])*sqrt(l[2]);
R = F*U.inverse();
}
//-----------------------------------------------------------------------------
// calculates the unique left polar decomposition F = V*R
void mat3d::left_polar(mat3ds& V, mat3d& R) const
{
const mat3d& F = *this;
mat3ds b = (F*F.transpose()).sym();
double l[3];
vec3d v[3];
b.eigen2(l, v);
V = dyad(v[0])*sqrt(l[0]) + dyad(v[1])*sqrt(l[1]) + dyad(v[2])*sqrt(l[2]);
R = V.inverse()*F;
}
//-----------------------------------------------------------------------------
// the "max shear" value
double mat3ds::max_shear() const
{
double e[3];
exact_eigen(e);
double t1 = fabs(0.5f*(e[1] - e[2]));
double t2 = fabs(0.5f*(e[2] - e[0]));
double t3 = fabs(0.5f*(e[0] - e[1]));
// TODO: is this necessary? I think the values returned
// by Principals are already ordered.
double tmax = t1;
if (t2 > tmax) tmax = t2;
if (t3 > tmax) tmax = t3;
return tmax;
}
//-----------------------------------------------------------------------------
void mat3fs::Principals(float e[3]) const
{
const static float ONETHIRD = 1.f / 3.f;
// pressure
float p = -(x + y + z) * ONETHIRD;
DeviatoricPrincipals(e);
e[0] -= p;
e[1] -= p;
e[2] -= p;
}
//-----------------------------------------------------------------------------
void mat3fs::DeviatoricPrincipals(float e[3]) const
{
const static float ONETHIRD = 1.f / 3.f;
// pressure
float p = -(x + y + z) * ONETHIRD;
// deviatoric stresses
float dev[3];
dev[0] = x + p;
dev[1] = y + p;
dev[2] = z + p;
// invariants
float I[3];
I[0] = dev[0] + dev[1] + dev[2]; // = tr[s']
I[1] = 0.5f * (dev[0] * dev[0]
+ dev[1] * dev[1]
+ dev[2] * dev[2])
+ xy * xy
+ yz * yz
+ xz * xz; // = s':s'
I[2] = -dev[0] * dev[1] * dev[2] - 2.0f * xy * yz * xz
+ dev[0] * yz * yz
+ dev[1] * xz * xz
+ dev[2] * xy * xy; // = -det(s')
// check to see if we can have a non-zero divisor, if no
// set principal stress to 0
if (I[1] != 0)
{
double a = -0.5 * sqrt(27.0 / I[1]) * I[2] / I[1];
if (a < 0)
a = MAX(a, -1.0);
else
a = MIN(a, 1.0);
double w = acos(a) * ONETHIRD;
double val = 2.0 * sqrt(I[1] * ONETHIRD);
e[0] = (float)(val * cos(w));
w = w - 2.0 * PI * ONETHIRD;
e[1] = (float)(val * cos(w));
w = w + 4.0 * PI * ONETHIRD;
e[2] = (float)(val * cos(w));
}
else
{
e[0] = e[1] = e[2] = 0.f;
}
}
//-----------------------------------------------------------------------------
float mat3fs::MaxShear() const
{
float e[3];
Principals(e);
float t1 = (float)fabs(0.5f * (e[1] - e[2]));
float t2 = (float)fabs(0.5f * (e[2] - e[0]));
float t3 = (float)fabs(0.5f * (e[0] - e[1]));
// TODO: is this necessary? I think the values returned
// by Principals are already ordered.
float tmax = t1;
if (t2 > tmax) tmax = t2;
if (t3 > tmax) tmax = t3;
return tmax;
}
//-----------------------------------------------------------------------------
#define ROTATE(a, i, j, k, l) g=a[i][j]; h=a[k][l];a[i][j]=g-s*(h+g*tau); a[k][l] = h + s*(g - h*tau);
#define SWAPF(a, b) { float t = a; a = b; b = t; }
#define SWAPV(a, b) { vec3f t = a; a = b; b = t; }
void mat3fs::eigen(vec3f e[3], float l[3]) const
{
const int NMAX = 50;
double sm, tresh, g, h, t, c, tau, s, th;
int i, j, k;
// copy the Matrix components since we will be overwriting them
double a[3][3] = {
{ x , xy, xz },
{ xy, y , yz },
{ xz, yz, z }
};
// the v Matrix contains the eigen vectors
// intialize to identity
double v[3][3] = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
};
// initialize b and d to the diagonal of a
double b[3] = { a[0][0], a[1][1], a[2][2] };
double d[3] = { a[0][0], a[1][1], a[2][2] };
double z[3] = { 0 };
const double eps = 0;//1.0e-15;
// loop
int n, nrot = 0;
for (n = 0; n < NMAX; ++n)
{
// sum off-diagonal elements
sm = fabs(a[0][1]) + fabs(a[0][2]) + fabs(a[1][2]);
if (sm <= eps) break;
// set the treshold
if (n < 3) tresh = 0.2 * sm / 9.0; else tresh = 0.0;
// loop over off-diagonal elements
for (i = 0; i < 2; ++i)
{
for (j = i + 1; j < 3; ++j)
{
g = 100.0 * fabs(a[i][j]);
// after four sweeps, skip the rotation if the off-diagonal element is small
if ((n > 3) && ((fabs(d[i]) + g) == fabs(d[i]))
&& ((fabs(d[j]) + g) == fabs(d[j])))
{
a[i][j] = 0.0;
}
else if (fabs(a[i][j]) > tresh)
{
h = d[j] - d[i];
if ((fabs(h) + g) == fabs(h))
t = a[i][j] / h;
else
{
th = 0.5 * h / a[i][j];
t = 1.0 / (fabs(th) + sqrt(1 + th * th));
if (th < 0.0) t = -t;
}
c = 1.0 / sqrt(1.0 + t * t);
s = t * c;
tau = s / (1.0 + c);
h = t * a[i][j];
z[i] -= h;
z[j] += h;
d[i] -= h;
d[j] += h;
a[i][j] = 0;
for (k = 0; k <= i - 1; ++k) { ROTATE(a, k, i, k, j) }
for (k = i + 1; k <= j - 1; ++k) { ROTATE(a, i, k, k, j) }
for (k = j + 1; k < 3; ++k) { ROTATE(a, i, k, j, k) }
for (k = 0; k < 3; ++k) { ROTATE(v, k, i, k, j) }
++nrot;
}
}
}
for (i = 0; i < 3; ++i)
{
b[i] += z[i];
d[i] = b[i];
z[i] = 0.0;
}
}
// we sure we converged
assert(n < NMAX);
// copy eigenvalues
l[0] = (float)d[0];
l[1] = (float)d[1];
l[2] = (float)d[2];
// copy eigenvectors
e[0].x = (float)v[0][0]; e[0].y = (float)v[1][0]; e[0].z = (float)v[2][0];
e[1].x = (float)v[0][1]; e[1].y = (float)v[1][1]; e[1].z = (float)v[2][1];
e[2].x = (float)v[0][2]; e[2].y = (float)v[1][2]; e[2].z = (float)v[2][2];
// we still need to sort the eigenvalues
if (l[1] > l[0]) { SWAPF(l[0], l[1]); SWAPV(e[0], e[1]); }
if (l[2] > l[0]) { SWAPF(l[0], l[2]); SWAPV(e[0], e[2]); }
if (l[2] > l[1]) { SWAPF(l[2], l[1]); SWAPV(e[2], e[1]); }
}
//-----------------------------------------------------------------------------
vec3f mat3fs::PrincDirection(int l)
{
vec3f e[3];
float lam[3];
eigen(e, lam);
return e[l] * lam[l];
}
//-----------------------------------------------------------------------------
double fractional_anisotropy(const mat3fs& m)
{
vec3f e[3];
float l[3];
m.eigen(e, l);
double la = (l[0] + l[1] + l[2]) / 3.0;
double D = sqrt(l[0] * l[0] + l[1] * l[1] + l[2] * l[2]);
double fa = 0.0;
if (D != 0) fa = sqrt(3.0 / 2.0) * sqrt((l[0] - la) * (l[0] - la) + (l[1] - la) * (l[1] - la) + (l[2] - la) * (l[2] - la)) / D;
return fa;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDomain.cpp | .cpp | 6,244 | 212 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEDomain.h"
#include "FEMaterial.h"
#include "DumpStream.h"
#include "FEMesh.h"
#include "FEGlobalMatrix.h"
//-----------------------------------------------------------------------------
FEDomain::FEDomain(int nclass, FEModel* fem) : FEMeshPartition(nclass, fem)
{
m_matAxis = nullptr;
}
//-----------------------------------------------------------------------------
void FEDomain::SetMaterial(FEMaterial* pm)
{
assert(pm);
if (pm) pm->AddDomain(this);
}
//-----------------------------------------------------------------------------
void FEDomain::SetMatID(int mid)
{
ForEachElement([=](FEElement& el) { el.SetMatID(mid); });
}
//-----------------------------------------------------------------------------
// This routine allocates the material point data for the element's integration points.
// Currently, this has to be called after the elements have been assigned a type (since this
// determines how many integration points an element gets).
void FEDomain::CreateMaterialPointData()
{
// This function is called before Init is called, so we need to do the
// initialization of the mat_axis here.
if (m_matAxis) m_matAxis->Init();
FEMaterial* pmat = GetMaterial();
FEMesh* mesh = GetMesh();
if (pmat) ForEachElement([=](FEElement& el) {
vec3d r[FEElement::MAX_NODES];
int ne = el.Nodes();
for (int i = 0; i < ne; ++i) r[i] = mesh->Node(el.m_node[i]).m_r0;
for (int k = 0; k < el.GaussPoints(); ++k)
{
FEMaterialPoint* mp = new FEMaterialPoint(pmat->CreateMaterialPointData());
mp->m_Q = (m_matAxis ? m_matAxis->operator()(*mp) : mat3d::identity());
mp->m_r0 = el.Evaluate(r, k);
mp->m_rt = mp->m_r0;
mp->m_index = k;
el.SetMaterialPointData(mp, k);
}
});
}
//-----------------------------------------------------------------------------
// serialization
void FEDomain::Serialize(DumpStream& ar)
{
FEMeshPartition::Serialize(ar);
if (ar.IsShallow())
{
int NEL = Elements();
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j) el.GetMaterialPoint(j)->Serialize(ar);
}
}
else
{
if (ar.IsSaving())
{
FEMaterial* mat = GetMaterial();
ar << mat;
int NEL = Elements();
ar << NEL;
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j) el.GetMaterialPoint(j)->Serialize(ar);
}
}
else
{
FEMaterial* pmat = 0;
ar >> pmat;
SetMaterial(pmat);
FE_Element_Spec espec; // invalid element spec!
int NEL = 0;
ar >> NEL;
Create(NEL, espec);
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
FEMaterialPoint* mp = new FEMaterialPoint(pmat->CreateMaterialPointData());
el.SetMaterialPointData(mp, j);
el.GetMaterialPoint(j)->Serialize(ar);
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Unpack the LM data for an element of this domain
void FEDomain::UnpackLM(FEElement& el, vector<int>& lm)
{
UnpackLM(el, GetDOFList(), lm);
}
//-----------------------------------------------------------------------------
//! Activate the domain
void FEDomain::Activate()
{
Activate(GetDOFList());
}
//-----------------------------------------------------------------------------
void FEDomain::IncrementalUpdate(std::vector<double>& ui, bool finalFlag)
{
}
//-----------------------------------------------------------------------------
// This is the default packing method.
// It stores all the degrees of freedom for the first node in the order defined
// by the DOF array, then for the second node, and so on.
void FEDomain::UnpackLM(FEElement& el, const FEDofList& dof, vector<int>& lm)
{
FEMesh* mesh = GetMesh();
int N = el.Nodes();
int ndofs = dof.Size();
lm.resize(N*ndofs);
for (int i = 0; i<N; ++i)
{
int n = el.m_node[i];
FENode& node = mesh->Node(n);
vector<int>& id = node.m_ID;
for (int j = 0; j<ndofs; ++j) lm[i*ndofs + j] = id[dof[j]];
}
}
//-----------------------------------------------------------------------------
void FEDomain::BuildMatrixProfile(FEGlobalMatrix& M)
{
vector<int> elm;
const int NE = Elements();
for (int j = 0; j<NE; ++j)
{
FEElement& el = ElementRef(j);
UnpackLM(el, elm);
M.build_add(elm);
}
}
//-----------------------------------------------------------------------------
void FEDomain::Activate(const FEDofList& dof)
{
// get the number of degrees of freedom for this domain.
const int ndofs = dof.Size();
// activate all the degrees of freedom of this domain
for (int i = 0; i<Nodes(); ++i)
{
FENode& node = Node(i);
if (node.HasFlags(FENode::EXCLUDE) == false)
{
for (int j = 0; j<ndofs; ++j)
if (dof[j] >= 0) node.set_active(dof[j]);
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/JFNKStrategy.cpp | .cpp | 4,464 | 157 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "JFNKStrategy.h"
#include "FENewtonSolver.h"
#include "JFNKMatrix.h"
#include "FEException.h"
#include "LinearSolver.h"
#include "log.h"
BEGIN_FECORE_CLASS(JFNKStrategy, FENewtonStrategy)
ADD_PARAMETER(m_jfnk_eps, "jfnk_eps");
END_FECORE_CLASS();
JFNKStrategy::JFNKStrategy(FEModel* fem) : FENewtonStrategy(fem)
{
// m_jfnk_eps = 5e-12;
m_jfnk_eps = 1e-6;
m_bprecondition = false;
m_A = nullptr;
m_plinsolve = nullptr;
m_neq = 0;
}
//! New initialization method
bool JFNKStrategy::Init()
{
if (m_pns == nullptr) return false;
m_plinsolve = m_pns->GetLinearSolver();
return true;
}
SparseMatrix* JFNKStrategy::CreateSparseMatrix(Matrix_Type mtype)
{
if (m_A) delete m_A;
m_A = 0;
// make sure the linear solver is an iterative linear solver
IterativeLinearSolver* ls = dynamic_cast<IterativeLinearSolver*>(m_pns->m_plinsolve);
if (ls)
{
// see if this solver has a preconditioner
m_bprecondition = ls->HasPreconditioner();
// if the solver has a preconditioner, we still need to create the stiffness matrix
SparseMatrix* K = 0;
if (m_bprecondition)
{
K = ls->CreateSparseMatrix(mtype);
if (K == 0) return 0;
}
// Now, override the matrix used
m_A = new JFNKMatrix(m_pns, K);
ls->SetSparseMatrix(m_A);
m_A->SetEpsilon(m_jfnk_eps);
// If there is no preconditioner we can do the pre-processing here
if (m_bprecondition == false)
{
ls->PreProcess();
}
else
{
if (ls->GetLeftPreconditioner()) ls->GetLeftPreconditioner()->SetSparseMatrix(K);
if (ls->GetRightPreconditioner()) ls->GetRightPreconditioner()->SetSparseMatrix(K);
}
}
return m_A;
}
//! perform a quasi-Newton udpate
bool JFNKStrategy::Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1)
{
// nothing to do here
return true;
}
//! solve the equations
void JFNKStrategy::SolveEquations(vector<double>& x, vector<double>& b)
{
// perform a backsubstitution
if (m_plinsolve->BackSolve(x, b) == false)
{
throw LinearSolverFailed();
}
}
bool JFNKStrategy::ReformStiffness()
{
if (m_bprecondition) return m_pns->ReformStiffness();
else return true;
}
//! override so we can store a copy of the residual before we add Fd
bool JFNKStrategy::Residual(std::vector<double>& R, bool binit)
{
// first calculate the residual
bool b = m_pns->Residual(R);
if (b == false) return false;
// store a copy
m_A->SetReferenceResidual(R);
// at the first iteration we need to calculate the Fd
if (binit)
{
// get the vector of prescribed displacements
std::vector<double>& ui = m_pns->m_ui;
// build m_Fd
vector<double>& Fd = m_pns->m_Fd;
m_A->SetPolicy(JFNKMatrix::ZERO_FREE_DOFS);
m_A->mult_vector(&ui[0], &Fd[0]);
m_A->SetPolicy(JFNKMatrix::ZERO_PRESCRIBED_DOFS);
// we need to flip the sign on Fd
for (size_t i = 0; i < Fd.size(); ++i) Fd[i] = -Fd[i];
// NOTE: Usually, the residual is called after an Update. However, here,
// the model is updated (via Update2) in m_A->mult_vector. I wonder
// if I need to restore the model's state to before the mult_vector call
// by calling another Update2 method with a zero vector.
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEItemList.h | .h | 2,098 | 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 <string>
#include "fecore_api.h"
#include "FECoreBase.h"
class FEMesh;
class FECORE_API FEItemList// : public FECoreBase
{
public:
enum FEItemType {
FE_NODE_SET,
FE_ELEMENT_SET,
FE_FACET_SET,
FE_SEGMENT_SET
};
public:
FEItemList(FEModel* fem, FEItemType type); // TODO: remove
FEItemList(FEMesh* mesh, FEItemType type);
virtual ~FEItemList();
// get the mesh
FEMesh* GetMesh() const;
void SetMesh(FEMesh* mesh);
const std::string& GetName() const;
void SetName(const std::string& name);
FEItemType Type() const { return m_type; }
public:
virtual void Serialize(DumpStream& ar);
static FEItemList* LoadClass(DumpStream& ar, FEItemList* p);
static void SaveClass(DumpStream& ar, FEItemList* p);
protected:
FEMesh* m_mesh;
FEItemType m_type;
std::string m_name;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBoundingBox.h | .h | 2,823 | 98 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
//-----------------------------------------------------------------------------
// This class stores the coordinates of a bounding box
//
class FECORE_API FEBoundingBox
{
public:
FEBoundingBox() {}
FEBoundingBox(const vec3d& x) : r0(x), r1(x) {}
FEBoundingBox(const vec3d& x0, const vec3d& x1) : r0(x0), r1(x1) {}
// center of box
vec3d center() const { return (r0 + r1)*0.5; }
// dimensions of box
double width() const { return (r1.x - r0.x); }
double height() const { return (r1.y - r0.y); }
double depth() const { return (r1.z - r0.z); }
// max dimension
double radius() const
{
double w = width();
double h = height();
double d = depth();
if ((w >= d) && (w >= h)) return w;
if ((h >= w) && (h >= d)) return h;
return d;
}
// add a point and grow the box if necessary
void add(const vec3d& r)
{
if (r.x < r0.x) r0.x = r.x;
if (r.y < r0.y) r0.y = r.y;
if (r.z < r0.z) r0.z = r.z;
if (r.x > r1.x) r1.x = r.x;
if (r.y > r1.y) r1.y = r.y;
if (r.z > r1.z) r1.z = r.z;
}
// inflate the box
void inflate(double dx, double dy, double dz)
{
r0.x -= dx; r1.x += dx;
r0.y -= dy; r1.y += dy;
r0.z -= dz; r1.z += dz;
}
// translate the box
void translate(const vec3d& t)
{
r0 += t;
r1 += t;
}
// check whether a point is inside or not
bool IsInside(const vec3d& r) const
{
return ((r.x >= r0.x) && (r.y >= r0.y) && (r.z >= r0.z) && (r.x <= r1.x) && (r.y <= r1.y) && (r.z <= r1.z));
}
private:
vec3d r0, r1; // coordinates of opposite corners
};
| Unknown |
3D | febiosoftware/FEBio | FECore/gamma.cpp | .cpp | 4,628 | 154 | /*This file 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 "gamma.h"
#include <limits>
#include <math.h>
#ifndef M_PI
#define M_PI 3.141592653589793238462643
#endif
//---------------------------------------------------------------------------------
// evaluate natural logarithm of gamma function
double gammaln(double x)
{
static double c[6] = {
76.18009172947146,
-86.50532032941677,
24.01409824083091,
-1.231739572450155,
0.1208650973866179e-2,
-0.5395239384953e-5};
double z = x;
double gln = x + 5.5;
gln -= (x+0.5)*log(gln);
double s = 1.000000000190015;
for (int i=0; i<6; ++i) s += c[i]/++z;
gln = -gln + log(2.5066282746310005*s/x);
return gln;
}
//---------------------------------------------------------------------------------
// evaluate the inverse of the gamma function
double gammainv(double x) {
if (x >= 0) return exp(-gammaln(x));
else return sin(M_PI*x)*exp(gammaln(1-x))/M_PI;
}
//---------------------------------------------------------------------------------
// evaluate the incomplete Gamma function
// adapted from Numerical Recipes in Fortran
bool gser(double& gamser, double a, double x, double& gln) {
const int ITMAX = 100;
const double EPS = 3e-7;
gln = gammaln(a);
if (x > 0) {
double ap = a;
double sum = 1./a;
double del = sum;
bool cnvgd = true;
for (int n=1; n<=ITMAX; ++n) {
ap += 1;
del*= x/ap;
sum += del;
if (fabs(del) < fabs(sum)*EPS) break;
if (n == ITMAX) cnvgd = false;
}
if (!cnvgd) return false;
gamser = sum*exp(-x+a*log(x)-gln);
}
else {
gamser = 0;
return false;
}
return true;
}
bool gcf(double& gammcf, double a, double x, double& gln) {
const int ITMAX = 100;
const double EPS = 3e-7, FPMIN = 10*std::numeric_limits<double>::epsilon();
gln = gammaln(a);
double b = x+1-a;
double c = 1./FPMIN;
double d = 1./b;
double h = d;
bool cnvgd = true;
for (int i=1; i<=ITMAX; ++i) {
double an = -i*(i-a);
b += 2;
d = an*d+b;
if (fabs(d) < FPMIN) d = FPMIN;
c = b + an/c;
if (fabs(c) < FPMIN) c = FPMIN;
d = 1./d;
double del = d*c;
h *= del;
if (fabs(del-1) < EPS) break;
if (i == ITMAX) cnvgd = false;
}
if (!cnvgd) return false;
gammcf = exp(-x+a*log(x)-gln)*h;
return true;
}
double gamma_inc_P(double a, double x)
{
// returns the lower incomplete Gamma function
if ((x >= 0) && (a >= 0)) {
if (x < a+1) {
double gamser, gln;
gser(gamser,a,x,gln);
return gamser*exp(gln);
}
else {
double gammcf, gln;
gcf(gammcf, a, x, gln);
return (1-gammcf)*exp(gln);
}
}
return 0.0;
}
double gamma_inc_Q(double a, double x)
{
// returns the upper incomplete Gamma function
if ((x >= 0) && (a >= 0)) {
if (x < a+1) {
double gamser, gln;
gser(gamser,a,x,gln);
return (1-gamser)*exp(gln);
}
else {
double gammcf, gln;
gcf(gammcf, a, x, gln);
return gammcf*exp(gln);
}
}
return 0.0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDomainList.cpp | .cpp | 2,486 | 103 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEDomainList.h"
#include "DumpStream.h"
#include "FEDomain.h"
#include "FEMesh.h"
#include <assert.h>
using namespace std;
FEDomainList::FEDomainList()
{
}
FEDomainList::FEDomainList(FEDomainList& domList)
{
m_dom = domList.m_dom;
}
FEDomainList::FEDomainList(std::vector<FEDomain*> domList)
{
m_dom = domList;
}
//! Clear the domain list
void FEDomainList::Clear()
{
m_dom.clear();
}
void FEDomainList::AddDomain(FEDomain* dom)
{
// see if this domain is already a member of this list
if (IsMember(dom))
{
// assert(false);
return;
}
// it's not, so let's add it
m_dom.push_back(dom);
}
//! Add a domain list
void FEDomainList::AddDomainList(const FEDomainList& domList)
{
for (int i = 0; i < domList.Domains(); ++i)
{
FEDomain* d = const_cast<FEDomain*>(domList.GetDomain(i));
AddDomain(d);
}
}
bool FEDomainList::IsMember(const FEDomain* dom) const
{
// loop over all the domains
for (size_t i = 0; i < m_dom.size(); ++i)
{
if (m_dom[i] == dom)
{
// found it!
return true;
}
}
// better luck next time!
return false;
}
//! serialization
void FEDomainList::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_dom;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEAugLagLinearConstraint.cpp | .cpp | 12,721 | 422 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEAugLagLinearConstraint.h"
#include "FEModel.h"
#include "FEMesh.h"
#include "log.h"
#include "FELinearSystem.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEAugLagLinearConstraintDOF, FECoreClass)
ADD_PARAMETER(m_nodeid, "id", FE_PARAM_ATTRIBUTE, 0);
ADD_PARAMETER(m_bc, "bc", FE_PARAM_ATTRIBUTE, "$(dof_list)");
ADD_PARAMETER(m_val, "node")->setLongName("Value");
END_FECORE_CLASS();
FEAugLagLinearConstraintDOF::FEAugLagLinearConstraintDOF(FEModel* fem) : FECoreClass(fem)
{
m_nodeid = m_bc = 0;
m_val = 0.0;
}
FENode& FEAugLagLinearConstraintDOF::Node()
{
FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
return *(mesh.FindNodeFromID(m_nodeid));
}
int FEAugLagLinearConstraintDOF::NodeIndex()
{
FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
return mesh.FindNodeIndexFromID(m_nodeid);
}
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEAugLagLinearConstraint, FECoreClass)
ADD_PROPERTY(m_dof, "node");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
void FEAugLagLinearConstraint::ClearDOFs()
{
for (int i = 0; i < m_dof.size(); ++i) delete m_dof[i];
m_dof.clear();
}
//-----------------------------------------------------------------------------
void FEAugLagLinearConstraint::AddDOF(int node, int bc, double val)
{
FEAugLagLinearConstraintDOF* dof = fecore_alloc(FEAugLagLinearConstraintDOF, GetFEModel());
dof->m_nodeid = node;
dof->m_bc = bc;
dof->m_val = val;
m_dof.push_back(dof);
}
//-----------------------------------------------------------------------------
void FEAugLagLinearConstraint::Serialize(DumpStream& ar)
{
FECoreClass::Serialize(ar);
ar & m_dof & m_lam;
}
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FELinearConstraintSet, FENLConstraint)
ADD_PARAMETER(m_laugon , "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0LAGMULT\0");
ADD_PARAMETER(m_tol , "tol");
ADD_PARAMETER(m_eps , "penalty");
ADD_PARAMETER(m_rhs , "rhs");
ADD_PARAMETER(m_naugmin, "minaug");
ADD_PARAMETER(m_naugmax, "maxaug");
ADD_PROPERTY(m_LC, "linear_constraint");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FELinearConstraintSet::FELinearConstraintSet(FEModel* pfem) : FENLConstraint(pfem)
{
static int nc = 1;
m_nID = nc++;
m_laugon = FECore::AUGLAG_METHOD;
m_eps = 1;
m_tol = 0.1;
m_rhs = 0;
m_naugmax = 50;
m_naugmin = 0;
}
//-----------------------------------------------------------------------------
void FELinearConstraintSet::BuildMatrixProfile(FEGlobalMatrix& M)
{
FEMesh& mesh = GetMesh();
vector<FEAugLagLinearConstraint*>& LC = m_LC;
vector<int> lm;
int N = (int)LC.size();
vector<FEAugLagLinearConstraint*>::iterator it = LC.begin();
if (m_laugon > FECore::AUGLAG_METHOD) {
for (int i=0; i<N; ++i, ++it)
{
int n = (int)(*it)->m_dof.size();
lm.resize(n+1);
FEAugLagLinearConstraint::Iterator is = (*it)->m_dof.begin();
for (int j = 0; j<n; ++j, ++is) lm[j] = (*is)->Node().m_ID[(*is)->m_bc];
lm[n] = m_EQ[i];
M.build_add(lm);
}
}
else {
for (int i=0; i<N; ++i, ++it)
{
int n = (int)(*it)->m_dof.size();
lm.resize(n);
FEAugLagLinearConstraint::Iterator is = (*it)->m_dof.begin();
for (int j = 0; j<n; ++j, ++is) lm[j] = (*is)->Node().m_ID[(*is)->m_bc];
M.build_add(lm);
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the current value of the constraint.
double FELinearConstraintSet::constraint(FEAugLagLinearConstraint& LC)
{
int n = (int)LC.m_dof.size();
double c = 0;
vector<FEAugLagLinearConstraintDOF*>::iterator it = LC.m_dof.begin();
double u;
FEMesh& mesh = GetMesh();
for (int i=0; i<n; ++i, ++it)
{
FENode& node = (*it)->Node();
switch ((*it)->m_bc)
{
case 0: u = node.m_rt.x - node.m_r0.x; break;
case 1: u = node.m_rt.y - node.m_r0.y; break;
case 2: u = node.m_rt.z - node.m_r0.z; break;
default:
u = node.get((*it)->m_bc);
}
c += (*it)->m_val*u;
}
return c;
}
//-----------------------------------------------------------------------------
//! This function performs an augmentation, if the Lagrange multiplier
//! has not converged
bool FELinearConstraintSet::Augment(int naug, const FETimeInfo& tp)
{
if (m_laugon != FECore::AUGLAG_METHOD) return true;
int M = (int)m_LC.size(), i;
vector<FEAugLagLinearConstraint*>::iterator im = m_LC.begin();
// calculate lag multipliers
double L0 = 0, L1 = 0;
for (i=0; i<M; ++i, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
double c = constraint(LC) - m_rhs;
double lam = LC.m_lam + m_eps*c;
L0 += LC.m_lam*LC.m_lam;
L1 += lam*lam;
}
L0 = sqrt(L0);
L1 = sqrt(L1);
double p;
if (L1 != 0)
p = fabs((L1 - L0)/L1);
else p = fabs(L1 - L0);
feLog("linear constraint set %d: %15.7lg %15.7lg %15.7lg\n", m_nID, L0, fabs(L1 - L0), fabs(m_tol*L1));
bool bconv = false;
if (p <= m_tol) bconv = true;
if ((m_naugmax >= 0) && (naug >= m_naugmax)) bconv = true;
if (naug < m_naugmin) bconv = false;
if (bconv == false)
{
im = m_LC.begin();
for (i=0; i<M; ++i, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
double c = constraint(LC) - m_rhs;
LC.m_lam += m_eps*c;
}
}
return bconv;
}
//-----------------------------------------------------------------------------
//! This function calculates the contribution to the residual.
void FELinearConstraintSet::LoadVector(FEGlobalVector& R, const FETimeInfo& tp)
{
FEMesh& mesh = GetMesh();
int M = (int)m_LC.size();
vector<FEAugLagLinearConstraint*>::iterator im = m_LC.begin();
if (m_laugon == FECore::LAGMULT_METHOD) {
double alpha = tp.alphaf;
for (int m=0; m<M; ++m, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
int n = (int)LC.m_dof.size();
double f = constraint(LC) - m_rhs;
double lam = m_Lm[m]*alpha + m_Lmp[m]*(1-alpha);
FEAugLagLinearConstraint::Iterator it = LC.m_dof.begin();
for (int i=0; i<n; ++i, ++it)
{
int neq = (*it)->Node().m_ID[(*it)->m_bc];
if (neq >= 0)
R[neq] -= lam * (*it)->m_val;
}
R[m_EQ[m]] -= f;
}
}
else {
for (int m=0; m<M; ++m, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
int n = (int)LC.m_dof.size();
double c = constraint(LC);
FEAugLagLinearConstraint::Iterator it = LC.m_dof.begin();
for (int i=0; i<n; ++i, ++it)
{
int neq = (*it)->Node().m_ID[(*it)->m_bc];
if (neq >= 0)
{
R[neq] -= (LC.m_lam+m_eps*c)* (*it)->m_val;
}
}
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the contribution to the stiffness matrix.
void FELinearConstraintSet::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp)
{
FEMesh& mesh = GetMesh();
vector<int> en;
vector<int> elm;
FEElementMatrix ke;
int M = (int)m_LC.size();
vector<FEAugLagLinearConstraint*>::iterator im = m_LC.begin();
if (m_laugon == FECore::LAGMULT_METHOD) {
double alpha = tp.alphaf;
for (int m=0; m<M; ++m, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
int n = (int)LC.m_dof.size();
double lam = m_Lm[m]*alpha + m_Lmp[m]*(1-alpha);
double f = constraint(LC) - m_rhs;
ke.resize(n+1, n+1);
ke.zero();
FEAugLagLinearConstraint::Iterator it = LC.m_dof.begin(), jt;
for (int i=0; i<n; ++i, ++it)
{
ke[n][i] = (*it)->m_val;
ke[i][n] = (*it)->m_val;
}
ke[n][n] = 0;
en.resize(n+1);
elm.resize(n+1);
it = LC.m_dof.begin();
for (int i=0; i<n; ++i, ++it)
{
en[i] = (*it)->NodeIndex();
int neq = (*it)->Node().m_ID[(*it)->m_bc];
elm[i] = neq;
}
en[n] = -1;
elm[n] = m_EQ[m];
ke.SetNodes(en);
ke.SetIndices(elm);
LS.Assemble(ke);
}
}
else {
for (int m=0; m<M; ++m, ++im)
{
FEAugLagLinearConstraint& LC = *(*im);
int n = (int)LC.m_dof.size();
ke.resize(n, n);
FEAugLagLinearConstraint::Iterator it = LC.m_dof.begin(), jt;
for (int i=0; i<n; ++i, ++it)
{
jt = LC.m_dof.begin();
for (int j=0; j<n; ++j, ++jt)
{
ke[i][j] = m_eps* (*it)->m_val*(*jt)->m_val;
}
}
en.resize(n);
elm.resize(n);
it = LC.m_dof.begin();
for (int i=0; i<n; ++i, ++it)
{
en[i] = (*it)->NodeIndex();
int neq = (*it)->Node().m_ID[(*it)->m_bc];
elm[i] = neq;
}
ke.SetNodes(en);
ke.SetIndices(elm);
LS.Assemble(ke);
}
}
}
//-----------------------------------------------------------------------------
void FELinearConstraintSet::Serialize(DumpStream& ar)
{
FENLConstraint::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_LC;
if (m_laugon > FECore::AUGLAG_METHOD)
ar & m_EQ & m_Lm & m_Lmp;
}
}
//-----------------------------------------------------------------------------
bool FELinearConstraintSet::Init()
{
if (FENLConstraint::Init() == false) return false;
int M = (int)m_LC.size();
if (m_laugon == FECore::LAGMULT_METHOD) {
m_EQ.resize(M, -1);
m_Lm.resize(M, 0.0);
m_Lmp.resize(M, 0.0);
}
return true;
}
//-----------------------------------------------------------------------------
// allocate equations
int FELinearConstraintSet::InitEquations(int neq)
{
if (m_laugon < FECore::LAGMULT_METHOD) return 0;
int n = neq;
for (int i = 0; i < (int)m_LC.size(); ++i) m_EQ[i] = n++;
return n - neq;
}
//-----------------------------------------------------------------------------
void FELinearConstraintSet::Update(const std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < (int)m_LC.size(); ++i)
{
if (m_EQ[i] != -1) m_Lm[i] = m_Lmp[i] + Ui[m_EQ[i]] + ui[m_EQ[i]];
}
}
void FELinearConstraintSet::PrepStep()
{
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < (int)m_LC.size(); ++i)
{
m_Lmp[i] = m_Lm[i];
}
}
void FELinearConstraintSet::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < (int)m_LC.size(); ++i)
{
if (m_EQ[i] != -1) Ui[m_EQ[i]] += ui[m_EQ[i]];
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELoadController.h | .h | 2,103 | 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 "FEModelComponent.h"
//-----------------------------------------------------------------------------
// Class that describes a load controller. A load controller can modify the value
// of model parameters during the analysis.
class FECORE_API FELoadController : public FEModelComponent
{
FECORE_SUPER_CLASS(FELOADCONTROLLER_ID)
FECORE_BASE_CLASS(FELoadController);
public:
FELoadController(FEModel* fem);
//! evaluate the load controller
void Evaluate(double time);
//! return the last calculated value
double Value() const { return m_value; }
//! serialization
void Serialize(DumpStream& ar) override;
virtual void Reset();
protected:
// This must be implemented by derived classes
virtual double GetValue(double time) = 0;
private:
double m_value; //!< last calculated value
};
| Unknown |
3D | febiosoftware/FEBio | FECore/ClassDescriptor.cpp | .cpp | 1,632 | 39 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "ClassDescriptor.h"
FEClassDescriptor::SimpleVariable* FEClassDescriptor::FindParameter(const char* szparam)
{
if (szparam == nullptr) return nullptr;
for (int i = 0; i < m_var.Count(); ++i)
{
Variable* vi = m_var.GetVariable(i);
if (vi->m_name == szparam) return dynamic_cast<SimpleVariable*>(vi);
}
return nullptr;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMat3dSphericalAngleMap.h | .h | 1,833 | 53 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEMat3dValuator.h"
#include "FEModelParam.h"
//-----------------------------------------------------------------------------
class FECORE_API FEMat3dSphericalAngleMap : public FEMat3dValuator
{
public:
FEMat3dSphericalAngleMap(FEModel* pfem);
bool Init() override;
void SetAngles(double theta, double phi);
mat3d operator () (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
void Serialize(DumpStream& ar) override;
private:
FEParamDouble m_theta;
FEParamDouble m_phi;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELinearConstraintManager.cpp | .cpp | 15,489 | 562 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELinearConstraintManager.h"
#include "FEMesh.h"
#include "FEModel.h"
#include "FEAnalysis.h"
#include "DumpStream.h"
#include "FEDomain.h"
#include "FEGlobalMatrix.h"
//-----------------------------------------------------------------------------
FELinearConstraintManager::FELinearConstraintManager(FEModel* fem) : m_fem(fem)
{
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::Clear()
{
for (size_t i = 0; i < m_LinC.size(); ++i) delete m_LinC[i];
m_LinC.clear();
}
//-----------------------------------------------------------------------------
FELinearConstraintManager::~FELinearConstraintManager()
{
Clear();
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::CopyFrom(const FELinearConstraintManager& lcm)
{
Clear();
for (int i=0; i<lcm.LinearConstraints(); ++i)
{
FELinearConstraint* lc = fecore_alloc(FELinearConstraint, m_fem);
lc->CopyFrom(&(const_cast<FELinearConstraint&>(lcm.LinearConstraint(i))));
m_LinC.push_back(lc);
}
InitTable();
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::AddLinearConstraint(FELinearConstraint* lc)
{
m_LinC.push_back(lc);
}
//-----------------------------------------------------------------------------
int FELinearConstraintManager::LinearConstraints() const
{
return (int)m_LinC.size();
}
//-----------------------------------------------------------------------------
const FELinearConstraint& FELinearConstraintManager::LinearConstraint(int i) const
{
return *m_LinC[i];
}
//-----------------------------------------------------------------------------
FELinearConstraint& FELinearConstraintManager::LinearConstraint(int i)
{
return *m_LinC[i];
}
//-----------------------------------------------------------------------------
//! remove a linear constraint
void FELinearConstraintManager::RemoveLinearConstraint(int i)
{
FELinearConstraint& lc = *m_LinC[i];
if (lc.IsActive()) lc.Deactivate();
m_LinC.erase(m_LinC.begin() + i);
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
ar << m_LinC;
int nr = m_LCT.rows();
int nc = m_LCT.columns();
ar << nr << nc;
if (nr*nc > 0)
{
ar.write(&m_LCT(0,0), sizeof(int), nr*nc);
}
}
else
{
FEModel& fem = ar.GetFEModel();
// linear constraints
ar >> m_LinC;
int nr, nc;
ar >> nr >> nc;
if (nr*nc > 0)
{
m_LCT.resize(nr, nc);
ar.read(&m_LCT(0,0), sizeof(int), nr*nc);
}
}
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::BuildMatrixProfile(FEGlobalMatrix& G)
{
int nlin = (int)m_LinC.size();
if (nlin == 0) return;
FEAnalysis* pstep = m_fem->GetCurrentStep();
FEMesh& mesh = m_fem->GetMesh();
// Add linear constraints to the profile
// TODO: we need to add a function build_add(lmi, lmj) for
// this type of "elements". Now we allocate too much memory
vector<int> lm, elm;
// do the cross-term
// TODO: I have to make this easier. For instance,
// keep a list that stores for each node the list of
// elements connected to that node.
// loop over all solid elements
for (int nd = 0; nd<pstep->Domains(); ++nd)
{
FEDomain& dom = *pstep->Domain(nd);
for (int i = 0; i<dom.Elements(); ++i)
{
FEElement& el = dom.ElementRef(i);
dom.UnpackLM(el, elm);
int ne = (int)elm.size();
// keep a list of the constraints this element connects to
vector<int> constraintList;
// see if this element connects to the
// parent node of a linear constraint ...
int m = el.Nodes();
for (int j = 0; j<m; ++j)
{
int ncols = m_LCT.columns();
for (int k = 0; k<ncols; ++k)
{
int n = m_LCT(el.m_node[j], k);
if (n >= 0)
{
// ... it does so we need to connect the
// element to the linear constraint
FELinearConstraint* plc = m_LinC[n];
constraintList.push_back(n);
int ns = (int)plc->Size();
lm.resize(ne + ns);
for (int l = 0; l<ne; ++l) lm[l] = elm[l];
FELinearConstraint::dof_iterator is = plc->begin();
for (int l = ne; l<ne + ns; ++l, ++is)
{
int neq = mesh.Node((*is)->node).m_ID[(*is)->dof];
lm[l] = neq;
}
G.build_add(lm);
}
}
}
// This replaces the commented out section below, which sets up the connectivity
// for the constraint block of the stiffness matrix.
// The problem is that this will only work for linear constraints that are connected
// the element, so not for constraints connected to contact "elements". Howerver, I
// don't think this was working anyway, so this is okay for now.
// TODO: Replace this with a more generic algorithm that looks at the matrix profile
// directly instead of element by element.
if (constraintList.empty() == false)
{
// do the constraint term
int n = 0;
for (int i = 0; i<constraintList.size(); ++i) n += (int)m_LinC[constraintList[i]]->Size();
lm.resize(n);
n = 0;
for (int i = 0; i<constraintList.size(); ++i)
{
FELinearConstraint& lc = *m_LinC[constraintList[i]];
int ni = (int)lc.Size();
for (int j = 0; j<ni; ++j)
{
const FELinearConstraintDOF& sj = lc.GetChildDof(j);
int neq = mesh.Node(sj.node).m_ID[sj.dof];
lm[n++] = neq;
}
}
G.build_add(lm);
}
}
}
// do the constraint term
// NOTE: This block was replaced by the section above which reduces the size
// of the stiffness matrix, but might be less generic (altough not entirely sure
// about that).
/* vector<FELinearConstraint>::iterator ic = m_LinC.begin();
int n = 0;
for (int i = 0; i<nlin; ++i, ++ic) n += (int) ic->m_childDof.size();
lm.resize(n);
ic = m_LinC.begin();
n = 0;
for (int i = 0; i<nlin; ++i, ++ic)
{
int ni = (int)ic->m_childDof.size();
vector<FELinearConstraintDOF>::iterator is = ic->m_childDof.begin();
for (int j = 0; j<ni; ++j, ++is)
{
int neq = mesh.Node(is->node).m_ID[is->dof];
lm[n++] = neq;
}
}
G.build_add(lm);
*/
}
//-----------------------------------------------------------------------------
//! This function initializes the linear constraint table (LCT). This table
//! contains for each dof the linear constraint it belongs to. (or -1 if it is
//! not constraint)
bool FELinearConstraintManager::Initialize()
{
int nlin = LinearConstraints();
if (nlin == 0) return true;
for (int i = 0; i < nlin; ++i)
{
FELinearConstraint& lci = *m_LinC[i];
if (lci.Init() == false) return false;
}
return true;
}
void FELinearConstraintManager::PrepStep()
{
FEMesh& mesh = m_fem->GetMesh();
for (int i=0; i<m_LinC.size(); ++i)
{
FELinearConstraint& lc = *m_LinC[i];
if (lc.IsActive())
{
FENode& node = mesh.Node(lc.GetParentNode());
double u = node.get(lc.GetParentDof());
double v = 0;
for (int j = 0; j < lc.Size(); ++j)
{
const FELinearConstraintDOF& dofj = lc.GetChildDof(j);
FENode& nj = mesh.Node(dofj.node);
v += dofj.val * nj.get(dofj.dof);
}
m_up[i] = v + lc.GetOffset() - u;
}
}
}
void FELinearConstraintManager::InitTable()
{
FEMesh& mesh = m_fem->GetMesh();
// create the linear constraint table
DOFS& fedofs = m_fem->GetDOFS();
int MAX_NDOFS = fedofs.GetTotalDOFS();
m_LCT.resize(mesh.Nodes(), MAX_NDOFS, -1);
m_LCT.set(-1);
vector<FELinearConstraint*>::iterator ic = m_LinC.begin();
int nlin = LinearConstraints();
for (int i = 0; i<nlin; ++i, ++ic)
{
FELinearConstraint& lc = *(*ic);
if (lc.IsActive())
{
int n = lc.GetParentNode();
int m = lc.GetParentDof();
m_LCT(n, m) = i;
}
}
}
//-----------------------------------------------------------------------------
// This gets called during model activation, i.e. activation of permanent model components.
bool FELinearConstraintManager::Activate()
{
int nlin = LinearConstraints();
if (nlin == 0) return true;
// initialize the lookup table
InitTable();
// ensure that none of the parent nodes are child nodes in any of the active linear constraints
for (int i = 0; i<nlin; ++i)
{
FELinearConstraint& lci = *m_LinC[i];
if (lci.IsActive())
{
int n = (int)lci.Size();
for (int k = 0; k<n; ++k)
{
const FELinearConstraintDOF& childDOF = lci.GetChildDof(k);
int n = m_LCT(childDOF.node, childDOF.dof);
if (n != -1)
{
return false;
}
}
}
}
// set the prescribed value array
m_up.assign(m_LinC.size(), 0.0);
if (m_LinC.size())
{
vector<FELinearConstraint*>::iterator il = m_LinC.begin();
for (int l = 0; l<(int)m_LinC.size(); ++l, ++il)
{
if ((*il)->IsActive()) (*il)->Activate();
}
}
return true;
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::AssembleResidual(vector<double>& R, vector<int>& en, vector<int>& elm, vector<double>& fe)
{
FEMesh& mesh = m_fem->GetMesh();
int ndof = (int)fe.size();
int ndn = ndof / (int)en.size();
const int nodes = (int)en.size();
// loop over all degrees of freedom of this element
for (int i = 0; i<ndof; ++i)
{
int nodei = i / ndn;
if (nodei < nodes) {
// see if this dof belongs to a linear constraint
int l = m_LCT(en[nodei], i%ndn);
if (l >= 0)
{
// if so, get the linear constraint
FELinearConstraint& lc = *m_LinC[l];
assert(elm[i] == -1);
// now loop over all child nodes and
// add the contribution to the residual
int ns = (int)lc.Size();
FELinearConstraint::dof_iterator is = lc.begin();
for (int j = 0; j < ns; ++j, ++is)
{
int I = mesh.Node((*is)->node).m_ID[(*is)->dof];
if (I >= 0)
{
double A = (*is)->val;
#pragma omp atomic
R[I] += A*fe[i];
}
}
}
}
}
}
//-----------------------------------------------------------------------------
void FELinearConstraintManager::AssembleStiffness(FEGlobalMatrix& G, vector<double>& R, vector<double>& ui, const vector<int>& en, const vector<int>& lmi, const vector<int>& lmj, const matrix& ke)
{
FEMesh& mesh = m_fem->GetMesh();
// make sure we have a node list
// (rigid matrices will not have the node list set and therefore should be ignored, since
// you cannot use rigid nodes in linear constraints)
if (en.size() == 0) return;
int ndof = ke.rows();
int ndn = ndof / (int)en.size();
const int nodes = (int)en.size();
SparseMatrix& K = *(&G);
// loop over all stiffness components
// and correct for linear constraints
for (int i = 0; i<ndof; ++i)
{
int nodei = i / ndn;
int li = (nodei < nodes ? m_LCT(en[nodei], i%ndn) : -1);
for (int j = 0; j < ndof; ++j)
{
int nodej = j / ndn;
int lj = (nodej < nodes ? m_LCT(en[nodej], j%ndn) : -1);
if ((li >= 0) && (lj < 0))
{
// dof i is constrained
FELinearConstraint& Li = *m_LinC[li];
assert(lmi[i] == -1);
FELinearConstraint::dof_iterator is = Li.begin();
for (int k = 0; k < (int)Li.Size(); ++k, ++is)
{
int I = mesh.Node((*is)->node).m_ID[(*is)->dof];
int J = lmj[j];
double kij = (*is)->val*ke[i][j];
if ((J >= 0) && (I >= 0)) K.add(I, J, kij);
else
{
// adjust for prescribed dofs
J = -J - 2;
if ((J >= 0) && (I >= 0)) R[I] -= kij*ui[J];
}
}
}
else if ((lj >= 0) && (li < 0))
{
// dof j is constrained
FELinearConstraint& Lj = *m_LinC[lj];
assert(lmj[j] == -1);
FELinearConstraint::dof_iterator js = Lj.begin();
for (int k = 0; k < (int)Lj.Size(); ++k, ++js)
{
int I = lmi[i];
int J = mesh.Node((*js)->node).m_ID[(*js)->dof];
double kij = (*js)->val*ke[i][j];
if ((J >= 0) && (I >= 0)) K.add(I, J, kij);
else
{
// adjust for prescribed dofs
J = -J - 2;
if ((J >= 0) && (I >= 0)) R[I] -= kij*ui[J];
}
}
// adjust right-hand side for inhomogeneous linear constraints
if (Lj.GetOffset() != 0.0)
{
double ri = ke[i][j] * m_up[lj];
int I = lmi[i];
if (I >= 0) R[I] -= ri;
}
}
else if ((li >= 0) && (lj >= 0))
{
// both dof i and j are constrained
FELinearConstraint& Li = *m_LinC[li];
FELinearConstraint& Lj = *m_LinC[lj];
FELinearConstraint::dof_iterator is = Li.begin();
FELinearConstraint::dof_iterator js = Lj.begin();
assert(lmi[i] == -1);
assert(lmj[j] == -1);
for (int k = 0; k < (int)Li.Size(); ++k, ++is)
{
js = Lj.begin();
for (int l = 0; l < (int)Lj.Size(); ++l, ++js)
{
int I = mesh.Node((*is)->node).m_ID[(*is)->dof];
int J = mesh.Node((*js)->node).m_ID[(*js)->dof];;
double kij = ke[i][j] * (*is)->val*(*js)->val;
if ((J >= 0) && (I >= 0)) K.add(I, J, kij);
else
{
// adjust for prescribed dofs
J = -J - 2;
if ((J >= 0) && (I >= 0)) R[I] -= kij*ui[J];
}
}
}
// adjust for inhomogeneous linear constraints
if (Lj.GetOffset() != 0.0)
{
is = Li.begin();
for (int k = 0; k < (int)Li.Size(); ++k, ++is)
{
int I = mesh.Node((*is)->node).m_ID[(*is)->dof];
double ri = (*is)->val * ke[i][j] * m_up[lj];
if (I >= 0) R[I] -= ri;
}
}
}
}
}
}
//-----------------------------------------------------------------------------
// This updates the nodal degrees of freedom of the parent nodes.
void FELinearConstraintManager::Update()
{
FEMesh& mesh = m_fem->GetMesh();
int nlin = LinearConstraints();
for (int n = 0; n<nlin; ++n)
{
FELinearConstraint& lc = LinearConstraint(n);
if (lc.IsActive())
{
// evaluate the linear constraint
double d = 0;
int ns = (int)lc.Size();
FELinearConstraint::dof_iterator si = lc.begin();
for (int i = 0; i < ns; ++i, ++si)
{
FENode& childNode = mesh.Node((*si)->node);
d += (*si)->val * childNode.get((*si)->dof);
}
// assign to parent node
FENode& parentNode = mesh.Node(lc.GetParentNode());
parentNode.set(lc.GetParentDof(), d + lc.GetOffset());
}
}
m_up.assign(m_LinC.size(), 0.0);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELogDomainVolume.h | .h | 1,495 | 35 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "DomainDataRecord.h"
class FECORE_API FELogDomainVolume : public FELogDomainData
{
public:
FELogDomainVolume(FEModel* fem) : FELogDomainData(fem) {}
double value(FEDomain& dom) override;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tensor_base.h | .h | 3,936 | 143 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
//-----------------------------------------------------------------------------
// traits class for tensors. Classes derived from tensor_base must specialize
// this class and define the NNZ enum variable which defines the number of components
// stored for that tensor class.
template <class T> class tensor_traits {};
//-----------------------------------------------------------------------------
// Template class for constructing some of the higher order tensor classes.
// Defines storage as well as some basic operations that do not depend on the
// order in which the tensor components are stored.
template <class T> class tensor_base
{
enum { NNZ = tensor_traits<T>::NNZ};
public:
tensor_base(){}
// arithmetic operators
T operator + (const T& t) const;
T operator - (const T& t) const;
T operator * (double g) const;
T operator / (double g) const;
// arithmetic assignment operators
T& operator += (const T& t);
T& operator -= (const T& t);
T& operator *= (double g);
T& operator /= (double g);
// unary operators
T operator - () const;
// initialize to zero
void zero();
public:
double d[NNZ];
};
// operator +
template<class T> T tensor_base<T>::operator + (const T& t) const
{
T s;
for (int i=0; i<NNZ; i++) s.d[i] = d[i] + t.d[i];
return s;
}
// operator -
template<class T> T tensor_base<T>::operator - (const T& t) const
{
T s;
for (int i=0; i<NNZ; i++) s.d[i] = d[i] - t.d[i];
return s;
}
// operator *
template<class T> T tensor_base<T>::operator * (double g) const
{
T s;
for (int i=0; i<NNZ; i++) s.d[i] = g*d[i];
return s;
}
// operator /
template<class T> T tensor_base<T>::operator / (double g) const
{
T s;
for (int i=0; i<NNZ; i++) s.d[i] = d[i]/g;
return s;
}
// assignment operator +=
template<class T> T& tensor_base<T>::operator += (const T& t)
{
for (int i=0; i<NNZ; i++) d[i] += t.d[i];
return static_cast<T&>(*this);
}
// assignment operator -=
template<class T> T& tensor_base<T>::operator -= (const T& t)
{
for (int i=0; i<NNZ; i++) d[i] -= t.d[i];
return static_cast<T&>(*this);
}
// assignment operator *=
template<class T> T& tensor_base<T>::operator *= (double g)
{
for (int i=0; i<NNZ; i++) d[i] *= g;
return static_cast<T&>(*this);
}
// assignment operator /=
template<class T> T& tensor_base<T>::operator /= (double g)
{
for (int i=0; i<NNZ; i++) d[i] /= g;
return static_cast<T&>(*this);
}
// unary operator -
template<class T> T tensor_base<T>::operator - () const
{
T s;
for (int i = 0; i < NNZ; i++) s.d[i] = -d[i];
return s;
}
// intialize to zero
template<class T> void tensor_base<T>::zero()
{
for (int i = 0; i < NNZ; i++) d[i] = 0.0;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/mortar.h | .h | 4,385 | 140 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include "FESurface.h"
#include <vector>
//-----------------------------------------------------------------------------
// Structure for representing 2D points
struct POINT2D
{
double x, y;
};
//-----------------------------------------------------------------------------
// Calculates the intersection between two convex polygons
FECORE_API int ConvexIntersect(POINT2D* P, int n, POINT2D* Q, int m, POINT2D* R);
//-----------------------------------------------------------------------------
class FECORE_API Patch
{
public:
struct FACET
{
FACET(){}
FACET(vec3d x[3]) { r[0] = x[0]; r[1] = x[1]; r[2] = x[2]; }
vec3d r[3]; //!< position of nodes
// Evaluate the spatial position using iso-parametric coordinates
vec3d Position(double rp, double sp)
{
return (r[0]*(1.0 - rp - sp) + r[1]*rp + r[2]*sp);
}
//! calculate the area of the patch
double Area()
{
vec3d n = (r[1] - r[0])^(r[2] - r[0]);
return n.norm()*0.5;
}
};
public:
Patch(int k, int l) : m_primary_facet_id(k), m_secondary_facet_id(l) {}
Patch(const Patch& p) {
m_tri = p.m_tri;
m_primary_facet_id = p.m_primary_facet_id;
m_secondary_facet_id = p.m_secondary_facet_id;
}
Patch& operator = (const Patch& p) {
m_tri = p.m_tri;
m_primary_facet_id = p.m_primary_facet_id;
m_secondary_facet_id = p.m_secondary_facet_id;
return *this;
}
int GetPrimaryFacetID() const { return m_primary_facet_id; }
int GetSecondaryFacetID() const { return m_secondary_facet_id; }
public:
//! Clear the patch
void Clear() { m_tri.clear(); }
//! Add a facet to the patch
void Add(vec3d x[3]) { m_tri.push_back(FACET(x)); }
//! retrieve a facet
FACET& Facet(int i) { return m_tri[i]; }
//! facet count
int Size() { return (int) m_tri.size(); }
//! See if the facet is empty
bool Empty() { return m_tri.empty(); }
private:
int m_primary_facet_id; //!< index of primary facet
int m_secondary_facet_id; //!< index of secondary facet
std::vector<FACET> m_tri; //!< triangular patches
};
//-----------------------------------------------------------------------------
class FECORE_API MortarSurface
{
public:
MortarSurface(){}
int Patches() { return (int) m_patch.size(); }
Patch& GetPatch(int i) { return m_patch[i]; }
void AddPatch(const Patch& p) { m_patch.push_back(p); }
void Clear() { m_patch.clear(); }
private:
std::vector<Patch> m_patch;
};
//-----------------------------------------------------------------------------
// Calculates the intersection between two segments and adds it to the patch
FECORE_API bool CalculateMortarIntersection(FESurface& ss, FESurface& ms, int k, int l, Patch& patch);
//-----------------------------------------------------------------------------
// Calculates the mortar intersection between two surfaces
FECORE_API void CalculateMortarSurface(FESurface& ss, FESurface& ms, MortarSurface& s);
//-----------------------------------------------------------------------------
// Stores the mortar surface in STL format
FECORE_API bool ExportMortar(MortarSurface& mortar, const char* szfile);
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfacePair.cpp | .cpp | 2,119 | 80 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FESurfacePair.h"
#include "FEFacetSet.h"
#include "FEMesh.h"
#include "DumpStream.h"
//--------------------------------------------------------
FESurfacePair::FESurfacePair(FEMesh* pm) : m_mesh(pm)
{
m_surface1 = 0;
m_surface2 = 0;
}
void FESurfacePair::SetName(const std::string& name)
{
m_name = name;
}
const std::string& FESurfacePair::GetName() const
{
return m_name;
}
FEFacetSet* FESurfacePair::GetPrimarySurface()
{
return m_surface1;
}
void FESurfacePair::SetPrimarySurface(FEFacetSet* pf)
{
m_surface1 = pf;
}
FEFacetSet* FESurfacePair::GetSecondarySurface()
{
return m_surface2;
}
void FESurfacePair::SetSecondarySurface(FEFacetSet* pf)
{
m_surface2 = pf;
}
void FESurfacePair::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar& m_surface1;
ar& m_surface2;
ar& m_mesh;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMeshPartition.cpp | .cpp | 5,106 | 189 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEMeshPartition.h"
#include "FEMaterial.h"
#include "FEDataExport.h"
#include "FEMesh.h"
#include "DOFS.h"
#include <string.h>
#include "FEModel.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
FEMeshPartition::FEMeshPartition(int nclass, FEModel* fem) : FECoreBase(fem), m_nclass(nclass)
{
m_pMesh = nullptr;
if (fem) m_pMesh = &fem->GetMesh();
m_bactive = true;
}
//-----------------------------------------------------------------------------
FEMeshPartition::~FEMeshPartition()
{
// delete all data export classes
if (m_Data.empty() == false)
{
size_t ND = m_Data.size();
for (size_t i = 0; i<ND; ++i) delete m_Data[i];
m_Data.clear();
}
}
//-----------------------------------------------------------------------------
void FEMeshPartition::AddDataExport(FEDataExport* pd)
{
if (pd) m_Data.push_back(pd);
}
//-----------------------------------------------------------------------------
FEElement* FEMeshPartition::FindElementFromID(int nid)
{
for (int i = 0; i<Elements(); ++i)
{
FEElement& el = ElementRef(i);
if (el.GetID() == nid) return ⪙
}
return 0;
}
//-----------------------------------------------------------------------------
void FEMeshPartition::Serialize(DumpStream& ar)
{
FECoreBase::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Node;
ar & m_nclass;
ar & m_bactive;
// ar & m_Data;
}
//-----------------------------------------------------------------------------
//! return a specific node
FENode& FEMeshPartition::Node(int i)
{
return m_pMesh->Node(m_Node[i]);
}
//-----------------------------------------------------------------------------
//! return a specific node
const FENode& FEMeshPartition::Node(int i) const
{
return m_pMesh->Node(m_Node[i]);
}
//-----------------------------------------------------------------------------
void FEMeshPartition::CopyFrom(FEMeshPartition* pd)
{
m_Node = pd->m_Node;
SetName(pd->GetName());
}
//-----------------------------------------------------------------------------
bool FEMeshPartition::Init()
{
// base class first
if (FECoreBase::Init() == false) return false;
// make sure that there are elements in this domain
if (Elements() == 0) return false;
// get the mesh to which this domain belongs
FEMesh& mesh = *GetMesh();
// This array is used to keep tags on each node
int NN = mesh.Nodes();
vector<int> tag; tag.assign(NN, -1);
// let's find all nodes the domain needs
int nn = 0;
int NE = Elements();
for (int i = 0; i<NE; ++i)
{
FEElement& el = ElementRef(i);
int ne = el.Nodes();
for (int j = 0; j<ne; ++j)
{
// get the global node number
int m = el.m_node[j];
// create a local node number
if (tag[m] == -1) tag[m] = nn++;
// set the local node number
el.m_lnode[j] = tag[m];
}
}
// allocate node index table
m_Node.assign(nn, -1);
// fill the node index table
for (int i = 0; i<NN; ++i)
{
if (tag[i] >= 0)
{
m_Node[tag[i]] = i;
}
}
#ifndef NDEBUG
// make sure all nodes are assigned a local index
for (int i = 0; i<nn; ++i)
{
assert(m_Node[i] >= 0);
}
#endif
return true;
}
//-----------------------------------------------------------------------------
void FEMeshPartition::ForEachMaterialPoint(std::function<void(FEMaterialPoint& mp)> f)
{
int NE = Elements();
#pragma omp parallel for shared(f)
for (int i = 0; i < NE; ++i)
{
FEElement& el = ElementRef(i);
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n) f(*el.GetMaterialPoint(n));
}
}
//-----------------------------------------------------------------------------
void FEMeshPartition::ForEachElement(std::function<void(FEElement& el)> f)
{
int NE = Elements();
#pragma omp parallel for shared(f)
for (int i = 0; i < NE; ++i)
{
f(ElementRef(i));
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens4d.cpp | .cpp | 2,604 | 87 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "tens4d.h"
#include <math.h>
//-----------------------------------------------------------------------------
//! This function checks the positive definiteness of a 4th order tensor
//! having both major and minor symmetries. The function does not do an
//! exhaustive test, in the sense it can only detect failure. If a tensor passes
//! it is not guaranteed that the tensor is indeed positive-definite.
bool IsPositiveDefinite(const tens4ds& t)
{
// test 1. all diagonal entries have to be positive
if (t(0,0) <= 0) return false;
if (t(1,1) <= 0) return false;
if (t(2,2) <= 0) return false;
if (t(3,3) <= 0) return false;
if (t(4,4) <= 0) return false;
if (t(5,5) <= 0) return false;
// test 2. t(i,i)+t(j,j) > 2t(i,j)
int i, j;
for (i=0; i<6; ++i)
{
for (j=i+1; j<6; ++j)
{
if (t(i,i)+t(j,j) <= 2*t(i,j))
{
return false;
}
}
}
// test 3. the element with largest modulus lies on the main diagonal
double l = -1, v;
bool d = false;
for (i=0; i<6; ++i)
{
for (j=i; j<6; ++j)
{
v = fabs(t(i,j));
if (v > l)
{
l = v;
d = (i==j);
}
}
}
if (d == false)
{
return false;
}
// if all tests pass, it is not guaranteed that the tensor is indeed positive-definite
// but we'd have some good reasons to believe so.
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMaterial.h | .h | 3,797 | 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 "FEModelComponent.h"
#include "FEMaterialPoint.h"
#include "FEModelParam.h"
#include "FEDomainList.h"
#include "FEDomainParameter.h"
//-----------------------------------------------------------------------------
// forward declaration of some classes
class FEDomain;
class DumpStream;
//-----------------------------------------------------------------------------
class FECORE_API FEMaterialBase : public FEModelComponent
{
public:
FEMaterialBase(FEModel* fem);
//! returns a pointer to a new material point object
virtual FEMaterialPointData* CreateMaterialPointData();
//! Update specialized material points at each iteration
virtual void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp);
// evaluate local coordinate system at material point
virtual mat3d GetLocalCS(const FEMaterialPoint& mp) = 0;
};
//-----------------------------------------------------------------------------
//! Abstract base class for material types
//! From this class all other material classes are derived.
class FECORE_API FEMaterial : public FEMaterialBase
{
FECORE_SUPER_CLASS(FEMATERIAL_ID)
FECORE_BASE_CLASS(FEMaterial)
public:
FEMaterial(FEModel* fem);
virtual ~FEMaterial();
//! performs initialization
bool Init() override;
//! get a domain parameter
FEDomainParameter* FindDomainParameter(const std::string& paramName);
// evaluate local coordinate system at material point
mat3d GetLocalCS(const FEMaterialPoint& mp) override;
// set the (local) material axis valuator
void SetMaterialAxis(FEMat3dValuator* val);
protected:
FEMat3dValuator* m_Q; //!< local material coordinate system
public:
//! Assign a domain to this material
void AddDomain(FEDomain* dom);
//! get the domaint list
FEDomainList& GetDomainList() { return m_domList; }
protected:
void AddDomainParameter(FEDomainParameter* p);
private:
FEDomainList m_domList; //!< list of domains that use this material
std::vector<FEDomainParameter*> m_param; //!< list of domain variables
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// Material properties are classes that can only be defined as properties of other materials
class FECORE_API FEMaterialProperty : public FEMaterialBase
{
FECORE_SUPER_CLASS(FEMATERIALPROP_ID)
public:
FEMaterialProperty(FEModel* fem);
// evaluate local coordinate system at material point
mat3d GetLocalCS(const FEMaterialPoint& mp) override;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfaceElement.h | .h | 7,209 | 259 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElement.h"
//-----------------------------------------------------------------------------
//! This class defines a surface element
class FECORE_API FESurfaceElement : public FEElement
{
public:
struct ELEMENT_REF {
FEElement* pe = nullptr; // solid element the surface is attached to (if any)
int face = -1; // local face index
int orient = 0; // orientation of surface element relative to solid element
void Reset()
{
pe = nullptr;
face = -1;
orient = 0;
}
};
public:
FESurfaceElement();
FESurfaceElement(const FESurfaceElement& el);
FESurfaceElement& operator = (const FESurfaceElement& el);
virtual void SetTraits(FEElementTraits* pt) override;
double* GaussWeights() { return &((FESurfaceElementTraits*)(m_pT))->gw[0]; } // weights of integration points
const double* GaussWeights() const { return &((FESurfaceElementTraits*)(m_pT))->gw[0]; } // weights of integration points
double gr(int n) const { return ((FESurfaceElementTraits*)(m_pT))->gr[n]; } // integration point coordinate r
double gs(int n) const { return ((FESurfaceElementTraits*)(m_pT))->gs[n]; } // integration point coordinate s
double cr() const { return ((FESurfaceElementTraits*)(m_pT))->cr; } // centroid point coordinate r
double cs() const { return ((FESurfaceElementTraits*)(m_pT))->cs; } // centroid point coordinate s
double* Gr(int n) const { return ((FESurfaceElementTraits*)(m_pT))->Gr[n]; } // shape function derivative to r
double* Gs(int n) const { return ((FESurfaceElementTraits*)(m_pT))->Gs[n]; } // shape function derivative to s
double eval(double* d, int n)
{
double* N = H(n);
int ne = Nodes();
double a = 0;
for (int i=0; i<ne; ++i) a += N[i]*d[i];
return a;
}
double eval(int order, double* d, int n)
{
double* N = H(order, n);
int ne = ShapeFunctions(order);
double a = 0;
for (int i = 0; i<ne; ++i) a += N[i] * d[i];
return a;
}
double eval(double* d, double r, double s)
{
int n = Nodes();
double H[FEElement::MAX_NODES];
shape_fnc(H, r, s);
double a = 0;
for (int i=0; i<n; ++i) a += H[i]*d[i];
return a;
}
double eval(int order, double* d, double r, double s)
{
int n = ShapeFunctions(order);
double H[FEElement::MAX_NODES];
shape_fnc(order, H, r, s);
double a = 0;
for (int i = 0; i<n; ++i) a += H[i] * d[i];
return a;
}
vec3d eval(vec3d* d, double r, double s)
{
int n = Nodes();
double H[FEElement::MAX_NODES];
shape_fnc(H, r, s);
vec3d a(0,0,0);
for (int i=0; i<n; ++i) a += d[i]*H[i];
return a;
}
vec3d eval(vec3d* d, int n)
{
int ne = Nodes();
double* N = H(n);
vec3d a(0,0,0);
for (int i=0; i<ne; ++i) a += d[i]*N[i];
return a;
}
double eval_deriv1(double* d, int j)
{
double* Hr = Gr(j);
int n = Nodes();
double s = 0;
for (int i=0; i<n; ++i) s += Hr[i]*d[i];
return s;
}
double eval_deriv1(int order, double* d, int j)
{
double* Hr = Gr(order, j);
int n = ShapeFunctions(order);
double s = 0;
for (int i = 0; i<n; ++i) s += Hr[i] * d[i];
return s;
}
double eval_deriv2(double* d, int j)
{
double* Hs = Gs(j);
int n = Nodes();
double s = 0;
for (int i=0; i<n; ++i) s += Hs[i]*d[i];
return s;
}
vec3d eval_deriv1(vec3d* d, int j)
{
double* Hr = Gr(j);
int n = Nodes();
vec3d v(0,0,0);
for (int i = 0; i<n; ++i) v += d[i]*Hr[i];
return v;
}
vec3d eval_deriv2(vec3d* d, int j)
{
double* Hs = Gs(j);
int n = Nodes();
vec3d v(0,0,0);
for (int i = 0; i<n; ++i) v += d[i]*Hs[i];
return v;
}
double eval_deriv1(double* d, double r, double s)
{
double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES];
shape_deriv(Hr, Hs, r, s);
int n = Nodes();
double a = 0;
for (int i = 0; i<n; ++i) a += Hr[i] * d[i];
return a;
}
double eval_deriv1(int order, double* d, double r, double s)
{
double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES];
shape_deriv(order, Hr, Hs, r, s);
int n = ShapeFunctions(order);
double a = 0;
for (int i=0; i<n; ++i) a += Hr[i]*d[i];
return a;
}
double eval_deriv2(double* d, double r, double s)
{
double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES];
shape_deriv(Hr, Hs, r, s);
int n = Nodes();
double a = 0;
for (int i=0; i<n; ++i) a += Hs[i]*d[i];
return a;
}
double eval_deriv2(int order, double* d, double r, double s)
{
double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES];
shape_deriv(order, Hr, Hs, r, s);
int n = ShapeFunctions(order);
double a = 0;
for (int i = 0; i<n; ++i) a += Hs[i] * d[i];
return a;
}
void shape_fnc(double* H, double r, double s)
{
((FESurfaceElementTraits*)m_pT)->shape_fnc(H, r, s);
}
void shape_deriv(double* Gr, double* Gs, double r, double s)
{
((FESurfaceElementTraits*)m_pT)->shape_deriv(Gr, Gs, r, s);
}
void shape_deriv(int order, double* Gr, double* Gs, double r, double s)
{
((FESurfaceElementTraits*)m_pT)->shape_deriv(order, Gr, Gs, r, s);
}
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s)
{
((FESurfaceElementTraits*)m_pT)->shape_deriv2(Grr, Grs, Gss, r, s);
}
void shape_fnc(int order, double* H, double r, double s)
{
((FESurfaceElementTraits*)m_pT)->shape_fnc(order, H, r, s);
}
//! return number of edges
int facet_edges() const;
//! return node list of edge
void facet_edge(int j, int* en) const;
// see if this element has the list of nodes n
int HasNodes(int* n, const int ns) const;
//! serialize
void Serialize(DumpStream& ar) override;
double* Gr(int order, int n) const;
double* Gs(int order, int n) const;
public:
//! local ID of surface element
int m_lid;
// indices of solid or shell element this surface is a face of
// For solids, a surface element can be connected to two elements
// if the surface is an inside surface. For boundary surfaces
// the second element index is -1.
ELEMENT_REF m_elem[2];
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDofList.h | .h | 2,673 | 91 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
#include <vector>
//-----------------------------------------------------------------------------
class FEModel;
class DumpStream;
//-----------------------------------------------------------------------------
// Convenience class for creating a list of degrees of freedom, without the
// need to go through the FEModel class;
class FECORE_API FEDofList
{
public:
FEDofList(FEModel* fem);
FEDofList(const FEDofList& dofs);
// assignment operator
void operator = (const FEDofList& dofs);
void operator = (const std::vector<int>& dofs);
// clear the list
void Clear();
// Add a degree of freedom
bool AddDof(const char* szdof);
// Add a degree of freedom
bool AddDof(int ndof);
// Add all the dofs of a variable
bool AddVariable(const char* szvar);
// Add all the dofs a variable
bool AddVariable(int nvar);
// Add degrees of freedom
bool AddDofs(const FEDofList& dofs);
// is the list empty
bool IsEmpty() const;
// number of dofs in the list
int Size() const;
// access a dof
int operator [] (int n) const;
// serialization
void Serialize(DumpStream& ar);
// see if this dof list contains all the dofs of a FEDofList
bool Contains(int dof);
bool Contains(const FEDofList& dof);
// Get the interpolation order
int InterpolationOrder(int index) const;
private:
FEModel* m_fem;
std::vector<int> m_dofList;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataGenerator.h | .h | 3,229 | 121 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEModelComponent.h"
class FENodeSet;
class FEEdgeList;
class FEFacetSet;
class FEElementSet;
class FEDataMap;
// Data generators are used to generate mesh data sections algorithmically
class FECORE_API FEMeshDataGenerator : public FEModelComponent
{
FECORE_SUPER_CLASS(FEMESHDATAGENERATOR_ID)
FECORE_BASE_CLASS(FEMeshDataGenerator)
public:
FEMeshDataGenerator(FEModel* fem);
virtual ~FEMeshDataGenerator();
// this function gives the data generator a chance to initialize itself
// and check for any input problems.
virtual bool Init();
// evaluate the data at specific time
virtual void Evaluate(double time);
// generate the mesh data section
virtual FEDataMap* Generate() = 0;
};
// class for generating data on node sets
class FECORE_API FENodeDataGenerator : public FEMeshDataGenerator
{
FECORE_BASE_CLASS(FENodeDataGenerator)
public:
FENodeDataGenerator(FEModel* fem);
void SetNodeSet(FENodeSet* nodeSet);
FENodeSet* GetNodeSet();
protected:
FENodeSet* m_nodeSet;
};
// class for generating data on edges
class FECORE_API FEEdgeDataGenerator : public FEMeshDataGenerator
{
FECORE_BASE_CLASS(FEEdgeDataGenerator)
public:
FEEdgeDataGenerator(FEModel* fem);
void SetEdgeList(FEEdgeList* edgeSet);
FEEdgeList* GetEdgeList();
protected:
FEEdgeList* m_edgeList;
};
// class for generating data on surfaces
class FECORE_API FEFaceDataGenerator : public FEMeshDataGenerator
{
FECORE_BASE_CLASS(FEFaceDataGenerator)
public:
FEFaceDataGenerator(FEModel* fem);
void SetFacetSet(FEFacetSet* surf);
FEFacetSet* GetFacetSet();
private:
FEFacetSet* m_surf;
};
// class for generating data on element sets
class FECORE_API FEElemDataGenerator : public FEMeshDataGenerator
{
FECORE_BASE_CLASS(FEElemDataGenerator)
public:
FEElemDataGenerator(FEModel* fem);
void SetElementSet(FEElementSet* elset);
FEElementSet* GetElementSet();
private:
FEElementSet* m_elemSet;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMaterialPoint.h | .h | 7,915 | 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.*/
#pragma once
#include "mat3d.h"
#include "quatd.h"
#include "FETimeInfo.h"
#include <vector>
class FEElement;
class FEMaterialPoint;
//-----------------------------------------------------------------------------
//! Material point class
//! This class implements the concept of a material point. This point carries
//! with it not only information about its location, both in the reference and
//! current configuration but also about the local deformation. In addition
//! it contains the state information that is associated with the current
//! point.
//!
class FECORE_API FEMaterialPointData
{
public:
FEMaterialPointData(FEMaterialPointData* ppt = 0);
virtual ~FEMaterialPointData();
public:
//! The init function is used to intialize data
virtual void Init();
//! The Update function is used to update material point data
//! Note that this gets called at the start of the time step during PreSolveUpdate
virtual void Update(const FETimeInfo& timeInfo);
//! copy material point data (for running restarts) \todo Is this still used?
virtual FEMaterialPointData* Copy() { return 0; }
// serialization
virtual void Serialize(DumpStream& ar);
public:
//! Get the next material point data
FEMaterialPointData* Next() { return m_pNext; }
//! Get the previous (parent) material point data
FEMaterialPointData* Prev() { return m_pPrev; }
// assign the previous pointer
void SetPrev(FEMaterialPointData* pt);
//! assign the next pointer
//! this also sets the prev pointer of the passed pointer
//! in other words, it makes this the parent of the passed pointer
void SetNext(FEMaterialPointData* pt);
//! append a material point
void Append(FEMaterialPointData* pt);
protected:
virtual int Components() const { return 0; }
virtual FEMaterialPoint* GetPointData(int i) { return nullptr; }
public:
//! Extract data (\todo Is it safe for a plugin to use this function?)
template <class T> T* ExtractData();
template <class T> const T* ExtractData() const;
protected:
FEMaterialPointData* m_pNext; //!< next data in the list
FEMaterialPointData* m_pPrev; //!< previous data in the list
friend class FEMaterialPoint;
};
//-----------------------------------------------------------------------------
class FECORE_API FEMaterialPoint
{
public:
FEMaterialPoint(FEMaterialPointData* data = nullptr);
virtual ~FEMaterialPoint();
// TODO: These functions copy nothing! They are only included because we need them to create vectors!
// I would like to delete these functions, but this means they cannot be used in vectors anymore.
FEMaterialPoint(const FEMaterialPoint&);
FEMaterialPoint& operator = (const FEMaterialPoint&);
//! The init function is used to intialize data
virtual void Init();
virtual FEMaterialPoint* Copy();
//! The Update function is used to update material point data
//! Note that this gets called at the start of the time step during PreSolveUpdate
virtual void Update(const FETimeInfo& timeInfo);
virtual void Serialize(DumpStream& ar);
void Append(FEMaterialPointData* pt);
public:
int Components() const { return (m_data ? m_data->Components() : 0); }
FEMaterialPoint* GetPointData(int i = 0)
{
if (m_data == nullptr) return this;
FEMaterialPoint* mp = m_data->GetPointData(i);
if (mp == nullptr) mp = this;
return mp;
}
public:
//! Extract data (\todo Is it safe for a plugin to use this function?)
template <class T> T* ExtractData();
template <class T> const T* ExtractData() const;
public:
vec3d m_r0; //!< material point position
vec3d m_rt; //!< current point position
double m_J0; //!< reference Jacobian
double m_Jt; //!< current Jacobian
quatd m_Q; //!< local coordinates
FEElement* m_elem; //!< Element where this material point is
int m_index; //!< local integration point index
// pointer to element's shape function values
double* m_shape;
protected:
FEMaterialPointData* m_data;
};
//-----------------------------------------------------------------------------
template <class T> inline T* FEMaterialPointData::ExtractData()
{
// first see if this is the correct type
T* p = dynamic_cast<T*>(this);
if (p) return p;
// check all the child classes
FEMaterialPointData* pt = this;
while (pt->m_pNext)
{
pt = pt->m_pNext;
p = dynamic_cast<T*>(pt);
if (p) return p;
}
// search up
pt = this;
while (pt->m_pPrev)
{
pt = pt->m_pPrev;
p = dynamic_cast<T*>(pt);
if (p) return p;
}
if (Components() > 0)
{
for (int i = 0; i < Components(); ++i)
{
FEMaterialPoint* mpi = GetPointData(i);
p = mpi->ExtractData<T>();
if (p) return p;
}
}
// Everything has failed. Material point data can not be found
return 0;
}
//-----------------------------------------------------------------------------
template <class T> inline const T* FEMaterialPointData::ExtractData() const
{
// first see if this is the correct type
const T* p = dynamic_cast<const T*>(this);
if (p) return p;
// check all the child classes
const FEMaterialPointData* pt = this;
while (pt->m_pNext)
{
pt = pt->m_pNext;
p = dynamic_cast<const T*>(pt);
if (p) return p;
}
// search up
pt = this;
while (pt->m_pPrev)
{
pt = pt->m_pPrev;
p = dynamic_cast<const T*>(pt);
if (p) return p;
}
// Everything has failed. Material point data can not be found
return 0;
}
//-----------------------------------------------------------------------------
template <class T> inline T* FEMaterialPoint::ExtractData()
{
return (m_data ? m_data->ExtractData<T>() : nullptr);
}
//-----------------------------------------------------------------------------
template <class T> inline const T* FEMaterialPoint::ExtractData() const
{
return (m_data ? m_data->ExtractData<T>() : nullptr);
}
//-----------------------------------------------------------------------------
// Material point base class for materials that define vector properties
class FECORE_API FEMaterialPointArray : public FEMaterialPointData
{
public:
FEMaterialPointArray(FEMaterialPointData* ppt = nullptr);
//! initialization
void Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
//! material point update
void Update(const FETimeInfo& timeInfo) override;
public:
//! Add a child material point
void AddMaterialPoint(FEMaterialPoint* pt);
//! get the number of material point components
int Components() const override { return (int)m_mp.size(); }
//! retrieve point data
FEMaterialPoint* GetPointData(int i) override { return m_mp[i]; }
protected:
std::vector<FEMaterialPoint*> m_mp; //!< material point data for indidivual properties
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEModelDataRecord.h | .h | 2,085 | 58 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "DataRecord.h"
//-----------------------------------------------------------------------------
//! This is the base class for a model data
class FECORE_API FEModelLogData : public FELogData
{
FECORE_SUPER_CLASS(FELOGMODELDATA_ID)
FECORE_BASE_CLASS(FEModelLogData)
public:
FEModelLogData(FEModel* fem);
virtual ~FEModelLogData();
virtual double value() = 0;
};
//-----------------------------------------------------------------------------
//! This class records model data
class FECORE_API FEModelDataRecord : public DataRecord
{
public:
FEModelDataRecord(FEModel* pfem);
double Evaluate(int item, int ndata);
void SetData(const char* sz);
void ClearData();
void SelectAllItems();
int Size() const;
private:
std::vector<FEModelLogData*> m_data;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/eig3.h | .h | 1,448 | 32 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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
// Symmetric matrix A => eigenvectors in columns of V, corresponding eigenvalues in d.
void eigen_decomposition(double A[3][3], double V[3][3], double d[3]);
| Unknown |
3D | febiosoftware/FEBio | FECore/MatrixOperator.h | .h | 1,599 | 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 "fecore_api.h"
// abstract base class for matrix operators, i.e. a class that can calculate a matrix-vector product
class FECORE_API MatrixOperator
{
public:
MatrixOperator() {}
virtual ~MatrixOperator() {}
// calculate the product Ax = y
virtual bool mult_vector(double* x, double* y) = 0;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/NLConstraintDataRecord.cpp | .cpp | 2,913 | 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 "NLConstraintDataRecord.h"
#include "FECoreKernel.h"
#include "FEModel.h"
//-----------------------------------------------------------------------------
void NLConstraintDataRecord::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;
FELogNLConstraintData* pdata = fecore_new<FELogNLConstraintData>(sz, GetFEModel());
if (pdata) m_Data.push_back(pdata);
else throw UnknownDataField(sz);
sz = ch;
}
while (ch);
}
//-----------------------------------------------------------------------------
NLConstraintDataRecord::NLConstraintDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_NLC) {}
//-----------------------------------------------------------------------------
int NLConstraintDataRecord::Size() const { return (int)m_Data.size(); }
//-----------------------------------------------------------------------------
double NLConstraintDataRecord::Evaluate(int item, int ndata)
{
FEModel* fem = GetFEModel();
int nc = item - 1;
if ((nc < 0) || (nc >= fem->NonlinearConstraints())) return 0;
FENLConstraint& nlc = *fem->NonlinearConstraint(nc);
return m_Data[ndata]->value(nlc);
}
//-----------------------------------------------------------------------------
void NLConstraintDataRecord::SelectAllItems()
{
FEModel* fem = GetFEModel();
int n = fem->NonlinearConstraints();
m_item.resize(n);
for (int i = 0; i<n; ++i) m_item[i] = i + 1;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEElementLibrary.h | .h | 3,217 | 94 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_enum.h"
#include "fecore_api.h"
class FEElement;
class FEElementTraits;
class FEElementShape;
//-----------------------------------------------------------------------------
//! This class stores the different element traits classes
//! The purpose of this class is to store all the different element traits classes.
//! It are these traits classes that define the different element types. All different
//! traits must be registered before they can be assigned to elements.
class FECORE_API FEElementLibrary
{
public:
//! destructor
~FEElementLibrary();
//! return the element library
static FEElementLibrary* GetInstance();
//! Assign a traits class to an element
static void SetElementTraits(FEElement& el, int id);
//! return element traits data
static FEElementTraits* GetElementTraits(int ntype);
//! return element shape class
static FEElementShape* GetElementShapeClass(FE_Element_Shape eshape);
//! return the element shape of a given element type
static FE_Element_Shape GetElementShape(int ntype);
//! return the element class of a given element type
static FE_Element_Class GetElementClass(int ntype);
//! checks if the element spec is valid
static bool IsValid(const FE_Element_Spec& c);
//! initialize library
static void Initialize();
//! get the element spec from the type
static FE_Element_Spec GetElementSpecFromType(FE_Element_Type elemType);
private:
//! constructor
FEElementLibrary(){}
FEElementLibrary(const FEElementLibrary&){}
//! Function to register an element shape class
int RegisterShape(FEElementShape* pshape);
//! Function to register an element traits class
int RegisterTraits(FEElementTraits* ptrait);
private:
std::vector<FEElementTraits*> m_Traits; //!< pointer to registered element traits
std::vector<FEElementShape*> m_Shape; //!< pointer to registered element shapes
static FEElementLibrary* m_pThis;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESPRProjection.cpp | .cpp | 8,546 | 299 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FESPRProjection.h"
#include "FESolidDomain.h"
#include "FEMesh.h"
using namespace std;
FESPRProjection::FESPRProjection(FESolidDomain& dom, int interpolationOrder) : m_dom(dom)
{
m_p = interpolationOrder;
Init();
}
void FESPRProjection::Init()
{
FESolidDomain& dom = m_dom;
// build the node-element-list. This will define our patches
NEL.Create(dom);
// get the mesh
FEMesh& mesh = *dom.GetMesh();
int NN = dom.Nodes();
// check element type
int NDOF = -1; // number of degrees of freedom of polynomial
int NCN = -1; // number of corner nodes
int nshape = dom.GetElementShape();
switch (nshape)
{
case ET_TET4:
case ET_TET5 : { NDOF = 4; NCN = 4; } break;
case ET_TET10: { NDOF = (m_p == 1 ? 4 : 10); NCN = 4; } break;
case ET_TET15: { NDOF = (m_p == 1 ? 4 : 10); NCN = 4; } break;
case ET_TET20: { NDOF = 10; NCN = 4; } break;
case ET_HEX8 : { NDOF = 7; NCN = 8; } break;
case ET_HEX20: { NDOF = (m_p == 1 ? 7 : 10); NCN = 8; } break;
case ET_HEX27: { NDOF = (m_p == 1 ? 7 : 10); NCN = 8; } break;
default:
return;
}
// we keep a tag array to keep track of which nodes we processed
int NM = mesh.Nodes();
vector<int> tag; tag.assign(NM, 0);
// for higher order elements
// we need to make sure that we don't process the edge nodes
// we assume here that the first NCN nodes of the element
// are the corner nodes and that all other nodes are edge or interior nodes
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int ne = el.Nodes();
for (int j = NCN; j < ne; ++j) tag[el.m_node[j]] = 2;
}
// loop over all nodes
m_valence.assign(NN, 0);
m_Ai.resize(NN);
#pragma omp parallel for schedule(static)
for (int i = 0; i < NN; ++i)
{
// get the node
FENode& node = dom.Node(i);
int in = dom.NodeIndex(i);
// don't loop over edge nodes (edge or interior nodes have a tag > 1)
if (tag[in] <= 1)
{
// get the nodal position
vec3d rc = node.m_rt;
// get the element patch
int ne = NEL.Valence(in);
FEElement** ppe = NEL.ElementList(in);
int* pei = NEL.ElementIndexList(in);
// setup the A-matrix
vector<double> pk(NDOF);
matrix A(NDOF, NDOF); A.zero();
int m = 0;
for (int j = 0; j < ne; ++j)
{
FEElement& el = *(ppe[j]);
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n, ++m)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
vec3d r = mp.m_rt - rc;
pk[0] = 1.0; pk[1] = r.x; pk[2] = r.y; pk[3] = r.z;
if (NDOF >= 7) { pk[4] = r.x * r.y; pk[5] = r.y * r.z; pk[6] = r.x * r.z; }
if (NDOF >= 10) { pk[7] = r.x * r.x; pk[8] = r.y * r.y; pk[9] = r.z * r.z; }
A += outer_product(pk);
}
}
// invert matrix and make sure condition number is good enough
matrix Ai = A.inverse();
m_Ai[i] = Ai;
m_valence[i] = m;
}
}
}
//! Projects the integration point data, stored in d, onto the nodes of the domain.
//! The result is stored in o.
void FESPRProjection::Project(const vector< vector<double> >& d, vector<double>& o)
{
FESolidDomain& dom = m_dom;
// get the mesh
FEMesh& mesh = *dom.GetMesh();
int NN = dom.Nodes();
// allocate output array
o.assign(NN, 0.0);
// check element type
int NDOF = -1; // number of degrees of freedom of polynomial
int NCN = -1; // number of corner nodes
int nshape = dom.GetElementShape();
switch (nshape)
{
case ET_TET4:
case ET_TET5: { NDOF = 4; NCN = 4; } break;
case ET_TET10: { NDOF = (m_p == 1 ? 4 : 10); NCN = 4; } break;
case ET_TET15: { NDOF = (m_p == 1 ? 4 : 10); NCN = 4; } break;
case ET_TET20: { NDOF = 10; NCN = 4; } break;
case ET_HEX8: { NDOF = 7; NCN = 8; } break;
case ET_HEX20: { NDOF = (m_p == 1 ? 7 : 10); NCN = 8; } break;
case ET_HEX27: { NDOF = (m_p == 1 ? 7 : 10); NCN = 8; } break;
default:
return;
}
// we keep a tag array to keep track of which nodes we processed
int NM = mesh.Nodes();
vector<int> tag; tag.assign(NM, 0);
// for higher order elements
// we need to make sure that we don't process the edge nodes
// we assume here that the first NCN nodes of the element
// are the corner nodes and that all other nodes are edge or interior nodes
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int ne = el.Nodes();
for (int j = NCN; j < ne; ++j) tag[el.m_node[j]] = 2;
}
// this array will store the results
vector<double> val;
val.assign(NM, 0.0);
// loop over all nodes
for (int i = 0; i < NN; ++i)
{
// get the node
FENode& node = dom.Node(i);
int in = dom.NodeIndex(i);
// don't loop over edge nodes (edge or interior nodes have a tag > 1)
if (tag[in] <= 1)
{
// get the nodal position
vec3d rc = node.m_rt;
// get the element patch
int ne = NEL.Valence(in);
FEElement** ppe = NEL.ElementList(in);
int* pei = NEL.ElementIndexList(in);
vector<double> pk(NDOF);
int m = m_valence[i];
matrix Ai = m_Ai[i];
// make sure we have enough sampling points
if (m > NDOF + 1)
{
vector<double> b; b.assign(NDOF, 0.0);
for (int j = 0; j < ne; ++j)
{
FEElement& el = *(ppe[j]);
const vector<double>& ed = d[pei[j]];
assert(ppe[j] == &dom.Element(pei[j]));
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
vec3d r = mp.m_rt - rc;
pk[0] = 1.0; pk[1] = r.x; pk[2] = r.y; pk[3] = r.z;
if (NDOF >= 7) { pk[4] = r.x * r.y; pk[5] = r.y * r.z; pk[6] = r.x * r.z; }
if (NDOF >= 10) { pk[7] = r.x * r.x; pk[8] = r.y * r.y; pk[9] = r.z * r.z; }
double s = ed[n];
for (int k = 0; k < NDOF; k++) b[k] += s * pk[k];
}
}
// solve the linear system
vector<double> c = Ai * b;
// tag this node as processed
tag[in] = 1;
// store result
val[in] = c[0];
// loop over all unprocessed nodes of this patch
for (int j = 0; j < ne; ++j)
{
FEElement& el = *(ppe[j]);
int en = el.Nodes();
for (int k = 0; k < en; ++k)
{
int em = el.m_node[k];
if (tag[em] != 1)
{
vec3d r = mesh.Node(em).m_rt - rc;
pk[0] = 1.0; pk[1] = r.x; pk[2] = r.y; pk[3] = r.z;
if (NDOF >= 7) { pk[4] = r.x * r.y; pk[5] = r.y * r.z; pk[6] = r.x * r.z; }
if (NDOF >= 10) { pk[7] = r.x * r.x; pk[8] = r.y * r.y; pk[9] = r.z * r.z; }
// calculate the value for this node
double v = 0;
for (int l = 0; l < NDOF; ++l) v += pk[l] * c[l];
// for edge nodes, we need to keep track of how often we visit this node
// Therefore we increment the tag.
// (remember that the tag started at 2 for edge/interior nodes)
{
if (tag[em] >= 2)
{
tag[em]++;
val[em] += v;
}
else val[em] = v;
}
}
}
}
}
}
}
// copy results to archive
for (int i = 0; i < NN; ++i)
{
int in = dom.NodeIndex(i);
double s = val[in];
// for edge nodes we need to average
// (remember that the tag started at 2 for edge/interior nodes)
if (tag[in] >= 2)
{
// assert(tag[in] > 2); // all edges nodes must be visited at least once!
int l = tag[in] - 2;
if (l > 0) s /= (double)(l);
}
o[i] = s;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/MExpand.cpp | .cpp | 6,982 | 297 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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;
//-----------------------------------------------------------------------------
MITEM MExpand(const MITEM& i)
{
return MExpand(i, MITEM((MItem*)0));
}
//-----------------------------------------------------------------------------
MITEM MExpand(const MITEM& i, const MITEM& s)
{
if (i == s) return i;
MITEM e = MEvaluate(i);
switch (e.Type())
{
case MFRAC:
{
FRACTION f = mfrac(i)->fraction();
if (f.d == 1.0) return f.n;
}
break;
case MNEG: return -MExpand(e.Item(),s);
case MMUL:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_add(r)&&(s != r))
{
MITEM a = r.Left();
MITEM b = r.Right();
return MExpand(l*a,s) + MExpand(l*b,s);
}
if (is_sub(r)&&(s != r))
{
MITEM a = r.Left();
MITEM b = r.Right();
return MExpand(l*a,s) - MExpand(l*b,s);
}
if (is_add(l)&&(s != l))
{
MITEM a = l.Left();
MITEM b = l.Right();
return MExpand(r*a,s) + MExpand(r*b,s);
}
if (is_sub(l)&&(s != l))
{
MITEM a = l.Left();
MITEM b = l.Right();
return MExpand(r*a,s) - MExpand(r*b,s);
}
MITEM Ml = MExpand(l,s);
MITEM Mr = MExpand(r,s);
// if ((l != Ml) || (r != Mr)) return Ml*Mr;
if ((l != Ml) || (r != Mr)) return MExpand(Ml*Mr,s); // it looks like this could create an infinite loop
}
break;
case MDIV:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_add(l)&&(s != l))
{
MITEM a = l.Left();
MITEM b = l.Right();
return MExpand(a/r,s) + MExpand(b/r,s);
}
if (is_sub(l)&&(s != l))
{
MITEM a = l.Left();
MITEM b = l.Right();
return MExpand(a/r,s) - MExpand(b/r,s);
}
MITEM Ml = MExpand(l,s);
MITEM Mr = MExpand(r, s);
if ((l != Ml) || (r != Mr)) return MExpand(Ml/Mr,s); else return Ml/Mr;
}
break;
case MADD:
{
MITEM l = e.Left();
MITEM r = e.Right();
return MExpand(l,s) + MExpand(r,s);
}
break;
case MSUB:
{
MITEM l = e.Left();
MITEM r = e.Right();
return MExpand(l,s) - MExpand(r,s);
}
break;
case MPOW:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_int(r) && is_add(l) && (l != s))
{
MITEM a = l.Left();
MITEM b = l.Right();
int n = (int) r.value();
if (n == 0) return 1.0;
MITEM sum(0.0);
for (int i=0; i<=n; ++i)
{
double C = binomial(n,i);
sum = sum + C*MExpand(a^(n-i),s)*MExpand(b^i,s);
}
return sum;
}
if (is_int(r) && is_sub(l))
{
MITEM a = l.Left();
MITEM b = l.Right();
int n = (int) r.value();
if (n == 0) return 1.0;
MITEM sum(0.0);
for (int i=0; i<=n; ++i)
{
double C = binomial(n,i);
MITEM t = C*MExpand(a^(n-i),s)*MExpand(b^i,s);
if (i%2 == 0) sum = sum + t;
else sum = sum - t;
}
return sum;
}
if (is_add(r) && (r != s))
{
MITEM a = r.Left();
MITEM b = r.Right();
return ((l^a)*(l^b));
}
MITEM le = MExpand(l);
MITEM re = MExpand(r);
return le^re;
}
break;
case MF1D:
{
const string& f = mfnc1d(e)->Name();
if (f.compare("cos") == 0)
{
MITEM p = e.Param();
if (p.Type() == MADD)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand(Cos(a)*Cos(b) - Sin(a)*Sin(b),s);
}
if (p.Type() == MSUB)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand(Cos(a)*Cos(b) + Sin(a)*Sin(b),s);
}
}
if (f.compare("sin") == 0)
{
MITEM p = e.Param();
if (p.Type() == MADD)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand(Sin(a)*Cos(b) + Cos(a)*Sin(b),s);
}
if (p.Type() == MSUB)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand(Sin(a)*Cos(b) - Cos(a)*Sin(b),s);
}
}
if (f.compare("tan") == 0)
{
MITEM p = e.Param();
if (p.Type() == MADD)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand((Tan(a)+Tan(b))/(1.0 - Tan(a)*Tan(b)),s);
}
if (p.Type() == MSUB)
{
MITEM a = p.Left();
MITEM b = p.Right();
return MExpand((Tan(a)-Tan(b))/(1.0 + Tan(a)*Tan(b)),s);
}
}
/* if (f.compare("ln") == 0)
{
MITEM p = e.Param();
if (is_mul(p))
{
MITEM a = MExpand(p.Left());
MITEM b = MExpand(p.Right());
return MExpand(Log(a)+Log(b));
}
if (is_div(p))
{
MITEM a = MExpand(p.Left());
MITEM b = MExpand(p.Right());
return MExpand(Log(a)-Log(b));
}
if (is_pow(p))
{
MITEM a = MExpand(p.Left());
MITEM b = MExpand(p.Right());
return MExpand(b*Log(a));
}
}
*/ const MFunc1D* pf = mfnc1d(e);
MITEM v = MExpand(e.Param(), s);
return new MFunc1D(pf->funcptr(), pf->Name(), v.copy());
}
break;
case MSFNC:
{
MITEM f(msfncnd(i)->Value()->copy());
return MExpand(f, s);
}
break;
case MEQUATION:
{
MITEM l = e.Left();
MITEM r = e.Right();
MITEM Ml = MExpand(l,s);
MITEM Mr = MExpand(r,s);
return new MEquation(Ml.copy(), Mr.copy());
}
break;
case MSEQUENCE:
{
const MSequence& q = *msequence(i);
MSequence* ps = new MSequence();
for (int i=0; i<q.size(); ++i)
{
MITEM qi = q[i]->copy();
MITEM vi = MExpand(qi, s);
ps->add(vi.copy());
}
return ps;
}
break;
case MMATRIX:
{
const MMatrix& m = *mmatrix(e);
int ncol = m.columns();
int nrow = m.rows();
MMatrix* pdm = new MMatrix;
pdm->Create(nrow, ncol);
for (int i=0; i<nrow; ++i)
for (int j=0; j<ncol; ++j)
{
MITEM mij(m.Item(i,j)->copy());
MITEM aij = MExpand(mij, s);
(*pdm)[i][j] = aij.copy();
}
return MITEM(pdm);
}
break;
}
return e;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEParameterList.h | .h | 9,265 | 245 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec2d.h"
#include "vec3d.h"
#include "mat3d.h"
#include <assert.h>
#include <list>
#include <memory>
#include "FEParam.h"
#include "FEParamValidator.h"
#include "ParamString.h"
#include "fecore_api.h"
#include <stdio.h>
using namespace std;
//-----------------------------------------------------------------------------
class DumpStream;
class FEParamContainer;
class FEParamDouble;
class FEParamVec3;
class FEParamMat3d;
class FEParamMat3ds;
class FEDataArray;
class tens3drs;
class FEMaterialPointProperty;
//-----------------------------------------------------------------------------
typedef std::list<FEParam>::iterator FEParamIterator;
typedef std::list<FEParam>::const_iterator FEParamIteratorConst;
//-----------------------------------------------------------------------------
//! A list of material parameters
class FECORE_API FEParameterList
{
public:
FEParameterList(FEParamContainer* pc);
virtual ~FEParameterList();
//! assignment operator
void operator = (FEParameterList& l);
//! Add a parameter to the list
FEParam* AddParameter(void* pv, FEParamType itype, int ndim, const char* sz, bool* watch = nullptr);
//! Add a parameter to the list
FEParam* AddParameter(void* pv, FEParamType type, int ndim, FEParamRange rng, double fmin, double fmax, const char* sz);
//! find a parameter using the data pointer
FEParam* FindFromData(void* pv);
//! find a parameter using its name (the safe way)
FEParam* FindFromName(const char* sz);
//! get a parameter (the dangerous way)
FEParam& operator [] (const char* sz) { return *FindFromName(sz); }
//! returs the first parameter
FEParamIterator first() { return m_pl.begin(); }
//! returs the first parameter
FEParamIteratorConst first() const { return m_pl.begin(); }
//! number of parameters
int Parameters() const { return (int) m_pl.size(); }
//! return the parameter container
FEParamContainer* GetContainer() { return m_pc; }
public:
int SetActiveGroup(const char* szgroup);
int GetActiveGroup();
int ParameterGroups() const;
const char* GetParameterGroupName(int i);
protected:
FEParamContainer* m_pc; //!< parent container
std::list<FEParam> m_pl; //!< the actual parameter list
std::vector<const char*> m_pg; //!< parameter groups
int m_currentGroup; //!< active parameter group (new parameters are assigned to the current group; can be -1)
};
//-----------------------------------------------------------------------------
//! Base class for classes that wish to support parameter lists
class FECORE_API FEParamContainer
{
public:
//! constructor
FEParamContainer();
//! destructor
virtual ~FEParamContainer();
//! return the material's parameter list
FEParameterList& GetParameterList();
const FEParameterList& GetParameterList() const;
//! find a parameter using it's name
virtual FEParam* GetParameter(const char* szname);
virtual FEParam* FindParameter(const ParamString& s);
//! find a parameter using a pointer to the variable
virtual FEParam* FindParameterFromData(void* pv);
//! serialize parameter data
virtual void Serialize(DumpStream& ar);
//! validate material parameters.
//! This function returns false on the first parameter encountered
//! that is not valid (i.e. is outside its defined range).
//! Overload this function to do additional validation. Make sure to always call the base class.
//! Use fecore_get_error_string() to find out which parameter failed validation.
virtual bool Validate();
public:
//! This copies the state of a parameter list (i.e. assigned load curve IDs)
//! This function assumes that there is a one-to-one correspondence between
//! source and target parameter lists.
void CopyParameterListState(const FEParameterList& pl);
public:
void BeginParameterGroup(const char* szname);
void EndParameterGroup();
public:
//! This function will be overridden by each class that defines a parameter list
virtual void BuildParamList();
//! Add a parameter to the list
FEParam* AddParameter(void* pv, FEParamType itype, int ndim, const char* sz, bool* watch = nullptr);
//! Add a parameter to the list
FEParam* AddParameter(void* pv, FEParamType type, int ndim, RANGE rng, const char* sz);
public:
FEParam* AddParameter(int& v, const char* sz);
FEParam* AddParameter(bool& v, const char* sz);
FEParam* AddParameter(double& v, const char* sz);
FEParam* AddParameter(vec2d& v, const char* sz);
FEParam* AddParameter(vec3d& v, const char* sz);
FEParam* AddParameter(mat3d& v, const char* sz);
FEParam* AddParameter(mat3ds& v, const char* sz);
FEParam* AddParameter(FEParamDouble& v, const char* sz);
FEParam* AddParameter(FEParamVec3& v, const char* sz);
FEParam* AddParameter(FEParamMat3d& v, const char* sz);
FEParam* AddParameter(FEParamMat3ds& v, const char* sz);
FEParam* AddParameter(FEDataArray& v, const char* sz);
FEParam* AddParameter(tens3drs& v, const char* sz);
FEParam* AddParameter(std::string& v, const char* sz);
FEParam* AddParameter(std::vector<int>& v , const char* sz);
FEParam* AddParameter(std::vector<double>& v, const char* sz);
FEParam* AddParameter(std::vector<vec2d>& v, const char* sz);
FEParam* AddParameter(std::vector<std::string>& v, const char* sz);
FEParam* AddParameter(FEMaterialPointProperty& v, const char* sz);
FEParam* AddParameter(int& v, RANGE rng, const char* sz);
FEParam* AddParameter(double& v, RANGE rng, const char* sz);
FEParam* AddParameter(FEParamDouble& v, RANGE rng, const char* sz);
FEParam* AddParameter(double& v, const char* sz, bool& watch);
FEParam* AddParameter(int* v, int ndim, const char* sz);
FEParam* AddParameter(double* v, int ndim, const char* sz);
FEParam* AddParameter(FEParamDouble* v, int ndim, const char* sz);
FEParam* AddParameter(int* v, int ndim, RANGE rng, const char* sz);
FEParam* AddParameter(double* v, int ndim, RANGE rng, const char* sz);
FEParam* AddParameter(FEParamDouble* v, int ndim, RANGE rng, const char* sz);
FEParam* AddParameter(int& v, const char* sz, unsigned int flags, const char* szenum);
FEParam* AddParameter(std::vector<int>& v, const char* sz, unsigned int flags, const char* szenum);
FEParam* AddParameter(std::string& s, const char* sz, unsigned int flags, const char* szenum = nullptr);
template <typename T> bool SetParameter(const char* sz, T v);
private:
FEParameterList* m_pParam; //!< parameter list
};
//-----------------------------------------------------------------------------
template <typename T> bool FEParamContainer::SetParameter(const char* sz, T v)
{
FEParam* p = m_pParam->FindFromName(sz);
if (p) p->value<T>() = v;
return (p != nullptr);
}
//-----------------------------------------------------------------------------
// To add parameter list to a class, simply do the following two steps
// 1) add the DECLARE_FECORE_CLASS macro in the material class declaration
// 2) use the BEGIN_FECORE_CLASS, ADD_PARAM and END_FECORE_CLASS to
// define a parameter list
// the following macro declares the parameter list for a material
#define DECLARE_FECORE_CLASS() \
public: void BuildParamList() override;
#define FECORE_BASE_CLASS(theClass) \
public: static const char* BaseClassName() { return #theClass; } \
// the BEGIN_FECORE_CLASS defines the beginning of a parameter list
#define BEGIN_FECORE_CLASS(theClass, baseClass) \
void theClass::BuildParamList() { \
baseClass::BuildParamList(); \
// the ADD_PARAMETER macro adds a parameter to the parameter list
#define ADD_PARAMETER(...) \
AddParameter(__VA_ARGS__)
// the END_FECORE_CLASS defines the end of a parameter list
#define END_FECORE_CLASS() \
}
// macro for starting a parameter group
#define BEGIN_PARAM_GROUP(a) BeginParameterGroup(a)
// macro for ending a parameter group
#define END_PARAM_GROUP() EndParameterGroup()
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataArray.h | .h | 9,148 | 317 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <assert.h>
#include <string>
#include "vec3d.h"
#include "vec2d.h"
#include "mat3d.h"
#include "fecore_api.h"
#include "fecore_enum.h"
#include "fecore_type.h"
//-----------------------------------------------------------------------------
class DumpStream;
//-----------------------------------------------------------------------------
class FECORE_API FEDataArray
{
public:
//! default constructor
FEDataArray(FEDataMapType mapType, FEDataType dataType);
virtual ~FEDataArray();
public:
virtual void setValue(int n, double v) = 0;
virtual void setValue(int n, const vec2d& v) = 0;
virtual void setValue(int n, const vec3d& v) = 0;
virtual void setValue(int n, const mat3d& v) = 0;
virtual void setValue(int n, const mat3ds& v) = 0;
virtual void fillValue(double v) = 0;
virtual void fillValue(const vec2d& v) = 0;
virtual void fillValue(const vec3d& v) = 0;
virtual void fillValue(const mat3d& v) = 0;
virtual void fillValue(const mat3ds& v) = 0;
public:
//! get the value for a given facet index
template <class T> T get(int n) const;
//! set the value
template <class T> bool set(const T& v);
//! set the value
template <class T> bool set(int n, const T& v);
//! add a value
template <class T> void push_back(const T& v);
//! allocate data
bool resize(int nsize, double val = 0.0);
bool realloc(int nsize);
//! set the data sized
void SetDataSize(int dataSize);
public:
//! get the data type
FEDataType DataType() const { return m_dataType; }
//! get the map type
FEDataMapType DataMapType() const { return m_mapType; }
//! get data size
int DataSize() const { return m_dataSize; }
// number of data items
int DataCount() const { return m_dataCount; }
//! return the buffer size (actual number of doubles)
int BufferSize() const { return (int) m_val.size(); }
public:
//! serialization
virtual void Serialize(DumpStream& ar);
static void SaveClass(DumpStream& ar, FEDataArray* p);
static FEDataArray* LoadClass(DumpStream& ar, FEDataArray* p);
protected:
//! copy constructor
FEDataArray(const FEDataArray& map);
//! assignment operator
FEDataArray& operator = (const FEDataArray& map);
private:
FEDataMapType m_mapType; //!< the map type
FEDataType m_dataType; //!< the data type
int m_dataSize; //!< size of each data item
int m_dataCount; //!< number of data items
std::vector<double> m_val; //!< data values
};
template <> inline double FEDataArray::get<double>(int n) const
{
assert(m_dataSize == fecoreType<double>::size());
return m_val[n];
}
template <> inline vec2d FEDataArray::get<vec2d>(int n) const
{
assert(m_dataSize == fecoreType<vec2d>::size());
return vec2d(m_val[2*n], m_val[2*n+1]);
}
template <> inline vec3d FEDataArray::get<vec3d>(int n) const
{
assert(m_dataSize == fecoreType<vec3d>::size());
return vec3d(m_val[3*n], m_val[3*n + 1], m_val[3*n+2]);
}
template <> inline mat3d FEDataArray::get<mat3d>(int n) const
{
assert(m_dataSize == fecoreType<mat3d>::size());
const double* v = &(m_val[9*n]);
return mat3d(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]);
}
template <> inline mat3ds FEDataArray::get<mat3ds>(int n) const
{
assert(m_dataSize == fecoreType<mat3ds>::size());
const double* v = &(m_val[6 * n]);
return mat3ds(v[0], v[1], v[2], v[3], v[4], v[5]);
}
template <> inline void FEDataArray::push_back<double>(const double& v)
{
assert(m_dataSize == fecoreType<double>::size());
m_val.push_back(v);
m_dataCount++;
}
template <> inline void FEDataArray::push_back<vec2d>(const vec2d& v)
{
assert(m_dataSize == fecoreType<vec2d>::size());
m_val.push_back(v.x());
m_val.push_back(v.y());
m_dataCount++;
}
template <> inline void FEDataArray::push_back<vec3d>(const vec3d& v)
{
assert(m_dataSize == fecoreType<vec3d>::size());
m_val.push_back(v.x);
m_val.push_back(v.y);
m_val.push_back(v.z);
m_dataCount++;
}
template <> inline void FEDataArray::push_back<mat3d>(const mat3d& v)
{
assert(m_dataSize == fecoreType<mat3d>::size());
m_val.push_back(v[0][0]); m_val.push_back(v[0][1]); m_val.push_back(v[0][2]);
m_val.push_back(v[1][0]); m_val.push_back(v[1][1]); m_val.push_back(v[1][2]);
m_val.push_back(v[2][0]); m_val.push_back(v[2][1]); m_val.push_back(v[2][2]);
m_dataCount++;
}
template <> inline void FEDataArray::push_back<mat3ds>(const mat3ds& v)
{
assert(m_dataSize == fecoreType<mat3ds>::size());
m_val.push_back(v.xx());
m_val.push_back(v.yy());
m_val.push_back(v.zz());
m_val.push_back(v.xy());
m_val.push_back(v.yz());
m_val.push_back(v.xz());
m_dataCount++;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<double>(int n, const double& v)
{
assert(m_dataSize == fecoreType<double>::size());
m_val[n] = v;
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<vec2d>(int n, const vec2d& v)
{
assert(m_dataSize == fecoreType<vec2d>::size());
m_val[2 * n] = v.x();
m_val[2 * n + 1] = v.y();
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<vec3d>(int n, const vec3d& v)
{
assert(m_dataSize == fecoreType<vec3d>::size());
m_val[3 * n] = v.x;
m_val[3 * n + 1] = v.y;
m_val[3 * n + 2] = v.z;
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<mat3d>(int n, const mat3d& v)
{
assert(m_dataSize == fecoreType<mat3d>::size());
double* d = &(m_val[9 * n]);
d[0] = v[0][0]; d[1] = v[0][1]; d[2] = v[0][2];
d[3] = v[1][0]; d[4] = v[1][1]; d[5] = v[1][2];
d[6] = v[2][0]; d[7] = v[2][1]; d[8] = v[2][2];
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<mat3ds>(int n, const mat3ds& v)
{
assert(m_dataSize == fecoreType<mat3ds>::size());
double* d = &(m_val[6 * n]);
d[0] = v.xx();
d[1] = v.yy();
d[2] = v.zz();
d[3] = v.xy();
d[4] = v.yz();
d[5] = v.xz();
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<double>(const double& v)
{
assert(m_dataSize == fecoreType<double>::size());
for (int i = 0; i<(int)m_val.size(); ++i) m_val[i] = v;
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<vec2d>(const vec2d& v)
{
assert(m_dataSize == fecoreType<vec2d>::size());
for (int i = 0; i<(int)m_val.size(); i += 2)
{
m_val[i] = v.x();
m_val[i + 1] = v.y();
}
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<vec3d>(const vec3d& v)
{
assert(m_dataSize == fecoreType<vec3d>::size());
for (int i = 0; i<(int)m_val.size(); i += 3)
{
m_val[i] = v.x;
m_val[i + 1] = v.y;
m_val[i + 2] = v.z;
}
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<mat3d>(const mat3d& v)
{
assert(m_dataSize == fecoreType<mat3d>::size());
for (int i = 0; i<(int)m_val.size(); i += 9)
{
double* d = &m_val[i];
d[0] = v[0][0]; d[1] = v[0][1]; d[2] = v[0][2];
d[3] = v[1][0]; d[4] = v[1][1]; d[5] = v[1][2];
d[6] = v[2][0]; d[7] = v[2][1]; d[8] = v[2][2];
}
return true;
}
//-----------------------------------------------------------------------------
template <> inline bool FEDataArray::set<mat3ds>(const mat3ds& v)
{
assert(m_dataSize == fecoreType<mat3ds>::size());
for (int i = 0; i < (int)m_val.size(); i += 6)
{
double* d = &m_val[i];
d[0] = v.xx();
d[1] = v.yy();
d[2] = v.zz();
d[3] = v.xy();
d[4] = v.yz();
d[5] = v.xz();
}
return true;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/DataStore.cpp | .cpp | 2,179 | 70 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "DataStore.h"
#include "log.h"
#include "FEModel.h"
#include "FEAnalysis.h"
//-----------------------------------------------------------------------------
DataStore::DataStore()
{
}
//-----------------------------------------------------------------------------
DataStore::~DataStore()
{
}
//-----------------------------------------------------------------------------
void DataStore::Clear()
{
for (size_t i=0; i<m_data.size(); ++i) delete m_data[i];
m_data.clear();
}
//-----------------------------------------------------------------------------
void DataStore::Write()
{
for (size_t i=0; i<m_data.size(); ++i)
{
DataRecord& DR = *m_data[i];
DR.Write();
}
}
//-----------------------------------------------------------------------------
void DataStore::AddRecord(DataRecord* prec)
{
prec->m_nid = (int) m_data.size() + 1;
m_data.push_back(prec);
}
| C++ |
3D | febiosoftware/FEBio | FECore/SurfaceDataRecord.cpp | .cpp | 3,089 | 83 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "SurfaceDataRecord.h"
#include "FECoreKernel.h"
#include "FEModel.h"
#include "FESurface.h"
//-----------------------------------------------------------------------------
void FESurfaceDataRecord::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;
FELogSurfaceData* pdata = fecore_new<FELogSurfaceData>(sz, GetFEModel());
if (pdata) m_Data.push_back(pdata);
else throw UnknownDataField(sz);
sz = ch;
} while (ch);
}
//-----------------------------------------------------------------------------
FESurfaceDataRecord::FESurfaceDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_SURFACE) {}
//-----------------------------------------------------------------------------
int FESurfaceDataRecord::Size() const { return (int)m_Data.size(); }
//-----------------------------------------------------------------------------
double FESurfaceDataRecord::Evaluate(int item, int ndata)
{
FEMesh& mesh = GetFEModel()->GetMesh();
int nd = item - 1;
if ((nd < 0) || (nd >= mesh.Surfaces())) return 0;
FESurface& surf = mesh.Surface(nd);
return m_Data[ndata]->value(surf);
}
//-----------------------------------------------------------------------------
void FESurfaceDataRecord::SetSurface(int surfIndex)
{
m_item.clear();
m_item.push_back(surfIndex + 1);
}
//-----------------------------------------------------------------------------
void FESurfaceDataRecord::SelectAllItems()
{
FEMesh& mesh = GetFEModel()->GetMesh();
int n = mesh.Surfaces();
m_item.resize(n);
for (int i = 0; i < n; ++i) m_item[i] = i + 1;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDataExport.cpp | .cpp | 2,010 | 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 "FEDataExport.h"
#include "vec3d.h"
using namespace std;
//-----------------------------------------------------------------------------
void FEDataExport::Serialize(FEDataStream& ar)
{
if ((m_type == PLT_VEC3F)&&(m_fmt == FMT_NODE))
{
vector<vec3d>& v = *(static_cast<vector<vec3d>*>(m_pd));
int n = (int) v.size();
for (int i=0; i<n; ++i) ar << v[i];
}
else if ((m_type == PLT_FLOAT)&&(m_fmt == FMT_REGION))
{
double& d = *(static_cast<double*>(m_pd));
ar << d;
}
else if ((m_type == PLT_FLOAT) && (m_fmt == FMT_NODE))
{
vector<double>& v = *(static_cast<vector<double>*>(m_pd));
int n = (int)v.size();
for (int i = 0; i<n; ++i) ar << v[i];
}
else
{
assert(false);
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELoadCurve.cpp | .cpp | 3,782 | 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 "FELoadCurve.h"
#include "DumpStream.h"
#include "FECoreKernel.h"
#include "FEFunction1D.h"
#include "log.h"
BEGIN_FECORE_CLASS(FELoadCurve, FELoadController)
ADD_PARAMETER(m_int, "interpolate", 0, "LINEAR\0STEP\0SMOOTH\0CUBIC SPLINE\0CONTROL POINTS\0APPROXIMATION\0SMOOTH STEP\0C2-SMOOTH\0");
ADD_PARAMETER(m_ext, "extend" , 0, "CONSTANT\0EXTRAPOLATE\0REPEAT\0REPEAT OFFSET\0");
ADD_PARAMETER(m_points, "points");
END_FECORE_CLASS();
FELoadCurve::FELoadCurve(FEModel* fem) : FELoadController(fem)
{
m_int = PointCurve::LINEAR;
m_ext = PointCurve::CONSTANT;
}
FELoadCurve::FELoadCurve(const FELoadCurve& lc) : FELoadController(lc)
{
m_fnc = lc.m_fnc;
m_int = lc.m_int;
m_ext = lc.m_ext;
}
void FELoadCurve::operator = (const FELoadCurve& lc)
{
m_fnc = lc.m_fnc;
m_int = lc.m_int;
m_ext = lc.m_ext;
}
FELoadCurve::~FELoadCurve()
{
}
bool FELoadCurve::Init()
{
m_fnc.SetInterpolator(m_int);
m_fnc.SetExtendMode(m_ext);
m_fnc.SetPoints(m_points);
// check points
if (m_fnc.Points() > 1)
{
for (int i = 1; i < m_points.size(); ++i)
{
double t0 = m_points[i - 1].x();
double t1 = m_points[i ].x();
if (t0 == t1) feLogWarning("Repeated time coordinate in load controller %d", GetID() + 1);
}
}
if (m_fnc.Update() == false) return false;
return FELoadController::Init();
}
void FELoadCurve::Reset()
{
FELoadController::Reset();
m_fnc.SetInterpolator(m_int);
m_fnc.SetExtendMode(m_ext);
m_fnc.SetPoints(m_points);
m_fnc.Update();
}
void FELoadCurve::Serialize(DumpStream& ar)
{
FELoadController::Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
ar << m_int << m_ext;
ar << m_points;
}
else
{
ar >> m_int >> m_ext;
ar >> m_points;
m_fnc.Clear();
m_fnc.SetInterpolator(m_int);
m_fnc.SetExtendMode(m_ext);
m_fnc.SetPoints(m_points);
m_fnc.Update();
}
}
//! evaluates the loadcurve at time
double FELoadCurve::GetValue(double time)
{
return m_fnc.value(time);
}
bool FELoadCurve::CopyFrom(FELoadCurve* lc)
{
m_int = lc->m_int;
m_ext = lc->m_ext;
m_points = lc->m_points;
m_fnc = lc->m_fnc;
return true;
}
void FELoadCurve::Add(double time, double value)
{
// m_fnc.Add(time, value);
m_points.push_back(vec2d(time, value));
}
void FELoadCurve::Clear()
{
m_fnc.Clear();
}
void FELoadCurve::SetInterpolation(PointCurve::INTFUNC f)
{
m_int = f;
// m_fnc.SetInterpolator(f);
}
void FELoadCurve::SetExtendMode(PointCurve::EXTMODE f)
{
m_ext = f;
// m_fnc.SetExtendMode(f);
}
| C++ |
3D | febiosoftware/FEBio | FECore/stdafx.cpp | .cpp | 1,385 | 33 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
| C++ |
3D | febiosoftware/FEBio | FECore/FEDataGenerator.cpp | .cpp | 3,049 | 111 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEDataGenerator.h"
#include "FEMesh.h"
#include "FENodeDataMap.h"
#include "FEDomainMap.h"
#include "FEElementSet.h"
#include "log.h"
FEMeshDataGenerator::FEMeshDataGenerator(FEModel* fem) : FEModelComponent(fem)
{
}
FEMeshDataGenerator::~FEMeshDataGenerator()
{
}
bool FEMeshDataGenerator::Init()
{
return true;
}
void FEMeshDataGenerator::Evaluate(double time)
{
}
//-----------------------------------------------------------------------------
FENodeDataGenerator::FENodeDataGenerator(FEModel* fem) : FEMeshDataGenerator(fem)
{
m_nodeSet = nullptr;
}
void FENodeDataGenerator::SetNodeSet(FENodeSet* nodeSet)
{
m_nodeSet = nodeSet;
}
FENodeSet* FENodeDataGenerator::GetNodeSet()
{
return m_nodeSet;
}
//-----------------------------------------------------------------------------
FEEdgeDataGenerator::FEEdgeDataGenerator(FEModel* fem) : FEMeshDataGenerator(fem)
{
m_edgeList = nullptr;
}
void FEEdgeDataGenerator::SetEdgeList(FEEdgeList* edgeSet)
{
m_edgeList = edgeSet;
}
FEEdgeList* FEEdgeDataGenerator::GetEdgeList()
{
return m_edgeList;
}
//-----------------------------------------------------------------------------
FEFaceDataGenerator::FEFaceDataGenerator(FEModel* fem) : FEMeshDataGenerator(fem)
{
m_surf = nullptr;
}
void FEFaceDataGenerator::SetFacetSet(FEFacetSet* surf)
{
m_surf = surf;
}
FEFacetSet* FEFaceDataGenerator::GetFacetSet()
{
return m_surf;
}
//-----------------------------------------------------------------------------
FEElemDataGenerator::FEElemDataGenerator(FEModel* fem) : FEMeshDataGenerator(fem)
{
m_elemSet = nullptr;
}
void FEElemDataGenerator::SetElementSet(FEElementSet* elset) { m_elemSet = elset; }
FEElementSet* FEElemDataGenerator::GetElementSet() { return m_elemSet; }
| C++ |
3D | febiosoftware/FEBio | FECore/FEStepComponent.h | .h | 2,570 | 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 "FEModelComponent.h"
//-----------------------------------------------------------------------------
// A Step component is a model component that can be assigned to a step.
// It adds a mechanism for activating and deactivating the component.
class FECORE_API FEStepComponent : public FEModelComponent
{
public:
FEStepComponent(FEModel* fem);
//-----------------------------------------------------------------------------------
//! This function checks if the component is active in the current step.
bool IsActive() const;
//-----------------------------------------------------------------------------------
//! Activate the component.
//! This function is called during the step initialization, right before the step is solved.
//! This function can be used to initialize any data that could depend on the model state.
//! Data allocation and initialization of data that does not depend on the model state should
//! be done in Init().
virtual void Activate();
//-----------------------------------------------------------------------------------
//! Deactivate the component
virtual void Deactivate();
public:
//! serialization
void Serialize(DumpStream& ar);
private:
bool m_bactive; //!< flag indicating whether the component is active
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MTypes.h | .h | 3,692 | 83 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
//-----------------------------------------------------------------------------
// class that describes a fraction of two real numbers
class FRACTION
{
public:
double n, d; // nominator, denominator
public:
FRACTION() : n(0), d(1) {}
FRACTION(double a) : n(a), d(1) {}
FRACTION(double a, double b) : n(a), d(b) {}
FRACTION(const FRACTION& f) { n = f.n; d = f.d; }
FRACTION& operator = (double a) { n = a; d = 1; return (*this); }
FRACTION& operator = (const FRACTION& f) { n = f.n; d = f.d; return (*this); }
FRACTION& operator += (double a) { n += a*d; return (*this); }
FRACTION& operator += (const FRACTION& a) { n = n*a.d + d*a.n; d *= a.d; return (*this); }
FRACTION& operator -= (double a) { n -= a*d; return (*this); }
FRACTION& operator -= (const FRACTION& a) { n = n*a.d - d*a.n; d *= a.d; return (*this); }
FRACTION& operator /= (double a) { d *= a; return (*this); }
operator double() { return n / d; }
void normalize();
};
//-----------------------------------------------------------------------------
// operators for FRACTION
inline FRACTION operator + (FRACTION& l, FRACTION& r) { return FRACTION(l.n*r.d + r.n*l.d, l.d*r.d); }
inline FRACTION operator + (FRACTION& l, double r) { return FRACTION(l.n + r*l.d, l.d); }
inline FRACTION operator + (double l, FRACTION& r) { return FRACTION(l*r.d + r.n, r.d); }
inline FRACTION operator - (FRACTION& l, FRACTION& r) { return FRACTION(l.n*r.d - r.n*l.d, l.d*r.d); }
inline FRACTION operator - (FRACTION& l, double r) { return FRACTION(l.n - r*l.d, l.d); }
inline FRACTION operator - (double l, FRACTION& r) { return FRACTION(l*r.d - r.n, r.d); }
inline FRACTION operator * (FRACTION& l, FRACTION& r) { return FRACTION(l.n*r.n, l.d*r.d); }
inline FRACTION operator * (FRACTION& l, double r) { return FRACTION(l.n*r, l.d); }
inline FRACTION operator * (double l, FRACTION& r) { return FRACTION(r.n*l, r.d); }
inline FRACTION operator / (FRACTION& l, FRACTION& r) { return FRACTION(l.n*r.d, l.d*r.n); }
inline FRACTION operator / (FRACTION& l, double r) { return FRACTION(l.n, l.d*r); }
inline FRACTION operator / (double l, FRACTION& r) { return FRACTION(l*r.d, r.n); }
inline FRACTION operator - (FRACTION& a) { return FRACTION(-a.n, a.d); }
//-----------------------------------------------------------------------------
// Calculates the greatest common factor
long gcf(long a, long b);
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBox.h | .h | 2,076 | 63 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class FEMesh;
class FEMeshPartition;
//-----------------------------------------------------------------------------
// Helper class for finding bounding boxes.
class FECORE_API FEBox
{
public:
FEBox();
FEBox(const vec3d& r0, const vec3d& r1);
FEBox(const FEMesh& mesh);
FEBox(const FEMeshPartition& dom);
vec3d center() { return (m_r0 + m_r1)*0.5; }
double width () { return m_r1.x - m_r0.x; }; //!< x-size
double height() { return m_r1.y - m_r0.y; }; //!< y-size
double depth () { return m_r1.z - m_r0.z; }; //!< z-size
// the maximum size
double maxsize();
// union of box and node
void add(const vec3d& r);
private:
vec3d m_r0, m_r1;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELevelStructure.cpp | .cpp | 13,281 | 493 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELevelStructure.h"
#include <stdlib.h>
#include <queue>
#include <stack>
#include "vector.h"
#include <assert.h>
using namespace std;
//-----------------------------------------------------------------------------
FELevelStructure::FELevelStructure()
{
m_pNL = 0;
}
//-----------------------------------------------------------------------------
FELevelStructure::~FELevelStructure()
{
}
FELevelStructure* FELevelStructure::m_pthis = 0;
//-----------------------------------------------------------------------------
//! the compare function compares the degree of two nodes. This function is used
//! in the FELevelStructure::SortLevels function. Note the use of the static
//! this pointer to identify the level structure that called this function.
int FELevelStructure::compare(const void* e1, const void* e2)
{
int n1 = *((int*) e1);
int n2 = *((int*) e2);
FENodeNodeList& L = *(m_pthis->m_pNL);
return (L.Valence(n1) - L.Valence(n2));
}
//-----------------------------------------------------------------------------
//! This function creates a level structure rooted at node nroot of the graph L
//! The root is placed in level 0 and then all nodes adjacent to nodes that have
//! been placed in the level structure are placed in the next level.
void FELevelStructure::Create(FENodeNodeList& L, int nroot)
{
int i, n, m, *pn;
int N = L.Size();
m_pNL = &L;
// create the node array. This array will store
// for each node to which level it belongs. We initialize
// the array with -1 to indicate that no node has been
// assigned to a level
m_node.assign(N, -1);
// place all nodes in a level. We use a queue for this
// since we want nodes to be processed in a first come
// first serve way. The root node is placed in level 0
// and then all nodes adjacent to processed nodes are
// placed in the next level.
queue<int> NQ;
int node = nroot;
NQ.push(node);
m_node[nroot] = 0;
int level;
while (NQ.size() > 0)
{
// get a node from the queue
node = NQ.front(); NQ.pop();
// get the next level index
level = m_node[node] + 1;
// now we have to place all neighbours on the queue
n = L.Valence(node);
pn = L.NodeList(node);
for (i=0; i<n; ++i)
{
// get an adjacent node
m = pn[i];
// make sure the node has not been assigned a level yet
if (m_node[m] < 0)
{
// assign the node to a level
m_node[m] = level;
// push the node on the queue
NQ.push(m);
}
}
}
// determine the total nr of levels we generated
int nlevels = 0;
for (i=0; i<N; ++i)
if (m_node[i] > nlevels) nlevels = m_node[i];
++nlevels;
// allocate levels data
m_lval.assign(nlevels, 0);
m_pl.resize(nlevels);
m_nref.resize(N);
// At this point it is important to realize that
// there still may be nodes that are not assigned to
// a level. The reason is that these nodes are not connected
// to the component that the root is part of. When looping
// over all nodes (as below) it is important to explicitly
// check whether the node belongs to the level structure or not.
// Nodes that are not part of it have m_node[i] < 0
// count the width of each level
for (i=0; i<N; ++i)
{
if (m_node[i] >= 0) ++m_lval[ m_node[i] ];
}
// set nref pointers
m_pl[0] = 0;
m_nwidth = m_lval[0];
for (i=1; i<nlevels; ++i)
{
m_pl[i] = m_pl[i-1] + m_lval[i-1];
if (m_lval[i] > m_nwidth) m_nwidth = m_lval[i];
}
// reset the valence
zero(m_lval);
// fill the nref list and recount the width of each level
// remember to see if the node is part of the level structure
for (i=0; i<N; ++i)
{
n = m_node[i];
if (n >= 0)
{
m_nref[ m_pl[n] + m_lval[n] ] = i;
++m_lval[n];
}
}
}
//-----------------------------------------------------------------------------
//! This function sorts the nodes in each level from level l0 to l1 in order
//! of increasing degree. Note that the static this pointer gets set since the
//! compare function has to be static and therefore will not receive the this function
//! from the calling class member
void FELevelStructure::SortLevels(int l0, int l1)
{
int n, *pn;
m_pthis = this;
for (int i=l0; i<=l1; ++i)
{
n = Valence(i);
pn = NodeList(i);
qsort(pn, n, sizeof(int), compare);
}
}
//-----------------------------------------------------------------------------
//! This function merges two level structures into one. The merging algorithm below
//! usually returns a level structure that has a smaller width than either L1 or L2.
//! The swap variable will be set to true if second index of the node-pair array G
//! was used of the first component.
void FELevelStructure::Merge(FELevelStructure& L1, FELevelStructure& L2, bool& bswap)
{
int i, j, m, l1, l2;
// get the node list that was used
// to generate L1 and L2
FENodeNodeList& NL = *L1.m_pNL;
// store the node list for later use
m_pNL = L1.m_pNL;
// get the level depth of L1 and
// make sure that it is the same as L2's
int k = L1.Depth();
assert( k == L2.Depth());
// get the level widths of L1 and L2
int w1 = L1.Width();
int w2 = L2.Width();
// get the number of nodes
int N = NL.Size();
// create the valence array
m_lval.assign(k, 0);
// create the nodal array
m_node.assign(N, -1);
// In a moment nodes of the graph NL will be marked
// as "removed". This will split the graph into
// several disconnected components. The comp array
// will store for each node the component to which
// it belongs.
// create the component array
// this array will store for each node
// the index of the component
// the nodes in the "0" component are the ones
// that are marked as "removed" from the graph
std::vector<int> comp;
comp.assign(N, -1);
// fill the level pair array G will store for each
// node the index of the level that it has in L1 and
// the reversed index of level L2.
// Note that l1 < 0 for nodes that are not part of L1
// and similar for l2.
vector<int> G1(N), G2(N);
for (i=0; i<N; ++i)
{
l1 = L1.m_node[i];
l2 = L2.m_node[i];
if ((l1>=0) && (l2>=0))
{
G1[i] = l1;
G2[i] = k-1-l2;
if (G1[i] == G2[i])
{
m_node[i] = l1;
++m_lval[l1];
comp[i] = 0;
}
}
else
{
// node i does not belong to L1 or L2
G1[i] = -1;
G2[i] = -1;
}
}
// Next, we find all connected components. A component
// is created by finding an unprocessed node and attaching all
// nodes that can be reached from this node. Remember that nodes
// which are assigned to component 0 are considered as removed
// from the graph
int nc = 1;
stack<int> NS;
do
{
// find a node that has not been assigned to a component
// (and that belongs to the graph (ie. node[i]>0))
int node = -1;
for (i=0; i<N; ++i)
{
if ((comp[i] == -1) && (L1.m_node[i] >= 0))
{
node = i;
break;
}
}
// if we didn't find one, we can stop
if (node == -1) break;
// assign the node and all adjacent nodes to a component
NS.push(node);
comp[node] = nc;
while (!NS.empty())
{
node = NS.top(); NS.pop();
int n = NL.Valence(node);
int* pn = NL.NodeList(node);
for (i=0; i<n; ++i)
if (comp[pn[i]] == -1)
{
comp[pn[i]] = nc;
NS.push(pn[i]);
}
}
// increase the component counter
++nc;
}
while (true);
// if we found more than 1 component than we'll have the process
// each component seperatly. Note that we will only have one component
// if all node-pairs of G are in the form (i,i). In that case all nodes
// are placed in level 0, ie. are considered as "removed"
if (nc>1)
{
// the vectors ni, hi and li will help us determine where to place
// a node of a component
std::vector<int> ni(k);
std::vector<int> hi(k);
std::vector<int> li(k);
// Next, we have to create the components explicitly. The Comp arrays
// will store for each component a list of nodes that belongs to this
// component. We do this in two steps. First, we determine the sizes
// of each component so that we can allocate the Comp array. Next, we
// fill the Comp array by looping over all nodes and placing each node
// in the correct component.
// count the elements of the components
// and determing the maximum component size
std::vector<int> cc;
cc.assign(nc, 0);
int ncmax = 0;
for (i=0; i<N; ++i)
{
// make sure the node belongs to the graph L
if (comp[i] >= 0)
{
++cc[ comp[i] ];
if (cc[ comp[i] ] > ncmax) ncmax = cc[comp[i]];
}
}
// create the component arrays
std::vector< std::vector<int> > Comp(nc);
for (i=0; i<nc; ++i)
{
Comp[i].resize(cc[i]);
cc[i] = 0;
}
// fill the components
for (i=0; i<N; ++i)
{
m = comp[i];
if (m>=0)
{
Comp[m][cc[m]] = i;
++cc[m];
}
}
// Next, we loop over all components and place each node of the
// component in a level. The level is determined by the node-pair
// graph G. We can use either G[i][0] or G[i][1] for node i. Which
// one gets picked determines on some criteria described below.
// Note that we skip the "0" component since the nodes of this component
// have already been assigned to a level.
int ns = -1, nsm;
for (i=1; i<nc; ++i)
{
// we need to loop over all components in order of increasing size.
// In stead of actually sorting the components we just find the next
// smallest component by looping again over all components. At the bottom
// we set cc[i] of the smallest component to -1 so that it can't get
// picked anymore.
nsm = ncmax;
int ncomp = -1;
for (j=1; j<nc; ++j)
{
if ((cc[j] >= ns) && (cc[j] <= nsm))
{
ncomp = j;
nsm = cc[j];
}
}
ns = nsm;
assert(ncomp > 0);
// calculate the vectors ni, hi, li
// ni[i] = number of nodes in level i
// li[i] = ni + nodes that would be put in level i based on G[node][0]
// hi[i] = ni + nodes that would be put in level i based on G[node][1]
for (j=0; j<k; ++j)
{
li[j] = hi[j] = ni[j] = m_lval[j];
}
std::vector<int>& pn = Comp[ncomp];
for (j=0; j<cc[ncomp]; ++j)
{
m = pn[j];
++hi[ G1[m] ];
++li[ G2[m] ];
}
// next, we determint h0 and l0, where
// h0 = max{hi[i] : hi[i] - ni[i] > 0} and similar for l0
int h0 = -1, l0 = -1;
for (j=0; j<k; ++j)
{
if ((hi[j] > h0) && (hi[j] > ni[j])) h0 = hi[j];
if ((li[j] > l0) && (li[j] > ni[j])) l0 = li[j];
}
assert(h0 >= 0);
assert(l0 >= 0);
// Next we can assign the nodes of the component to a level.
// the criteria are:
// if (h0 < l0) place the node in level G[i][0]
// if (l0 < h0) place the node in level G[i][1]
// if (l0 == h0) use the level of the rooted level structure
// with smallest width
if ((h0 < l0) || ((h0 == l0) && (w1 <= w2)))
{
std::vector<int>& pn = Comp[ncomp];
for (j=0; j<cc[ncomp]; ++j)
{
m = pn[j];
m_node[m] = G1[m];
++m_lval[ G1[m] ];
}
if (i==1) bswap = false;
}
else if ((l0 < h0) || ((h0 == l0) && (w1 > w2)))
{
std::vector<int>& pn = Comp[ncomp];
for (j=0; j<cc[ncomp]; ++j)
{
m = pn[j];
m_node[m] = G2[m];
++m_lval[ G2[m] ];
}
if (i==1) bswap = true;
}
// set cc[ncomp] to an impossible value so that it won't get picked any more
// in the search for the next smallest component
cc[ncomp] = -1;
}
}
// All nodes are now placed in a level and we now the size of each level
// We can now finish allocating and initializing the rest of the level structure data
// allocate levels data
m_pl.resize(k);
m_nref.resize(N);
// set nref pointers
m_pl[0] = 0;
m_nwidth = m_lval[0];
for (i=1; i<k; ++i)
{
m_pl[i] = m_pl[i-1] + m_lval[i-1];
if (m_lval[i] > m_nwidth) m_nwidth = m_lval[i];
}
// reset the valence
zero(m_lval);
// fill the nref list
// Remember to check to see if the node belongs to the graph
for (i=0; i<N; ++i)
{
m = m_node[i];
if (m>=0)
{
m_nref[ m_pl[m] + m_lval[m] ] = i;
++m_lval[m];
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/DomainDataRecord.cpp | .cpp | 7,053 | 245 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "DomainDataRecord.h"
#include "FECoreKernel.h"
#include "FEModel.h"
#include "FEDomain.h"
//-----------------------------------------------------------------------------
void FEDomainDataRecord::SetData(const char* szexpr)
{
char szcopy[MAX_STRING] = { 0 };
strcpy(szcopy, szexpr);
char* sz = szcopy, * ch;
m_Data.clear();
strcpy(m_szdata, szexpr);
do
{
const char* szparam = nullptr;
ch = strchr(sz, ';');
if (ch) *ch++ = 0;
// see if parameters are defined
char* cl = strchr(sz, '(');
if (cl)
{
char* cr = strrchr(sz, ')');
if (cr == nullptr) throw UnknownDataField(sz);
*cl++ = 0;
*cr = 0;
cl = strchr (cl, '\''); if (cl == nullptr) throw UnknownDataField(sz);
cr = strrchr(cl, '\''); if (cr == nullptr) throw UnknownDataField(sz);
*cl++ = 0;
*cr = 0;
szparam = cl;
}
FELogDomainData* pdata = fecore_new<FELogDomainData>(sz, GetFEModel());
if (pdata)
{
m_Data.push_back(pdata);
if (szparam)
{
vector<string> params; params.push_back(szparam);
if (pdata->SetParameters(params) == false) throw UnknownDataField(sz);
}
}
else throw UnknownDataField(sz);
sz = ch;
} while (ch);
}
//-----------------------------------------------------------------------------
FEDomainDataRecord::FEDomainDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_DOMAIN) {}
//-----------------------------------------------------------------------------
int FEDomainDataRecord::Size() const { return (int)m_Data.size(); }
//-----------------------------------------------------------------------------
double FEDomainDataRecord::Evaluate(int item, int ndata)
{
FEMesh& mesh = GetFEModel()->GetMesh();
int nd = item - 1;
if ((nd < 0) || (nd >= mesh.Domains())) return 0;
FEDomain& dom = mesh.Domain(nd);
return m_Data[ndata]->value(dom);
}
//-----------------------------------------------------------------------------
void FEDomainDataRecord::SetDomain(int domainIndex)
{
m_item.clear();
m_item.push_back(domainIndex + 1);
}
//-----------------------------------------------------------------------------
void FEDomainDataRecord::SelectAllItems()
{
FEMesh& mesh = GetFEModel()->GetMesh();
int n = mesh.Domains();
m_item.resize(n);
for (int i = 0; i < n; ++i) m_item[i] = i + 1;
}
//============================================================================
FELogAvgDomainData::FELogAvgDomainData(FEModel* pfem) : FELogDomainData(pfem)
{
m_elemData = nullptr;
}
FELogAvgDomainData::~FELogAvgDomainData()
{
if (m_elemData) delete m_elemData;
m_elemData = nullptr;
}
bool FELogAvgDomainData::SetParameters(std::vector<std::string>& params)
{
if (params.size() != 1) return false;
std::string& v1 = params[0];
if (v1.empty()) return false;
m_elemData = fecore_new<FELogElemData>(v1.c_str(), GetFEModel());
if (m_elemData == nullptr) return false;
return true;
}
//-----------------------------------------------------------------------------
double FELogAvgDomainData::value(FEDomain& dom)
{
if (m_elemData == nullptr) return 0.0;
double avg = 0.0;
const int NE = dom.Elements();
for (int i = 0; i < dom.Elements(); ++i)
{
FEElement& el = dom.ElementRef(i);
double eval = m_elemData->value(el);
avg += eval;
}
avg /= (double)NE;
return avg;
}
//============================================================================
FELogPctDomainData::FELogPctDomainData(FEModel* pfem) : FELogDomainData(pfem)
{
m_pct = 0.0;
m_elemData = nullptr;
}
FELogPctDomainData::~FELogPctDomainData()
{
if (m_elemData) delete m_elemData;
m_elemData = nullptr;
}
bool FELogPctDomainData::SetParameters(std::vector<std::string>& params)
{
if (params.size() != 2) return false;
std::string& v1 = params[0];
std::string& v2 = params[1];
if (v1.empty() || v2.empty()) return false;
m_elemData = fecore_new<FELogElemData>(v1.c_str(), GetFEModel());
if (m_elemData == nullptr) return false;
m_pct = atof(v2.c_str());
if ((m_pct < 0.0) || (m_pct > 1.0)) return false;
return true;
}
//-----------------------------------------------------------------------------
double FELogPctDomainData::value(FEDomain& dom)
{
if (m_elemData == nullptr) return 0.0;
const int NE = dom.Elements();
vector<double> val(NE, 0.0);
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom.ElementRef(i);
val[i] = m_elemData->value(el);
}
std::sort(val.begin(), val.end());
int n = (int) (m_pct * ((double)val.size() - 1.0));
return val[n];
}
//============================================================================
FELogIntegralDomainData::FELogIntegralDomainData(FEModel* pfem) : FELogDomainData(pfem)
{
m_elemData = nullptr;
}
FELogIntegralDomainData::~FELogIntegralDomainData()
{
if (m_elemData) delete m_elemData;
m_elemData = nullptr;
}
bool FELogIntegralDomainData::SetParameters(std::vector<std::string>& params)
{
if (params.size() != 1) return false;
std::string& v1 = params[0];
if (v1.empty()) return false;
m_elemData = fecore_new<FELogElemData>(v1.c_str(), GetFEModel());
if (m_elemData == nullptr) return false;
return true;
}
//-----------------------------------------------------------------------------
double FELogIntegralDomainData::value(FEDomain& dom)
{
if (m_elemData == nullptr) return 0.0;
FEMesh* mesh = dom.GetMesh();
double sum = 0.0;
const int NE = dom.Elements();
for (int i = 0; i < dom.Elements(); ++i)
{
FEElement& el = dom.ElementRef(i);
double eval = m_elemData->value(el);
double vol = mesh->ElementVolume(el);
sum += eval*vol;
}
return sum;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEParam.h | .h | 8,187 | 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.*/
#pragma once
#include "vec3d.h"
#include "mat3d.h"
#include <assert.h>
#include <vector>
#include "fecore_api.h"
#include "ParamString.h"
#include "units.h"
//-----------------------------------------------------------------------------
class FEParamValidator;
class DumpStream;
class FEParamContainer;
//-----------------------------------------------------------------------------
// Different supported parameter types
enum FEParamType {
FE_PARAM_INVALID,
FE_PARAM_INT,
FE_PARAM_BOOL,
FE_PARAM_DOUBLE,
FE_PARAM_VEC2D,
FE_PARAM_VEC3D,
FE_PARAM_MAT3D,
FE_PARAM_MAT3DS,
FE_PARAM_STRING,
FE_PARAM_DATA_ARRAY,
FE_PARAM_TENS3DRS,
FE_PARAM_STD_STRING,
FE_PARAM_STD_VECTOR_INT,
FE_PARAM_STD_VECTOR_DOUBLE,
FE_PARAM_STD_VECTOR_VEC2D,
FE_PARAM_STD_VECTOR_STRING,
FE_PARAM_DOUBLE_MAPPED,
FE_PARAM_VEC3D_MAPPED,
FE_PARAM_MAT3D_MAPPED,
FE_PARAM_MAT3DS_MAPPED,
FE_PARAM_MATERIALPOINT,
};
//-----------------------------------------------------------------------------
// Parameter flags
enum FEParamFlag {
FE_PARAM_ATTRIBUTE = 0x01, // parameter will be read as attribute
FE_PARAM_USER = 0x02, // user parameter (owned by parameter list)
FE_PARAM_HIDDEN = 0x04, // Hides parameter (in FEBio Studio)
FE_PARAM_ADDLC = 0x08, // parameter should get a default load curve in FEBio Studio
FE_PARAM_VOLATILE = 0x10, // parameter can change (e.g. via a load curve)
FE_PARAM_TOPLEVEL = 0x20, // parameter should only defined at top-level (materials only)
FE_PARAM_WATCH = 0x40, // This is a watch parameter
FE_PARAM_OBSOLETE = 0x80 // Parameter is obsolete
};
class FEParam;
//-----------------------------------------------------------------------------
// class describing the value of parameter
class FEParamValue
{
private:
void* m_pv; // pointer to variable data
FEParamType m_itype; // type of variable (this is not the type of the param!)
FEParam* m_param; // the parameter (can be null if it is not a parameter)
public:
FEParamValue()
{
m_pv = 0;
m_itype = FE_PARAM_INVALID;
m_param = 0;
}
explicit FEParamValue(FEParam* p, void* v, FEParamType itype)
{
m_pv = v;
m_itype = itype;
m_param = p;
}
FEParamValue(int& v) : FEParamValue(0, &v, FE_PARAM_INT) {}
FEParamValue(double& v) : FEParamValue(0, &v, FE_PARAM_DOUBLE) {}
FEParamValue(vec2d& v) : FEParamValue(0, &v, FE_PARAM_VEC2D) {}
FEParamValue(vec3d& v) : FEParamValue(0, &v, FE_PARAM_VEC3D) {}
FEParamValue(mat3ds& v) : FEParamValue(0, &v, FE_PARAM_MAT3DS) {}
FEParamValue(mat3d& v) : FEParamValue(0, &v, FE_PARAM_MAT3D ) {}
bool isValid() const { return (m_pv != 0); }
FEParamType type() const { return m_itype; }
void* data_ptr() const { return m_pv; }
FEParam* param() { return m_param; }
template <typename T> T& value() { return *((T*)m_pv); }
template <typename T> const T& value() const { return *((T*)m_pv); }
FECORE_API FEParamValue component(int n);
};
//-----------------------------------------------------------------------------
//! This class describes a user-defined parameter
class FECORE_API FEParam
{
private:
void* m_pv; // pointer to variable data
int m_dim; // dimension (in case data is array)
FEParamType m_type; // type of variable
unsigned int m_flag; // parameter flags
bool* m_watch; // parameter watch (set to true if read in)
int m_group; // index of parameter group (-1 by default)
const char* m_szname; // name of the parameter
const char* m_szenum; // enumerate values for ints
const char* m_szunit; // unit string
const char* m_szlongname; // a longer, more descriptive name (optional)
// parameter validator
FEParamValidator* m_pvalid;
FEParamContainer* m_parent; // parent object of parameter
public:
// constructor
FEParam(void* pdata, FEParamType itype, int ndim, const char* szname, bool* watch = nullptr);
FEParam(const FEParam& p);
~FEParam();
FEParam& operator = (const FEParam& p);
// set the parameter's validator
void SetValidator(FEParamValidator* pvalid);
FEParamValidator* GetValidator();
// see if the parameter's value is valid
bool is_valid() const;
// return the name of the parameter
const char* name() const;
// return the long name of the parameter
const char* longName() const;
// return the enum values
const char* enums() const;
// get the current enum value (or nullptr)
const char* enumKey() const;
// get the unit string
const char* units() const;
FEParam* setUnits(const char* szunit);
// set the enum values (\0 separated. Make sure the end of the string has two \0's)
FEParam* setEnums(const char* sz);
// set the long name
FEParam* setLongName(const char* sz);
// parameter dimension
int dim() const;
// parameter type
FEParamType type() const;
// data pointer
void* data_ptr() const;
// get the param value
FEParamValue paramValue(int i = -1);
// Copy the state of one parameter to this parameter.
// This requires that the parameters are compatible (i.e. same type, etc.)
bool CopyState(const FEParam& p);
void setParent(FEParamContainer* pc);
FEParamContainer* parent();
FEParam* SetFlags(unsigned int flags);
unsigned int GetFlags() const;
void SetWatchVariable(bool* watchVar);
bool* GetWatchVariable();
void SetWatchFlag(bool b);
bool IsHidden() const;
bool IsObsolete() const;
bool IsVolatile() const;
FEParam* MakeVolatile(bool b);
bool IsTopLevel() const;
FEParam* MakeTopLevel(bool b);
public:
int GetParamGroup() const;
void SetParamGroup(int i);
public:
void Serialize(DumpStream& ar);
static void SaveClass(DumpStream& ar, FEParam* p);
static FEParam* LoadClass(DumpStream& ar, FEParam* p);
public:
//! retrieves the value for a non-array item
template <class T> T& value() { return *((T*) data_ptr()); }
//! retrieves the value for a non-array item
template <class T> const T& value() const { return *((T*) data_ptr()); }
//! retrieves the value for an array item
template <class T> T* pvalue() { return (T*) data_ptr(); }
//! retrieves the value for an array item
template <class T> T& value(int i) { return ((T*)data_ptr())[i]; }
template <class T> T value(int i) const { return ((T*) data_ptr())[i]; }
//! retrieves pointer to element in array
template <class T> T* pvalue(int n);
//! override the template for char pointers
char* cvalue();
};
//-----------------------------------------------------------------------------
//! Retrieves a pointer to element in array
template<class T> inline T* FEParam::pvalue(int n)
{
assert((n >= 0) && (n < m_dim));
return &(pvalue<T>()[n]);
}
//-----------------------------------------------------------------------------
FECORE_API FEParamValue GetParameterComponent(const ParamString& paramName, FEParam* param);
FECORE_API FEParamValue GetParameterComponent(FEParamValue& paramVal, int index);
FECORE_API FEParamValue GetParameterComponent(FEParamValue& paramVal, const char* szcomp);
| Unknown |
3D | febiosoftware/FEBio | FECore/FESolidElementShape.cpp | .cpp | 54,545 | 1,482 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FESolidElementShape.h"
//=============================================================================
// H E X 8
//=============================================================================
//-----------------------------------------------------------------------------
void FEHex8::shape_fnc(double* H, double r, double s, double t)
{
H[0] = 0.125*(1 - r)*(1 - s)*(1 - t);
H[1] = 0.125*(1 + r)*(1 - s)*(1 - t);
H[2] = 0.125*(1 + r)*(1 + s)*(1 - t);
H[3] = 0.125*(1 - r)*(1 + s)*(1 - t);
H[4] = 0.125*(1 - r)*(1 - s)*(1 + t);
H[5] = 0.125*(1 + r)*(1 - s)*(1 + t);
H[6] = 0.125*(1 + r)*(1 + s)*(1 + t);
H[7] = 0.125*(1 - r)*(1 + s)*(1 + t);
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FEHex8::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -0.125*(1 - s)*(1 - t);
Hr[1] = 0.125*(1 - s)*(1 - t);
Hr[2] = 0.125*(1 + s)*(1 - t);
Hr[3] = -0.125*(1 + s)*(1 - t);
Hr[4] = -0.125*(1 - s)*(1 + t);
Hr[5] = 0.125*(1 - s)*(1 + t);
Hr[6] = 0.125*(1 + s)*(1 + t);
Hr[7] = -0.125*(1 + s)*(1 + t);
Hs[0] = -0.125*(1 - r)*(1 - t);
Hs[1] = -0.125*(1 + r)*(1 - t);
Hs[2] = 0.125*(1 + r)*(1 - t);
Hs[3] = 0.125*(1 - r)*(1 - t);
Hs[4] = -0.125*(1 - r)*(1 + t);
Hs[5] = -0.125*(1 + r)*(1 + t);
Hs[6] = 0.125*(1 + r)*(1 + t);
Hs[7] = 0.125*(1 - r)*(1 + t);
Ht[0] = -0.125*(1 - r)*(1 - s);
Ht[1] = -0.125*(1 + r)*(1 - s);
Ht[2] = -0.125*(1 + r)*(1 + s);
Ht[3] = -0.125*(1 - r)*(1 + s);
Ht[4] = 0.125*(1 - r)*(1 - s);
Ht[5] = 0.125*(1 + r)*(1 - s);
Ht[6] = 0.125*(1 + r)*(1 + s);
Ht[7] = 0.125*(1 - r)*(1 + s);
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FEHex8::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 0.0; Hss[0] = 0.0; Htt[0] = 0.0;
Hrr[1] = 0.0; Hss[1] = 0.0; Htt[1] = 0.0;
Hrr[2] = 0.0; Hss[2] = 0.0; Htt[2] = 0.0;
Hrr[3] = 0.0; Hss[3] = 0.0; Htt[3] = 0.0;
Hrr[4] = 0.0; Hss[4] = 0.0; Htt[4] = 0.0;
Hrr[5] = 0.0; Hss[5] = 0.0; Htt[5] = 0.0;
Hrr[6] = 0.0; Hss[6] = 0.0; Htt[6] = 0.0;
Hrr[7] = 0.0; Hss[7] = 0.0; Htt[7] = 0.0;
Hrs[0] = 0.125*(1 - t);
Hrs[1] = -0.125*(1 - t);
Hrs[2] = 0.125*(1 - t);
Hrs[3] = -0.125*(1 - t);
Hrs[4] = 0.125*(1 + t);
Hrs[5] = -0.125*(1 + t);
Hrs[6] = 0.125*(1 + t);
Hrs[7] = -0.125*(1 + t);
Hrt[0] = 0.125*(1 - s);
Hrt[1] = -0.125*(1 - s);
Hrt[2] = -0.125*(1 + s);
Hrt[3] = 0.125*(1 + s);
Hrt[4] = -0.125*(1 - s);
Hrt[5] = 0.125*(1 - s);
Hrt[6] = 0.125*(1 + s);
Hrt[7] = -0.125*(1 + s);
Hst[0] = 0.125*(1 - r);
Hst[1] = 0.125*(1 + r);
Hst[2] = -0.125*(1 + r);
Hst[3] = -0.125*(1 - r);
Hst[4] = -0.125*(1 - r);
Hst[5] = -0.125*(1 + r);
Hst[6] = 0.125*(1 + r);
Hst[7] = 0.125*(1 - r);
}
//=============================================================================
// T E T 4
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FETet4::shape_fnc(double* H, double r, double s, double t)
{
H[0] = 1 - r - s - t;
H[1] = r;
H[2] = s;
H[3] = t;
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FETet4::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -1; Hs[0] = -1; Ht[0] = -1;
Hr[1] = 1; Hs[1] = 0; Ht[1] = 0;
Hr[2] = 0; Hs[2] = 1; Ht[2] = 0;
Hr[3] = 0; Hs[3] = 0; Ht[3] = 1;
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FETet4::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 0.0; Hss[0] = 0.0; Htt[0] = 0.0;
Hrr[1] = 0.0; Hss[1] = 0.0; Htt[1] = 0.0;
Hrr[2] = 0.0; Hss[2] = 0.0; Htt[2] = 0.0;
Hrr[3] = 0.0; Hss[3] = 0.0; Htt[3] = 0.0;
Hrs[0] = 0.0; Hst[0] = 0.0; Hrt[0] = 0.0;
Hrs[1] = 0.0; Hst[1] = 0.0; Hrt[1] = 0.0;
Hrs[2] = 0.0; Hst[2] = 0.0; Hrt[2] = 0.0;
Hrs[3] = 0.0; Hst[3] = 0.0; Hrt[3] = 0.0;
}
//=============================================================================
// T E T 5
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FETet5::shape_fnc(double* H, double r, double s, double t)
{
H[0] = 1 - r - s - t;
H[1] = r;
H[2] = s;
H[3] = t;
H[4] = 256.0 * H[0] * H[1] * H[2] * H[3];
H[0] -= 0.25*H[4];
H[1] -= 0.25*H[4];
H[2] -= 0.25*H[4];
H[3] -= 0.25*H[4];
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FETet5::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -1; Hs[0] = -1; Ht[0] = -1;
Hr[1] = 1; Hs[1] = 0; Ht[1] = 0;
Hr[2] = 0; Hs[2] = 1; Ht[2] = 0;
Hr[3] = 0; Hs[3] = 0; Ht[3] = 1;
Hr[4] = 256.0*s*t*(1.0 - 2.0*r - s - t);
Hs[4] = 256.0*r*t*(1.0 - r - 2.0*s - t);
Ht[4] = 256.0*r*s*(1.0 - r - s - 2.0*t);
Hr[0] -= 0.25*Hr[4]; Hr[1] -= 0.25*Hr[4]; Hr[2] -= 0.25*Hr[4]; Hr[3] -= 0.25*Hr[4];
Hs[0] -= 0.25*Hs[4]; Hs[1] -= 0.25*Hs[4]; Hs[2] -= 0.25*Hs[4]; Hs[3] -= 0.25*Hs[4];
Ht[0] -= 0.25*Ht[4]; Ht[1] -= 0.25*Ht[4]; Ht[2] -= 0.25*Ht[4]; Ht[3] -= 0.25*Ht[4];
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FETet5::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[4] = -512 * s*t;
Hss[4] = -512 * r*t;
Htt[4] = -512 * r*s;
Hrs[4] = 256.0*t*(1.0 - 2.0*r - 2.0*s - t);
Hst[4] = 256.0*r*(1.0 - r - 2.0*s - 2.0*t);
Hrt[4] = 256.0*s*(1.0 - 2.0*r - s - 2.0*t);
Hrr[0] = -0.25*Hrr[4]; Hss[0] = -0.25*Hss[4]; Htt[0] = -0.25*Htt[4];
Hrr[1] = -0.25*Hrr[4]; Hss[1] = -0.25*Hss[4]; Htt[1] = -0.25*Htt[4];
Hrr[2] = -0.25*Hrr[4]; Hss[2] = -0.25*Hss[4]; Htt[2] = -0.25*Htt[4];
Hrr[3] = -0.25*Hrr[4]; Hss[3] = -0.25*Hss[4]; Htt[3] = -0.25*Htt[4];
Hrs[0] = -0.25*Hrs[4]; Hst[0] = -0.25*Hst[4]; Hrt[0] = -Hrt[4];
Hrs[1] = -0.25*Hrs[4]; Hst[1] = -0.25*Hst[4]; Hrt[1] = -Hrt[4];
Hrs[2] = -0.25*Hrs[4]; Hst[2] = -0.25*Hst[4]; Hrt[2] = -Hrt[4];
Hrs[3] = -0.25*Hrs[4]; Hst[3] = -0.25*Hst[4]; Hrt[3] = -Hrt[4];
}
//=============================================================================
// P E N T A 6
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FEPenta6::shape_fnc(double* H, double r, double s, double t)
{
H[0] = 0.5*(1 - t)*(1 - r - s);
H[1] = 0.5*(1 - t)*r;
H[2] = 0.5*(1 - t)*s;
H[3] = 0.5*(1 + t)*(1 - r - s);
H[4] = 0.5*(1 + t)*r;
H[5] = 0.5*(1 + t)*s;
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FEPenta6::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -0.5*(1 - t);
Hr[1] = 0.5*(1 - t);
Hr[2] = 0.0;
Hr[3] = -0.5*(1 + t);
Hr[4] = 0.5*(1 + t);
Hr[5] = 0.0;
Hs[0] = -0.5*(1 - t);
Hs[1] = 0.0;
Hs[2] = 0.5*(1 - t);
Hs[3] = -0.5*(1 + t);
Hs[4] = 0.0;
Hs[5] = 0.5*(1 + t);
Ht[0] = -0.5*(1 - r - s);
Ht[1] = -0.5*r;
Ht[2] = -0.5*s;
Ht[3] = 0.5*(1 - r - s);
Ht[4] = 0.5*r;
Ht[5] = 0.5*s;
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FEPenta6::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 0.0; Hss[0] = 0.0; Htt[0] = 0.0;
Hrr[1] = 0.0; Hss[1] = 0.0; Htt[1] = 0.0;
Hrr[2] = 0.0; Hss[2] = 0.0; Htt[2] = 0.0;
Hrr[3] = 0.0; Hss[3] = 0.0; Htt[3] = 0.0;
Hrr[4] = 0.0; Hss[4] = 0.0; Htt[4] = 0.0;
Hrr[5] = 0.0; Hss[5] = 0.0; Htt[5] = 0.0;
Hrs[0] = 0.0; Hst[0] = 0.5; Hrt[0] = 0.5;
Hrs[1] = 0.0; Hst[1] = 0.0; Hrt[1] = -0.5;
Hrs[2] = 0.0; Hst[2] = -0.5; Hrt[2] = 0.0;
Hrs[3] = 0.0; Hst[3] = -0.5; Hrt[3] = -0.5;
Hrs[4] = 0.0; Hst[4] = 0.0; Hrt[4] = 0.5;
Hrs[5] = 0.0; Hst[5] = 0.5; Hrt[5] = 0.0;
}
//=============================================================================
// P E N T A 1 5
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FEPenta15::shape_fnc(double* H, double r, double s, double t)
{
double u = 1 - r - s;
H[0] = -((1 - t*t)*u) / 2. + ((1 - t)*u*(-1 + 2 * u)) / 2.;
H[1] = (r*(-1 + 2 * r)*(1 - t)) / 2. - (r*(1 - t*t)) / 2.;
H[2] = (s*(-1 + 2 * s)*(1 - t)) / 2. - (s*(1 - t*t)) / 2.;
H[3] = -((1 - t*t)*u) / 2. + ((1 + t)*u*(-1 + 2 * u)) / 2.;
H[4] = (r*(-1 + 2 * r)*(1 + t)) / 2. - (r*(1 - t*t)) / 2.;
H[5] = (s*(-1 + 2 * s)*(1 + t)) / 2. - (s*(1 - t*t)) / 2.;
H[6] = 2 * r*(1 - t)*u;
H[7] = 2 * r*s*(1 - t);
H[8] = 2 * s*(1 - t)*u;
H[9] = 2 * r*(1 + t)*u;
H[10] = 2 * r*s*(1 + t);
H[11] = 2 * s*(1 + t)*u;
H[12] = (1 - t*t)*u;
H[13] = r*(1 - t*t);
H[14] = s*(1 - t*t);
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FEPenta15::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -((-1 + t)*(-2 + 4 * r + 4 * s + t)) / 2.;
Hr[1] = (-2 - 4 * r*(-1 + t) + t + t*t) / 2.;
Hr[2] = 0;
Hr[3] = ((-2 + 4 * r + 4 * s - t)*(1 + t)) / 2.;
Hr[4] = ((1 + t)*(-2 + 4 * r + t)) / 2.;
Hr[5] = 0;
Hr[6] = 2 * (-1 + 2 * r + s)*(-1 + t);
Hr[7] = -2 * s*(-1 + t);
Hr[8] = 2 * s*(-1 + t);
Hr[9] = -2 * (-1 + 2 * r + s)*(1 + t);
Hr[10] = 2 * s*(1 + t);
Hr[11] = -2 * s*(1 + t);
Hr[12] = -1 + t*t;
Hr[13] = 1 - t*t;
Hr[14] = 0;
Hs[0] = -((-1 + t)*(-2 + 4 * r + 4 * s + t)) / 2.;
Hs[1] = 0;
Hs[2] = (-2 - 4 * s*(-1 + t) + t + t*t) / 2.;
Hs[3] = ((-2 + 4 * r + 4 * s - t)*(1 + t)) / 2.;
Hs[4] = 0;
Hs[5] = ((1 + t)*(-2 + 4 * s + t)) / 2.;
Hs[6] = 2 * r*(-1 + t);
Hs[7] = -2 * r*(-1 + t);
Hs[8] = 2 * (-1 + r + 2 * s)*(-1 + t);
Hs[9] = -2 * r*(1 + t);
Hs[10] = 2 * r*(1 + t);
Hs[11] = -2 * (-1 + r + 2 * s)*(1 + t);
Hs[12] = -1 + t*t;
Hs[13] = 0;
Hs[14] = 1 - t*t;
Ht[0] = -((-1 + r + s)*(-1 + 2 * r + 2 * s + 2 * t)) / 2.;
Ht[1] = (r*(1 - 2 * r + 2 * t)) / 2.;
Ht[2] = (s*(1 - 2 * s + 2 * t)) / 2.;
Ht[3] = ((-1 + r + s)*(-1 + 2 * r + 2 * s - 2 * t)) / 2.;
Ht[4] = r*(-0.5 + r + t);
Ht[5] = s*(-0.5 + s + t);
Ht[6] = 2 * r*(-1 + r + s);
Ht[7] = -2 * r*s;
Ht[8] = 2 * s*(-1 + r + s);
Ht[9] = -2 * r*(-1 + r + s);
Ht[10] = 2 * r*s;
Ht[11] = -2 * s*(-1 + r + s);
Ht[12] = 2 * (-1 + r + s)*t;
Ht[13] = -2 * r*t;
Ht[14] = -2 * s*t;
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FEPenta15::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 2 - 2 * t;
Hrr[1] = 2 - 2 * t;
Hrr[2] = 0;
Hrr[3] = 2 * (1 + t);
Hrr[4] = 2 * (1 + t);
Hrr[5] = 0;
Hrr[6] = 4 * (-1 + t);
Hrr[7] = 0;
Hrr[8] = 0;
Hrr[9] = -4 * (1 + t);
Hrr[10] = 0;
Hrr[11] = 0;
Hrr[12] = 0;
Hrr[13] = 0;
Hrr[14] = 0;
Hss[0] = 2 - 2 * t;
Hss[1] = 0;
Hss[2] = 2 - 2 * t;
Hss[3] = 2 * (1 + t);
Hss[4] = 0;
Hss[5] = 2 * (1 + t);
Hss[6] = 0;
Hss[7] = 0;
Hss[8] = 4 * (-1 + t);
Hss[9] = 0;
Hss[10] = 0;
Hss[11] = -4 * (1 + t);
Hss[12] = 0;
Hss[13] = 0;
Hss[14] = 0;
Htt[0] = 1 - r - s;
Htt[1] = r;
Htt[2] = s;
Htt[3] = 1 - r - s;
Htt[4] = r;
Htt[5] = s;
Htt[6] = 0;
Htt[7] = 0;
Htt[8] = 0;
Htt[9] = 0;
Htt[10] = 0;
Htt[11] = 0;
Htt[12] = 2 * (-1 + r + s);
Htt[13] = -2 * r;
Htt[14] = -2 * s;
Hrs[0] = 2 - 2 * t;
Hrs[1] = 0;
Hrs[2] = 0;
Hrs[3] = 2 * (1 + t);
Hrs[4] = 0;
Hrs[5] = 0;
Hrs[6] = 2 * (-1 + t);
Hrs[7] = 2 - 2 * t;
Hrs[8] = 2 * (-1 + t);
Hrs[9] = -2 * (1 + t);
Hrs[10] = 2 * (1 + t);
Hrs[11] = -2 * (1 + t);
Hrs[12] = 0;
Hrs[13] = 0;
Hrs[14] = 0;
Hst[0] = 1.5 - 2 * r - 2 * s - t;
Hst[1] = 0;
Hst[2] = 0.5 - 2 * s + t;
Hst[3] = -1.5 + 2 * r + 2 * s - t;
Hst[4] = 0;
Hst[5] = -0.5 + 2 * s + t;
Hst[6] = 2 * r;
Hst[7] = -2 * r;
Hst[8] = 2 * (-1 + r + 2 * s);
Hst[9] = -2 * r;
Hst[10] = 2 * r;
Hst[11] = -2 * (-1 + r + 2 * s);
Hst[12] = 2 * t;
Hst[13] = 0;
Hst[14] = -2 * t;
Hrt[0] = 1.5 - 2 * r - 2 * s - t;
Hrt[1] = 0.5 - 2 * r + t;
Hrt[2] = 0;
Hrt[3] = -1.5 + 2 * r + 2 * s - t;
Hrt[4] = -0.5 + 2 * r + t;
Hrt[5] = 0;
Hrt[6] = 2 * (-1 + 2 * r + s);
Hrt[7] = -2 * s;
Hrt[8] = 2 * s;
Hrt[9] = -2 * (-1 + 2 * r + s);
Hrt[10] = 2 * s;
Hrt[11] = -2 * s;
Hrt[12] = 2 * t;
Hrt[13] = -2 * t;
Hrt[14] = 0;
}
//=============================================================================
// T E T 1 0
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FETet10::shape_fnc(double* H, double r, double s, double t)
{
double r1 = 1.0 - r - s - t;
double r2 = r;
double r3 = s;
double r4 = t;
H[0] = r1*(2.0*r1 - 1.0);
H[1] = r2*(2.0*r2 - 1.0);
H[2] = r3*(2.0*r3 - 1.0);
H[3] = r4*(2.0*r4 - 1.0);
H[4] = 4.0*r1*r2;
H[5] = 4.0*r2*r3;
H[6] = 4.0*r3*r1;
H[7] = 4.0*r1*r4;
H[8] = 4.0*r2*r4;
H[9] = 4.0*r3*r4;
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FETet10::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -3.0 + 4.0*r + 4.0*(s + t);
Hr[1] = 4.0*r - 1.0;
Hr[2] = 0.0;
Hr[3] = 0.0;
Hr[4] = 4.0 - 8.0*r - 4.0*(s + t);
Hr[5] = 4.0*s;
Hr[6] = -4.0*s;
Hr[7] = -4.0*t;
Hr[8] = 4.0*t;
Hr[9] = 0.0;
Hs[0] = -3.0 + 4.0*s + 4.0*(r + t);
Hs[1] = 0.0;
Hs[2] = 4.0*s - 1.0;
Hs[3] = 0.0;
Hs[4] = -4.0*r;
Hs[5] = 4.0*r;
Hs[6] = 4.0 - 8.0*s - 4.0*(r + t);
Hs[7] = -4.0*t;
Hs[8] = 0.0;
Hs[9] = 4.0*t;
Ht[0] = -3.0 + 4.0*t + 4.0*(r + s);
Ht[1] = 0.0;
Ht[2] = 0.0;
Ht[3] = 4.0*t - 1.0;
Ht[4] = -4.0*r;
Ht[5] = 0.0;
Ht[6] = -4.0*s;
Ht[7] = 4.0 - 8.0*t - 4.0*(r + s);
Ht[8] = 4.0*r;
Ht[9] = 4.0*s;
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FETet10::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 4.0; Hss[0] = 4.0; Htt[0] = 4.0;
Hrr[1] = 4.0; Hss[1] = 0.0; Htt[1] = 0.0;
Hrr[2] = 0.0; Hss[2] = 4.0; Htt[2] = 0.0;
Hrr[3] = 0.0; Hss[3] = 0.0; Htt[3] = 4.0;
Hrr[4] = -8.0; Hss[4] = 0.0; Htt[4] = 0.0;
Hrr[5] = 0.0; Hss[5] = 0.0; Htt[5] = 0.0;
Hrr[6] = 0.0; Hss[6] = -8.0; Htt[6] = 0.0;
Hrr[7] = 0.0; Hss[7] = 0.0; Htt[7] = -8.0;
Hrr[8] = 0.0; Hss[8] = 0.0; Htt[8] = 0.0;
Hrr[9] = 0.0; Hss[9] = 0.0; Htt[9] = 0.0;
Hrs[0] = 4.0; Hst[0] = 4.0; Hrt[0] = 4.0;
Hrs[1] = 0.0; Hst[1] = 0.0; Hrt[1] = 0.0;
Hrs[2] = 0.0; Hst[2] = 0.0; Hrt[2] = 0.0;
Hrs[3] = 0.0; Hst[3] = 0.0; Hrt[3] = 0.0;
Hrs[4] = -4.0; Hst[4] = 0.0; Hrt[4] = -4.0;
Hrs[5] = 4.0; Hst[5] = 0.0; Hrt[5] = 0.0;
Hrs[6] = -4.0; Hst[6] = -4.0; Hrt[6] = 0.0;
Hrs[7] = 0.0; Hst[7] = -4.0; Hrt[7] = -4.0;
Hrs[8] = 0.0; Hst[8] = 0.0; Hrt[8] = 4.0;
Hrs[9] = 0.0; Hst[9] = 4.0; Hrt[9] = 0.0;
}
//=============================================================================
// T E T 1 5
//=============================================================================
//-----------------------------------------------------------------------------
void FETet15::shape_fnc(double* H, double r, double s, double t)
{
double r1 = 1.0 - r - s - t;
double r2 = r;
double r3 = s;
double r4 = t;
H[14] = 256 * r1*r2*r3*r4;
H[10] = 27.0*r1*r2*r3 - 27.0*H[14] / 64.0;
H[11] = 27.0*r1*r2*r4 - 27.0*H[14] / 64.0;
H[12] = 27.0*r2*r3*r4 - 27.0*H[14] / 64.0;
H[13] = 27.0*r3*r1*r4 - 27.0*H[14] / 64.0;
H[0] = r1*(2.0*r1 - 1.0) + (H[10] + H[11] + H[13]) / 9.0 + H[14] / 8.0;
H[1] = r2*(2.0*r2 - 1.0) + (H[10] + H[11] + H[12]) / 9.0 + H[14] / 8.0;
H[2] = r3*(2.0*r3 - 1.0) + (H[10] + H[12] + H[13]) / 9.0 + H[14] / 8.0;
H[3] = r4*(2.0*r4 - 1.0) + (H[11] + H[12] + H[13]) / 9.0 + H[14] / 8.0;
H[4] = 4.0*r1*r2 - 4.0*(H[10] + H[11]) / 9.0 - H[14] / 4.0;
H[5] = 4.0*r2*r3 - 4.0*(H[10] + H[12]) / 9.0 - H[14] / 4.0;
H[6] = 4.0*r3*r1 - 4.0*(H[10] + H[13]) / 9.0 - H[14] / 4.0;
H[7] = 4.0*r1*r4 - 4.0*(H[11] + H[13]) / 9.0 - H[14] / 4.0;
H[8] = 4.0*r2*r4 - 4.0*(H[11] + H[12]) / 9.0 - H[14] / 4.0;
H[9] = 4.0*r3*r4 - 4.0*(H[12] + H[13]) / 9.0 - H[14] / 4.0;
}
//-----------------------------------------------------------------------------
void FETet15::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
double u = 1.0 - r - s - t;
Hr[14] = 256.0*s*t*(u - r);
Hs[14] = 256.0*r*t*(u - s);
Ht[14] = 256.0*r*s*(u - t);
Hr[10] = 27.0*s*(u - r) - 27.0*Hr[14] / 64.0;
Hr[11] = 27.0*t*(u - r) - 27.0*Hr[14] / 64.0;
Hr[12] = 27.0*s*t - 27.0*Hr[14] / 64.0;
Hr[13] = -27.0*s*t - 27.0*Hr[14] / 64.0;
Hs[10] = 27.0*r*(u - s) - 27.0*Hs[14] / 64.0;
Hs[11] = -27.0*r*t - 27.0*Hs[14] / 64.0;
Hs[12] = 27.0*r*t - 27.0*Hs[14] / 64.0;
Hs[13] = 27.0*t*(u - s) - 27.0*Hs[14] / 64.0;
Ht[10] = -27.0*r*s - 27.0*Ht[14] / 64.0;
Ht[11] = 27.0*r*(u - t) - 27.0*Ht[14] / 64.0;
Ht[12] = 27.0*r*s - 27.0*Ht[14] / 64.0;
Ht[13] = 27.0*s*(u - t) - 27.0*Ht[14] / 64.0;
Hr[0] = -(4.0*u - 1.0) + (Hr[10] + Hr[11] + Hr[13]) / 9.0 + Hr[14] / 8.0;
Hr[1] = (4.0*r - 1.0) + (Hr[10] + Hr[11] + Hr[12]) / 9.0 + Hr[14] / 8.0;
Hr[2] = 0.0 + (Hr[10] + Hr[12] + Hr[13]) / 9.0 + Hr[14] / 8.0;
Hr[3] = 0.0 + (Hr[11] + Hr[12] + Hr[13]) / 9.0 + Hr[14] / 8.0;
Hr[4] = 4.0*(u - r) - 4.0*(Hr[10] + Hr[11]) / 9.0 - Hr[14] / 4.0;
Hr[5] = 4.0*s - 4.0*(Hr[10] + Hr[12]) / 9.0 - Hr[14] / 4.0;
Hr[6] = -4.0*s - 4.0*(Hr[10] + Hr[13]) / 9.0 - Hr[14] / 4.0;
Hr[7] = -4.0*t - 4.0*(Hr[11] + Hr[13]) / 9.0 - Hr[14] / 4.0;
Hr[8] = 4.0*t - 4.0*(Hr[11] + Hr[12]) / 9.0 - Hr[14] / 4.0;
Hr[9] = 0.0 - 4.0*(Hr[12] + Hr[13]) / 9.0 - Hr[14] / 4.0;
Hs[0] = -(4.0*u - 1.0) + (Hs[10] + Hs[11] + Hs[13]) / 9.0 + Hs[14] / 8.0;
Hs[1] = 0.0 + (Hs[10] + Hs[11] + Hs[12]) / 9.0 + Hs[14] / 8.0;
Hs[2] = (4.0*s - 1.0) + (Hs[10] + Hs[12] + Hs[13]) / 9.0 + Hs[14] / 8.0;
Hs[3] = 0.0 + (Hs[11] + Hs[12] + Hs[13]) / 9.0 + Hs[14] / 8.0;
Hs[4] = -4.0*r - 4.0*(Hs[10] + Hs[11]) / 9.0 - Hs[14] / 4.0;
Hs[5] = 4.0*r - 4.0*(Hs[10] + Hs[12]) / 9.0 - Hs[14] / 4.0;
Hs[6] = 4.0*(u - s) - 4.0*(Hs[10] + Hs[13]) / 9.0 - Hs[14] / 4.0;
Hs[7] = -4.0*t - 4.0*(Hs[11] + Hs[13]) / 9.0 - Hs[14] / 4.0;
Hs[8] = 0.0 - 4.0*(Hs[11] + Hs[12]) / 9.0 - Hs[14] / 4.0;
Hs[9] = 4.0*t - 4.0*(Hs[12] + Hs[13]) / 9.0 - Hs[14] / 4.0;
Ht[0] = -(4.0*u - 1.0) + (Ht[10] + Ht[11] + Ht[13]) / 9.0 + Ht[14] / 8.0;
Ht[1] = 0.0 + (Ht[10] + Ht[11] + Ht[12]) / 9.0 + Ht[14] / 8.0;
Ht[2] = 0.0 + (Ht[10] + Ht[12] + Ht[13]) / 9.0 + Ht[14] / 8.0;
Ht[3] = (4.0*t - 1.0) + (Ht[11] + Ht[12] + Ht[13]) / 9.0 + Ht[14] / 8.0;
Ht[4] = -4.0*r - 4.0*(Ht[10] + Ht[11]) / 9.0 - Ht[14] / 4.0;
Ht[5] = 0.0 - 4.0*(Ht[10] + Ht[12]) / 9.0 - Ht[14] / 4.0;
Ht[6] = -4.0*s - 4.0*(Ht[10] + Ht[13]) / 9.0 - Ht[14] / 4.0;
Ht[7] = 4.0*(u - t) - 4.0*(Ht[11] + Ht[13]) / 9.0 - Ht[14] / 4.0;
Ht[8] = 4.0*r - 4.0*(Ht[11] + Ht[12]) / 9.0 - Ht[14] / 4.0;
Ht[9] = 4.0*s - 4.0*(Ht[12] + Ht[13]) / 9.0 - Ht[14] / 4.0;
}
//-----------------------------------------------------------------------------
void FETet15::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
double u = 1.0 - r - s - t;
Hrr[14] = -512 * s*t;
Hss[14] = -512 * r*t;
Htt[14] = -512 * r*s;
Hrs[14] = 256.0*t*(u - r - s);
Hst[14] = 256.0*r*(u - s - t);
Hrt[14] = 256.0*s*(u - r - t);
Hrr[10] = -54.0*s - 27.0*Hrr[14] / 64.0;
Hss[10] = -54.0*r - 27.0*Hss[14] / 64.0;
Htt[10] = 0.0 - 27.0*Htt[14] / 64.0;
Hrs[10] = 27.0*(u - r - s) - 27.0*Hrs[14] / 64.0;
Hst[10] = -27.0*r - 27.0*Hst[14] / 64.0;
Hrt[10] = -27.0*s - 27.0*Hrt[14] / 64.0;
Hrr[11] = -54.0*t - 27.0*Hrr[14] / 64.0;
Hss[11] = 0.0 - 27.0*Hss[14] / 64.0;
Htt[11] = -54.*r - 27.0*Htt[14] / 64.0;
Hrs[11] = -27.0*t - 27.0*Hrs[14] / 64.0;
Hst[11] = -27.0*r - 27.0*Hst[14] / 64.0;
Hrt[11] = 27.0*(u - r - t) - 27.0*Hrt[14] / 64.0;
Hrr[12] = 0.0 - 27.0*Hrr[14] / 64.0;
Hss[12] = 0.0 - 27.0*Hss[14] / 64.0;
Htt[12] = 0.0 - 27.0*Htt[14] / 64.0;
Hrs[12] = 27.0*t - 27.0*Hrs[14] / 64.0;
Hst[12] = 27.0*r - 27.0*Hst[14] / 64.0;
Hrt[12] = 27.0*s - 27.0*Hrt[14] / 64.0;
Hrr[13] = 0.0 - 27.0*Hrr[14] / 64.0;
Hss[13] = -54.0*t - 27.0*Hss[14] / 64.0;
Htt[13] = -54.0*s - 27.0*Htt[14] / 64.0;
Hrs[13] = -27.0*t - 27.0*Hrs[14] / 64.0;
Hst[13] = 27.0*(u - t - s) - 27.0*Hst[14] / 64.0;
Hrt[13] = -27.0*s - 27.0*Hrt[14] / 64.0;
Hrr[0] = 4.0 + (Hrr[10] + Hrr[11] + Hrr[13]) / 9.0 + Hrr[14] / 8.0;
Hss[0] = 4.0 + (Hss[10] + Hss[11] + Hss[13]) / 9.0 + Hss[14] / 8.0;
Htt[0] = 4.0 + (Htt[10] + Htt[11] + Htt[13]) / 9.0 + Htt[14] / 8.0;
Hrs[0] = 4.0 + (Hrs[10] + Hrs[11] + Hrs[13]) / 9.0 + Hrs[14] / 8.0;
Hst[0] = 4.0 + (Hst[10] + Hst[11] + Hst[13]) / 9.0 + Hst[14] / 8.0;
Hrt[0] = 4.0 + (Hrt[10] + Hrt[11] + Hrt[13]) / 9.0 + Hrt[14] / 8.0;
Hrr[1] = 4.0 + (Hrr[10] + Hrr[11] + Hrr[12]) / 9.0 + Hrr[14] / 8.0;
Hss[1] = 0.0 + (Hss[10] + Hss[11] + Hss[12]) / 9.0 + Hss[14] / 8.0;
Htt[1] = 0.0 + (Htt[10] + Htt[11] + Htt[12]) / 9.0 + Htt[14] / 8.0;
Hrs[1] = 0.0 + (Hrs[10] + Hrs[11] + Hrs[12]) / 9.0 + Hrs[14] / 8.0;
Hst[1] = 0.0 + (Hst[10] + Hst[11] + Hst[12]) / 9.0 + Hst[14] / 8.0;
Hrt[1] = 0.0 + (Hrt[10] + Hrt[11] + Hrt[12]) / 9.0 + Hrt[14] / 8.0;
Hrr[2] = 0.0 + (Hrr[10] + Hrr[12] + Hrr[13]) / 9.0 + Hrr[14] / 8.0;
Hss[2] = 4.0 + (Hss[10] + Hss[12] + Hss[13]) / 9.0 + Hss[14] / 8.0;
Htt[2] = 0.0 + (Htt[10] + Htt[12] + Htt[13]) / 9.0 + Htt[14] / 8.0;
Hrs[2] = 0.0 + (Hrs[10] + Hrs[12] + Hrs[13]) / 9.0 + Hrs[14] / 8.0;
Hst[2] = 0.0 + (Hst[10] + Hst[12] + Hst[13]) / 9.0 + Hst[14] / 8.0;
Hrt[2] = 0.0 + (Hrt[10] + Hrt[12] + Hrt[13]) / 9.0 + Hrt[14] / 8.0;
Hrr[3] = 0.0 + (Hrr[11] + Hrr[12] + Hrr[13]) / 9.0 + Hrr[14] / 8.0;
Hss[3] = 0.0 + (Hss[11] + Hss[12] + Hss[13]) / 9.0 + Hss[14] / 8.0;
Htt[3] = 4.0 + (Htt[11] + Htt[12] + Htt[13]) / 9.0 + Htt[14] / 8.0;
Hrs[3] = 0.0 + (Hrs[11] + Hrs[12] + Hrs[13]) / 9.0 + Hrs[14] / 8.0;
Hst[3] = 0.0 + (Hst[11] + Hst[12] + Hst[13]) / 9.0 + Hst[14] / 8.0;
Hrt[3] = 0.0 + (Hrt[11] + Hrt[12] + Hrt[13]) / 9.0 + Hrt[14] / 8.0;
Hrr[4] = -8.0 - 4.0*(Hrr[10] + Hrr[11]) / 9.0 - Hrr[14] / 4.0;
Hss[4] = 0.0 - 4.0*(Hss[10] + Hss[11]) / 9.0 - Hss[14] / 4.0;
Htt[4] = 0.0 - 4.0*(Htt[10] + Htt[11]) / 9.0 - Htt[14] / 4.0;
Hrs[4] = -4.0 - 4.0*(Hrs[10] + Hrs[11]) / 9.0 - Hrs[14] / 4.0;
Hst[4] = 0.0 - 4.0*(Hst[10] + Hst[11]) / 9.0 - Hst[14] / 4.0;
Hrt[4] = -4.0 - 4.0*(Hrt[10] + Hrt[11]) / 9.0 - Hrt[14] / 4.0;
Hrr[5] = 0.0 - 4.0*(Hrr[10] + Hrr[12]) / 9.0 - Hrr[14] / 4.0;
Hss[5] = 0.0 - 4.0*(Hss[10] + Hss[12]) / 9.0 - Hss[14] / 4.0;
Htt[5] = 0.0 - 4.0*(Htt[10] + Htt[12]) / 9.0 - Htt[14] / 4.0;
Hrs[5] = 4.0 - 4.0*(Hrs[10] + Hrs[12]) / 9.0 - Hrs[14] / 4.0;
Hst[5] = 0.0 - 4.0*(Hst[10] + Hst[12]) / 9.0 - Hst[14] / 4.0;
Hrt[5] = 0.0 - 4.0*(Hrt[10] + Hrt[12]) / 9.0 - Hrt[14] / 4.0;
Hrr[6] = 0.0 - 4.0*(Hrr[10] + Hrr[13]) / 9.0 - Hrr[14] / 4.0;
Hss[6] = -8.0 - 4.0*(Hss[10] + Hss[13]) / 9.0 - Hss[14] / 4.0;
Htt[6] = 0.0 - 4.0*(Htt[10] + Htt[13]) / 9.0 - Htt[14] / 4.0;
Hrs[6] = -4.0 - 4.0*(Hrs[10] + Hrs[13]) / 9.0 - Hrs[14] / 4.0;
Hst[6] = -4.0 - 4.0*(Hst[10] + Hst[13]) / 9.0 - Hst[14] / 4.0;
Hrt[6] = 0.0 - 4.0*(Hrt[10] + Hrt[13]) / 9.0 - Hrt[14] / 4.0;
Hrr[7] = 0.0 - 4.0*(Hrr[11] + Hrr[13]) / 9.0 - Hrr[14] / 4.0;
Hss[7] = 0.0 - 4.0*(Hss[11] + Hss[13]) / 9.0 - Hss[14] / 4.0;
Htt[7] = -8.0 - 4.0*(Htt[11] + Htt[13]) / 9.0 - Htt[14] / 4.0;
Hrs[7] = 0.0 - 4.0*(Hrs[11] + Hrs[13]) / 9.0 - Hrs[14] / 4.0;
Hst[7] = -4.0 - 4.0*(Hst[11] + Hst[13]) / 9.0 - Hst[14] / 4.0;
Hrt[7] = -4.0 - 4.0*(Hrt[11] + Hrt[13]) / 9.0 - Hrt[14] / 4.0;
Hrr[8] = 0.0 - 4.0*(Hrr[11] + Hrr[12]) / 9.0 - Hrr[14] / 4.0;
Hss[8] = 0.0 - 4.0*(Hss[11] + Hss[12]) / 9.0 - Hss[14] / 4.0;
Htt[8] = 0.0 - 4.0*(Htt[11] + Htt[12]) / 9.0 - Htt[14] / 4.0;
Hrs[8] = 0.0 - 4.0*(Hrs[11] + Hrs[12]) / 9.0 - Hrs[14] / 4.0;
Hst[8] = 0.0 - 4.0*(Hst[11] + Hst[12]) / 9.0 - Hst[14] / 4.0;
Hrt[8] = 4.0 - 4.0*(Hrt[11] + Hrt[12]) / 9.0 - Hrt[14] / 4.0;
Hrr[9] = 0.0 - 4.0*(Hrr[12] + Hrr[13]) / 9.0 - Hrr[14] / 4.0;
Hss[9] = 0.0 - 4.0*(Hss[12] + Hss[13]) / 9.0 - Hss[14] / 4.0;
Htt[9] = 0.0 - 4.0*(Htt[12] + Htt[13]) / 9.0 - Htt[14] / 4.0;
Hrs[9] = 0.0 - 4.0*(Hrs[12] + Hrs[13]) / 9.0 - Hrs[14] / 4.0;
Hst[9] = 4.0 - 4.0*(Hst[12] + Hst[13]) / 9.0 - Hst[14] / 4.0;
Hrt[9] = 0.0 - 4.0*(Hrt[12] + Hrt[13]) / 9.0 - Hrt[14] / 4.0;
}
//=============================================================================
// T E T 2 0
//=============================================================================
//-----------------------------------------------------------------------------
//! values of shape functions
void FETet20::shape_fnc(double* H, double r, double s, double t)
{
double L1 = 1.0 - r - s - t;
double L2 = r;
double L3 = s;
double L4 = t;
H[0] = 0.5*(3 * L1 - 1)*(3 * L1 - 2)*L1;
H[1] = 0.5*(3 * L2 - 1)*(3 * L2 - 2)*L2;
H[2] = 0.5*(3 * L3 - 1)*(3 * L3 - 2)*L3;
H[3] = 0.5*(3 * L4 - 1)*(3 * L4 - 2)*L4;
H[4] = 9.0 / 2.0*(3 * L1 - 1)*L1*L2;
H[5] = 9.0 / 2.0*(3 * L2 - 1)*L1*L2;
H[6] = 9.0 / 2.0*(3 * L2 - 1)*L2*L3;
H[7] = 9.0 / 2.0*(3 * L3 - 1)*L2*L3;
H[8] = 9.0 / 2.0*(3 * L1 - 1)*L1*L3;
H[9] = 9.0 / 2.0*(3 * L3 - 1)*L1*L3;
H[10] = 9.0 / 2.0*(3 * L1 - 1)*L1*L4;
H[11] = 9.0 / 2.0*(3 * L4 - 1)*L1*L4;
H[12] = 9.0 / 2.0*(3 * L2 - 1)*L2*L4;
H[13] = 9.0 / 2.0*(3 * L4 - 1)*L2*L4;
H[14] = 9.0 / 2.0*(3 * L3 - 1)*L3*L4;
H[15] = 9.0 / 2.0*(3 * L4 - 1)*L3*L4;
H[16] = 27.0*L1*L2*L4;
H[17] = 27.0*L2*L3*L4;
H[18] = 27.0*L1*L3*L4;
H[19] = 27.0*L1*L2*L3;
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FETet20::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
double L1 = 1.0 - r - s - t;
double L2 = r;
double L3 = s;
double L4 = t;
Hr[0] = -3. / 2.*(3 * L1 - 2)*L1 - 3. / 2.*(3 * L1 - 1)*L1 - 0.5*(3 * L1 - 1)*(3 * L1 - 2);
Hr[1] = 3. / 2.*(3 * L2 - 2)*L2 + 3. / 2.*(3 * L2 - 1)*L2 + 0.5*(3 * L2 - 1)*(3 * L2 - 2);
Hr[2] = 0.0;
Hr[3] = 0.0;
Hr[4] = -27. / 2.*L1*L2 - 9.0 / 2.0*(3 * L1 - 1)*L2 + 9.0 / 2.0*(3 * L1 - 1)*L1;
Hr[5] = 27. / 2.*L1*L2 - 9.0 / 2.0*(3 * L2 - 1)*L2 + 9.0 / 2.0*(3 * L2 - 1)*L1;
Hr[6] = 27. / 2.*L2*L3 + 9.0 / 2.0*(3 * L2 - 1)*L3;
Hr[7] = 9.0 / 2.0*(3 * L3 - 1)*L3;
Hr[8] = -27. / 2.*L1*L3 - 9.0 / 2.0*(3 * L1 - 1)*L3;
Hr[9] = -9.0 / 2.0*(3 * L3 - 1)*L3;
Hr[10] = -27. / 2.*L1*L4 - 9.0 / 2.0*(3 * L1 - 1)*L4;
Hr[11] = -9. / 2.*(3 * L4 - 1)*L4;
Hr[12] = 27. / 2.*L2*L4 + 9. / 2.*(3 * L2 - 1)*L4;
Hr[13] = 9. / 2.*(3 * L4 - 1)*L4;
Hr[14] = 0.0;
Hr[15] = 0.0;
Hr[16] = -27 * L2*L4 + 27 * L1*L4;
Hr[17] = 27 * L3*L4;
Hr[18] = -27 * L3*L4;
Hr[19] = -27 * L2*L3 + 27 * L1*L3;
Hs[0] = -3. / 2.*(3 * L1 - 2)*L1 - 3. / 2.*(3 * L1 - 1)*L1 - 0.5*(3 * L1 - 1)*(3 * L1 - 2);
Hs[1] = 0.0;
Hs[2] = 3. / 2.*(3 * L3 - 2)*L3 + 3. / 2.*(3 * L3 - 1)*L3 + 0.5*(3 * L3 - 1)*(3 * L3 - 2);
Hs[3] = 0.0;
Hs[4] = -27. / 2.*L1*L2 - 9. / 2.*(3 * L1 - 1)*L2;
Hs[5] = -9. / 2.*(3 * L2 - 1)*L2;
Hs[6] = 9. / 2.*(3 * L2 - 1)*L2;
Hs[7] = 27. / 2.*L2*L3 + 9. / 2.*(3 * L3 - 1)*L2;
Hs[8] = -27. / 2.*L1*L3 - 9. / 2.*(3 * L1 - 1)*L3 + 9. / 2.*(3 * L1 - 1)*L1;
Hs[9] = 27. / 2.*L1*L3 - 9. / 2.*(3 * L3 - 1)*L3 + 9. / 2.*(3 * L3 - 1)*L1;
Hs[10] = -27. / 2.*L1*L4 - 9. / 2.*(3 * L1 - 1)*L4;
Hs[11] = -9. / 2.*(3 * L4 - 1)*L4;
Hs[12] = 0.0;
Hs[13] = 0.0;
Hs[14] = 27. / 2.*L3*L4 + 9. / 2.*(3 * L3 - 1)*L4;
Hs[15] = 9. / 2.*(3 * L4 - 1)*L4;
Hs[16] = -27 * L2*L4;
Hs[17] = 27 * L2*L4;
Hs[18] = -27 * L3*L4 + 27 * L1*L4;
Hs[19] = -27 * L2*L3 + 27 * L1*L2;
Ht[0] = -3. / 2.*(3 * L1 - 2)*L1 - 3. / 2.*(3 * L1 - 1)*L1 - 0.5*(3 * L1 - 1)*(3 * L1 - 2);
Ht[1] = 0.0;
Ht[2] = 0.0;
Ht[3] = 3. / 2.*(3 * L4 - 2)*L4 + 3. / 2.*(3 * L4 - 1)*L4 + 0.5*(3 * L4 - 1)*(3 * L4 - 2);
Ht[4] = -27. / 2.*L1*L2 - 9. / 2.*(3 * L1 - 1)*L2;
Ht[5] = -9. / 2.*(3 * L2 - 1)*L2;
Ht[6] = 0.0;
Ht[7] = 0.0;
Ht[8] = -27. / 2.*L1*L3 - 9. / 2.*(3 * L1 - 1)*L3;
Ht[9] = -9. / 2.*(3 * L3 - 1)*L3;
Ht[10] = -27. / 2.*L1*L4 - 9. / 2.*(3 * L1 - 1)*L4 + 9. / 2.*(3 * L1 - 1)*L1;
Ht[11] = 27. / 2.*L1*L4 - 9. / 2.*(3 * L4 - 1)*L4 + 9. / 2.*(3 * L4 - 1)*L1;
Ht[12] = 9. / 2.*(3 * L2 - 1)*L2;
Ht[13] = 27. / 2.*L2*L4 + 9. / 2.*(3 * L4 - 1)*L2;
Ht[14] = 9. / 2.*(3 * L3 - 1)*L3;
Ht[15] = 27. / 2.*L3*L4 + 9. / 2.*(3 * L4 - 1)*L3;
Ht[16] = -27 * L2*L4 + 27 * L1*L2;
Ht[17] = 27 * L2*L3;
Ht[18] = -27 * L3*L4 + 27 * L1*L3;
Ht[19] = -27 * L2*L3;
}
//-----------------------------------------------------------------------------
//! \todo implement this
void FETet20::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
// do this
}
//=============================================================================
// H E X 2 0
//=============================================================================
//-----------------------------------------------------------------------------
void FEHex20::shape_fnc(double* H, double r, double s, double t)
{
H[8] = 0.25*(1 - r*r)*(1 - s)*(1 - t);
H[9] = 0.25*(1 - s*s)*(1 + r)*(1 - t);
H[10] = 0.25*(1 - r*r)*(1 + s)*(1 - t);
H[11] = 0.25*(1 - s*s)*(1 - r)*(1 - t);
H[12] = 0.25*(1 - r*r)*(1 - s)*(1 + t);
H[13] = 0.25*(1 - s*s)*(1 + r)*(1 + t);
H[14] = 0.25*(1 - r*r)*(1 + s)*(1 + t);
H[15] = 0.25*(1 - s*s)*(1 - r)*(1 + t);
H[16] = 0.25*(1 - t*t)*(1 - r)*(1 - s);
H[17] = 0.25*(1 - t*t)*(1 + r)*(1 - s);
H[18] = 0.25*(1 - t*t)*(1 + r)*(1 + s);
H[19] = 0.25*(1 - t*t)*(1 - r)*(1 + s);
H[0] = 0.125*(1 - r)*(1 - s)*(1 - t) - 0.5*(H[8] + H[11] + H[16]);
H[1] = 0.125*(1 + r)*(1 - s)*(1 - t) - 0.5*(H[8] + H[9] + H[17]);
H[2] = 0.125*(1 + r)*(1 + s)*(1 - t) - 0.5*(H[9] + H[10] + H[18]);
H[3] = 0.125*(1 - r)*(1 + s)*(1 - t) - 0.5*(H[10] + H[11] + H[19]);
H[4] = 0.125*(1 - r)*(1 - s)*(1 + t) - 0.5*(H[12] + H[15] + H[16]);
H[5] = 0.125*(1 + r)*(1 - s)*(1 + t) - 0.5*(H[12] + H[13] + H[17]);
H[6] = 0.125*(1 + r)*(1 + s)*(1 + t) - 0.5*(H[13] + H[14] + H[18]);
H[7] = 0.125*(1 - r)*(1 + s)*(1 + t) - 0.5*(H[14] + H[15] + H[19]);
}
//-----------------------------------------------------------------------------
void FEHex20::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[8] = -0.5*r*(1 - s)*(1 - t);
Hr[9] = 0.25*(1 - s*s)*(1 - t);
Hr[10] = -0.5*r*(1 + s)*(1 - t);
Hr[11] = -0.25*(1 - s*s)*(1 - t);
Hr[12] = -0.5*r*(1 - s)*(1 + t);
Hr[13] = 0.25*(1 - s*s)*(1 + t);
Hr[14] = -0.5*r*(1 + s)*(1 + t);
Hr[15] = -0.25*(1 - s*s)*(1 + t);
Hr[16] = -0.25*(1 - t*t)*(1 - s);
Hr[17] = 0.25*(1 - t*t)*(1 - s);
Hr[18] = 0.25*(1 - t*t)*(1 + s);
Hr[19] = -0.25*(1 - t*t)*(1 + s);
Hr[0] = -0.125*(1 - s)*(1 - t) - 0.5*(Hr[8] + Hr[11] + Hr[16]);
Hr[1] = 0.125*(1 - s)*(1 - t) - 0.5*(Hr[8] + Hr[9] + Hr[17]);
Hr[2] = 0.125*(1 + s)*(1 - t) - 0.5*(Hr[9] + Hr[10] + Hr[18]);
Hr[3] = -0.125*(1 + s)*(1 - t) - 0.5*(Hr[10] + Hr[11] + Hr[19]);
Hr[4] = -0.125*(1 - s)*(1 + t) - 0.5*(Hr[12] + Hr[15] + Hr[16]);
Hr[5] = 0.125*(1 - s)*(1 + t) - 0.5*(Hr[12] + Hr[13] + Hr[17]);
Hr[6] = 0.125*(1 + s)*(1 + t) - 0.5*(Hr[13] + Hr[14] + Hr[18]);
Hr[7] = -0.125*(1 + s)*(1 + t) - 0.5*(Hr[14] + Hr[15] + Hr[19]);
Hs[8] = -0.25*(1 - r*r)*(1 - t);
Hs[9] = -0.5*s*(1 + r)*(1 - t);
Hs[10] = 0.25*(1 - r*r)*(1 - t);
Hs[11] = -0.5*s*(1 - r)*(1 - t);
Hs[12] = -0.25*(1 - r*r)*(1 + t);
Hs[13] = -0.5*s*(1 + r)*(1 + t);
Hs[14] = 0.25*(1 - r*r)*(1 + t);
Hs[15] = -0.5*s*(1 - r)*(1 + t);
Hs[16] = -0.25*(1 - t*t)*(1 - r);
Hs[17] = -0.25*(1 - t*t)*(1 + r);
Hs[18] = 0.25*(1 - t*t)*(1 + r);
Hs[19] = 0.25*(1 - t*t)*(1 - r);
Hs[0] = -0.125*(1 - r)*(1 - t) - 0.5*(Hs[8] + Hs[11] + Hs[16]);
Hs[1] = -0.125*(1 + r)*(1 - t) - 0.5*(Hs[8] + Hs[9] + Hs[17]);
Hs[2] = 0.125*(1 + r)*(1 - t) - 0.5*(Hs[9] + Hs[10] + Hs[18]);
Hs[3] = 0.125*(1 - r)*(1 - t) - 0.5*(Hs[10] + Hs[11] + Hs[19]);
Hs[4] = -0.125*(1 - r)*(1 + t) - 0.5*(Hs[12] + Hs[15] + Hs[16]);
Hs[5] = -0.125*(1 + r)*(1 + t) - 0.5*(Hs[12] + Hs[13] + Hs[17]);
Hs[6] = 0.125*(1 + r)*(1 + t) - 0.5*(Hs[13] + Hs[14] + Hs[18]);
Hs[7] = 0.125*(1 - r)*(1 + t) - 0.5*(Hs[14] + Hs[15] + Hs[19]);
Ht[8] = -0.25*(1 - r*r)*(1 - s);
Ht[9] = -0.25*(1 - s*s)*(1 + r);
Ht[10] = -0.25*(1 - r*r)*(1 + s);
Ht[11] = -0.25*(1 - s*s)*(1 - r);
Ht[12] = 0.25*(1 - r*r)*(1 - s);
Ht[13] = 0.25*(1 - s*s)*(1 + r);
Ht[14] = 0.25*(1 - r*r)*(1 + s);
Ht[15] = 0.25*(1 - s*s)*(1 - r);
Ht[16] = -0.5*t*(1 - r)*(1 - s);
Ht[17] = -0.5*t*(1 + r)*(1 - s);
Ht[18] = -0.5*t*(1 + r)*(1 + s);
Ht[19] = -0.5*t*(1 - r)*(1 + s);
Ht[0] = -0.125*(1 - r)*(1 - s) - 0.5*(Ht[8] + Ht[11] + Ht[16]);
Ht[1] = -0.125*(1 + r)*(1 - s) - 0.5*(Ht[8] + Ht[9] + Ht[17]);
Ht[2] = -0.125*(1 + r)*(1 + s) - 0.5*(Ht[9] + Ht[10] + Ht[18]);
Ht[3] = -0.125*(1 - r)*(1 + s) - 0.5*(Ht[10] + Ht[11] + Ht[19]);
Ht[4] = 0.125*(1 - r)*(1 - s) - 0.5*(Ht[12] + Ht[15] + Ht[16]);
Ht[5] = 0.125*(1 + r)*(1 - s) - 0.5*(Ht[12] + Ht[13] + Ht[17]);
Ht[6] = 0.125*(1 + r)*(1 + s) - 0.5*(Ht[13] + Ht[14] + Ht[18]);
Ht[7] = 0.125*(1 - r)*(1 + s) - 0.5*(Ht[14] + Ht[15] + Ht[19]);
}
//-----------------------------------------------------------------------------
void FEHex20::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
// Hrr
Hrr[8] = -0.5*(1 - s)*(1 - t);
Hrr[9] = 0.;
Hrr[10] = -0.5*(1 + s)*(1 - t);
Hrr[11] = 0.;
Hrr[12] = -0.5*(1 - s)*(1 + t);
Hrr[13] = 0.;
Hrr[14] = -0.5*(1 + s)*(1 + t);
Hrr[15] = 0.;
Hrr[16] = 0.;
Hrr[17] = 0.;
Hrr[18] = 0.;
Hrr[19] = 0.;
Hrr[0] = -0.5*(Hrr[8] + Hrr[11] + Hrr[16]);
Hrr[1] = -0.5*(Hrr[8] + Hrr[9] + Hrr[17]);
Hrr[2] = -0.5*(Hrr[9] + Hrr[10] + Hrr[18]);
Hrr[3] = -0.5*(Hrr[10] + Hrr[11] + Hrr[19]);
Hrr[4] = -0.5*(Hrr[12] + Hrr[15] + Hrr[16]);
Hrr[5] = -0.5*(Hrr[12] + Hrr[13] + Hrr[17]);
Hrr[6] = -0.5*(Hrr[13] + Hrr[14] + Hrr[18]);
Hrr[7] = -0.5*(Hrr[14] + Hrr[15] + Hrr[19]);
// Hss
Hss[8] = 0.;
Hss[9] = -0.5*(1 + r)*(1 - t);
Hss[10] = 0.;
Hss[11] = -0.5*(1 - r)*(1 - t);
Hss[12] = 0.;
Hss[13] = -0.5*(1 + r)*(1 + t);
Hss[14] = 0.;
Hss[15] = -0.5*(1 - r)*(1 + t);
Hss[16] = 0.;
Hss[17] = 0.;
Hss[18] = 0.;
Hss[19] = 0.;
Hss[0] = -0.5*(Hss[8] + Hss[11] + Hss[16]);
Hss[1] = -0.5*(Hss[8] + Hss[9] + Hss[17]);
Hss[2] = -0.5*(Hss[9] + Hss[10] + Hss[18]);
Hss[3] = -0.5*(Hss[10] + Hss[11] + Hss[19]);
Hss[4] = -0.5*(Hss[12] + Hss[15] + Hss[16]);
Hss[5] = -0.5*(Hss[12] + Hss[13] + Hss[17]);
Hss[6] = -0.5*(Hss[13] + Hss[14] + Hss[18]);
Hss[7] = -0.5*(Hss[14] + Hss[15] + Hss[19]);
// Htt
Htt[8] = 0.;
Htt[9] = 0.;
Htt[10] = 0.;
Htt[11] = 0.;
Htt[12] = 0.;
Htt[13] = 0.;
Htt[14] = 0.;
Htt[15] = 0.;
Htt[16] = -0.5*(1 - r)*(1 - s);
Htt[17] = -0.5*(1 + r)*(1 - s);
Htt[18] = -0.5*(1 + r)*(1 + s);
Htt[19] = -0.5*(1 - r)*(1 + s);
Htt[0] = -0.5*(Htt[8] + Htt[11] + Htt[16]);
Htt[1] = -0.5*(Htt[8] + Htt[9] + Htt[17]);
Htt[2] = -0.5*(Htt[9] + Htt[10] + Htt[18]);
Htt[3] = -0.5*(Htt[10] + Htt[11] + Htt[19]);
Htt[4] = -0.5*(Htt[12] + Htt[15] + Htt[16]);
Htt[5] = -0.5*(Htt[12] + Htt[13] + Htt[17]);
Htt[6] = -0.5*(Htt[13] + Htt[14] + Htt[18]);
Htt[7] = -0.5*(Htt[14] + Htt[15] + Htt[19]);
// Hrs
Hrs[8] = 0.5*r*(1 - t);
Hrs[9] = -0.5*s*(1 - t);
Hrs[10] = -0.5*r*(1 - t);
Hrs[11] = 0.5*s*(1 - t);
Hrs[12] = 0.5*r*(1 + t);
Hrs[13] = -0.5*s*(1 + t);
Hrs[14] = -0.5*r*(1 + t);
Hrs[15] = 0.5*s*(1 + t);
Hrs[16] = 0.25*(1 - t*t);
Hrs[17] = -0.25*(1 - t*t);
Hrs[18] = 0.25*(1 - t*t);
Hrs[19] = -0.25*(1 - t*t);
Hrs[0] = 0.125*(1 - t) - 0.5*(Hrs[8] + Hrs[11] + Hrs[16]);
Hrs[1] = -0.125*(1 - t) - 0.5*(Hrs[8] + Hrs[9] + Hrs[17]);
Hrs[2] = 0.125*(1 - t) - 0.5*(Hrs[9] + Hrs[10] + Hrs[18]);
Hrs[3] = -0.125*(1 - t) - 0.5*(Hrs[10] + Hrs[11] + Hrs[19]);
Hrs[4] = 0.125*(1 + t) - 0.5*(Hrs[12] + Hrs[15] + Hrs[16]);
Hrs[5] = -0.125*(1 + t) - 0.5*(Hrs[12] + Hrs[13] + Hrs[17]);
Hrs[6] = 0.125*(1 + t) - 0.5*(Hrs[13] + Hrs[14] + Hrs[18]);
Hrs[7] = -0.125*(1 + t) - 0.5*(Hrs[14] + Hrs[15] + Hrs[19]);
// Hst
Hst[8] = 0.25*(1 - r*r);
Hst[9] = 0.5*s*(1 + r);
Hst[10] = -0.25*(1 - r*r);
Hst[11] = 0.5*s*(1 - r);
Hst[12] = -0.25*(1 - r*r);
Hst[13] = -0.5*s*(1 + r);
Hst[14] = 0.25*(1 - r*r);
Hst[15] = -0.5*s*(1 - r);
Hst[16] = 0.5*t*(1 - r);
Hst[17] = 0.5*t*(1 + r);
Hst[18] = -0.5*t*(1 + r);
Hst[19] = -0.5*t*(1 - r);
Hst[0] = 0.125*(1 - r) - 0.5*(Hst[8] + Hst[11] + Hst[16]);
Hst[1] = 0.125*(1 + r) - 0.5*(Hst[8] + Hst[9] + Hst[17]);
Hst[2] = -0.125*(1 + r) - 0.5*(Hst[9] + Hst[10] + Hst[18]);
Hst[3] = -0.125*(1 - r) - 0.5*(Hst[10] + Hst[11] + Hst[19]);
Hst[4] = -0.125*(1 - r) - 0.5*(Hst[12] + Hst[15] + Hst[16]);
Hst[5] = -0.125*(1 + r) - 0.5*(Hst[12] + Hst[13] + Hst[17]);
Hst[6] = 0.125*(1 + r) - 0.5*(Hst[13] + Hst[14] + Hst[18]);
Hst[7] = 0.125*(1 - r) - 0.5*(Hst[14] + Hst[15] + Hst[19]);
// Hrt
Hrt[8] = 0.5*r*(1 - s);
Hrt[9] = -0.25*(1 - s*s);
Hrt[10] = 0.5*r*(1 + s);
Hrt[11] = 0.25*(1 - s*s);
Hrt[12] = -0.5*r*(1 - s);
Hrt[13] = 0.25*(1 - s*s);
Hrt[14] = -0.5*r*(1 + s);
Hrt[15] = -0.25*(1 - s*s);
Hrt[16] = 0.5*t*(1 - s);
Hrt[17] = -0.5*t*(1 - s);
Hrt[18] = -0.5*t*(1 + s);
Hrt[19] = 0.5*t*(1 + s);
Hrt[0] = 0.125*(1 - s) - 0.5*(Hrt[8] + Hrt[11] + Hrt[16]);
Hrt[1] = -0.125*(1 - s) - 0.5*(Hrt[8] + Hrt[9] + Hrt[17]);
Hrt[2] = -0.125*(1 + s) - 0.5*(Hrt[9] + Hrt[10] + Hrt[18]);
Hrt[3] = 0.125*(1 + s) - 0.5*(Hrt[10] + Hrt[11] + Hrt[19]);
Hrt[4] = -0.125*(1 - s) - 0.5*(Hrt[12] + Hrt[15] + Hrt[16]);
Hrt[5] = 0.125*(1 - s) - 0.5*(Hrt[12] + Hrt[13] + Hrt[17]);
Hrt[6] = 0.125*(1 + s) - 0.5*(Hrt[13] + Hrt[14] + Hrt[18]);
Hrt[7] = -0.125*(1 + s) - 0.5*(Hrt[14] + Hrt[15] + Hrt[19]);
}
//=============================================================================
// H E X 2 7
//=============================================================================
// Lookup table for 27-node hex that maps a node index into a triplet that identifies
// the shape functions.
static int HEX27_LUT[27][3] = {
{ 0,0,0 },
{ 1,0,0 },
{ 1,1,0 },
{ 0,1,0 },
{ 0,0,1 },
{ 1,0,1 },
{ 1,1,1 },
{ 0,1,1 },
{ 2,0,0 },
{ 1,2,0 },
{ 2,1,0 },
{ 0,2,0 },
{ 2,0,1 },
{ 1,2,1 },
{ 2,1,1 },
{ 0,2,1 },
{ 0,0,2 },
{ 1,0,2 },
{ 1,1,2 },
{ 0,1,2 },
{ 2,0,2 },
{ 1,2,2 },
{ 2,1,2 },
{ 0,2,2 },
{ 2,2,0 },
{ 2,2,1 },
{ 2,2,2 }
};
//-----------------------------------------------------------------------------
//! values of shape functions
void FEHex27::shape_fnc(double* H, double r, double s, double t)
{
double R[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r };
double S[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s };
double T[3] = { 0.5*t*(t - 1.0), 0.5*t*(t + 1.0), 1.0 - t*t };
H[0] = R[0] * S[0] * T[0];
H[1] = R[1] * S[0] * T[0];
H[2] = R[1] * S[1] * T[0];
H[3] = R[0] * S[1] * T[0];
H[4] = R[0] * S[0] * T[1];
H[5] = R[1] * S[0] * T[1];
H[6] = R[1] * S[1] * T[1];
H[7] = R[0] * S[1] * T[1];
H[8] = R[2] * S[0] * T[0];
H[9] = R[1] * S[2] * T[0];
H[10] = R[2] * S[1] * T[0];
H[11] = R[0] * S[2] * T[0];
H[12] = R[2] * S[0] * T[1];
H[13] = R[1] * S[2] * T[1];
H[14] = R[2] * S[1] * T[1];
H[15] = R[0] * S[2] * T[1];
H[16] = R[0] * S[0] * T[2];
H[17] = R[1] * S[0] * T[2];
H[18] = R[1] * S[1] * T[2];
H[19] = R[0] * S[1] * T[2];
H[20] = R[2] * S[0] * T[2];
H[21] = R[1] * S[2] * T[2];
H[22] = R[2] * S[1] * T[2];
H[23] = R[0] * S[2] * T[2];
H[24] = R[2] * S[2] * T[0];
H[25] = R[2] * S[2] * T[1];
H[26] = R[2] * S[2] * T[2];
}
//-----------------------------------------------------------------------------
//! values of shape function derivatives
void FEHex27::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
double R[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r };
double S[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s };
double T[3] = { 0.5*t*(t - 1.0), 0.5*t*(t + 1.0), 1.0 - t*t };
double DR[3] = { r - 0.5, r + 0.5, -2.0*r };
double DS[3] = { s - 0.5, s + 0.5, -2.0*s };
double DT[3] = { t - 0.5, t + 0.5, -2.0*t };
Hr[0] = DR[0] * S[0] * T[0]; Hs[0] = R[0] * DS[0] * T[0]; Ht[0] = R[0] * S[0] * DT[0];
Hr[1] = DR[1] * S[0] * T[0]; Hs[1] = R[1] * DS[0] * T[0]; Ht[1] = R[1] * S[0] * DT[0];
Hr[2] = DR[1] * S[1] * T[0]; Hs[2] = R[1] * DS[1] * T[0]; Ht[2] = R[1] * S[1] * DT[0];
Hr[3] = DR[0] * S[1] * T[0]; Hs[3] = R[0] * DS[1] * T[0]; Ht[3] = R[0] * S[1] * DT[0];
Hr[4] = DR[0] * S[0] * T[1]; Hs[4] = R[0] * DS[0] * T[1]; Ht[4] = R[0] * S[0] * DT[1];
Hr[5] = DR[1] * S[0] * T[1]; Hs[5] = R[1] * DS[0] * T[1]; Ht[5] = R[1] * S[0] * DT[1];
Hr[6] = DR[1] * S[1] * T[1]; Hs[6] = R[1] * DS[1] * T[1]; Ht[6] = R[1] * S[1] * DT[1];
Hr[7] = DR[0] * S[1] * T[1]; Hs[7] = R[0] * DS[1] * T[1]; Ht[7] = R[0] * S[1] * DT[1];
Hr[8] = DR[2] * S[0] * T[0]; Hs[8] = R[2] * DS[0] * T[0]; Ht[8] = R[2] * S[0] * DT[0];
Hr[9] = DR[1] * S[2] * T[0]; Hs[9] = R[1] * DS[2] * T[0]; Ht[9] = R[1] * S[2] * DT[0];
Hr[10] = DR[2] * S[1] * T[0]; Hs[10] = R[2] * DS[1] * T[0]; Ht[10] = R[2] * S[1] * DT[0];
Hr[11] = DR[0] * S[2] * T[0]; Hs[11] = R[0] * DS[2] * T[0]; Ht[11] = R[0] * S[2] * DT[0];
Hr[12] = DR[2] * S[0] * T[1]; Hs[12] = R[2] * DS[0] * T[1]; Ht[12] = R[2] * S[0] * DT[1];
Hr[13] = DR[1] * S[2] * T[1]; Hs[13] = R[1] * DS[2] * T[1]; Ht[13] = R[1] * S[2] * DT[1];
Hr[14] = DR[2] * S[1] * T[1]; Hs[14] = R[2] * DS[1] * T[1]; Ht[14] = R[2] * S[1] * DT[1];
Hr[15] = DR[0] * S[2] * T[1]; Hs[15] = R[0] * DS[2] * T[1]; Ht[15] = R[0] * S[2] * DT[1];
Hr[16] = DR[0] * S[0] * T[2]; Hs[16] = R[0] * DS[0] * T[2]; Ht[16] = R[0] * S[0] * DT[2];
Hr[17] = DR[1] * S[0] * T[2]; Hs[17] = R[1] * DS[0] * T[2]; Ht[17] = R[1] * S[0] * DT[2];
Hr[18] = DR[1] * S[1] * T[2]; Hs[18] = R[1] * DS[1] * T[2]; Ht[18] = R[1] * S[1] * DT[2];
Hr[19] = DR[0] * S[1] * T[2]; Hs[19] = R[0] * DS[1] * T[2]; Ht[19] = R[0] * S[1] * DT[2];
Hr[20] = DR[2] * S[0] * T[2]; Hs[20] = R[2] * DS[0] * T[2]; Ht[20] = R[2] * S[0] * DT[2];
Hr[21] = DR[1] * S[2] * T[2]; Hs[21] = R[1] * DS[2] * T[2]; Ht[21] = R[1] * S[2] * DT[2];
Hr[22] = DR[2] * S[1] * T[2]; Hs[22] = R[2] * DS[1] * T[2]; Ht[22] = R[2] * S[1] * DT[2];
Hr[23] = DR[0] * S[2] * T[2]; Hs[23] = R[0] * DS[2] * T[2]; Ht[23] = R[0] * S[2] * DT[2];
Hr[24] = DR[2] * S[2] * T[0]; Hs[24] = R[2] * DS[2] * T[0]; Ht[24] = R[2] * S[2] * DT[0];
Hr[25] = DR[2] * S[2] * T[1]; Hs[25] = R[2] * DS[2] * T[1]; Ht[25] = R[2] * S[2] * DT[1];
Hr[26] = DR[2] * S[2] * T[2]; Hs[26] = R[2] * DS[2] * T[2]; Ht[26] = R[2] * S[2] * DT[2];
}
//-----------------------------------------------------------------------------
//! values of shape function second derivatives
void FEHex27::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
double NR[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r };
double NS[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s };
double NT[3] = { 0.5*t*(t - 1.0), 0.5*t*(t + 1.0), 1.0 - t*t };
double DR[3] = { r - 0.5, r + 0.5, -2.0*r };
double DS[3] = { s - 0.5, s + 0.5, -2.0*s };
double DT[3] = { t - 0.5, t + 0.5, -2.0*t };
double HR[3] = { 1.0, 1.0, -2.0 };
double HS[3] = { 1.0, 1.0, -2.0 };
double HT[3] = { 1.0, 1.0, -2.0 };
for (int a = 0; a<27; ++a)
{
int i = HEX27_LUT[a][0];
int j = HEX27_LUT[a][1];
int k = HEX27_LUT[a][2];
Hrr[a] = HR[i] * NS[j] * NT[k];
Hss[a] = NR[i] * HS[j] * NT[k];
Htt[a] = NR[i] * NS[j] * HT[k];
Hrs[a] = DR[i] * DS[j] * NT[k];
Hst[a] = NR[i] * DS[j] * DT[k];
Hrt[a] = DR[i] * NS[j] * DT[k];
}
}
//=============================================================================
// P Y R A 5
//=============================================================================
//! values of shape functions
void FEPyra5::shape_fnc(double* H, double r, double s, double t)
{
H[0] = 0.125*(1.0 - r)*(1.0 - s)*(1.0 - t);
H[1] = 0.125*(1.0 + r)*(1.0 - s)*(1.0 - t);
H[2] = 0.125*(1.0 + r)*(1.0 + s)*(1.0 - t);
H[3] = 0.125*(1.0 - r)*(1.0 + s)*(1.0 - t);
H[4] = 0.5*(1.0 + t);
}
//! values of shape function derivatives
void FEPyra5::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[0] = -0.125*(1.0 - s)*(1.0 - t);
Hr[1] = 0.125*(1.0 - s)*(1.0 - t);
Hr[2] = 0.125*(1.0 + s)*(1.0 - t);
Hr[3] = -0.125*(1.0 + s)*(1.0 - t);
Hr[4] = 0.0;
Hs[0] = -0.125*(1.0 - r)*(1.0 - t);
Hs[1] = -0.125*(1.0 + r)*(1.0 - t);
Hs[2] = 0.125*(1.0 + r)*(1.0 - t);
Hs[3] = 0.125*(1.0 - r)*(1.0 - t);
Hs[4] = 0.0;
Ht[0] = -0.125*(1.0 - r)*(1.0 - s);
Ht[1] = -0.125*(1.0 + r)*(1.0 - s);
Ht[2] = -0.125*(1.0 + r)*(1.0 + s);
Ht[3] = -0.125*(1.0 - r)*(1.0 + s);
Ht[4] = 0.5;
}
//! values of shape function second derivatives
void FEPyra5::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[0] = 0.0; Hss[0] = 0.0; Htt[0] = 0.0;
Hrr[1] = 0.0; Hss[1] = 0.0; Htt[1] = 0.0;
Hrr[2] = 0.0; Hss[2] = 0.0; Htt[2] = 0.0;
Hrr[3] = 0.0; Hss[3] = 0.0; Htt[3] = 0.0;
Hrr[4] = 0.0; Hss[4] = 0.0; Htt[4] = 0.0;
Hrs[0] = 0.125*(1.0 - t); Hrt[0] = 0.125*(1.0 - s); Hst[0] = 0.125*(1.0 - r);
Hrs[1] = -0.125*(1.0 - t); Hrt[1] = -0.125*(1.0 - s); Hst[1] = 0.125*(1.0 + r);
Hrs[2] = 0.125*(1.0 - t); Hrt[2] = -0.125*(1.0 + s); Hst[2] = -0.125*(1.0 + r);
Hrs[3] = -0.125*(1.0 - t); Hrt[3] = 0.125*(1.0 + s); Hst[3] = -0.125*(1.0 - r);
Hrs[4] = 0.0; Hrt[4] = 0.0; Hst[4] = 0.0;
}
//=============================================================================
// P Y R A 1 3
//=============================================================================
//! values of shape functions
void FEPyra13::shape_fnc(double* H, double r, double s, double t)
{
H[5] = 0.25*(1 - r*r)*(1 - s)*(1 - t);
H[6] = 0.25*(1 - s*s)*(1 + r)*(1 - t);
H[7] = 0.25*(1 - r*r)*(1 + s)*(1 - t);
H[8] = 0.25*(1 - s*s)*(1 - r)*(1 - t);
H[9] = 0.25*(1 - t*t)*(1 - r)*(1 - s);
H[10] = 0.25*(1 - t*t)*(1 + r)*(1 - s);
H[11] = 0.25*(1 - t*t)*(1 + r)*(1 + s);
H[12] = 0.25*(1 - t*t)*(1 - r)*(1 + s);
H[0] = 0.125*(1 - r)*(1 - s)*(1 - t) - 0.5*(H[5] + H[8] + H[9]);
H[1] = 0.125*(1 + r)*(1 - s)*(1 - t) - 0.5*(H[5] + H[6] + H[10]);
H[2] = 0.125*(1 + r)*(1 + s)*(1 - t) - 0.5*(H[6] + H[7] + H[11]);
H[3] = 0.125*(1 - r)*(1 + s)*(1 - t) - 0.5*(H[7] + H[8] + H[12]);
H[4] = 0.5*t*(1 + t);
}
//! values of shape function derivatives
void FEPyra13::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t)
{
Hr[ 0] = 0.125 + r*(0.25 + s*(-0.25 + 0.25*t) - 0.25*t) + s*s*(-0.125 + 0.125*t) +
s*(-0.125 + 0.125*t)*t - 0.125*t*t;
Hr[ 1] = -0.125 + r*(0.25 + s*(-0.25 + 0.25*t) - 0.25*t) + s*s*(0.125 - 0.125*t) +
s*(0.125 - 0.125*t)*t + 0.125*t*t;
Hr[ 2] = -0.125 + r*(0.25 + s*(0.25 - 0.25*t) - 0.25*t) + s*s*(0.125 - 0.125*t) +
s*(-0.125 + 0.125*t)*t + 0.125*t*t;
Hr[ 3] = 0.125 + r*(0.25 + s*(0.25 - 0.25*t) - 0.25*t) + s*s*(-0.125 + 0.125*t) +
s*(0.125 - 0.125*t)*t - 0.125*t*t;
Hr[ 4] = 0;
Hr[ 5] = -0.5*r*(-1. + s)*(-1. + t);
Hr[ 6] = 0.25*(-1. + s*s)*(-1. + t);
Hr[ 7] = 0.5*r*(1. + s)*(-1. + t);
Hr[ 8] = -0.25*(-1. + s*s)*(-1. + t);
Hr[ 9] = -0.25*(-1. + s)*(-1. + t*t);
Hr[10] = 0.25*(-1. + s)*(-1. + t*t);
Hr[11] = -0.25*(1. + s)*(-1. + t*t);
Hr[12] = 0.25*(1. + s)*(-1. + t*t);
Hs[ 0] = 0.125 + s*(0.25 - 0.25*t) + r*r*(-0.125 + 0.125*t) - 0.125*t*t +
r*(s*(-0.25 + 0.25*t) + (-0.125 + 0.125*t)*t);
Hs[ 1] = 0.125 + s*(0.25 - 0.25*t) + r*r*(-0.125 + 0.125*t) - 0.125*t*t +
r*(s*(0.25 - 0.25*t) + (0.125 - 0.125*t)*t);
Hs[ 2] = -0.125 + s*(0.25 - 0.25*t) + r*r*(0.125 - 0.125*t) + 0.125*t*t +
r*(s*(0.25 - 0.25*t) + (-0.125 + 0.125*t)*t);
Hs[ 3] = -0.125 + s*(0.25 - 0.25*t) + r*r*(0.125 - 0.125*t) + 0.125*t*t +
r*(s*(-0.25 + 0.25*t) + (0.125 - 0.125*t)*t);
Hs[ 4] = 0;
Hs[ 5] = -0.25*(-1. + r*r)*(-1. + t);
Hs[ 6] = 0.5*(1. + r)*s*(-1. + t);
Hs[ 7] = 0.25*(-1. + r*r)*(-1. + t);
Hs[ 8] = -0.5*(-1. + r)*s*(-1. + t);
Hs[ 9] = -0.25*(-1. + r)*(-1. + t*t);
Hs[10] = 0.25*(1. + r)*(-1. + t*t);
Hs[11] = -0.25*(1. + r)*(-1. + t*t);
Hs[12] = 0.25*(-1. + r)*(-1. + t*t);
Ht[ 0] = -0.125*(-1. + r)*(-1. + s) + 0.125*(-1. + r*r)*(-1. + s) +
0.125*(-1. + r)*(-1. + s*s) + 0.25*(-1. + r)*(-1. + s)*t;
Ht[ 1] = 0.125*(1. + r)*(-1. + s) + 0.125*(-1. + r*r)*(-1. + s) -
0.125*(1. + r)*(-1. + s*s) - 0.25*(1. + r)*(-1. + s)*t;
Ht[ 2] = -0.125*(1. + r)*(1. + s) - 0.125*(-1. + r*r)*(1. + s) -
0.125*(1. + r)*(-1. + s*s) + 0.25*(1. + r)*(1. + s)*t;
Ht[ 3] = 0.125*(-1. + r)*(1. + s) - 0.125*(-1. + r*r)*(1. + s) +
0.125*(-1. + r)*(-1. + s*s) - 0.25*(-1. + r)*(1. + s)*t;
Ht[ 4] = 0.5 + 1.*t;
Ht[ 5] = -0.25*(-1. + r*r)*(-1. + s);
Ht[ 6] = 0.25*(1. + r)*(-1. + s*s);
Ht[ 7] = 0.25*(-1. + r*r)*(1. + s);
Ht[ 8] = -0.25*(-1. + r)*(-1. + s*s);
Ht[ 9] = -0.5*(-1. + r)*(-1. + s)*t;
Ht[10] = 0.5*(1. + r)*(-1. + s)*t;
Ht[11] = -0.5*(1. + r)*(1. + s)*t;
Ht[12] = 0.5*(-1. + r)*(1. + s)*t;
}
//! values of shape function second derivatives
void FEPyra13::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t)
{
Hrr[ 0] = 0.25*(-1. + s)*(-1. + t);
Hrr[ 1] = 0.25*(-1. + s)*(-1. + t);
Hrr[ 2] = -0.25*(1. + s)*(-1. + t);
Hrr[ 3] = -0.25*(1. + s)*(-1. + t);
Hrr[ 4] = 0;
Hrr[ 5] = -0.5*(-1. + s)*(-1. + t);
Hrr[ 6] = 0.;
Hrr[ 7] = 0.5*(1. + s)*(-1. + t);
Hrr[ 8] = 0.;
Hrr[ 9] = 0.;
Hrr[10] = 0.;
Hrr[11] = 0.;
Hrr[12] = 0.;
Hss[ 0] = 0.25*(-1. + r)*(-1. + t);
Hss[ 1] = -0.25*(1. + r)*(-1. + t);
Hss[ 2] = -0.25*(1. + r)*(-1. + t);
Hss[ 3] = 0.25*(-1. + r)*(-1. + t);
Hss[ 4] = 0;
Hss[ 5] = 0;
Hss[ 6] = 0.5*(1. + r)*(-1. + t);
Hss[ 7] = 0;
Hss[ 8] = -0.5*(-1. + r)*(-1. + t);
Hss[ 9] = 0;
Hss[10] = 0;
Hss[11] = 0;
Hss[12] = 0;
Htt[ 0] = 0.25*(-1. + r)*(-1. + s);
Htt[ 1] = -0.25*(1. + r)*(-1. + s);
Htt[ 2] = 0.25*(1. + r)*(1. + s);
Htt[ 3] = -0.25*(-1. + r)*(1. + s);
Htt[ 4] = 1.;
Htt[ 5] = 0;
Htt[ 6] = 0;
Htt[ 7] = 0;
Htt[ 8] = 0;
Htt[ 9] = -0.5*(-1. + r)*(-1. + s);
Htt[10] = 0.5*(1. + r)*(-1. + s);
Htt[11] = -0.5*(1. + r)*(1. + s);
Htt[12] = 0.5*(-1. + r)*(1. + s);
Hrs[ 0] = r*(-0.25 + 0.25*t) + s*(-0.25 + 0.25*t) - 0.125*t + 0.125*t*t;
Hrs[ 1] = s*(0.25 - 0.25*t) + r*(-0.25 + 0.25*t) + 0.125*t - 0.125*t*t;
Hrs[ 2] = r*(0.25 - 0.25*t) + s*(0.25 - 0.25*t) - 0.125*t + 0.125*t*t;
Hrs[ 3] = r*(0.25 - 0.25*t) + s*(-0.25 + 0.25*t) + 0.125*t - 0.125*t*t;
Hrs[ 4] = 0;
Hrs[ 5] = -0.5*r*(-1. + t);
Hrs[ 6] = 0.5*s*(-1. + t);
Hrs[ 7] = 0.5*r*(-1. + t);
Hrs[ 8] = -0.5*s*(-1. + t);
Hrs[ 9] = -0.25*(-1. + t*t);
Hrs[10] = 0.25*(-1. + t*t);
Hrs[11] = -0.25*(-1. + t*t);
Hrs[12] = 0.25*(-1. + t*t);
Hrs[ 0] = 0.125*r*r - 0.25*s + r*(-0.125 + 0.25*s + 0.25*t) - 0.25*t;
Hst[ 1] = 0.125*r*r - 0.25*s + r*(0.125 - 0.25*s - 0.25*t) - 0.25*t;
Hst[ 2] = -0.125*r*r - 0.25*s + r*(-0.125 - 0.25*s + 0.25*t) + 0.25*t;
Hst[ 3] = -0.125*r*r - 0.25*s + r*(0.125 + 0.25*s - 0.25*t) + 0.25*t;
Hst[ 4] = 0;
Hst[ 5] = -0.25*(-1. + r*r);
Hst[ 6] = 0.5*(1. + r)*s;
Hst[ 7] = 0.25*(-1. + r*r);
Hst[ 8] = -0.5*(-1. + r)*s;
Hst[ 9] = -0.5*(-1. + r)*t;
Hst[10] = 0.5*(1. + r)*t;
Hst[11] = -0.5*(1. + r)*t;
Hst[12] = 0.5*(-1. + r)*t;
Hrt[ 0] = r*(-0.25 + 0.25*s) + 0.125*s*s + s*(-0.125 + 0.25*t) - 0.25*t;
Hrt[ 1] = r*(-0.25 + 0.25*s) - 0.125*s*s + s*(0.125 - 0.25*t) + 0.25*t;
Hrt[ 2] = r*(-0.25 - 0.25*s) - 0.125*s*s + s*(-0.125 + 0.25*t) + 0.25*t;
Hrt[ 3] = r*(-0.25 - 0.25*s) + 0.125*s*s + s*(0.125 - 0.25*t) - 0.25*t;
Hrt[ 4] = 0;
Hrt[ 5] = -0.5*r*(-1. + s);
Hrt[ 6] = 0.25*(-1. + s*s);
Hrt[ 7] = 0.5*r*(1. + s);
Hrt[ 8] = -0.25*(-1. + s*s);
Hrt[ 9] = -0.5*(-1. + s)*t;
Hrt[10] = 0.5*(-1. + s)*t;
Hrt[11] = -0.5*(1. + s)*t;
Hrt[12] = 0.5*(1. + s)*t;
Hrs[0] = 0.125*(1.0 - t); Hrt[0] = 0.125*(1.0 - s); Hst[0] = 0.125*(1.0 - r);
Hrs[1] = -0.125*(1.0 - t); Hrt[1] = -0.125*(1.0 - s); Hst[1] = 0.125*(1.0 + r);
Hrs[2] = 0.125*(1.0 - t); Hrt[2] = -0.125*(1.0 + s); Hst[2] = -0.125*(1.0 + r);
Hrs[3] = -0.125*(1.0 - t); Hrt[3] = 0.125*(1.0 + s); Hst[3] = -0.125*(1.0 - r);
Hrs[4] = 0.0; Hrt[4] = 0.0; Hst[4] = 0.0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/mat3d.h | .h | 20,840 | 850 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <assert.h>
#include "vec3d.h"
#include "mat2d.h"
//-----------------------------------------------------------------------------
// useful constants for trig
#ifndef PI
#define PI 3.141592653589793
#endif
#ifndef RAD2DEG
#define RAD2DEG (180.0/PI)
#endif
#ifndef DEG2RAD
#define DEG2RAD (PI/180.0)
#endif
#ifndef MAX
#define MAX(a, b) ((a)>(b)?(a):(b))
#endif
#ifndef MIN
#define MIN(a, b) ((a)<(b)?(a):(b))
#endif
//-----------------------------------------------------------------------------
// The following classes are defined in this file
class mat3d; // general 3D matrix of doubles
class mat3ds; // symmetric 3D matrix of doubles
class mat3da; // anti-symmetric 3D matrix of doubles
class mat3dd; // diagonal matrix of doubles
//-----------------------------------------------------------------------------
//! This class describes a diagonal matrix of doubles in 3D
class mat3dd
{
public:
// default constructor
mat3dd(){}
// constructors
explicit mat3dd(double a);
mat3dd(double a0, double a1, double a2);
// assignment operators
mat3dd& operator = (const mat3dd& m);
mat3dd& operator = (double a);
// access operators
double operator () (int i, int j) const;
double& diag(int i);
const double& diag(int i) const;
// arithmetic operators
mat3dd operator + (const mat3dd& m) const;
mat3dd operator - (const mat3dd& m) const;
mat3dd operator * (const mat3dd& m) const;
mat3dd operator * (double a) const;
mat3dd operator / (double a) const;
mat3dd operator - () const;
// arithmetic operators for mat3ds
mat3ds operator + (const mat3ds& m) const;
mat3ds operator - (const mat3ds& m) const;
mat3ds operator * (const mat3ds& m) const;
// arithmetic operators for mat3d
mat3d operator + (const mat3d& m) const;
mat3d operator - (const mat3d& m) const;
mat3d operator * (const mat3d& m) const;
// arithmetic operators for mat3da const;
mat3d operator + (const mat3da& m) const;
mat3d operator - (const mat3da& m) const;
mat3d operator * (const mat3da& m) const;
// arithmetic assignment operators
mat3dd& operator += (const mat3dd& m);
mat3dd& operator -= (const mat3dd& m);
mat3dd& operator *= (const mat3dd& m);
mat3dd& operator *= (double a);
mat3dd& operator /= (double a);
// matrix-vector multiplication
vec3d operator * (const vec3d& r) const;
// trace
double tr() const;
// determinant
double det() const;
double xx() const { return d[0]; }
double yy() const { return d[1]; }
double zz() const { return d[2]; }
// TODO: Make these constexpr
double xy() const { return 0.0; }
double yz() const { return 0.0; }
double xz() const { return 0.0; }
protected:
double d[3]; // the diagonal elements
friend class mat3d;
friend class mat3ds;
friend class mat3da;
};
inline mat3dd operator * (double a, const mat3dd& d) { return d*a; }
//-----------------------------------------------------------------------------
//! This class describes a symmetric 3D matrix of doubles
class mat3ds
{
protected:
// 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 };
public:
// default constructor
mat3ds(){}
// constructors
explicit mat3ds(double a);
mat3ds(double xx, double yy, double zz, double xy, double yz, double xz);
mat3ds(const mat3dd& d);
mat3ds(const mat3ds& d);
// access operators
double& operator () (int i, int j);
const double& operator () (int i, int j) const;
double& xx() { return m[XX]; }
double& yy() { return m[YY]; }
double& zz() { return m[ZZ]; }
double& xy() { return m[XY]; }
double& yz() { return m[YZ]; }
double& xz() { return m[XZ]; }
const double& xx() const { return m[XX]; }
const double& yy() const { return m[YY]; }
const double& zz() const { return m[ZZ]; }
const double& xy() const { return m[XY]; }
const double& yz() const { return m[YZ]; }
const double& xz() const { return m[XZ]; }
// arithmetic operators for mat3dd objects
mat3ds operator + (const mat3dd& d) const;
mat3ds operator - (const mat3dd& d) const;
mat3ds operator * (const mat3dd& d) const;
// arithmetic operators
mat3ds operator + (const mat3ds& t) const;
mat3ds operator - (const mat3ds& t) const;
mat3d operator * (const mat3ds& t) const;
mat3ds operator * (double g) const;
mat3ds operator / (double g) const;
// arithmetic operators for mat3d objects
mat3d operator + (const mat3d& t) const;
mat3d operator - (const mat3d& t) const;
mat3d operator * (const mat3d& t) const;
// arithmetic operators for mat3da objects
mat3d operator + (const mat3da& t) const;
mat3d operator - (const mat3da& t) const;
mat3d operator * (const mat3da& t) const;
// unary operators
mat3ds operator - () const;
// arithmetic assignment operators
mat3ds& operator += (const mat3ds& t);
mat3ds& operator -= (const mat3ds& t);
mat3ds& operator *= (const mat3ds& t);
mat3ds& operator *= (double g);
mat3ds& operator /= (double g);
// arithmetic assignment operators for mat3dd
mat3ds& operator += (const mat3dd& d);
mat3ds& operator -= (const mat3dd& d);
// comparison
bool operator == (const mat3ds& d);
// matrix-vector multiplication
vec3d operator * (const vec3d& r) const;
// trace
double tr() const;
// determinant
double det() const;
// intialize to zero
void zero();
// initialize to unit tensor
void unit();
// deviator
mat3ds dev() const;
// isotropic part
mat3ds iso() const;
// return the square
mat3ds sqr() const;
// calculates the inverse
mat3ds inverse() const;
double invert(mat3ds& Ai);
// determine eigen values and vectors
FECORE_API void eigen(double d[3], vec3d r[3] = 0) const;
FECORE_API void exact_eigen(double l[3]) const;
FECORE_API void eigen2(double d[3], vec3d r[3] = 0) const;
// L2-norm
double norm() const;
// double contraction
double dotdot(const mat3ds& S) const;
// "effective" or von-Mises norm
double effective_norm() const;
// the "max shear" value
FECORE_API double max_shear() const;
protected:
double m[6]; // stores data in the order xx, xy, yy, xz, yz, zz
friend class mat3dd;
friend class mat3d;
};
inline mat3ds operator * (double a, const mat3ds& m) { return m*a; }
//-----------------------------------------------------------------------------
//! This class describes an anti-symmetric 3D matrix of doubles
//! The matrix is defined such that for a vector b the following is true:
//! A.b = a x b where A = mat3da(a).
//!
// | 0 -z y | | 0 d0 d2 |
// A = | z 0 -x | = | -d0 0 d1 |
// |-y x 0 | | -d2 -d1 0 |
//
class mat3da
{
public:
// default constructor
mat3da(){}
// constructors
mat3da(double xy, double yz, double xz);
// calculates the antisymmetric matrix from a vector
// A.b = a x b where A = mat3da(a).
explicit mat3da(const vec3d& a);
// access operator
double operator () (int i, int j) const;
double& xy() { return d[0]; }
double& yz() { return d[1]; }
double& xz() { return d[2]; }
const double& xy() const { return d[0]; }
const double& yz() const { return d[1]; }
const double& xz() const { return d[2]; }
mat3da operator + (const mat3da& a);
mat3da operator - (const mat3da& a);
mat3da operator - () const;
mat3da operator * (double g) const;
mat3da transpose() const;
// matrix algebra
mat3d operator * (const mat3d& a);
// return the equivalent vector
vec3d vec() const { return vec3d(-d[1], d[2], -d[0]); }
vec3d operator * (const vec3d& a);
// arithmetic operators for mat3ds objects
mat3d operator + (const mat3ds& t) const;
mat3d operator - (const mat3ds& t) const;
protected:
double d[3]; // stores xy, yz, xz
friend class mat3dd;
friend class mat3ds;
friend class mat3d;
};
//-----------------------------------------------------------------------------
//! This class describes a general 3D matrix of doubles
class mat3d
{
public:
// default constructor
mat3d() {}
explicit mat3d(double a);
// constructors
mat3d(double a00, double a01, double a02,
double a10, double a11, double a12,
double a20, double a21, double a22);
mat3d(double m[3][3]);
mat3d(double a[9]);
mat3d(const mat3dd& m);
mat3d(const mat3ds& m);
mat3d(const mat3da& m);
mat3d(const mat2d& m);
mat3d(const vec3d& e1, const vec3d& e2, const vec3d& e3);
// construct a matrix from two vectors a and b. (a and b not colinear!)
// e1 = a.unit()
// e3 = (a ^ b).unit()
// e2 = e3 ^ e1
// Q = [e1 e2 e3]
mat3d(const vec3d& a, const vec3d& b);
// assignment operators
mat3d& operator = (const mat3dd& m);
mat3d& operator = (const mat3ds& m);
mat3d& operator = (const mat3d& m);
mat3d& operator = (const double m[3][3]);
// mat3d
mat3d operator - () const
{
return mat3d(-d[0][0], -d[0][1], -d[0][2], \
-d[1][0], -d[1][1], -d[1][2], \
-d[2][0], -d[2][1], -d[2][2]);
}
// access operators
double& operator () (int i, int j);
const double& operator () (int i, int j) const;
double* operator [] (int i);
const double* operator [] (int i) const;
// arithmetic operators
mat3d operator + (const mat3d& m) const;
mat3d operator - (const mat3d& m) const;
mat3d operator * (const mat3d& m) const;
mat3d operator * (double a) const;
mat3d operator / (double a) const;
// arithmetic operators for mat3dd
mat3d operator + (const mat3dd& m) const;
mat3d operator - (const mat3dd& m) const;
mat3d operator * (const mat3dd& m) const;
// arithmetic operators for mat3ds
mat3d operator + (const mat3ds& m) const;
mat3d operator - (const mat3ds& m) const;
mat3d operator * (const mat3ds& m) const;
// arithmetic assignment operators
mat3d& operator += (const mat3d& m);
mat3d& operator -= (const mat3d& m);
mat3d& operator *= (const mat3d& m);
mat3d& operator *= (double a);
mat3d& operator /= (double a);
// arithmetic assignment operators for mat3dd
mat3d& operator += (const mat3dd& m);
mat3d& operator -= (const mat3dd& m);
mat3d& operator *= (const mat3dd& m);
// arithmetic assignment operators for mat3ds
mat3d& operator += (const mat3ds& m);
mat3d& operator -= (const mat3ds& m);
mat3d& operator *= (const mat3ds& m);
// matrix-vector muliplication
vec3d operator * (const vec3d& r) const;
// determinant
double det() const;
// trace
double trace() const;
// zero the matrix
void zero();
// make unit matrix
void unit();
// return a column vector from the matrix
vec3d col(int j) const;
// return a row vector from the matrix
vec3d row(int j) const;
// set the column of the matrix
void setCol(int i, const vec3d& a);
// set the row of the matrix
void setRow(int i, const vec3d& a);
// return the symmetric matrix 0.5*(A+A^T)
mat3ds sym() const;
// return the antisymmetric matrix 0.5*(A-A^T)
mat3da skew() const;
// calculates the inverse
mat3d inverse() const;
// inverts the matrix.
bool invert();
// calculates the transpose
mat3d transpose() const;
// calculates the transposed inverse
mat3d transinv() const;
// calculate the skew-symmetric matrix from a vector
void skew(const vec3d& v);
// calculate the exponential map
void exp(const vec3d& v);
// calculate the one-norm
double norm() const;
// double contraction
double dotdot(const mat3d& T) const;
// polar decomposition
FECORE_API void right_polar(mat3d& R, mat3ds& U) const;
FECORE_API void left_polar(mat3ds& V, mat3d& R) const;
// return identity matrix
static mat3d identity() { return mat3d(1,0,0, 0,1,0, 0,0,1); }
protected:
double d[3][3]; // matrix data
friend class mat3dd;
friend class mat3ds;
friend class mat3da;
};
// outer product for vectors
inline mat3d operator & (const vec3d& a, const vec3d& b)
{
return mat3d(a.x*b.x, a.x*b.y, a.x*b.z,
a.y*b.x, a.y*b.y, a.y*b.z,
a.z*b.x, a.z*b.y, a.z*b.z);
}
inline mat3ds dyad(const vec3d& a)
{
return mat3ds(a.x*a.x, a.y*a.y, a.z*a.z, a.x*a.y, a.y*a.z, a.x*a.z);
}
// c_ij = a_i*b_j + a_j*b_i
inline mat3ds dyads(const vec3d& a, const vec3d& b)
{
return mat3ds(2.0*a.x*b.x, 2.0*a.y*b.y, 2.0*a.z*b.z, a.x*b.y + a.y*b.x, a.y*b.z + a.z*b.y, a.x*b.z + a.z*b.x);
}
// skew-symmetric matrix of dual vector
inline mat3d skew(const vec3d& a)
{
return mat3d( 0, -a.z, a.y,
a.z, 0, -a.x,
-a.y, a.x, 0);
}
//-----------------------------------------------------------------------------
// This class stores a 2nd order diagonal tensor
class mat3fd
{
public:
mat3fd() { x = y = z = 0.f; }
mat3fd(float X, float Y, float Z) { x = X; y = Y; z = Z; }
public:
float x, y, z;
};
//-----------------------------------------------------------------------------
// mat3fs stores a 2nd order symmetric tensor
//
class mat3fs
{
public:
// constructors
mat3fs() { x = y = z = xy = yz = xz = 0; }
mat3fs(float fx, float fy, float fz, float fxy, float fyz, float fxz)
{
x = fx; y = fy; z = fz;
xy = fxy; yz = fyz; xz = fxz;
}
// operators
mat3fs& operator += (const mat3fs& v)
{
x += v.x;
y += v.y;
z += v.z;
xy += v.xy;
yz += v.yz;
xz += v.xz;
return (*this);
}
// operators
mat3fs& operator -= (const mat3fs& v)
{
x -= v.x;
y -= v.y;
z -= v.z;
xy -= v.xy;
yz -= v.yz;
xz -= v.xz;
return (*this);
}
mat3fs& operator *= (float g)
{
x *= g;
y *= g;
z *= g;
xy *= g;
yz *= g;
xz *= g;
return (*this);
}
mat3fs& operator /= (float g)
{
x /= g;
y /= g;
z /= g;
xy /= g;
yz /= g;
xz /= g;
return (*this);
}
mat3fs operator + (const mat3fs& a) { return mat3fs(x + a.x, y + a.y, z + a.z, xy + a.xy, yz + a.yz, xz + a.xz); }
mat3fs operator - (const mat3fs& a) { return mat3fs(x - a.x, y - a.y, z - a.z, xy - a.xy, yz - a.yz, xz - a.xz); }
mat3fs operator * (float a)
{
return mat3fs(x * a, y * a, z * a, xy * a, yz * a, xz * a);
}
mat3fs operator / (float g)
{
return mat3fs(x / g, y / g, z / g, xy / g, yz / g, xz / g);
}
vec3f operator * (vec3f& r)
{
return vec3f(
x * r.x + xy * r.y + xz * r.z,
xy * r.x + y * r.y + yz * r.z,
xz * r.x + yz * r.y + z * r.z);
}
// Effective or von-mises value
float von_mises() const
{
float vm;
vm = x * x + y * y + z * z;
vm -= x * y + y * z + x * z;
vm += 3 * (xy * xy + yz * yz + xz * xz);
vm = (float)sqrt(vm >= 0.0 ? vm : 0.0);
return vm;
}
// principle values
FECORE_API void Principals(float e[3]) const;
// principle directions
FECORE_API vec3f PrincDirection(int l);
// deviatroric principle values
FECORE_API void DeviatoricPrincipals(float e[3]) const;
// max-shear value
FECORE_API float MaxShear() const;
// eigen-vectors and values
FECORE_API void eigen(vec3f e[3], float l[3]) const;
// trace
float tr() const { return x + y + z; }
// determinant
float det() const { return (x * y * z + xy * yz * xz + xz * xy * yz - y * xz * xz - x * yz * yz - z * xy * xy); }
// L2 norm
float norm() const {
double d = x * x + y * y + z * z + 2 * (xy * xy + yz * yz + xz * xz);
return (float)sqrt(d);
}
public:
float x, y, z;
float xy, yz, xz;
};
FECORE_API double fractional_anisotropy(const mat3fs& m);
///////////////////////////////////////////////////////////////////
// mat3f
class mat3f
{
public:
mat3f() { zero(); }
mat3f(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
{
d[0][0] = a00; d[0][1] = a01; d[0][2] = a02;
d[1][0] = a10; d[1][1] = a11; d[1][2] = a12;
d[2][0] = a20; d[2][1] = a21; d[2][2] = a22;
}
mat3f(const mat3fs& a)
{
d[0][0] = a.x; d[0][1] = a.xy; d[0][2] = a.xz;
d[1][0] = a.xy; d[1][1] = a.y; d[1][2] = a.yz;
d[2][0] = a.xz; d[2][1] = a.yz; d[2][2] = a.z;
}
float* operator [] (int i) { return d[i]; }
const float* operator [] (int i) const { return d[i]; }
float& operator () (int i, int j) { return d[i][j]; }
float operator () (int i, int j) const { return d[i][j]; }
mat3f operator * (float a) const
{
return mat3f(\
d[0][0] * a, d[0][1] * a, d[0][2] * a, \
d[1][0] * a, d[1][1] * a, d[1][2] * a, \
d[2][0] * a, d[2][1] * a, d[2][2] * a);
}
mat3f operator * (mat3f& m)
{
mat3f a;
int k;
for (k = 0; k < 3; k++)
{
a[0][0] += d[0][k] * m[k][0]; a[0][1] += d[0][k] * m[k][1]; a[0][2] += d[0][k] * m[k][2];
a[1][0] += d[1][k] * m[k][0]; a[1][1] += d[1][k] * m[k][1]; a[1][2] += d[1][k] * m[k][2];
a[2][0] += d[2][k] * m[k][0]; a[2][1] += d[2][k] * m[k][1]; a[2][2] += d[2][k] * m[k][2];
}
return a;
}
vec3f operator * (const vec3f& a) const
{
return vec3f(
d[0][0] * a.x + d[0][1] * a.y + d[0][2] * a.z,
d[1][0] * a.x + d[1][1] * a.y + d[1][2] * a.z,
d[2][0] * a.x + d[2][1] * a.y + d[2][2] * a.z
);
}
mat3f& operator *= (float g)
{
d[0][0] *= g; d[0][1] *= g; d[0][2] *= g;
d[1][0] *= g; d[1][1] *= g; d[1][2] *= g;
d[2][0] *= g; d[2][1] *= g; d[2][2] *= g;
return (*this);
}
mat3f& operator /= (float g)
{
d[0][0] /= g; d[0][1] /= g; d[0][2] /= g;
d[1][0] /= g; d[1][1] /= g; d[1][2] /= g;
d[2][0] /= g; d[2][1] /= g; d[2][2] /= g;
return (*this);
}
mat3f operator + (const mat3f& a) const
{
return mat3f( \
d[0][0] + a.d[0][0], d[0][1] + a.d[0][1], d[0][2] + a.d[0][2], \
d[1][0] + a.d[1][0], d[1][1] + a.d[1][1], d[1][2] + a.d[1][2], \
d[2][0] + a.d[2][0], d[2][1] + a.d[2][1], d[2][2] + a.d[2][2]);
}
mat3f operator - (const mat3f& a) const
{
return mat3f(\
d[0][0] - a.d[0][0], d[0][1] - a.d[0][1], d[0][2] - a.d[0][2], \
d[1][0] - a.d[1][0], d[1][1] - a.d[1][1], d[1][2] - a.d[1][2], \
d[2][0] - a.d[2][0], d[2][1] - a.d[2][1], d[2][2] - a.d[2][2]);
}
mat3f operator += (const mat3f& a)
{
d[0][0] += a.d[0][0]; d[0][1] += a.d[0][1]; d[0][2] += a.d[0][2];
d[1][0] += a.d[1][0]; d[1][1] += a.d[1][1]; d[1][2] += a.d[1][2];
d[2][0] += a.d[2][0]; d[2][1] += a.d[2][1]; d[2][2] += a.d[2][2];
return (*this);
}
mat3f operator -= (const mat3f& a)
{
d[0][0] -= a.d[0][0]; d[0][1] -= a.d[0][1]; d[0][2] -= a.d[0][2];
d[1][0] -= a.d[1][0]; d[1][1] -= a.d[1][1]; d[1][2] -= a.d[1][2];
d[2][0] -= a.d[2][0]; d[2][1] -= a.d[2][1]; d[2][2] -= a.d[2][2];
return (*this);
}
mat3fs sym() const
{
return mat3fs(d[0][0], d[1][1], d[2][2], 0.5f * (d[0][1] + d[1][0]), 0.5f * (d[1][2] + d[2][1]), 0.5f * (d[0][2] + d[2][0]));
}
void zero()
{
d[0][0] = d[0][1] = d[0][2] = 0.f;
d[1][0] = d[1][1] = d[1][2] = 0.f;
d[2][0] = d[2][1] = d[2][2] = 0.f;
}
vec3f col(int i) const
{
vec3f r;
switch (i)
{
case 0: r.x = d[0][0]; r.y = d[1][0]; r.z = d[2][0]; break;
case 1: r.x = d[0][1]; r.y = d[1][1]; r.z = d[2][1]; break;
case 2: r.x = d[0][2]; r.y = d[1][2]; r.z = d[2][2]; break;
}
return r;
}
vec3f row(int i) const
{
vec3f r;
switch (i)
{
case 0: r.x = d[0][0]; r.y = d[0][1]; r.z = d[0][2]; break;
case 1: r.x = d[1][0]; r.y = d[1][1]; r.z = d[1][2]; break;
case 2: r.x = d[2][0]; r.y = d[2][1]; r.z = d[2][2]; break;
}
return r;
}
mat3f transpose() const
{
return mat3f(
d[0][0], d[1][0], d[2][0],
d[0][1], d[1][1], d[2][1],
d[0][2], d[1][2], d[2][2]
);
}
// inverts the matrix.
bool invert();
public:
float d[3][3];
};
inline mat3f to_mat3f(const mat3d& m)
{
return mat3f(
(float)m[0][0], (float)m[0][1], (float)m[0][2],
(float)m[1][0], (float)m[1][1], (float)m[1][2],
(float)m[2][0], (float)m[2][1], (float)m[2][2]);
}
inline mat3d to_mat3d(const mat3f& m)
{
return mat3d(
m[0][0], m[0][1], m[0][2],
m[1][0], m[1][1], m[1][2],
m[2][0], m[2][1], m[2][2]);
}
// The following file contains the actual definition of the class functions
#include "mat3d.hpp"
| Unknown |
3D | febiosoftware/FEBio | FECore/mathalg.h | .h | 1,899 | 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 "mat3d.h"
#include <functional>
#include "fecore_api.h"
template <class T> T weightedAverage(T* d, double* w, int n)
{
T s = d[0] * w[0];
for (int i = 1; i < n; ++i) s += d[i] * w[i];
return s;
}
template <class T> T weightedAverage(T* d, double* w, int n, std::function<T(const T&)> fnc)
{
T s = fnc(d[0]) * w[0];
for (int i = 1; i < n; ++i) s += fnc(d[i]) * w[i];
return s;
}
FECORE_API mat3ds weightedAverageStructureTensor(mat3ds* d, double* w, int n);
// evaluate Log_p (X)
FECORE_API mat3ds Log(const mat3ds& p, const mat3ds& X);
FECORE_API mat3ds Exp(const mat3ds& p, const mat3ds& X);
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFacetSet.h | .h | 3,046 | 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 "fecore_api.h"
#include "FEItemList.h"
#include "FEElement.h"
#include "FENodeSet.h"
#include <vector>
#include <string>
class FESurface;
//-----------------------------------------------------------------------------
//! This class defines a set of facets. This can be used in the creation of
//! surfaces.
class FECORE_API FEFacetSet : public FEItemList
{
public:
struct FACET
{
// max nr of nodes for each facet
enum { MAX_NODES = 10};
// different facet types
enum FacetType {
INVALID = 0,
TRI3 = 3,
QUAD4 = 4,
TRI6 = 6,
TRI7 = 7,
QUAD8 = 8,
QUAD9 = 9,
TRI10 = 10
};
int node[FACET::MAX_NODES];
int ntype; // 3=tri3, 4=quad4, 6=tri6, 7=tri7, 8=quad8, 9=quad9
void Serialize(DumpStream& ar);
int Nodes() const { return ntype; }
FACET() { ntype = FACET::INVALID; }
};
public:
// Constructor
FEFacetSet(FEModel* fem);
// Allocate facets
void Create(int n);
// create from a surface
void Create(const FESurface& surf);
void Clear();
// return the size of the facet ste
int Faces() const;
// return a facet
FACET& Face(int i);
const FACET& Face(int i) const;
// add a facet set
void Add(FEFacetSet* pf);
// extract the node set from the facet set
FENodeList GetNodeList() const;
public:
// serialize
void Serialize(DumpStream& ar);
static void SaveClass(DumpStream& ar, FEFacetSet* p);
static FEFacetSet* LoadClass(DumpStream& ar, FEFacetSet* p);
// TODO: This is a hack used to convert between a surface and a facet set when reading face data records
void SetSurface(FESurface* surf);
FESurface* GetSurface();
private:
std::vector<FACET> m_Face; // the list of facets
FESurface* m_surface; // the surface this facet list refers to (can be zero!)
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogSolutionNorm.h | .h | 1,555 | 37 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEModelDataRecord.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class FECORE_API FELogSolutionNorm : public FEModelLogData
{
public:
FELogSolutionNorm(FEModel* fem);
double value() override;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMat3dValuator.h | .h | 5,853 | 232 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
class FEDataMap;
//---------------------------------------------------------------------------------------
// Base class for evaluating vec3d parameters
class FECORE_API FEMat3dValuator : public FEValuator
{
FECORE_SUPER_CLASS(FEMAT3DVALUATOR_ID)
FECORE_BASE_CLASS(FEMat3dValuator)
public:
FEMat3dValuator(FEModel* fem) : FEValuator(fem) {};
virtual mat3d operator()(const FEMaterialPoint& pt) = 0;
virtual FEMat3dValuator* copy() = 0;
virtual bool isConst() { return false; }
virtual mat3d* constValue() { return nullptr; }
};
//-----------------------------------------------------------------------------
// A constant valuator
class FECORE_API FEConstValueMat3d : public FEMat3dValuator
{
public:
FEConstValueMat3d(FEModel* fem);
FEMat3dValuator* copy() override;
mat3d 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)
mat3d* constValue() override { return &m_val; }
mat3d& value() { return m_val; }
private:
mat3d m_val;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
//! This class generates a material axes based on the local element node numbering.
class FECORE_API FEMat3dLocalElementMap : public FEMat3dValuator
{
public:
FEMat3dLocalElementMap(FEModel* pfem);
bool Init() override;
mat3d operator () (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
void Serialize(DumpStream& ar) override;
public:
int m_n[3]; // local element nodes
protected:
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
//! This class generates material axes based on a spherical map.
class FECORE_API FEMat3dSphericalMap : public FEMat3dValuator
{
public:
FEMat3dSphericalMap(FEModel* pfem);
bool Init() override;
void SetSphereCenter(const vec3d& c) { m_c = c; }
void SetSphereVector(const vec3d& r) { m_r = r; }
mat3d operator() (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
public:
vec3d m_c; // center of map
vec3d m_r; // vector for parallel transport
protected:
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FEMat3dCylindricalMap : public FEMat3dValuator
{
public:
FEMat3dCylindricalMap(FEModel* pfem);
bool Init() override;
void SetCylinderCenter(vec3d c) { m_c = c; }
void SetCylinderAxis(vec3d a) { m_a = a; m_a.unit(); }
void SetCylinderRef(vec3d r) { m_r = r; m_r.unit(); }
mat3d operator () (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
public:
vec3d m_c; // center of map
vec3d m_a; // axis
vec3d m_r; // reference direction
protected:
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FEMat3dPolarMap : public FEMat3dValuator
{
public:
FEMat3dPolarMap(FEModel* pfem);
bool Init() override;
void SetCenter(vec3d c) { m_c = c; }
void SetAxis(vec3d a) { m_a = a; m_a.unit(); }
void SetVector0(vec3d r) { m_d0 = r; m_d0.unit(); }
void SetVector1(vec3d r) { m_d1 = r; m_d1.unit(); }
void SetRadius0(double r) { m_R0 = r; }
void SetRadius1(double r) { m_R1 = r; }
mat3d operator () (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
public:
vec3d m_c; // center of map
vec3d m_a; // axis
vec3d m_d0, m_d1; // reference direction
double m_R0, m_R1;
protected:
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FECORE_API FEMat3dVectorMap : public FEMat3dValuator
{
public:
FEMat3dVectorMap(FEModel* pfem);
bool Init() override;
void SetVectors(vec3d a, vec3d d);
mat3d operator () (const FEMaterialPoint& mp) override;
FEMat3dValuator* copy() override;
void Serialize(DumpStream& ar) override;
public:
vec3d m_a, m_d;
mat3d m_Q;
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
class FECORE_API FEMappedValueMat3d : public FEMat3dValuator
{
public:
FEMappedValueMat3d(FEModel* fem);
void setDataMap(FEDataMap* val);
FEDataMap* dataMap();
mat3d operator()(const FEMaterialPoint& pt) override;
FEMat3dValuator* copy() override;
void Serialize(DumpStream& ar) override;
private:
std::string m_mapName;
private:
FEDataMap* m_val;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/Quadric.cpp | .cpp | 10,707 | 335 | /*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.*/
#include "Quadric.h"
#include "matrix.h"
#include <math.h>
using namespace std;
#ifndef M_PI
#define M_PI 3.141592653589793238462643
#endif
//-------------------------------------------------------------------------------
// constructor
Quadric::Quadric(Quadric* q)
{
for (int i=0; i<10; ++i) m_c[i] = q->m_c[i];
m_p = q->m_p;
}
//-------------------------------------------------------------------------------
// copy constructor
Quadric::Quadric(const Quadric& q)
{
for (int i=0; i<10; ++i) m_c[i] = q.m_c[i];
m_p = q.m_p;
}
//-------------------------------------------------------------------------------
// destructor
Quadric::~Quadric()
{
for (int i=0; i<10; ++i) m_c[i] = 0;
m_p.clear();
}
//--------------------------------------------------------------------------------------
bool Quadric::GetQuadricCoeficients()
{
// get number of points in point cloud
int N = (int)m_p.size();
matrix A(10,10);
matrix d(1,10);
//Populate D
A.zero();
for (int j = 0; j < N; ++j)
{
vec3d p = m_p[j];
d(0,0) = p.x*p.x;
d(0,1) = p.y*p.y;
d(0,2) = p.z*p.z;
d(0,3) = p.y*p.z;
d(0,4) = p.x*p.z;
d(0,5) = p.x*p.y;
d(0,6) = p.x;
d(0,7) = p.y;
d(0,8) = p.z;
d(0,9) = 1;
matrix D(10,10);
D = d.transpose()*d;
A += D;
}
// find eigenvalues and eigenvectors of A
vector<double> Aval;
matrix Avec(10,10);
bool good = A.eigen_vectors(Avec, Aval);
if (good) {
// find smallest eigenvalue
int imin=0;
for (int i=1; i<10; ++i)
if (fabs(Aval[i]) < fabs(Aval[imin])) imin = i;
//if (Aval[i] < Aval[imin]) imin = i;
// store the coefficients of the quadric surface
for (int j=0; j<10; ++j)
m_c[j] = Avec(j,imin);
return true;
}
return false;
}
//--------------------------------------------------------------------------------------
// Evaluate the surface normal at point p
vec3d Quadric::SurfaceNormal(const vec3d p)
{
// extract quadric surface coefficients
// F(x,y,z) = a x^2 + b y^2 + c z^2 + e y z + f z x + g x y + l x + m y + n z + d = 0
double a = m_c[0];
double b = m_c[1];
double c = m_c[2];
double e = m_c[3];
double f = m_c[4];
double g = m_c[5];
double l = m_c[6];
double m = m_c[7];
double n = m_c[8];
// evaluate first derivatives
double Fx = 2*a*p.x + f*p.z + g*p.y + l;
double Fy = 2*b*p.y + e*p.z + g*p.x + m;
double Fz = 2*c*p.z + e*p.y + f*p.x + n;
vec3d xn(Fx,Fy,Fz);
xn.unit();
return xn;
}
//--------------------------------------------------------------------------------------
void Quadric::SurfaceCurvature(const vec3d p, const vec3d pn, vec2d& kappa, vec3d* v)
{
double eps = 1e-9;
// find magnitude of quadric gradient components
// to determine if we need to do permutation of axes
double f1 = fabs(2*m_c[0]*p.x + 2*m_c[4]*p.z + 2*m_c[5]*p.y + 2*m_c[6]);
double f2 = fabs(2*m_c[1]*p.y + 2*m_c[3]*p.z + 2*m_c[5]*p.x + 2*m_c[7]);
double f3 = fabs(2*m_c[2]*p.z + 2*m_c[3]*p.y + 2*m_c[4]*p.x + 2*m_c[8]);
// pick direction with maximum gradient component magnitude
int e1 = 0, e2 = 1, e3 = 2;
double vmax = fmax(fmax(f1,f2),f3);
if (vmax == f1) { e3 = 0; e1 = 1; e2 = 2; }
else if (vmax == f2) { e3 = 1; e1 = 2; e2 = 0; }
// extract quadric surface coefficients (and clean up roundoff errors)
// F(x,y,z) = a x^2 + b y^2 + c z^2 + e y z + f z x + g x y + l x + m y + n z + d = 0
double a = (fabs(m_c[e1]) > eps) ? m_c[e1] : 0;
double b = (fabs(m_c[e2]) > eps) ? m_c[e2] : 0;
double c = (fabs(m_c[e3]) > eps) ? m_c[e3] : 0;
double e = (fabs(m_c[e1+3]) > eps) ? m_c[e1+3] : 0;
double f = (fabs(m_c[e2+3]) > eps) ? m_c[e2+3] : 0;
double g = (fabs(m_c[e3+3]) > eps) ? m_c[e3+3] : 0;
double l = (fabs(m_c[e1+6]) > eps) ? m_c[e1+6] : 0;
double m = (fabs(m_c[e2+6]) > eps) ? m_c[e2+6] : 0;
double n = (fabs(m_c[e3+6]) > eps) ? m_c[e3+6] : 0;
// evaluate quadric surface derivatives and normal
double x = p(e1), y = p(e2), z = p(e3);
double den = n + f*x + e*y + 2*c*z;
double zx = -(l + 2*a*x + g*y + f*z)/den;
double zy = -(m + g*x + 2*b*y + e*z)/den;
double zxx = -2*(a + (f + c*zx)*zx)/den;
double zyy = -2*(b + (e + c*zy)*zy)/den;
double zxy = -(g + e*zx + f*zy + 2*c*zx*zy)/den;
vec3d xu, xv;
xu(e1) = 1; xu(e2) = 0; xu(e3) = zx;
xv(e1) = 0; xv(e2) = 1; xv(e3) = zy;
vec3d xuu, xvv, xuv;
xuu(e1) = 0; xuu(e2) = 0; xuu(e3) = zxx;
xvv(e1) = 0; xvv(e2) = 0; xvv(e3) = zyy;
xuv(e1) = 0; xuv(e2) = 0; xuv(e3) = zxy;
vec3d xn = (xu ^ xv).normalized();
// get coefficients of fundamental forms
double E = xu*xu, F = xu*xv, G = xv*xv;
double L = xuu*xn, M = xuv*xn, N = xvv*xn;
// evaluate mean and gaussian curvatures
double tmp = E*G - F*F;
// gaussian
double kg = (L*N - M*M)/tmp;
// mean
double km = (2*F*M - E*N - G*L)/2./tmp;
// evaluate principal curvatures
double d1 = sqrt(km*km - kg);
// max curvature
double kmax = km + d1;
double kmin = km - d1;
// evaluate principal directions of curvature
double a2 = F*N - G*M, b2 = E*N - G*L, c2 = E*M - F*L;
double d2 = b2*b2 - 4*a2*c2; if (fabs(d2) < 0) d2 = 0;
d2 = sqrt(d2); // d2=0 represents an umbilical point
double thmax = atan2(-b2 + d2, 2*a2);
double thmin = (d2 != 0) ? atan2(-b2 - d2, 2*a2) : thmax + M_PI/2;
vec3d xmax = xu*cos(thmax) + xv*sin(thmax); xmax.unit();
vec3d xmin = xu*cos(thmin) + xv*sin(thmin); xmin.unit();
// check quadric normal versus face normal
if (xn*pn >= 0) {
kappa.x() = kmax; kappa.y() = kmin;
v[0] = xmax; v[1] = xmin;
}
else {
kappa.x() = kmin; kappa.y() = kmax;
v[0] = xmin; v[1] = xmax;
}
// fix handedness if neeeded
if ((v[0]^v[1])*pn < 0) v[0] = -v[0];
}
//--------------------------------------------------------------------------------------
// Find ray-quadric surface intersections x: p is point on ray, n is normal along ray
// There are three possible solutions: 0 roots, 1 root, and 2 roots
// When 2 roots are found, sort results from closest to farthest
void Quadric::RayQuadricIntersection(const vec3d p, const vec3d n, vector<vec3d>* x, vector<double>* t)
{
double a = n.x*n.x*m_c[0]+n.y*n.y*m_c[1]+n.z*n.z*m_c[2]+n.y*n.z*m_c[3]+n.x*n.z*m_c[4]+n.x*n.y*m_c[5];
double b = n.x*(2*p.x*m_c[0]+p.z*m_c[4]+p.y*m_c[5]+m_c[6])
+n.y*(2*p.y*m_c[1]+p.z*m_c[3]+p.x*m_c[5]+m_c[7])
+n.z*(2*p.z*m_c[2]+p.y*m_c[3]+p.x*m_c[4]+m_c[8]);
double c = p.x*p.x*m_c[0]+p.y*p.y*m_c[1]+p.z*p.z*m_c[2]
+p.x*(p.z*m_c[4]+p.y*m_c[5]+m_c[6])
+p.y*(p.z*m_c[3]+m_c[7])+p.z*m_c[8]+m_c[9];
x->clear();
t->clear();
double d = b*b - 4*a*c;
if (d < 0) return;
else if ((a == 0) && (b != 0)) {
double t1 = -c/b;
t->push_back(t1);
x->push_back(p + n*t1);
return;
}
else if ((d == 0) && (a != 0)) {
double t1 = -b/(2*a);
t->push_back(t1);
x->push_back(p + n*t1);
return;
}
else if (a != 0) {
d = sqrt(d);
double t1 = (-b - d)/(2*a);
double t2 = (-b + d)/(2*a);
if (fabs(t1) < fabs(t2)) {
t->push_back(t1);
t->push_back(t2);
x->push_back(p + n*t1);
x->push_back(p + n*t2);
}
else {
t->push_back(t2);
t->push_back(t1);
x->push_back(p + n*t2);
x->push_back(p + n*t1);
}
}
}
//--------------------------------------------------------------------------------------
// This routine finds a closest point approximation (not the exact solution)
vec3d Quadric::ClosestPoint(const vec3d p)
{
vector<vec3d> xsol;
vector<double> tsol;
vec3d n1 = vec3d(1,0,0);
vec3d n2 = vec3d(0,1,0);
vec3d n3 = vec3d(0,0,1);
vector<vec3d> x1, x2, x3;
vector<double> t1, t2, t3;
RayQuadricIntersection(p, n1, &x1, &t1);
RayQuadricIntersection(p, n2, &x2, &t2);
RayQuadricIntersection(p, n3, &x3, &t3);
if (t1.size() > 0) {
xsol.push_back(x1[0]);
tsol.push_back(t1[0]);
}
if (t2.size() > 0) {
xsol.push_back(x2[0]);
tsol.push_back(t2[0]);
}
if (t3.size() > 0) {
xsol.push_back(x3[0]);
tsol.push_back(t3[0]);
}
int N = (int)tsol.size();
if (N > 0) {
int imin = 0;
double tmin = fabs(tsol[imin]);
for (int i = 1; i<N; ++i) {
if (fabs(tsol[i]) < tmin) {
imin = i;
tmin = fabs(tsol[i]);
}
}
return xsol[imin];
}
return p;
}
//--------------------------------------------------------------------------------------
// This routine finds a closest point approximation (use norm of face)
vec3d Quadric::ClosestPoint(const vec3d p, const vec3d norm)
{
vec3d xsol;
double tsol;
vector<vec3d> x;
vector<double> t;
RayQuadricIntersection(p, norm, &x, &t);
if (t.size() > 0) {
xsol = x[0];
tsol = t[0];
return xsol;
}
else {
ClosestPoint(p);
}
return p;
}
| C++ |
3D | febiosoftware/FEBio | FECore/MSolve.cpp | .cpp | 6,079 | 218 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
//-----------------------------------------------------------------------------
MITEM MSolve(const MITEM& e, const MVariable& x);
MITEM MSolve(const MITEM& l, const MITEM& r, const MVariable& x);
MITEM MSolve(const MSequence& e, const MSequence& x);
MITEM MSolve(const MEquation& e, const MVariable& x);
//-----------------------------------------------------------------------------
// Solve an expression e for the variable(s) v.
// The expression can be an equation linear in v or a system of linear equations.
MITEM MSolve(const MITEM& e, const MITEM& v)
{
if (is_sequence(e))
{
// solve a linear system of equations
// make sure v contains a list of variables
if (is_sequence(v) == false) throw InvalidOperation();
const MSequence& se = *msequence(e);
const MSequence& sv = *msequence(v);
// make sure we have as many equations as unknowns
if (se.size() != sv.size()) throw InvalidOperation();
// make sure all entries in e are equations
for (int i=0; i<se.size(); ++i) if (is_equation(se[i]) == false) throw InvalidOperation();
// make sure all items in v are variables
for (int i=0; i<sv.size(); ++i) if (is_var(sv[i]) == false) throw InvalidOperation();
// solve the system of equations
return MSolve(se, sv);
}
else
{
if (is_var(v))
{
const MVariable& x = *mvar(v)->GetVariable();
return MSolve(e, x);
}
else throw InvalidOperation();
}
assert(false);
return e;
}
//-----------------------------------------------------------------------------
// solve a system of linear equations
MITEM MSolve(const MSequence& e, const MSequence& v)
{
MSequence sol = e;
MSequence var = v;
int neq = e.size();
for (int i=0; i<neq; ++i)
{
const MEquation& eqi = *mequation(sol[i]);
// find a variable this equation depends on
int nvar = var.size();
const MVariable* pv = 0;
for (int j=0; j<nvar; ++j)
{
const MVariable* pvj = mvar(var[j])->GetVariable();
if (is_dependent(sol[i], *pvj))
{
pv = pvj;
var.remove(j);
break;
}
}
if (pv == 0) throw InvalidOperation();
const MVariable& x = *pv;
// solve the i-th equation for x
MITEM si = MSolve(eqi, x);
// make sure the LHS is the variable
if (is_equation(si) == false) throw InvalidOperation();
const MEquation& ei = *mequation(si);
if (is_equal(ei.LeftItem(), x) == false) throw InvalidOperation();
// replace i-th equation with this solution
sol.replace(i, si.copy());
// substitute the solution in all other equations
for (int j=0; j<neq; ++j)
{
if (i != j)
{
MITEM ej = sol[j]->copy();
MITEM newj = MReplace(ej, si);
sol.replace(j, newj.copy());
}
}
}
return sol.copy();
}
//-----------------------------------------------------------------------------
MITEM MSolve(const MEquation& e, const MVariable& x)
{
MITEM l = e.LeftItem()->copy();
MITEM r = e.RightItem()->copy();
return MSolve(l, r, x);
}
//-----------------------------------------------------------------------------
MITEM MSolve(const MITEM& e, const MVariable& x)
{
if (is_equation(e))
{
const MEquation& eq = *mequation(e);
return MSolve(eq, x);
}
else
{
MITEM i(new MEquation(e.copy(), new MConstant(0)));
return MSolve(i, x);
}
}
//-----------------------------------------------------------------------------
MITEM MSolve(const MITEM& L, const MITEM& r, const MVariable& x)
{
// if the RHS depends on x, bring it to the left side
if (is_dependent(r,x))
{
MITEM c(0.0);
return MEvaluate(MSolve(L - r, c, x));
}
// simplify LHS as much as possible
MITEM l = MEvaluate(L);
// check LHS for dependancy on x and try to solve
switch (l.Type())
{
case MNEG: return MEvaluate(MSolve(l.Item(), -r, x)); break;
case MADD:
{
MITEM a = l.Left();
MITEM b = l.Right();
if (is_dependent(a, x) == false) return MEvaluate(MSolve(b, r - a, x));
if (is_dependent(b, x) == false) return MEvaluate(MSolve(a, r - b, x));
else
{
MITEM v(x);
MITEM a = MCollect(l, v);
return MSolve(a, r, x);
}
}
break;
case MSUB:
{
MITEM a = l.Left();
MITEM b = l.Right();
if (is_dependent(a, x) == false) return MEvaluate(MSolve(-b, r - a, x));
if (is_dependent(b, x) == false) return MEvaluate(MSolve(a, r + b, x));
else
{
MITEM v(x);
MITEM a = MCollect(l, v);
return MSolve(a, r, x);
}
}
break;
case MMUL:
{
MITEM a = l.Left();
MITEM b = l.Right();
if (is_dependent(a, x) == false) return MEvaluate(MSolve(b, r/a, x));
if (is_dependent(b, x) == false) return MEvaluate(MSolve(a, r/b, x));
}
break;
case MDIV:
{
MITEM a = l.Left();
MITEM b = l.Right();
return MEvaluate(MSolve(a, r*b, x));
}
break;
}
return MITEM(new MEquation(l.copy(), r.copy()));
}
| C++ |
3D | febiosoftware/FEBio | FECore/DOFS.cpp | .cpp | 16,350 | 622 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "DOFS.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "DumpStream.h"
using namespace std;
//-----------------------------------------------------------------------------
DOFS::DOF_ITEM::DOF_ITEM()
{
sz[0] = 0;
ndof = -1;
nvar = -1;
}
//-----------------------------------------------------------------------------
DOFS::DOF_ITEM::DOF_ITEM(const char* sz)
{
SetName(sz);
ndof = -1;
nvar = -1;
}
//-----------------------------------------------------------------------------
DOFS::DOF_ITEM::DOF_ITEM(const DOFS::DOF_ITEM& d)
{
SetName(d.sz);
ndof = d.ndof;
nvar = d.nvar;
}
//-----------------------------------------------------------------------------
void DOFS::DOF_ITEM::operator = (const DOFS::DOF_ITEM& d)
{
SetName(d.sz);
ndof = d.ndof;
nvar = d.nvar;
}
//-----------------------------------------------------------------------------
DOFS::~DOFS()
{
}
//-----------------------------------------------------------------------------
void DOFS::DOF_ITEM::SetName(const char* szdof)
{
strcpy(sz, szdof);
}
//-----------------------------------------------------------------------------
void DOFS::DOF_ITEM::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & sz;
ar & ndof & nvar;
}
//-----------------------------------------------------------------------------
// constructor for the DOFS class
DOFS::DOFS()
{
m_maxdofs = 0;
}
//-----------------------------------------------------------------------------
DOFS::DOFS(const DOFS& dofs)
{
m_var = dofs.m_var;
m_maxdofs = dofs.m_maxdofs;
}
//-----------------------------------------------------------------------------
DOFS& DOFS::operator = (const DOFS& dofs)
{
m_var = dofs.m_var;
m_maxdofs = dofs.m_maxdofs;
return *this;
}
//-----------------------------------------------------------------------------
// destructor for the DOFS class
//
DOFS::DOF_ITEM::~DOF_ITEM()
{
}
//-----------------------------------------------------------------------------
DOFS::Var::Var()
{
m_ntype = -1; // invalid
m_order = -1; // assumed full interpolation order as implied by element nodes
}
//-----------------------------------------------------------------------------
DOFS::Var::Var(const DOFS::Var& v)
{
m_ntype = v.m_ntype;
m_order = v.m_order;
m_dof = v.m_dof;
m_name = v.m_name;
}
//-----------------------------------------------------------------------------
void DOFS::Var::operator = (const DOFS::Var& v)
{
m_ntype = v.m_ntype;
m_order = v.m_order;
m_dof = v.m_dof;
m_name = v.m_name;
}
//-----------------------------------------------------------------------------
void DOFS::Var::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_ntype & m_order;
ar & m_name;
ar & m_dof;
}
//-----------------------------------------------------------------------------
void DOFS::Reset()
{
// clear the DOFS
if (m_var.empty() == false) m_var.clear();
m_maxdofs = 0;
}
//-----------------------------------------------------------------------------
//! Define a variable.
//! This creates an empty variable. Add DOFs to this variable using one of the
//! DOFS::AddDOF functions.
int DOFS::AddVariable(const char* szvar, int ntype)
{
// Make sure szvar is a valid symbol
if (szvar == 0) return -1; // cannot be null
if (szvar[0] == 0) return -1; // must have non-zero length
// Make sure the variable does not exist yet
int nvar = GetVariableIndex(szvar);
if (nvar >= 0) return -1;
// Okay, add the variable
Var var;
var.m_name = szvar;
var.m_ntype = ntype;
// allocate degrees of freedom
int ndof = 0;
if (ntype == VAR_SCALAR) ndof = 1;
else if (ntype == VAR_VEC2 ) ndof = 2;
else if (ntype == VAR_VEC3 ) ndof = 3;
else if (ntype == VAR_ARRAY ) ndof = 0; // for array we start with no dofs predefined (use AddDOF to a dofs to an array variable)
else { assert(false); return -1; }
if (ndof > 0) var.m_dof.resize(ndof);
m_var.push_back(var);
Update();
// return the index to this variable
return (int) m_var.size() - 1;
}
//-----------------------------------------------------------------------------
//! Get number of variables
int DOFS::Variables() const
{
return (int) m_var.size();
}
//-----------------------------------------------------------------------------
DOFS::Var* DOFS::GetVariable(const char* szvar)
{
if (m_var.empty()) return 0;
int NVAR = (int) m_var.size();
for (int i=0; i<NVAR; ++i)
{
Var& var = m_var[i];
if (var.m_name == szvar) return &var;
}
return 0;
}
//-----------------------------------------------------------------------------
int DOFS::GetVariableIndex(const char* szvar)
{
if (m_var.empty()) return -1;
int NVAR = (int) m_var.size();
for (int i=0; i<NVAR; ++i)
{
Var& var = m_var[i];
if (var.m_name == szvar) return i;
}
return -1;
}
//-----------------------------------------------------------------------------
//! Get the variable name
std::string DOFS::GetVariableName(int n) const
{
std::string varName;
if ((n >= 0) && (n < Variables()))
{
const Var& var = m_var[n];
varName = var.m_name;
}
return varName;
}
//-----------------------------------------------------------------------------
//! Add a degree of freedom to a variable.
// This only works on array variables
//! Returns -1 if the degree of freedom exists or if the symbol is invalid
//! \sa DOFS::GetDOF
int DOFS::AddDOF(const char* szvar, const char* sz)
{
// Make sure sz is a valid symbol
if (sz == 0) return -1; // cannot be null
if (sz[0] == 0) return -1; // must have non-zero length
// Make sure the symbol does not exist yet
int ndof = GetDOF(sz);
if (ndof >= 0) return -1;
// Make sure the variable is valid
Var* pvar = GetVariable(szvar);
if (pvar && (pvar->m_ntype == VAR_ARRAY))
{
Var& var = *pvar;
DOF_ITEM it(sz);
var.m_dof.push_back(it);
// update all dofs
Update();
// return a nonnegative number
return 0;
}
// if we get here, the variable does not exist
return -1;
}
//-----------------------------------------------------------------------------
//! Add a degree of freedom to a variable.
//! Returns -1 if the degree of freedom exists or if the symbol is invalid
//! \sa DOFS::GetDOF
int DOFS::AddDOF(int nvar, const char* sz)
{
// Make sure sz is a valid symbol
if (sz == 0) return -1; // cannot be null
if (sz[0] == 0) return -1; // must have non-zero length
// Make sure the symbol is not defined yet
int ndof = GetDOF(sz);
if (ndof >= 0) return -1;
// Make sure the variable index is valid
if (nvar < 0) return -1;
if (nvar >= (int) m_var.size()) return -1;
Var& var = m_var[nvar];
if (var.m_ntype == VAR_ARRAY)
{
// Add the DOF
DOF_ITEM it(sz);
m_var[nvar].m_dof.push_back(it);
// update all dofs
Update();
// return a nonnegative number
return 0;
}
return -1;
}
//-----------------------------------------------------------------------------
int DOFS::GetIndex(const char* varName, const char* szdof)
{
Var* var = GetVariable(varName);
if (var == 0) return -1;
for (int i=0; i<(int)var->m_dof.size(); ++i)
{
if (strcmp(var->m_dof[i].sz, szdof) == 0) return i;
}
return -1;
}
//-----------------------------------------------------------------------------
//! Return the DOF index from a variable and an index into the variable's dof array.
//! This index is used in the FENode::get(), FENode::set() functions to set
//! the values of nodal values. This index is also used in the FENode::m_ID and FENode::m_BC arrays.
int DOFS::GetDOF(const char* szvar, int n)
{
Var* pvar = GetVariable(szvar);
if (pvar)
{
// assert((n >= 0) && (n<(int)pvar->m_dof.size()));
if ((n >= 0) && (n<(int)pvar->m_dof.size()))
{
DOF_ITEM& it = pvar->m_dof[n];
return it.ndof;
}
}
return -1;
}
//-----------------------------------------------------------------------------
//! Return the DOF index from a variable and an index into the variable's dof array.
//! This index is used in the FENode::get(), FENode::set() functions to set
//! the values of nodal values. This index is also used in the FENode::m_ID and FENode::m_BC arrays.
int DOFS::GetDOF(int nvar, int n)
{
assert((nvar>=0)&&(nvar<(int)m_var.size()));
Var& var = m_var[nvar];
assert((n>=0)&&(n<(int)var.m_dof.size()));
DOF_ITEM& it = var.m_dof[n];
return it.ndof;
}
//-----------------------------------------------------------------------------
//! Return the DOF index from a dof symbol.
//! This index is used in the FENode::get(), FENode::set() functions to set
//! the values of nodal values. This index is also used in the FENode::m_ID and FENode::m_BC arrays.
int DOFS::GetDOF(const char* szdof, const char* szvarName)
{
const int NVAR = (int)m_var.size();
for (int i=0; i<NVAR; ++i)
{
Var& var = m_var[i];
if ((szvarName == nullptr) || (var.m_name == std::string(szvarName)))
{
int ndof = (int)var.m_dof.size();
for (int j = 0; j < ndof; ++j)
{
DOF_ITEM& it = var.m_dof[j];
if (strcmp(it.sz, szdof) == 0) return it.ndof;
}
}
}
return -1;
}
//-----------------------------------------------------------------------------
//! Returns a list of DOF indices for a variable.
//! The returned list will be empty if the variable is not known
void DOFS::GetDOFList(const char* varName, std::vector<int>& dofs)
{
// make sure we start with an empty list
dofs.clear();
// get the variable
Var* var = GetVariable(varName);
if (var == 0) return;
// fill the dof list
int n = (int) var->m_dof.size();
if (n==0) return;
dofs.resize(n);
for (int i=0; i<n; ++i) dofs[i] = var->m_dof[i].ndof;
}
//-----------------------------------------------------------------------------
//! Returns a list of DOF indices for a variable.
//! The returned list will be empty if the variable is not known
void DOFS::GetDOFList(int nvar, std::vector<int>& dofs)
{
// make sure we start with an empty list
dofs.clear();
// get the variable
Var& var = m_var[nvar];
// fill the dof list
int n = (int)var.m_dof.size();
if (n == 0) return;
dofs.resize(n);
for (int i = 0; i<n; ++i) dofs[i] = var.m_dof[i].ndof;
}
//-----------------------------------------------------------------------------
bool DOFS::ParseDOFString(const char* sz, std::vector<int>& dofs, const char* szvar)
{
const char* ch = sz;
char szdof[8] = {0}, *c = szdof;
do
{
if ((*ch==',')||(*ch==0))
{
*c = 0;
int ndof = GetDOF(szdof, szvar);
if (ndof != -1) dofs.push_back(ndof); else return false;
c = szdof;
if (*ch != 0) ch++; else ch = 0;
}
else
{
if (isspace(*ch) == 0) *c++ = *ch;
ch++;
}
}
while (ch);
return true;
}
//-----------------------------------------------------------------------------
//! get the size of the dof array of a variable
int DOFS::GetVariableSize(const char* szvar)
{
Var* pvar = GetVariable(szvar);
if (pvar) return (int)pvar->m_dof.size();
return -1;
}
//-----------------------------------------------------------------------------
//! get the size of the dof array of a variable
int DOFS::GetVariableSize(int nvar)
{
if ((nvar < 0) || (nvar >= (int) m_var.size())) return -1;
return (int)m_var[nvar].m_dof.size();
}
//-----------------------------------------------------------------------------
//! get the size of the dof array of a variable
int DOFS::GetVariableType(int nvar)
{
if ((nvar < 0) || (nvar >= (int) m_var.size())) return -1;
return m_var[nvar].m_ntype;
}
//-----------------------------------------------------------------------------
//! return the total number of degrees of freedom
int DOFS::GetTotalDOFS() const { return m_maxdofs; }
//-----------------------------------------------------------------------------
// Updates the DOF indices.
// This is called after a dof is added.
void DOFS::Update()
{
m_maxdofs = 0;
int NVAR = (int) m_var.size();
for (int i=0; i<NVAR; ++i)
{
Var& var = m_var[i];
int NDOF = (int) var.m_dof.size();
for (int j=0; j<NDOF; ++j)
{
DOF_ITEM& it = var.m_dof[j];
it.ndof = m_maxdofs++;
it.nvar = i;
}
}
}
//-----------------------------------------------------------------------------
DOFS::DOF_ITEM* DOFS::GetDOFPtr(const char* szdof)
{
const int NVAR = (int)m_var.size();
for (int i=0; i<NVAR; ++i)
{
Var& var = m_var[i];
int ndof = (int)var.m_dof.size();
for (int j=0; j<ndof; ++j)
{
DOF_ITEM& it = var.m_dof[j];
if (strcmp(it.sz, szdof) == 0) return ⁢
}
}
return 0;
}
//-----------------------------------------------------------------------------
void DOFS::SetDOFName(const char* szvar, int n, const char* szname)
{
Var* pvar = GetVariable(szvar);
if (pvar)
{
int nsize = (int) pvar->m_dof.size();
if ((n>=0)&&(n<nsize))
{
DOF_ITEM& it = pvar->m_dof[n];
it.SetName(szname);
}
}
}
//-----------------------------------------------------------------------------
void DOFS::SetDOFName(int nvar, int n, const char* szname)
{
if ((nvar>=0)&&(nvar<(int)m_var.size()))
{
Var& var = m_var[nvar];
int nsize = (int) var.m_dof.size();
if ((n>=0)&&(n<nsize))
{
DOF_ITEM& it = var.m_dof[n];
it.SetName(szname);
}
}
}
//-----------------------------------------------------------------------------
const char* DOFS::GetDOFName(int nvar, int n)
{
if ((nvar >= 0) && (nvar<(int)m_var.size()))
{
Var& var = m_var[nvar];
int nsize = (int)var.m_dof.size();
if ((n >= 0) && (n<nsize))
{
DOF_ITEM& it = var.m_dof[n];
return it.sz;
}
}
return 0;
}
//-----------------------------------------------------------------------------
const char* DOFS::GetDOFName(int ndof)
{
int n = 0;
for (int i = 0; i < m_var.size(); ++i)
{
Var& var = m_var[i];
for (int j = 0; j < var.m_dof.size(); ++j)
{
DOF_ITEM& dof = var.m_dof[j];
if (dof.ndof == ndof)
{
return dof.sz;
}
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
void DOFS::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_maxdofs;
ar & m_var;
}
//-----------------------------------------------------------------------------
//! set the interpolation order for a variable
void DOFS::SetVariableInterpolationOrder(int nvar, int order)
{
m_var[nvar].m_order = order;
}
//-----------------------------------------------------------------------------
// return the interpolation order of a variable
int DOFS::GetVariableInterpolationOrder(int nvar)
{
return m_var[nvar].m_order;
}
//-----------------------------------------------------------------------------
// Find the variable from a dof
int DOFS::FindVariableFromDOF(int ndof)
{
for (int i=0; i<Variables(); ++i)
{
Var& v = m_var[i];
size_t dofs = v.m_dof.size();
for (size_t j = 0; j < dofs; ++j)
{
if (v.m_dof[j].ndof == ndof) return i;
}
}
assert(false);
return -1;
}
//-----------------------------------------------------------------------------
// return the interpolation order for a degree of freedom
int DOFS::GetDOFInterpolationOrder(int ndof)
{
// find the variable for this dof
int nvar = FindVariableFromDOF(ndof);
assert(nvar >= 0);
return m_var[nvar].m_order;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDiscreteMaterial.h | .h | 2,064 | 57 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEMaterial.h"
//-----------------------------------------------------------------------------
// Material point data for discrete materials.
class FECORE_API FEDiscreteMaterialPoint : public FEMaterialPointData
{
public:
FEMaterialPointData* Copy() override;
void Serialize(DumpStream& ar) override;
public:
vec3d m_dr0; // initial relative position
vec3d m_drp; // previous relative position
vec3d m_drt; // relative position r_b - r_a
vec3d m_dvt; // relative velocity v_b - v_a
};
//-----------------------------------------------------------------------------
//! material class for discrete elements
class FECORE_API FEDiscreteMaterial : public FEMaterial
{
FECORE_SUPER_CLASS(FEDISCRETEMATERIAL_ID)
public:
FEDiscreteMaterial(FEModel* pfem);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/AkimaSpline.cpp | .cpp | 6,383 | 196 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2023 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "AkimaSpline.h"
#include <limits>
//--------------------------------------------------------------------------------
struct AkimaSpline::Impl
{
int ncoef; //! number of B-spline coefficients
std::vector<double> xknot; //! knot sequence
std::vector<double> acoef; //! Akima spline coefficient a
std::vector<double> bcoef; //! Akima spline coefficient b
std::vector<double> ccoef; //! Akima spline coefficient c
std::vector<double> dcoef; //! Akima spline coefficient d
};
//--------------------------------------------------------------------------------
AkimaSpline::AkimaSpline() : im(new AkimaSpline::Impl)
{
im->ncoef = 0;
}
//--------------------------------------------------------------------------------
// destructor
AkimaSpline::~AkimaSpline()
{
delete im;
im = nullptr;
}
//--------------------------------------------------------------------------------
// copy constructor
AkimaSpline::AkimaSpline(const AkimaSpline& as) : im(new AkimaSpline::Impl)
{
im->ncoef = as.im->ncoef;
im->xknot = as.im->xknot;
im->acoef = as.im->acoef;
im->bcoef = as.im->bcoef;
im->ccoef = as.im->ccoef;
im->dcoef = as.im->dcoef;
}
//--------------------------------------------------------------------------------
void AkimaSpline::operator = (const AkimaSpline& as)
{
im->ncoef = as.im->ncoef;
im->xknot = as.im->xknot;
im->acoef = as.im->acoef;
im->bcoef = as.im->bcoef;
im->ccoef = as.im->ccoef;
im->dcoef = as.im->dcoef;
}
//--------------------------------------------------------------------------------
// initialize B-spline, using p as control points
bool AkimaSpline::init(const std::vector<vec2d>& p)
{
int ncoef = (int)p.size();
if (ncoef < 2) return false;
im->ncoef = ncoef;
im->xknot.resize(ncoef);
im->acoef.resize(ncoef-1);
im->bcoef.resize(ncoef-1);
im->ccoef.resize(ncoef-1);
im->dcoef.resize(ncoef-1);
// extract m sequence
std::vector<double> m(ncoef-1);
for (int i=0; i< ncoef-1; ++i)
m[i] = (p[i+1].y()-p[i].y())/(p[i+1].x()-p[i].x());
// extract slopes s
const double eps = 10*std::numeric_limits<double>::epsilon();
std::vector<double> s(ncoef);
s[0] = m[0];
s[1] = (m[0]+m[1])/2;
if (ncoef > 2) {
s[ncoef-2] = (m[ncoef-3]+m[ncoef-2])/2;
s[ncoef-1] = m[ncoef-2];
for (int i=2; i<ncoef-2; ++i) {
double d = fabs(m[i+1]-m[i]) + fabs(m[i-1]-m[i-2]);
s[i] = (fabs(d) > eps) ? (fabs(m[i+1]-m[i])*m[i-1]+fabs(m[i-1]-m[i-2])*m[i])/d : (m[i-1]+m[i])/2;
}
}
// evaluate knots and coefficients
if (ncoef == 2) {
double dx = p[1].x()-p[0].x();
if (fabs(dx) <= eps) return false;
im->xknot[0] = p[0].x();
im->xknot[1] = p[1].x();
im->acoef[0] = p[0].y();
im->bcoef[0] = s[0];
im->ccoef[0] = 0;
im->dcoef[0] = 0;
}
else {
for (int i=0; i<ncoef-1; ++i) {
double dx = p[i+1].x()-p[i].x();
if (fabs(dx) <= eps) return false;
im->xknot[i] = p[i].x();
im->acoef[i] = p[i].y();
im->bcoef[i] = s[i];
im->ccoef[i] = (3*m[i] - 2*s[i] - s[i+1])/dx;
im->dcoef[i] = (s[i] + s[i+1] - 2*m[i])/(dx*dx);
}
im->xknot[ncoef-1] = p[ncoef-1].x();
}
return true;
}
//--------------------------------------------------------------------------------
// evaluate Akima spline at x
double AkimaSpline::eval(double x) const
{
// perform binary search to locate knot interval that encloses x
int j = 0, jh = im->ncoef-1;
while (jh - j > 1) {
int jm = (j+jh)/2;
if ((im->xknot[j] <= x) && (x < im->xknot[jm]))
jh = jm;
else
j = jm;
}
double dx = x - im->xknot[j];
double y = im->acoef[j] + dx*(im->bcoef[j] + dx*(im->ccoef[j] + dx*im->dcoef[j]));
return y;
}
//--------------------------------------------------------------------------------
double AkimaSpline::eval_deriv(double x) const
{
// perform binary search to locate knot interval that encloses x
int j = 0, jh = im->ncoef-1;
while (jh - j > 1) {
int jm = (j+jh)/2;
if ((im->xknot[j] <= x) && (x < im->xknot[jm]))
jh = jm;
else
j = jm;
}
double dx = x - im->xknot[j];
double dy = im->bcoef[j] + dx*(2*im->ccoef[j] + 3*dx*im->dcoef[j]);
return dy;
}
//--------------------------------------------------------------------------------
double AkimaSpline::eval_deriv2(double x) const
{
// perform binary search to locate knot interval that encloses x
int j = 0, jh = im->ncoef-1;
while (jh - j > 1) {
int jm = (j+jh)/2;
if ((im->xknot[j] <= x) && (x < im->xknot[jm]))
jh = jm;
else
j = jm;
}
double dx = x - im->xknot[j];
double d2y = 2*(im->ccoef[j] + 3*dx*im->dcoef[j]);
return d2y;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENodeElemList.cpp | .cpp | 7,753 | 341 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FENodeElemList.h"
#include "FESurface.h"
#include "FEMesh.h"
#include "FEDomain.h"
#include "FEShellDomain.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
int FENodeElemList::MaxValence()
{
int nmax = 0;
int N = (int) m_nval.size();
for (int i=0; i<N; ++i) if (m_nval[i] > nmax) nmax = m_nval[i];
return nmax;
}
//-----------------------------------------------------------------------------
//! This function builds the node-element list for a surface
void FENodeElemList::Create(const FESurface& s)
{
int i, j, n;
// get the number of nodes
int nn = s.Nodes();
// get the number of elements
int ne = s.Elements();
// create nodal valence array
m_nval.assign(nn, 0);
m_pn.resize(nn);
// fill valence table
int nsize = 0;
for (i=0; i<ne; ++i)
{
const FESurfaceElement& el = s.Element(i);
for (j=0; j<el.Nodes(); ++j)
{
n = el.m_lnode[j];
m_nval[n]++;
nsize++;
}
}
// create the element reference array
m_eref.resize(nsize);
m_iref.resize(nsize);
// set eref pointers
m_pn[0] = 0;
for (i=1; i<nn; ++i)
{
m_pn[i] = m_pn[i-1] + m_nval[i-1];
}
// reset valence pointers
for (i=0; i<nn; ++i) m_nval[i] = 0;
// fill eref table
for (i=0; i<ne; ++i)
{
const FESurfaceElement& el = s.Element(i);
for (j=0; j<el.Nodes(); ++j)
{
n = el.m_lnode[j];
m_eref[m_pn[n] + m_nval[n]] = const_cast<FESurfaceElement*>(&el);
m_iref[m_pn[n] + m_nval[n]] = i;
m_nval[n]++;
}
}
}
//-----------------------------------------------------------------------------
//! This function builds the node-element list for a mesh
void FENodeElemList::Create(FEMesh& mesh)
{
int i, j, n, nd;
// get the number of nodes
int NN = mesh.Nodes();
// create nodal valence array
m_nval.assign(NN, 0);
m_pn.resize(NN);
// fill valence table
int nsize = 0;
for (nd=0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
for (i=0; i<d.Elements(); ++i)
{
FEElement& el = d.ElementRef(i);
for (j=0; j<el.Nodes(); ++j)
{
n = el.m_node[j];
m_nval[n]++;
nsize++;
}
}
}
// create the element reference array
m_eref.resize(nsize);
m_iref.resize(nsize);
// set eref pointers
m_pn[0] = 0;
for (i=1; i<NN; ++i)
{
m_pn[i] = m_pn[i-1] + m_nval[i-1];
}
// reset valence pointers
for (i=0; i<NN; ++i) m_nval[i] = 0;
// fill eref table
// Prioritize shell domains over other domains.
// This is needed when shells are connected to solids
// and contact interfaces need to use the shell properties
// for auto-penalty calculation.
int nindex = 0;
for (nd=0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
if (d.Class() == FE_DOMAIN_SHELL) {
for (i = 0; i < d.Elements(); ++i, ++nindex)
{
FEElement& el = d.ElementRef(i);
for (j = 0; j < el.Nodes(); ++j)
{
n = el.m_node[j];
m_eref[m_pn[n] + m_nval[n]] = ⪙
m_iref[m_pn[n] + m_nval[n]] = nindex;
m_nval[n]++;
}
}
}
else nindex += d.Elements();
}
assert(nindex == mesh.Elements());
nindex = 0;
for (nd=0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
if (d.Class() != FE_DOMAIN_SHELL) {
for (i = 0; i < d.Elements(); ++i, ++nindex)
{
FEElement& el = d.ElementRef(i);
for (j = 0; j < el.Nodes(); ++j)
{
n = el.m_node[j];
m_eref[m_pn[n] + m_nval[n]] = ⪙
m_iref[m_pn[n] + m_nval[n]] = nindex;
m_nval[n]++;
}
}
}
else nindex += d.Elements();
}
assert(nindex == mesh.Elements());
}
//-----------------------------------------------------------------------------
//! This function builds the node-element list for a domain
void FENodeElemList::Create(FEDomain& dom)
{
int i, j, n;
// get the mesh
FEMesh& mesh = *dom.GetMesh();
// get the number of nodes
int NN = mesh.Nodes();
// create nodal valence array
m_nval.assign(NN, 0);
m_pn.resize(NN);
// fill valence table
int nsize = 0;
for (i=0; i<dom.Elements(); ++i)
{
FEElement& el = dom.ElementRef(i);
for (j=0; j<el.Nodes(); ++j)
{
n = el.m_node[j];
m_nval[n]++;
nsize++;
}
}
// create the element reference array
m_eref.resize(nsize);
m_iref.resize(nsize);
// set eref pointers
m_pn[0] = 0;
for (i=1; i<NN; ++i)
{
m_pn[i] = m_pn[i-1] + m_nval[i-1];
}
// reset valence pointers
for (i=0; i<NN; ++i) m_nval[i] = 0;
// fill eref table
for (i=0; i<dom.Elements(); ++i)
{
FEElement& el = dom.ElementRef(i);
for (j=0; j<el.Nodes(); ++j)
{
n = el.m_node[j];
m_eref[m_pn[n] + m_nval[n]] = ⪙
m_iref[m_pn[n] + m_nval[n]] = i;
m_nval[n]++;
}
}
}
//-----------------------------------------------------------------------------
void FENodeElemList::Clear()
{
m_nval.clear();
m_eref.clear();
m_iref.clear();
m_pn.clear();
}
//-----------------------------------------------------------------------------
//! Save data to dump file
void FENodeElemList::Serialize(DumpStream& ar)
{
ar & m_nval & m_iref & m_pn;
}
//-----------------------------------------------------------------------------
void FENodeElemTree::Create(FESurface* ps, int k)
{
int NN = ps->Nodes();
int NE = ps->Elements();
// temporary arrays
vector< vector<int> > nel;
vector<int> tag;
nel.resize(NN);
tag.assign(NE, -1);
// build the first level
for (int i=0; i<NE; ++i)
{
FESurfaceElement* pe = &ps->Element(i);
int ne = pe->Nodes();
for (int j=0; j<ne; ++j) nel[pe->m_lnode[j]].push_back(i);
}
// build the other levels
for (int l=0; l<k; ++l)
{
vector<int> ns(NN);
for (int i=0; i<NN; ++i) ns[i] = (int) nel[i].size();
for (int i=0; i<NN; ++i)
{
int ntag = l*NN + i;
vector<int>& NI = nel[i];
int ni = ns[i];
for (int j=0; j<ni; ++j) tag[NI[j]] = ntag;
for (int j=0; j<ni; ++j)
{
FESurfaceElement& e = ps->Element(NI[j]);
int ne = e.Nodes();
for (int n=0; n<ne; ++n)
{
if (e.m_lnode[n] != i)
{
vector<int>& NJ = nel[e.m_lnode[n]];
int nj = ns[e.m_lnode[n]];
for (int m=0; m<nj; ++m)
{
if (tag[NJ[m]] < ntag)
{
NI.push_back(NJ[m]);
tag[NJ[m]] = ntag;
}
}
}
}
}
}
}
// assign the element pointers
m_nel.resize(NN);
for (int i=0; i<NN; ++i)
{
vector<int>& NI = nel[i];
sort(NI.begin(), NI.end());
int ni = (int)NI.size();
m_nel[i].resize(ni);
for (int j=0; j<ni; ++j) m_nel[i][j] = &ps->Element(NI[j]);
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEAnalysis.cpp | .cpp | 19,427 | 707 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEAnalysis.h"
#include "FEModel.h"
#include "FECoreKernel.h"
#include "log.h"
#include "DOFS.h"
#include "MatrixProfile.h"
#include "FEBoundaryCondition.h"
#include "DumpMemStream.h"
#include "FELinearConstraintManager.h"
#include "FEShellDomain.h"
#include "FEMeshAdaptor.h"
#include "FETimeStepController.h"
#include "FEModule.h"
//---------------------------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEAnalysis, FECoreBase)
BEGIN_PARAM_GROUP("Analysis");
ADD_PARAMETER(m_nanalysis, "analysis");// , 0, "STATIC\0DYNAMIC\0STEADY-STATE\0TRANSIENT=1\0");
END_PARAM_GROUP();
BEGIN_PARAM_GROUP("Time stepping");
ADD_PARAMETER(m_ntime , FE_RANGE_GREATER_OR_EQUAL(-1) , "time_steps");
ADD_PARAMETER(m_dt0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "step_size")->setUnits(UNIT_TIME)->SetFlags(0);
ADD_PARAMETER(m_final_time , FE_RANGE_GREATER_OR_EQUAL(0.0), "final_time")->SetFlags(FE_PARAM_HIDDEN);
END_PARAM_GROUP();
BEGIN_PARAM_GROUP("Output");
ADD_PARAMETER(m_bplotZero, "plot_zero_state");
ADD_PARAMETER(m_nplotRange, 2, "plot_range");
ADD_PARAMETER(m_nplot, "plot_level", 0, "PLOT_NEVER\0PLOT_MAJOR_ITRS\0PLOT_MINOR_ITRS\0PLOT_MUST_POINTS\0PLOT_FINAL\0PLOT_AUGMENTATIONS\0PLOT_STEP_FINAL\0");
ADD_PARAMETER(m_noutput, "output_level", 0, "OUTPUT_NEVER\0OUTPUT_MAJOR_ITRS\0OUTPUT_MINOR_ITRS\0OUTPUT_MUST_POINTS\0OUTPUT_FINAL\0");
ADD_PARAMETER(m_nplot_stride, "plot_stride");
ADD_PARAMETER(m_noutput_stride, "output_stride");
END_PARAM_GROUP();
BEGIN_PARAM_GROUP("Advanced settings");
ADD_PARAMETER(m_badaptorReSolve, "adaptor_re_solve")->setLongName("re-solve after adaptation");
END_PARAM_GROUP();
ADD_PROPERTY(m_timeController, "time_stepper", FEProperty::Preferred)->SetDefaultType("default").SetLongName("Auto time stepper");
FEProperty* solver = ADD_PROPERTY(m_psolver, "solver");
// the default type of the solver should match the active module's name
FECoreKernel& fecore = FECoreKernel::GetInstance();
FEModule* mod = fecore.GetActiveModule();
if (mod)
{
const char* szmod = mod->GetName();
if (szmod)
{
solver->SetDefaultType(szmod);
}
}
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEAnalysis::FEAnalysis(FEModel* fem) : FECoreBase(fem)
{
m_psolver = nullptr;
m_tend = 0.0;
m_timeController = nullptr;
// --- Analysis data ---
m_nanalysis = 0;
m_badaptorReSolve = true;
// --- Time Step Data ---
m_ntime = 10;
m_final_time = 0.0;
m_dt0 = 0.1;
m_dt = 0;
// initialize counters
m_ntotref = 0; // total nr of stiffness reformations
m_ntotiter = 0; // total nr of non-linear iterations
m_ntimesteps = 0; // time steps completed
m_ntotrhs = 0; // total nr of right hand side evaluations
// --- I/O Data ---
m_nplot = FE_PLOT_MAJOR_ITRS;
m_noutput = FE_OUTPUT_MAJOR_ITRS;
m_nplot_stride = 1;
m_noutput_stride = 1;
m_nplotRange[0] = 0; // by default, will store step zero.
m_nplotRange[1] = -1; // by default, store last time step
m_bplotZero = false; // don't force plotting step zero.
m_plotHint = 0;
m_bactive = false;
}
//-----------------------------------------------------------------------------
FEAnalysis::~FEAnalysis()
{
if (m_psolver) delete m_psolver;
}
//-----------------------------------------------------------------------------
//! copy data from another analysis
void FEAnalysis::CopyFrom(FEAnalysis* step)
{
m_nanalysis = step->m_nanalysis;
m_ntime = step->m_ntime;
m_final_time = step->m_final_time;
m_dt = step->m_dt;
m_dt0 = step->m_dt0;
m_tstart = step->m_tstart;
m_tend = step->m_tend;
if (step->m_timeController)
{
m_timeController = new FETimeStepController(GetFEModel());
m_timeController->SetAnalysis(this);
m_timeController->CopyFrom(step->m_timeController);
}
}
//-----------------------------------------------------------------------------
//! Return a domain
FEDomain* FEAnalysis::Domain(int i)
{
return &(GetFEModel()->GetMesh().Domain(m_Dom[i]));
}
//-----------------------------------------------------------------------------
void FEAnalysis::AddStepComponent(FEStepComponent* pmc)
{
if (pmc) m_MC.push_back(pmc);
}
//-----------------------------------------------------------------------------
int FEAnalysis::StepComponents() const
{
return (int) m_MC.size();
}
//-----------------------------------------------------------------------------
//! get a model component
FEStepComponent* FEAnalysis::GetStepComponent(int i)
{
return m_MC[i];
}
//-----------------------------------------------------------------------------
//! sets the plot level
void FEAnalysis::SetPlotLevel(int n) { m_nplot = n; }
//-----------------------------------------------------------------------------
//! sets the plot stride
void FEAnalysis::SetPlotStride(int n) { m_nplot_stride = n; }
//-----------------------------------------------------------------------------
//! sets the plot range
void FEAnalysis::SetPlotRange(int n0, int n1)
{
m_nplotRange[0] = n0;
m_nplotRange[1] = n1;
}
//-----------------------------------------------------------------------------
//! sets the zero-state plot flag
void FEAnalysis::SetPlotZeroState(bool b)
{
m_bplotZero = b;
}
//-----------------------------------------------------------------------------
//! sets the plot hint
void FEAnalysis::SetPlotHint(int plotHint)
{
m_plotHint = plotHint;
}
//-----------------------------------------------------------------------------
//! get the plot hint
int FEAnalysis::GetPlotHint() const
{
return m_plotHint;
}
//-----------------------------------------------------------------------------
//! get the plot level
int FEAnalysis::GetPlotLevel() { return m_nplot; }
//! Set the output level
void FEAnalysis::SetOutputLevel(int n) { m_noutput = n; }
//! Get the output level
int FEAnalysis::GetOutputLevel() { return m_noutput; }
//-----------------------------------------------------------------------------
void FEAnalysis::Reset()
{
m_ntotref = 0; // total nr of stiffness reformations
m_ntotiter = 0; // total nr of non-linear iterations
m_ntimesteps = 0; // time steps completed
m_ntotrhs = 0; // total nr of right hand side evaluations
m_dt = m_dt0;
if (m_timeController) m_timeController->Reset();
// Deactivate the step
Deactivate();
if (m_psolver) m_psolver->Reset();
}
//-----------------------------------------------------------------------------
FESolver* FEAnalysis::GetFESolver()
{
return m_psolver;
}
//-----------------------------------------------------------------------------
void FEAnalysis::SetFESolver(FESolver* psolver)
{
if (m_psolver) delete m_psolver;
m_psolver = psolver;
}
//-----------------------------------------------------------------------------
//! Data initialization and data checking.
bool FEAnalysis::Init()
{
m_dt = m_dt0;
if (m_timeController)
{
m_timeController->SetAnalysis(this);
if (m_timeController->Init() == false) return false;
}
if (m_nplot_stride <= 0) return false;
if (m_noutput_stride <= 0) return false;
return Validate();
}
//-----------------------------------------------------------------------------
//! See if this step is active
bool FEAnalysis::IsActive()
{
return m_bactive;
}
//-----------------------------------------------------------------------------
//! This function gets called right before the step needs to be solved.
bool FEAnalysis::Activate()
{
FEModel& fem = *GetFEModel();
// Make sure we are not activated yet
// This can happen after a restart during FEModel::Solve
if (m_bactive) return true;
// activate the time step
m_bactive = true;
// set first time step
// We can't do this since it will mess up the value from a restart
// m_dt = m_dt0;
// determine the end time
double Dt;
if (m_ntime == -1) Dt = m_final_time; else Dt = m_dt0*m_ntime;
m_tstart = fem.GetStartTime();
m_tend = m_tstart + Dt;
// For now, add all domains to the analysis step
FEMesh& mesh = fem.GetMesh();
int ndom = mesh.Domains();
ClearDomains();
for (int i=0; i<ndom; ++i) AddDomain(i);
// activate the model components assigned to this step
// NOTE: This currently does not ensure that initial conditions are
// applied first. This is important since relative prescribed displacements must
// be applied after initial conditions.
for (int i=0; i<(int) m_MC.size(); ++i) m_MC[i]->Activate();
// Next, we need to determine which degrees of freedom are active.
// We start by resetting all nodal degrees of freedom.
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
for (int j=0; j<(int)node.dofs(); ++j) node.set_inactive(j);
}
// Then, we activate the domains.
// This will activate the relevant degrees of freedom
// NOTE: this must be done after the model components are activated.
// This is to make sure that all initial and prescribed values are applied.
// Activate all domains
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.Class() != FE_DOMAIN_SHELL)
dom.Activate();
}
// but activate shell domains last (to deal with sandwiched shells)
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.Class() == FE_DOMAIN_SHELL)
dom.Activate();
}
// active the linear constraints
fem.GetLinearConstraintManager().Activate();
return true;
}
//-----------------------------------------------------------------------------
//! This function deactivates all boundary conditions and contact interfaces.
//! It also gives the linear solver to clean its data.
//! This is called at the completion of an analysis step.
void FEAnalysis::Deactivate()
{
// deactivate the model components
for (size_t i=0; i<(int) m_MC.size(); ++i) m_MC[i]->Deactivate();
// clean up solver data (i.e. destroy linear solver)
FESolver* solver = GetFESolver();
if (solver) solver->Clean();
// deactivate the time step
m_bactive = false;
}
//-----------------------------------------------------------------------------
// initialize the solver
bool FEAnalysis::InitSolver()
{
TRACK_TIME(TimerID::Timer_Init);
FEModel& fem = *GetFEModel();
// initialize equations
FESolver* psolver = GetFESolver();
if (psolver == nullptr) return false;
if (psolver->InitEquations() == false) return false;
// do initialization of solver data
if (psolver->Init() == false) return false;
// initialize linear constraints
// Must be done after equations are initialized
if (fem.GetLinearConstraintManager().Initialize() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
bool FEAnalysis::Solve()
{
FEModel& fem = *GetFEModel();
fem.GetTime().timeIncrement = m_dt0;
// Initialize the solver
if (InitSolver() == false) return false;
// convergence flag
// we initialize it to true so that when a restart is performed after
// the last time step we terminate normally.
bool bconv = true;
// calculate end time value
double starttime = fem.GetStartTime();
// double endtime = fem.m_ftime0 + m_ntime*m_dt0;
double endtime = m_tend;
const double eps = endtime*1e-7;
// if we restarted we need to update the timestep
// before continuing
if (m_ntimesteps != 0)
{
// update time step
if (m_timeController && (fem.GetCurrentTime() + eps < endtime)) m_timeController->AutoTimeStep(GetFESolver()->m_niter);
}
else
{
// make sure that the timestep is at least the min time step size
if (m_timeController) m_timeController->AutoTimeStep(0);
}
// dump stream for running restarts
DumpMemStream dmp(fem);
// repeat for all timesteps
if (m_timeController) m_timeController->m_nretries = 0;
while (endtime - fem.GetCurrentTime() > eps)
{
// keep a copy of the current state, in case
// we need to retry this time step
if (m_timeController && (m_timeController->m_maxretries > 0))
{
dmp.clear();
fem.Serialize(dmp);
}
// Inform that the time is about to change. (Plugins can use
// this callback to modify time step)
if (fem.DoCallback(CB_UPDATE_TIME) == false) return false;
// update time
FETimeInfo& tp = fem.GetTime();
double newTime = tp.currentTime + m_dt;
if (newTime > endtime)
{
tp.timeIncrement = endtime - tp.currentTime;
tp.currentTime = endtime;
}
else
{
tp.currentTime = newTime;
tp.timeIncrement = m_dt;
}
tp.timeStep = m_ntimesteps;
feLog("\n===== beginning time step %d : %lg =====\n", m_ntimesteps + 1, newTime);
// initialize the solver step
// (This basically evaluates all the parameter lists, but let's the solver
// customize this process to the specific needs of the solver)
if (GetFESolver()->InitStep(newTime) == false)
{
bconv = false;
break;
}
// Solve the time step
int ierr = SolveTimeStep();
// see if we want to abort
if (ierr == 2)
{
bconv = false;
break;
}
// update counters
FESolver* psolver = GetFESolver();
m_ntotref += psolver->m_ntotref;
m_ntotiter += psolver->m_niter;
m_ntotrhs += psolver->m_nrhs;
// see if we have converged
if (ierr == 0)
{
bconv = true;
// Yes! We have converged!
feLog("\n------- converged at time : %lg\n\n", fem.GetCurrentTime());
// update nr of completed timesteps
m_ntimesteps++;
// call callback function
if (fem.DoCallback(CB_MAJOR_ITERS) == false)
{
bconv = false;
feLogWarning("Early termination on user's request");
break;
}
// reset retry counter
if (m_timeController) m_timeController->m_nretries = 0;
// update time step
if (m_timeController && (fem.GetCurrentTime() + eps < endtime)) m_timeController->AutoTimeStep(psolver->m_niter);
}
else
{
// We failed to converge.
bconv = false;
// Report the sad news to the user.
feLog("\n\n------- failed to converge at time : %lg\n\n", fem.GetCurrentTime());
// This will allow states that have negative Jacobians to be stored
fem.DoCallback(CB_TIMESTEP_FAILED);
// If we have auto time stepping, decrease time step and let's retry
if (m_timeController && (m_timeController->m_nretries < m_timeController->m_maxretries))
{
// restore the previous state
dmp.Open(false, true);
fem.Serialize(dmp);
// let's try again
m_timeController->Retry();
// rewind the solver
GetFESolver()->Rewind();
}
else
{
// can't retry, so abort
if (m_timeController && (m_timeController->m_nretries >= m_timeController->m_maxretries))
feLog("Max. nr of retries reached.\n\n");
break;
}
}
}
// TODO: Why is this here?
fem.SetStartTime(fem.GetCurrentTime());
return bconv;
}
//-----------------------------------------------------------------------------
// This function calls the FE Solver for solving this analysis and also handles
// all the exceptions.
int FEAnalysis::SolveTimeStep()
{
int nerr = 0;
try
{
// solve this timestep,
int niter = 0;
bool bconv = false;
while (bconv == false) {
// solve the time step
bconv = GetFESolver()->SolveStep();
// Apply any mesh adaptors
if (bconv)
{
FEModel& fem = *GetFEModel();
if (fem.DoCallback(CB_TIMESTEP_SOLVED) == false)
{
return false;
}
if (fem.MeshAdaptors())
{
fem.GetTime().augmentation = niter;
feLog("\n=== Applying mesh adaptors: iteration %d\n", niter + 1);
for (int i = 0; i < fem.MeshAdaptors(); ++i)
{
FEMeshAdaptor* meshAdaptor = fem.MeshAdaptor(i);
if (meshAdaptor->IsActive())
{
feLog("*mesh adaptor %d (%s):\n", i + 1, meshAdaptor->GetTypeStr());
// Apply the mesh adaptor.
// It will return true if the mesh was modified.
bool meshModified = meshAdaptor->Apply(niter);
bconv = ((meshModified == false) && bconv);
feLog("\n");
}
}
niter++;
if (bconv == false)
{
// we need to clear the FE solver and then reinitialize it again
FESolver* solver = GetFESolver();
solver->Clean();
// reinitialize it
InitSolver();
// inform listeners that the mesh was remeshed
fem.DoCallback(CB_REMESH);
}
feLog("\n");
if (m_badaptorReSolve == false)
{
bconv = true;
break;
}
}
}
else break;
}
nerr = (bconv ? 0 : 1);
}
catch (LinearSolverFailed e)
{
feLogError(e.what());
nerr = 2;
}
catch (FactorizationError e)
{
feLogError(e.what());
nerr = 2;
}
catch (NANInResidualDetected e)
{
feLogError(e.what());
nerr = 1; // don't abort, instead let's retry the step
}
catch (NANInSolutionDetected e)
{
feLogError(e.what());
nerr = 1; // don't abort, instead let's retry the step
}
catch (FEMultiScaleException)
{
feLogError("The RVE problem has failed. Aborting macro run.");
nerr = 2;
}
catch (std::bad_alloc e)
{
feLogError("A memory allocation failure has occured.\nThe program will now be terminated.");
nerr = 2;
}
catch (std::exception e)
{
feLogError("Exception detected: %s\n", e.what());
nerr = 2;
}
catch (...)
{
nerr = 2;
}
return nerr;
}
//-----------------------------------------------------------------------------
void FEAnalysis::Serialize(DumpStream& ar)
{
FEModel& fem = *GetFEModel();
// --- analysis data ---
ar & m_nanalysis;
ar & m_bactive;
// --- Time Step Data ---
ar & m_ntime;
ar & m_final_time;
ar & m_dt0 & m_dt;
ar & m_tstart & m_tend;
ar & m_ntotrhs;
ar & m_ntotref;
ar & m_ntotiter;
ar & m_ntimesteps;
// --- I/O Data ---
ar & m_nplot;
ar & m_noutput;
ar & m_nplotRange;
ar & m_bplotZero;
// Serialize solver data
ar & m_psolver;
// don't serialize for shallow copies
if (ar.IsShallow()) return;
// Serialize model components
ar & m_MC;
if (ar.IsSaving() == false)
{
// For now, add all domains to the analysis step
FEMesh& mesh = fem.GetMesh();
int ndom = mesh.Domains();
ClearDomains();
for (int i = 0; i<ndom; ++i) AddDomain(i);
}
// serialize time controller
ar & m_timeController;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECube.h | .h | 2,190 | 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 "FEMesh.h"
//-----------------------------------------------------------------------------
// This class tries to identify surfaces, edges, and corner nodes on a mesh,
// assuming that it is a cube.
// The surfaces are ordered as follows:
// 1: +X, 2: -X, 3: +Y, 4: -Y, 5: +Z, 6: -Z
class FECORE_API FECube
{
public:
// constructor
FECube();
// destructor
~FECube();
// build the cube data
bool Build(FEModel* fem);
// get the mesh of this cube
FEMesh* GetMesh();
public:
// Get a surface
FESurface* GetSurface(int i);
// get the node set of the corner nodes
const FENodeSet& GetCornerNodes() const;
// get the node set of boundary nodes
const FENodeSet& GetBoundaryNodes() const;
private:
FEMesh* m_mesh;
FESurface* m_surf[6]; // the six boundary surfaces
FENodeSet* m_corners; // the eight corner nodes
FENodeSet* m_boundary; // set of all boundary nodes
};
| Unknown |
3D | febiosoftware/FEBio | FECore/ad2.cpp | .cpp | 2,178 | 67 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "ad2.h"
double ad2::Evaluate(std::function<ad2::number(ad2::mat3ds& C)> W, const ::mat3ds& C)
{
ad2::mat3ds dC(C);
return W(dC).r;
}
::mat3ds ad2::Derive(std::function<ad2::number(ad2::mat3ds& C)> W, const ::mat3ds& C)
{
ad2::mat3ds dC(C);
double S[6] = { 0.0 };
for (int i = 0; i < 6; ++i)
{
dC[i].d1 = 1;
S[i] = W(dC).d1;
dC[i].d1 = 0;
}
return ::mat3ds(S[0], S[2], S[5], 0.5 * S[1], 0.5 * S[4], 0.5 * S[3]);
}
::tens4ds ad2::Derive2(std::function<ad2::number(ad2::mat3ds& C)> W, const ::mat3ds& C)
{
constexpr int l[6] = { 0, 2, 5, 1, 4, 3 };
constexpr double w[6] = { 1.0, 1.0, 1.0, 0.5, 0.5, 0.5 };
ad2::mat3ds dC(C);
double D[6][6] = { 0 };
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 6; ++j)
{
dC[l[i]].d1 = 1;
dC[l[j]].d2 = 1;
double ddW = W(dC).dd;
dC[l[i]].d1 = 0;
dC[l[j]].d2 = 0;
D[i][j] = ddW*w[i]*w[j];
}
return ::tens4ds(D);
}
| C++ |
3D | febiosoftware/FEBio | FECore/ParamString.h | .h | 3,224 | 130 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include <string>
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class ParamRef
{
public:
int _index; // zero-based index of parameter (-1 if not available)
int _id; // ID of parameter (-1 if not available)
std::string _name; // name of parameter
std::string _idName; // string ID of parameter
public:
ParamRef() : _id(-1), _index(-1) {}
ParamRef(const ParamRef& p)
{
_name = p._name;
_id = p._id;
_index = p._index;
_idName = p._idName;
}
void operator = (const ParamRef& p)
{
_name = p._name;
_id = p._id;
_index = p._index;
_idName = p._idName;
}
void clear()
{
_name.clear();
_id = _index = -1;
_idName.clear();
}
};
//-----------------------------------------------------------------------------
// helper class for retrieving parameters
class FECORE_API ParamString
{
public:
//! constructor
ParamString(const char* sz);
//! copy constructor
ParamString(const ParamString& p);
//! assignment operator
void operator = (const ParamString& p);
//! destructor
~ParamString();
//! number of refs in string
int count() const;
//! return a new string starting from the next component
ParamString next() const;
//! return the last string
ParamString last() const;
//! is the string valid
bool isValid() const;
//! clear the string
void clear();
public:
//! compare to a string
bool operator == (const std::string& s) const;
//! compare to a string
bool operator != (const std::string& s) const;
//! Get the ID (-1 if ID not a number)
int ID() const;
//! get the index (-1 if index not used)
int Index() const;
//! get the index name (null if not defined)
const char* IDString() const;
//! get the zero-valued string
const char* c_str() const;
//! return a string
std::string string() const;
private:
ParamString() {}
private:
std::vector<ParamRef> m_param;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDomainParameter.h | .h | 1,941 | 52 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEParam.h"
#include "FEMaterialPoint.h"
//! The domain parameter is a mechanism for accessing material point data
//! indirectly through the domain.
//! Domains keep lists of domain parameters that can be queried.
//! Notice that these classes return FEParamValue so that they can be used in optimization
class FECORE_API FEDomainParameter
{
public:
FEDomainParameter(const std::string& name);
virtual ~FEDomainParameter();
void setName(const std::string& name);
const std::string& name() const;
//! derived classes must override this function
virtual FEParamValue value(FEMaterialPoint& mp) = 0;
private:
std::string m_name;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FETimeInfo.cpp | .cpp | 1,957 | 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.*/
#include "stdafx.h"
#include "FETimeInfo.h"
#include "DumpStream.h"
FETimeInfo::FETimeInfo()
{
currentTime = 0.0;
timeIncrement = 0.0;
alpha = 1.0;
beta = 0.25;
gamma = 0.5;
alphaf = 1.0;
alpham = 1.0;
currentIteration = 0;
augmentation = 0;
timeStep = 0;
}
FETimeInfo::FETimeInfo(double time, double tinc)
{
currentTime = time;
timeIncrement = tinc;
alpha = 1.0;
beta = 0.25;
gamma = 0.5;
alphaf = 1.0;
alpham = 1.0;
currentIteration = 0;
augmentation = 0;
}
void FETimeInfo::Serialize(DumpStream& ar)
{
ar & currentTime;
ar & timeIncrement;
ar & currentIteration;
ar & augmentation;
ar & alpha;
ar & alphaf;
ar & alpham;
ar & beta;
ar & gamma;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEPIDController.cpp | .cpp | 3,036 | 112 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEPIDController.h"
#include "FEModel.h"
#include "log.h"
BEGIN_FECORE_CLASS(FEPIDController, FELoadController)
ADD_PARAMETER(m_paramName, "var");
ADD_PARAMETER(m_trg, "target");
ADD_PARAMETER(m_Kp, "Kp");
ADD_PARAMETER(m_Ki, "Ki");
ADD_PARAMETER(m_Kd, "Kd");
END_FECORE_CLASS();
FEPIDController::FEPIDController(FEModel* fem) : FELoadController(fem)
{
m_prev = 0;
m_int = 0;
m_prevTime = 0.0;
m_paramVal = 0.0;
m_error = 0.0;
}
bool FEPIDController::Init()
{
FEModel& fem = *GetFEModel();
ParamString ps(m_paramName.c_str());
m_param = fem.GetParameterValue(ps);
if (m_param.isValid() == false) return false;
if (m_param.type() != FE_PARAM_DOUBLE) return false;
return FELoadController::Init();
}
double FEPIDController::GetValue(double time)
{
m_paramVal = m_param.value<double>();
m_error = m_trg - m_paramVal;
double newVal = m_Kp* m_error;
double dt = time - m_prevTime;
if (dt != 0.0)
{
double der = (m_error - m_prev) / dt;
m_int += m_error *dt;
newVal += m_Kd*der + m_Ki*m_int;
}
m_prev = m_error;
m_prevTime = time;
if (GetFEModel()->GetPrintParametersFlag())
{
feLog("PID controller %d:\n", GetID());
feLog("\tparameter = %lg\n", m_paramVal);
feLog("\terror = %lg\n", m_error);
feLog("\tvalue = %lg\n", newVal);
}
return newVal;
}
void FEPIDController::Serialize(DumpStream& ar)
{
FELoadController::Serialize(ar);
if (ar.IsSaving())
{
ar << m_paramVal << m_error << m_prev << m_prevTime << m_int;
}
else
{
ar >> m_paramVal >> m_error >> m_prev >> m_prevTime >> m_int;
if (ar.IsShallow())
{
FEModel& fem = *GetFEModel();
ParamString ps(m_paramName.c_str());
m_param = fem.GetParameterValue(ps);
assert(m_param.isValid());
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/CompactUnSymmMatrix.cpp | .cpp | 22,092 | 928 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "CompactUnSymmMatrix.h"
using namespace std;
//-----------------------------------------------------------------------------
// this sort function is defined in qsort.cpp
void qsort(int n, const int* arr, int* indx);
//=================================================================================================
CRSSparseMatrix::Iterator::Iterator(CRSSparseMatrix* A) : m_A(A)
{
reset();
}
bool CRSSparseMatrix::Iterator::valid()
{
return (n != -1);
}
void CRSSparseMatrix::Iterator::next()
{
if (valid())
{
int* pr = m_A->Pointers();
int l = pr[r+1] - pr[r];
if (n < l-1) n++;
else
{
r++;
if (r >= m_A->Rows()) n = -1;
else n = 0;
}
}
else assert(false);
}
void CRSSparseMatrix::Iterator::reset()
{
r = 0;
n = 0;
if (m_A == nullptr) n = -1;
}
MatrixItem CRSSparseMatrix::Iterator::get()
{
assert(valid());
int* pr = m_A->Pointers();
int* pi = m_A->Indices() + (pr[r] - m_A->Offset());
double* pv = m_A->Values() + (pr[r] - m_A->Offset());
MatrixItem m;
m.row = r;
m.col = pi[n] - m_A->Offset();
m.val = pv[n];
return m;
}
void CRSSparseMatrix::Iterator::set(double v)
{
assert(valid());
int* pr = m_A->Pointers();
double* pv = m_A->Values() + (pr[r] - m_A->Offset());
pv[n] = v;
}
//=================================================================================================
// CRSSparseMatrix
//=================================================================================================
//-----------------------------------------------------------------------------
//! Constructor for CRSSparseMatrix class
CRSSparseMatrix::CRSSparseMatrix(int offset) : CompactMatrix(offset)
{
}
//-----------------------------------------------------------------------------
CRSSparseMatrix::CRSSparseMatrix(const CRSSparseMatrix& A) : CompactMatrix(A.m_offset)
{
m_nrow = A.m_nrow;
m_ncol = A.m_ncol;
m_nsize = A.m_nsize;
m_ppointers = new int[m_nrow + 1];
m_pindices = new int[m_nsize];
m_pd = new double[m_nsize];
for (int i = 0; i <= m_nrow; ++i) m_ppointers[i] = A.m_ppointers[i];
for (int i = 0; i<m_nsize; ++i) m_pindices[i] = A.m_pindices[i];
for (int i = 0; i<m_nsize; ++i) m_pd[i] = A.m_pd[i];
}
//-----------------------------------------------------------------------------
void CRSSparseMatrix::Create(SparseMatrixProfile& mp)
{
int nr = mp.Rows();
int nc = mp.Columns();
int* pointers = new int[nr + 1];
for (int i = 0; i <= nr; ++i) pointers[i] = 0;
int nsize = 0;
for (int i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
int n = (int)a.size();
for (int j = 0; j<n; j++)
{
int asize = a[j].end - a[j].start + 1;
nsize += asize;
for (int k = a[j].start; k <= a[j].end; ++k) pointers[k]++;
}
}
int* pindices = new int[nsize];
int m = 0;
for (int i = 0; i <= nr; ++i)
{
int n = pointers[i];
pointers[i] = m;
m += n;
}
assert(pointers[nr] == nsize);
vector<int> pval(nr, 0);
for (int i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
int n = (int)a.size();
for (int j = 0; j<n; j++)
{
for (int k = a[j].start; k <= a[j].end; ++k)
{
pindices[pointers[k] + pval[k]] = i;
++pval[k];
}
}
}
// offset the indicies for fortran arrays
if (Offset())
{
for (int i = 0; i <= nr; ++i) pointers[i]++;
for (int i = 0; i<nsize; ++i) pindices[i]++;
}
// create the values array
double* pvalues = new double[nsize];
// create the stiffness matrix
CompactMatrix::alloc(nr, nc, nsize, pvalues, pindices, pointers);
// calculate and print matrix bandwidth
// feLog("\tMatrix bandwidth .......................... : %d\n", bandWidth());
}
void CRSSparseMatrix::Assemble(const matrix& ke, const vector<int>& LM)
{
// get the number of degrees of freedom
const int N = ke.rows();
// find the permutation array that sorts LM in ascending order
// we can use this to speed up the row search (i.e. loop over n below)
P.resize(N);
qsort(N, &LM[0], &P[0]);
// get the data pointers
int* indices = Indices();
int* pointers = Pointers();
double* pd = Values();
int offset = Offset();
// find the starting index
int N0 = 0;
while ((N0<N) && (LM[P[N0]]<0)) ++N0;
// assemble element stiffness
for (int k = N0; k<N; ++k)
{
int i = P[k];
int I = LM[i];
int n = 0;
double* pm = pd + (pointers[I] - offset);
int* pi = indices + (pointers[I] - offset);
int l = pointers[I + 1] - pointers[I];
for (int m = N0; m<N; ++m)
{
int j = P[m];
int J = LM[j] + offset;
double kij = ke[i][j];
for (; n<l; ++n)
if (pi[n] == J)
{
#pragma omp atomic
pm[n] += kij;
break;
}
}
}
}
//-----------------------------------------------------------------------------
void CRSSparseMatrix::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) add(I, J, ke[i][j]);
}
}
}
}
//-----------------------------------------------------------------------------
// This algorithm uses a binary search for locating the correct row index
// This assumes that the indices are ordered!
void CRSSparseMatrix::add(int i, int j, double v)
{
assert((i >= 0) && (i<m_nrow));
assert((j >= 0) && (j<m_ncol));
int* pi = m_pindices + (m_ppointers[i] - m_offset);
double* pd = m_pd + (m_ppointers[i] - m_offset);
int n1 = m_ppointers[i + 1] - m_ppointers[i] - 1;
int n0 = 0;
int n = n1 / 2;
j += m_offset;
do
{
int m = pi[n];
if (m == j)
{
#pragma omp atomic
pd[n] += v;
return;
}
else if (m < j)
{
n0 = n;
n = (n0 + n1 + 1) >> 1;
}
else
{
n1 = n;
n = (n0 + n1) >> 1;
}
} while (n0 != n1);
assert(false);
}
//-----------------------------------------------------------------------------
void CRSSparseMatrix::set(int i, int j, double v)
{
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int l = m_ppointers[i + 1] - m_ppointers[i];
for (int n = 0; n<l; ++n)
{
if (pi[n] == j + m_offset)
{
#pragma omp critical (CM_set)
m_pd[m_ppointers[i] + n - m_offset] = v;
return;
}
}
assert(false);
}
//-----------------------------------------------------------------------------
double CRSSparseMatrix::get(int i, int j)
{
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int l = m_ppointers[i + 1] - m_ppointers[i];
for (int n = 0; n<l; ++n)
{
if (pi[n] == j + m_offset) return m_pd[m_ppointers[i] + n - m_offset];
}
return 0;
}
//-----------------------------------------------------------------------------
bool CRSSparseMatrix::check(int i, int j)
{
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int l = m_ppointers[i + 1] - m_ppointers[i];
for (int n = 0; n<l; ++n)
{
if (pi[n] == j + m_offset) return true;
}
return false;
}
//-----------------------------------------------------------------------------
double CRSSparseMatrix::diag(int i)
{
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int l = m_ppointers[i + 1] - m_ppointers[i];
for (int n = 0; n<l; ++n)
{
if (pi[n] == i + m_offset)
{
return m_pd[m_ppointers[i] + n - m_offset];
}
}
assert(false);
return 0;
}
//-----------------------------------------------------------------------------
bool CRSSparseMatrix::mult_vector(double* x, double* r)
{
// get the matrix size
const int N = Rows();
// loop over all rows
#pragma omp parallel for schedule(guided)
for (int i = 0; i < N; ++i)
{
const double* pv = m_pd + (m_ppointers[i] - m_offset);
const int* pi = m_pindices + (m_ppointers[i] - m_offset);
const int n = m_ppointers[i + 1] - m_ppointers[i];
r[i] = 0.0;
for (int j = 0; j < n; j ++)
{
r[i] += (*pv++) * x[*pi++ - m_offset];
}
}
return true;
}
//! calculate the abs row sum
double CRSSparseMatrix::infNorm() const
{
// get the matrix size
const int N = Rows();
double norm = 0.0;
// loop over all rows
for (int i = 0; i<N; ++i)
{
double ri = 0.0;
double* pv = m_pd + m_ppointers[i] - m_offset;
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; ++j) ri += fabs(pv[j]);
if (ri > norm) norm = ri;
}
return norm;
}
//! calculate the one norm
double CRSSparseMatrix::oneNorm() const
{
// get the matrix size
const int NR = Rows();
const int NC = Columns();
vector<double> colNorms(NC, 0.0);
// loop over all rows
for (int i = 0; i<NR; ++i)
{
double ri = 0.0;
double* pv = m_pd + m_ppointers[i] - m_offset;
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; ++j) colNorms[pi[j]-m_offset] += fabs(pv[j]);
}
// find max value
double rmax = 0;
for (int i = 0; i < NC; ++i)
{
if (colNorms[i] > rmax) rmax = colNorms[i];
}
return rmax;
}
//! make the matrix a unit matrix (retains sparsity pattern)
void CRSSparseMatrix::makeUnit()
{
// loop over all rows
const int N = Rows();
for (int i = 0; i<N; ++i)
{
double* pv = m_pd + m_ppointers[i] - m_offset;
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j < n; ++j)
{
if (pi[j] - m_offset == i) pv[j] = 1.0;
else pv[j] = 0.0;
}
}
}
void CRSSparseMatrix::scale(double s)
{
int N = NonZeroes();
for (int i = 0; i < N; ++i) m_pd[i] *= s;
}
void CRSSparseMatrix::scale(const vector<double>& L, const vector<double>& R)
{
const int N = Rows();
assert(L.size() == Rows());
assert(R.size() == Columns());
for (int i = 0; i<N; ++i)
{
double* pv = m_pd + m_ppointers[i] - m_offset;
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; ++j)
{
pv[j] *= L[i] * R[pi[j] - m_offset];
}
}
}
//! extract a block of this matrix
void CRSSparseMatrix::get(int i0, int j0, int nr, int nc, CSRMatrix& M)
{
// create the matrix
M.create(nr, nc, m_offset);
vector<double>& val = M.values();
vector<int>& ind = M.indices();
vector<int>& pnt = M.pointers(); assert(pnt.size() == nr + 1);
// count how many values we'll need to copy
int nnz = 0;
for (int i = i0; i<i0 + nr; ++i)
{
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; ++j)
{
int colj = pi[j] - m_offset;
if ((colj >= j0) && (colj < j0 + nc)) nnz++;
}
pnt[i - i0 + 1] = nnz + m_offset;
}
// allocate arrays
val.resize(nnz);
ind.resize(nnz);
// copy data
nnz = 0;
for (int i = i0; i<i0 + nr; ++i)
{
double* pv = m_pd + m_ppointers[i] - m_offset;
int* pi = m_pindices + m_ppointers[i] - m_offset;
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; ++j)
{
int colj = pi[j] - m_offset;
if ((colj >= j0) && (colj < j0 + nc))
{
val[nnz] = pv[j];
ind[nnz] = colj - j0 + m_offset;
nnz++;
}
}
}
}
//=================================================================================================
// CCSSparseMatrix
//=================================================================================================
//-----------------------------------------------------------------------------
//! Constructor for CCSSparseMatrix class
CCSSparseMatrix::CCSSparseMatrix(int offset) : CompactMatrix(offset)
{
}
//-----------------------------------------------------------------------------
CCSSparseMatrix::CCSSparseMatrix(const CCSSparseMatrix& A) : CompactMatrix(A.m_offset)
{
m_nrow = A.m_nrow;
m_ncol = A.m_ncol;
m_nsize = A.m_nsize;
m_ppointers = new int[m_ncol + 1];
m_pindices = new int[m_nsize];
m_pd = new double[m_nsize];
for (int i = 0; i <= m_ncol; ++i) m_ppointers[i] = A.m_ppointers[i];
for (int i = 0; i<m_nsize; ++i) m_pindices[i] = A.m_pindices[i];
for (int i = 0; i<m_nsize; ++i) m_pd[i] = A.m_pd[i];
}
//-----------------------------------------------------------------------------
void CCSSparseMatrix::Create(SparseMatrixProfile& mp)
{
int nr = mp.Rows();
int nc = mp.Columns();
int* pointers = new int[nc + 1];
for (int i = 0; i <= nc; ++i) pointers[i] = 0;
int nsize = 0;
for (int i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
int n = (int)a.size();
for (int j = 0; j<n; j++)
{
int asize = a[j].end - a[j].start + 1;
nsize += asize;
pointers[i] += asize;
}
}
int* pindices = new int[nsize];
int m = 0;
for (int i = 0; i <= nc; ++i)
{
int n = pointers[i];
pointers[i] = m;
m += n;
}
assert(pointers[nc] == nsize);
for (int i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
int n = (int)a.size();
int nval = 0;
for (int j = 0; j<n; j++)
{
for (int k = a[j].start; k <= a[j].end; ++k)
{
pindices[pointers[i] + nval] = k;
nval++;
}
}
}
// offset the indicies for fortran arrays
if (Offset())
{
for (int i = 0; i <= nc; ++i) pointers[i]++;
for (int i = 0; i<nsize; ++i) pindices[i]++;
}
// create the values array
double* pvalues = new double[nsize];
// create the stiffness matrix
CompactMatrix::alloc(nr, nc, nsize, pvalues, pindices, pointers);
}
//-----------------------------------------------------------------------------
void CCSSparseMatrix::Assemble(const matrix& ke, const vector<int>& LM)
{
// get the number of degrees of freedom
const int N = ke.rows();
// find the permutation array that sorts LM in ascending order
// we can use this to speed up the row search (i.e. loop over n below)
P.resize(N);
qsort(N, &LM[0], &P[0]);
// get the data pointers
int* indices = Indices();
int* pointers = Pointers();
double* pd = Values();
int offset = Offset();
// find the starting index
int N0 = 0;
while ((N0<N) && (LM[P[N0]]<0)) ++N0;
for (int m = N0; m<N; ++m)
{
int j = P[m];
int J = LM[j];
int n = 0;
double* pm = pd + (pointers[J] - offset);
int* pi = indices + (pointers[J] - offset);
int l = pointers[J + 1] - pointers[J];
for (int k = N0; k<N; ++k)
{
int i = P[k];
int I = LM[i] + offset;
for (; n<l; ++n)
if (pi[n] == I)
{
#pragma omp atomic
pm[n] += ke[i][j];
break;
}
}
}
}
//-----------------------------------------------------------------------------
void CCSSparseMatrix::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) add(I, J, ke[i][j]);
}
}
}
}
//-----------------------------------------------------------------------------
// This algorithm uses a binary search for locating the correct row index
// This assumes that the indices are ordered!
void CCSSparseMatrix::add(int i, int j, double v)
{
assert((i >= 0) && (i<m_nrow));
assert((j >= 0) && (j<m_ncol));
int* pi = m_pindices + (m_ppointers[j] - m_offset);
i += m_offset;
double* pd = m_pd + (m_ppointers[j] - m_offset);
int n1 = m_ppointers[j + 1] - m_ppointers[j] - 1;
int n0 = 0;
int n = n1 / 2;
do
{
int m = pi[n];
if (m == i)
{
#pragma omp atomic
pd[n] += v;
return;
}
else if (m < i)
{
n0 = n;
n = (n0 + n1 + 1) >> 1;
}
else
{
n1 = n;
n = (n0 + n1) >> 1;
}
} while (n0 != n1);
assert(false);
}
//-----------------------------------------------------------------------------
void CCSSparseMatrix::set(int i, int j, double v)
{
int* pi = m_pindices + (m_ppointers[j] - m_offset);
int l = m_ppointers[j + 1] - m_ppointers[j];
for (int n = 0; n<l; ++n)
{
if (pi[n] == i + m_offset)
{
#pragma omp critical (CC_set)
m_pd[m_ppointers[j] + n - m_offset] = v;
return;
}
}
assert(false);
}
//-----------------------------------------------------------------------------
double CCSSparseMatrix::get(int i, int j)
{
int* pi = m_pindices + (m_ppointers[j] - m_offset);
int l = m_ppointers[j + 1] - m_ppointers[j];
for (int n = 0; n<l; ++n)
{
if (pi[n] == i + m_offset) return m_pd[m_ppointers[j] + n - m_offset];
}
return 0;
}
//-----------------------------------------------------------------------------
bool CCSSparseMatrix::check(int i, int j)
{
int* pi = m_pindices + m_ppointers[j] - m_offset;
int l = m_ppointers[j + 1] - m_ppointers[j];
for (int n = 0; n<l; ++n)
{
if (pi[n] == i + m_offset) return true;
}
return false;
}
//-----------------------------------------------------------------------------
double CCSSparseMatrix::diag(int i)
{
int* pi = m_pindices + m_ppointers[i] - m_offset;
int l = m_ppointers[i + 1] - m_ppointers[i];
for (int n = 0; n<l; ++n)
{
if (pi[n] == i + m_offset)
{
return m_pd[m_ppointers[i] + n - m_offset];
}
}
assert(false);
return 0;
}
//-----------------------------------------------------------------------------
bool CCSSparseMatrix::mult_vector(double* x, double* r)
{
// get the matrix size
const int N = Rows();
const int M = Columns();
// zero r
for (int i=0; i<N; ++i) r[i] = 0.0;
// loop over all columns
for (int i = 0; i<M; ++i)
{
double* pv = m_pd + (m_ppointers[i] - m_offset);
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int j = 0; j<n; j++) r[pi[j] - m_offset] += pv[j] * x[i];
}
return true;
}
//-----------------------------------------------------------------------------
//! calculate the inf norm
double CCSSparseMatrix::infNorm() const
{
// get the matrix size
const int NR = Rows();
const int NC = Columns();
// keep track of row sums
vector<double> rowSums(NR, 0.0);
// loop over all columns
for (int j = 0; j<NC; ++j)
{
double* pv = m_pd + m_ppointers[j] - m_offset;
int* pr = m_pindices + m_ppointers[j] - m_offset;
int n = m_ppointers[j + 1] - m_ppointers[j];
for (int i = 0; i < n; ++i)
{
int irow = pr[i] - m_offset;
double vij = fabs(pv[i]);
rowSums[irow] += vij;
}
}
// find the largest row sum
double rmax = rowSums[0];
for (int i = 1; i < NR; ++i)
{
if (rowSums[i] > rmax) rmax = rowSums[i];
}
return rmax;
}
//-----------------------------------------------------------------------------
//! calculate the one norm
double CCSSparseMatrix::oneNorm() const
{
// get the matrix size
const int NR = Rows();
const int NC = Columns();
// max col sum
double cmax = 0.0;
// loop over all columns
for (int j = 0; j<NC; ++j)
{
double* pv = m_pd + m_ppointers[j] - m_offset;
int* pr = m_pindices + m_ppointers[j] - m_offset;
int n = m_ppointers[j + 1] - m_ppointers[j];
double cj = 0.0;
for (int i = 0; i < n; ++i)
{
double vij = fabs(pv[i]);
cj += vij;
}
if (cj > cmax) cmax = cj;
}
return cmax;
}
//-----------------------------------------------------------------------------
void CCSSparseMatrix::scale(const vector<double>& L, const vector<double>& R)
{
// get the matrix size
const int N = Columns();
// loop over all columns
for (int j = 0; j < N; ++j)
{
double* pv = m_pd + m_ppointers[j] - m_offset;
int* pr = m_pindices + m_ppointers[j] - m_offset;
int n = m_ppointers[j + 1] - m_ppointers[j];
for (int i = 0; i < n; ++i)
{
pv[i] *= L[pr[i] - m_offset] * R[j];
}
}
}
//-----------------------------------------------------------------------------
//! Create a copy of the matrix (does not copy values)
CRSSparseMatrix* CRSSparseMatrix::Copy(int offset)
{
CRSSparseMatrix* A = new CRSSparseMatrix(offset);
int nnz = NonZeroes();
int nrow = Rows();
int ncol = Columns();
int nn = (isRowBased() ? nrow : ncol);
// allocate memory for copy
double* vd = new double[nnz];
int* id = new int[nnz];
int* pd = new int[nn + 1];
A->alloc(nrow, ncol, nnz, vd, id, pd);
int offs = Offset();
// copy indices
int* is = Indices();
for (int i = 0; i < nnz; ++i) id[i] = (is[i] - offs) + offset;
// copy pointers
int* ps = Pointers();
for (int i = 0; i < nn + 1; ++i) pd[i] = (ps[i] - offs) + offset;
return A;
}
//-----------------------------------------------------------------------------
//! Copy the values from another matrix
void CRSSparseMatrix::CopyValues(CompactMatrix* A)
{
assert(NonZeroes() == A->NonZeroes());
memcpy(Values(), A->Values(), sizeof(double)*NonZeroes());
}
//-----------------------------------------------------------------------------
//! convert to another format (currently only offset can be changed)
bool CRSSparseMatrix::Convert(int newOffset)
{
if (newOffset == m_offset) return true;
int d_off = newOffset - m_offset;
int nn = Rows();
int nnz = NonZeroes();
m_offset = newOffset;
// copy indices
int* is = Indices();
for (int i = 0; i < nnz; ++i) is[i] += d_off;
// copy pointers
int* ps = Pointers();
for (int i = 0; i < nn + 1; ++i) ps[i] += d_off;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/EigenSolver.h | .h | 1,676 | 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 "FECoreBase.h"
#include <vector>
#include "matrix.h"
class SparseMatrix;
class FECORE_API EigenSolver : public FECoreBase
{
FECORE_SUPER_CLASS(FEEIGENSOLVER_ID)
FECORE_BASE_CLASS(EigenSolver)
public:
EigenSolver(FEModel* fem);
virtual bool Init();
virtual bool EigenSolve(SparseMatrix* A, SparseMatrix* B, std::vector<double>& eigenValues, matrix& eigenVectors) = 0;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFaceList.cpp | .cpp | 10,900 | 479 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFaceList.h"
#include "FEMesh.h"
#include "FEDomain.h"
#include "FEElemElemList.h"
#include "FEElementList.h"
#include "FEEdgeList.h"
bool FEFaceList::FACE::IsEqual(int* n) const
{
if (ntype == 3)
{
if ((node[0] != n[0]) && (node[0] != n[1]) && (node[0] != n[2])) return false;
if ((node[1] != n[0]) && (node[1] != n[1]) && (node[1] != n[2])) return false;
if ((node[2] != n[0]) && (node[2] != n[1]) && (node[2] != n[2])) return false;
}
else if (ntype == 4)
{
if ((node[0] != n[0]) && (node[0] != n[1]) && (node[0] != n[2]) && (node[0] != n[3])) return false;
if ((node[1] != n[0]) && (node[1] != n[1]) && (node[1] != n[2]) && (node[1] != n[3])) return false;
if ((node[2] != n[0]) && (node[2] != n[1]) && (node[2] != n[2]) && (node[2] != n[3])) return false;
if ((node[3] != n[0]) && (node[3] != n[1]) && (node[3] != n[2]) && (node[3] != n[3])) return false;
}
else
{
assert(false);
return false;
}
return true;
}
bool FEFaceList::FACE::HasEdge(int a, int b) const
{
const int* n = node;
if (ntype == 3)
{
if (((n[0] == a) && (n[1] == b)) || ((n[0] == b) && (n[1] == a))) return true;
if (((n[1] == a) && (n[2] == b)) || ((n[1] == b) && (n[2] == a))) return true;
if (((n[2] == a) && (n[0] == b)) || ((n[2] == b) && (n[0] == a))) return true;
}
else if (ntype == 4)
{
if (((n[0] == a) && (n[1] == b)) || ((n[0] == b) && (n[1] == a))) return true;
if (((n[1] == a) && (n[2] == b)) || ((n[1] == b) && (n[2] == a))) return true;
if (((n[2] == a) && (n[3] == b)) || ((n[2] == b) && (n[3] == a))) return true;
if (((n[3] == a) && (n[0] == b)) || ((n[3] == b) && (n[0] == a))) return true;
}
else
{
assert(false);
}
return false;
}
FEFaceList::FEFaceList() : m_mesh(nullptr)
{
}
FEFaceList::FEFaceList(const FEFaceList& faceList)
{
m_mesh = faceList.m_mesh;
m_faceList = faceList.m_faceList;
}
int FEFaceList::Faces() const
{
return (int) m_faceList.size();
}
const FEFaceList::FACE& FEFaceList::operator [] (int i) const
{
return m_faceList[i];
}
const FEFaceList::FACE& FEFaceList::Face(int i) const
{
return m_faceList[i];
}
FEMesh* FEFaceList::GetMesh()
{
return m_mesh;
}
int FEElementFaceList::Faces(int elem) const
{
return (int)m_EFL[elem].size();
}
const std::vector<int>& FEElementFaceList::FaceList(int elem) const
{
return m_EFL[elem];
}
// Extract the surface only
FEFaceList FEFaceList::GetSurface() const
{
FEFaceList surface;
surface.m_mesh = m_mesh;
int faces = Faces();
for (int i = 0; i < faces; ++i)
{
const FEFaceList::FACE& f = m_faceList[i];
if (f.nsurf == 1) surface.m_faceList.push_back(f);
}
return surface;
}
bool FEFaceList::Create(FEMesh& mesh, FEElemElemList& EEL)
{
m_mesh = &mesh;
// get the number of elements in this mesh
int NE = mesh.Elements();
// count the number of facets we have to create
int NF = 0;
FEElementList EL(mesh);
FEElementList::iterator it = EL.begin();
for (int i = 0; i<NE; ++i, ++it)
{
FEElement& el = *it;
int nf = el.Faces();
for (int j = 0; j<nf; ++j)
{
FEElement* pen = EEL.Neighbor(i, j);
if (pen == 0) ++NF;
if ((pen != 0) && (el.GetID() < pen->GetID())) ++NF;
}
}
// create the facet list
m_faceList.resize(NF);
// build the facets
int face[FEElement::MAX_NODES];
NF = 0;
it = EL.begin();
for (int i = 0; i<NE; ++i, ++it)
{
FEElement& el = *it;
if (el.Class() == FE_ELEM_SOLID)
{
int nf = el.Faces();
for (int j = 0; j < nf; ++j)
{
FEElement* pen = EEL.Neighbor(i, j);
if ((pen == 0) || ((pen != 0) && (el.GetID() < pen->GetID())))
{
FACE& se = m_faceList[NF++];
int nn = el.GetFace(j, face);
se.ntype = nn;
for (int k = 0; k < nn; ++k)
{
se.node[k] = face[k];
}
// The facet is a surface facet if the element neighbor is null
se.nsurf = (pen == 0 ? 1 : 0);
}
}
}
}
return true;
}
// build the neighbor list
void FEFaceList::BuildNeighbors()
{
// build a node-face list
FENodeFaceList NFL;
NFL.Create(*this);
for (int i = 0; i < Faces(); ++i)
{
FACE& f = m_faceList[i];
f.nbr[0] = f.nbr[1] = f.nbr[2] = f.nbr[3] = -1;
if (f.nsurf == 1)
{
int fn = f.ntype;
for (int j = 0; j < fn; ++j)
{
int n0 = f.node[j];
int n1 = f.node[(j + 1) % fn];
int nval = NFL.Faces(n0);
std::vector<int> fl = NFL.FaceList(n0);
for (int k = 0; k < nval; ++k)
{
if (fl[k] != i)
{
FACE& fk = m_faceList[fl[k]];
if ((fk.nsurf == 1) && fk.HasEdge(n0, n1))
{
f.nbr[j] = fl[k];
break;
}
}
}
}
}
}
}
//=============================================================================
FENodeFaceList::FENodeFaceList()
{
}
int FENodeFaceList::Faces(int node) const
{
return (int)m_NFL[node].size();
}
const std::vector<int>& FENodeFaceList::FaceList(int node) const
{
return m_NFL[node];
}
bool FENodeFaceList::Create(FEFaceList& FL)
{
FEMesh& mesh = *FL.GetMesh();
int NN = mesh.Nodes();
m_NFL.resize(NN);
int NF = FL.Faces();
for (int i = 0; i < NF; ++i)
{
const FEFaceList::FACE& face = FL[i];
for (int j = 0; j < face.ntype; ++j)
{
m_NFL[face.node[j]].push_back(i);
}
}
return true;
}
//=============================================================================
FEElementFaceList::FEElementFaceList()
{
}
//NOTE: only works for hex elements
bool FEElementFaceList::Create(FEElementList& elemList, FEFaceList& faceList)
{
FEMesh& mesh = *faceList.GetMesh();
const int FTET[4][3] = {
{ 0, 1, 3},
{ 1, 2, 3},
{ 2, 0, 3},
{ 2, 1, 0}
};
const int FHEX[6][4] = {
{ 0, 1, 5, 4 },
{ 1, 2, 6, 5 },
{ 2, 3, 7, 6 },
{ 3, 0, 4, 7 },
{ 3, 2, 1, 0 },
{ 4, 5, 6, 7 }};
const int FPENTA[5][4] = {
{ 0, 1, 4, 3 },
{ 1, 2, 5, 4 },
{ 0, 3, 5, 2 },
{ 0, 2, 1, 1 },
{ 3, 4, 5, 5 }};
// build a node face table for FT to facilitate searching
int NN = mesh.Nodes();
vector<vector<int> > NFT; NFT.resize(NN);
for (int i = 0; i<faceList.Faces(); ++i)
{
const FEFaceList::FACE& f = faceList.Face(i);
NFT[f.node[0]].push_back(i);
NFT[f.node[1]].push_back(i);
NFT[f.node[2]].push_back(i);
if (f.ntype == 4) NFT[f.node[3]].push_back(i);
}
int NE = mesh.Elements();
m_EFL.resize(NE);
int i = 0;
for (FEElementList::iterator it = elemList.begin(); it != elemList.end(); ++it, ++i)
{
const FEElement& el = *it;
vector<int>& EFLi = m_EFL[i];
if ((el.Shape() == ET_TET4) || (el.Shape() == ET_TET5))
{
EFLi.resize(4);
for (int j = 0; j < 4; ++j)
{
int fj[3] = { el.m_node[FTET[j][0]], el.m_node[FTET[j][1]], el.m_node[FTET[j][2]] };
EFLi[j] = -1;
vector<int>& nfi = NFT[fj[0]];
for (int k = 0; k<(int)nfi.size(); ++k)
{
const FEFaceList::FACE& fk = faceList.Face(nfi[k]);
if (fk.IsEqual(fj))
{
EFLi[j] = nfi[k];
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_HEX8)
{
EFLi.resize(6);
for (int j = 0; j < 6; ++j)
{
int fj[4] = { el.m_node[FHEX[j][0]], el.m_node[FHEX[j][1]], el.m_node[FHEX[j][2]], el.m_node[FHEX[j][3]] };
EFLi[j] = -1;
vector<int>& nfi = NFT[fj[0]];
for (int k = 0; k<(int)nfi.size(); ++k)
{
const FEFaceList::FACE& fk = faceList.Face(nfi[k]);
if (fk.IsEqual(fj))
{
EFLi[j] = nfi[k];
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_PENTA6)
{
EFLi.resize(5);
for (int j = 0; j < 5; ++j)
{
int fj[4] = { el.m_node[FPENTA[j][0]], el.m_node[FPENTA[j][1]], el.m_node[FPENTA[j][2]], el.m_node[FPENTA[j][3]] };
EFLi[j] = -1;
vector<int>& nfi = NFT[fj[0]];
for (int k = 0; k < (int)nfi.size(); ++k)
{
const FEFaceList::FACE& fk = faceList.Face(nfi[k]);
if (fk.IsEqual(fj))
{
EFLi[j] = nfi[k];
break;
}
}
}
}
else if (el.Shape() == FE_Element_Shape::ET_QUAD4)
{
}
else if (el.Shape() == FE_Element_Shape::ET_TRI3)
{
}
else return false;
}
return true;
}
//=============================================================================
FEFaceEdgeList::FEFaceEdgeList()
{
}
bool FEFaceEdgeList::Create(FEFaceList& faceList, FEEdgeList& edgeList)
{
FENodeEdgeList NEL;
NEL.Create(edgeList);
int faces = faceList.Faces();
m_FEL.resize(faces);
for (int i = 0; i < faces; ++i)
{
vector<int>& edges = m_FEL[i];
edges.clear();
FEFaceList::FACE face = faceList.Face(i);
// find the corresponding edges
int n = face.ntype;
for (int j = 0; j < n; ++j)
{
int a = face.node[j];
int b = face.node[(j + 1) % n];
int edge = -1;
const std::vector<int>& a_edges = NEL.EdgeList(a);
for (int k = 0; k < a_edges.size(); ++k)
{
const FEEdgeList::EDGE& ek = edgeList[a_edges[k]];
if (((ek.node[0] == a) && (ek.node[1] == b)) ||
((ek.node[1] == a) && (ek.node[0] == b)))
{
edge = a_edges[k];
break;
}
}
assert(edge >= 0);
if (edge == -1) return false;
edges.push_back(edge);
}
}
return true;
}
int FEFaceEdgeList::Edges(int nface)
{
return (int)m_FEL[nface].size();
}
const std::vector<int>& FEFaceEdgeList::EdgeList(int nface) const
{
return m_FEL[nface];
}
//=============================================================================
FENodeEdgeList::FENodeEdgeList()
{
}
bool FENodeEdgeList::Create(FEEdgeList& edgeList)
{
m_NEL.clear();
FEMesh* mesh = edgeList.GetMesh();
int N = mesh->Nodes();
m_NEL.resize(N);
int NE = edgeList.Edges();
for (int i = 0; i < NE; ++i)
{
const FEEdgeList::EDGE& edge = edgeList[i];
m_NEL[edge.node[0]].push_back(i);
m_NEL[edge.node[1]].push_back(i);
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENewtonSolver.cpp | .cpp | 31,386 | 1,138 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENewtonSolver.h"
#include "FEModel.h"
#include "FEGlobalMatrix.h"
#include "LinearSolver.h"
#include "FELinearConstraintManager.h"
#include "FEAnalysis.h"
#include "FEPrescribedDOF.h"
#include "log.h"
#include "sys.h"
#include "FEDomain.h"
#include "DumpStream.h"
#include "FELinearSystem.h"
//-----------------------------------------------------------------------------
// define the parameter list
BEGIN_FECORE_CLASS(FENewtonSolver, FESolver)
BEGIN_PARAM_GROUP("line search");
ADD_PARAMETER(m_lineSearch->m_LStol , FE_RANGE_GREATER_OR_EQUAL(0.0), "lstol" );
ADD_PARAMETER(m_lineSearch->m_LSmin , FE_RANGE_GREATER_OR_EQUAL(0.0), "lsmin" );
ADD_PARAMETER(m_lineSearch->m_LSiter, FE_RANGE_GREATER_OR_EQUAL(0), "lsiter" );
ADD_PARAMETER(m_lineSearch->m_checkJacobians, "ls_check_jacobians");
END_PARAM_GROUP();
BEGIN_PARAM_GROUP("Nonlinear solver");
ADD_PARAMETER(m_maxref , FE_RANGE_GREATER_OR_EQUAL(0.0), "max_refs");
ADD_PARAMETER(m_bzero_diagonal , "check_zero_diagonal");
ADD_PARAMETER(m_zero_tol , "zero_diagonal_tol" );
ADD_PARAMETER(m_force_partition , "force_partition");
ADD_PARAMETER(m_breformtimestep , "reform_each_time_step");
ADD_PARAMETER(m_breformAugment , "reform_augment");
ADD_PARAMETER(m_bdivreform , "diverge_reform");
// ADD_PARAMETER(m_bdoreforms , "do_reforms" );
ADD_PARAMETER(m_Rmin, FE_RANGE_GREATER_OR_EQUAL(0.0), "min_residual");
ADD_PARAMETER(m_Rmax, FE_RANGE_GREATER_OR_EQUAL(0.0), "max_residual");
END_PARAM_GROUP();
ADD_PROPERTY(m_qnstrategy, "qn_method", FEProperty::Preferred)->SetDefaultType("BFGS").SetLongName("Quasi-Newton method");
ADD_PROPERTY(m_plinsolve, "linear_solver", FEProperty::Optional)->SetDefaultType("pardiso");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FENewtonSolver::FENewtonSolver(FEModel* pfem) : FESolver(pfem)
{
m_lineSearch = new FELineSearch(this);
m_ls = 0.0;
// default parameters
m_maxref = 15;
m_nref = 0;
m_neq = 0;
m_plinsolve = 0;
m_pK = 0;
m_Rtol = 0.001;
m_Etol = 0.01;
m_Rmin = 1.0e-20;
m_Rmax = 0; // not used if zero
m_qnstrategy = nullptr;
m_bforceReform = true;
m_bdivreform = true;
m_bdoreforms = true;
m_persistMatrix = true;
m_bzero_diagonal = false;
m_zero_tol = 0.0;
m_force_partition = 0;
m_breformtimestep = true;
m_breformAugment = false;
}
//-----------------------------------------------------------------------------
//! Set the default solution strategy
void FENewtonSolver::SetDefaultStrategy(QN_STRATEGY qn)
{
GetParameterList(); // This needs to be called to ensure that the parameter and property lists have been setup.
FEProperty& p = *FindProperty("qn_method");
switch (qn)
{
case QN_BFGS : p.SetDefaultType("BFGS"); break;
case QN_BROYDEN: p.SetDefaultType("Broyden"); break;
case QN_JFNK : p.SetDefaultType("JFNK"); break;
default:
assert(false);
}
}
//-----------------------------------------------------------------------------
void FENewtonSolver::SetSolutionStrategy(FENewtonStrategy* pstrategy)
{
if (m_qnstrategy) delete m_qnstrategy;
m_qnstrategy = pstrategy;
m_qnstrategy->SetNewtonSolver(this);
}
//-----------------------------------------------------------------------------
FENewtonSolver::~FENewtonSolver()
{
if (m_plinsolve) delete m_plinsolve;
m_plinsolve = nullptr;
Clean();
}
//-----------------------------------------------------------------------------
//! Add a degree of freedom list for convergence
void FENewtonSolver::AddSolutionVariable(FEDofList* dofs, int order, const char* szname, double tol)
{
// Add a variable
FESolutionVariable var(szname, dofs, order);
m_Var.push_back(var);
// Set convergence info on variable
ConvergenceInfo cinfo;
cinfo.nvar = (int) m_Var.size() - 1;
cinfo.tol = tol;
m_solutionNorm.push_back(cinfo);
}
//-----------------------------------------------------------------------------
// return line search
FELineSearch* FENewtonSolver::GetLineSearch()
{
return m_lineSearch;
}
//-----------------------------------------------------------------------------
FEGlobalMatrix* FENewtonSolver::GetStiffnessMatrix()
{
return m_pK;
}
//-----------------------------------------------------------------------------
//! Check the zero diagonal
void FENewtonSolver::CheckZeroDiagonal(bool bcheck, double ztol)
{
m_bzero_diagonal = bcheck;
m_zero_tol = fabs(ztol);
}
//-----------------------------------------------------------------------------
//! Reforms a stiffness matrix and factorizes it
bool FENewtonSolver::ReformStiffness()
{
feLog("Reforming stiffness matrix: reformation #%d\n\n", m_nref + 1);
// first, let's make sure we have not reached the max nr of reformations allowed
if (m_nref >= m_maxref) throw MaxStiffnessReformations();
FEModel& fem = *GetFEModel();
// recalculate the shape of the stiffness matrix if necessary
if (m_breshape)
{
// reshape the stiffness matrix
if (!CreateStiffness(m_niter == 0)) return false;
// reset reshape flag, except for contact
m_breshape = (((fem.SurfacePairConstraints() > 0) || (fem.NonlinearConstraints() > 0)) ? true : false);
}
// calculate the global stiffness matrix
bool bret = false;
{
TRACK_TIME(TimerID::Timer_Stiffness);
// zero the stiffness matrix
m_pK->Zero();
// Zero the rhs adjustment vector
zero(m_Fd);
// calculate the global stiffness matrix
bret = StiffnessMatrix();
// check for zero diagonals
if (m_bzero_diagonal)
{
// get the stiffness matrix
SparseMatrix& K = *m_pK;
vector<int> zd;
int neq = K.Rows();
for (int i=0; i<neq; ++i)
{
double di = fabs(K.diag(i));
if (di <= m_zero_tol)
{
zd.push_back(i);
}
}
if (zd.empty() == false) throw ZeroDiagonal(-1, -1);
}
}
// if the stiffness matrix was evaluated successfully,
// we factor it.
if (bret)
{
{
TRACK_TIME(TimerID::Timer_LinSol_Factor);
// factorize the stiffness matrix
if (m_plinsolve->Factor() == false)
{
throw FactorizationError();
}
}
// increase total nr of reformations
m_nref++;
m_ntotref++;
// reset bfgs update counter
m_qnstrategy->m_nups = 0;
}
return bret;
}
//-----------------------------------------------------------------------------
//! get the RHS
std::vector<double> FENewtonSolver::GetLoadVector()
{
return m_R0;
}
//-----------------------------------------------------------------------------
//! Get the total solution vector (for current Newton iteration)
void FENewtonSolver::GetSolutionVector(std::vector<double>& U)
{
U = m_Ui + m_ui;
}
//-----------------------------------------------------------------------------
//! Get the total solution vector
std::vector<double> FENewtonSolver::GetSolutionVector() const
{
return m_Ut;
}
//-----------------------------------------------------------------------------
//! Creates the global stiffness matrix
//! \todo Can we move this to the FEGlobalMatrix::Create function?
bool FENewtonSolver::CreateStiffness(bool breset)
{
{
TRACK_TIME(TimerID::Timer_Reform);
// clean up the solver
m_plinsolve->Destroy();
// clean up the stiffness matrix
m_pK->Clear();
// create the stiffness matrix
feLog("===== reforming stiffness matrix:\n");
if (m_pK->Create(GetFEModel(), m_neq, breset) == false)
{
feLogError("An error occured while building the stiffness matrix\n\n");
return false;
}
else
{
// output some information about the direct linear solver
int neq = m_pK->Rows();
int nnz = m_pK->NonZeroes();
feLog("\tNr of equations ........................... : %d\n", neq);
feLog("\tNr of nonzeroes in stiffness matrix ....... : %d\n", nnz);
int parts = m_plinsolve->Partitions();
if (parts > 1)
{
feLog("\tNr of partitions .......................... : %d\n", parts);
for (int i = 0; i < parts; ++i)
{
feLog("\t\tpartition %d ............................ : %d\n", i+1, m_plinsolve->GetPartitionSize(i));
}
}
}
}
// Do the preprocessing of the solver
{
if (!m_plinsolve->PreProcess())
{
feLogError("An error occurred during preprocessing of linear solver");
return false;
}
}
// done!
return true;
}
//-----------------------------------------------------------------------------
//! return the linear solver
LinearSolver* FENewtonSolver::GetLinearSolver()
{
return m_plinsolve;
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::AllocateLinearSystem()
{
// Now that we have determined the equation numbers we can continue
// with creating the stiffness matrix. First we select the linear solver
// The stiffness matrix is created in CreateStiffness
// Note that if a particular solver was requested in the input file
// then the solver might already be allocated. That's way we need to check it.
if (m_plinsolve == 0)
{
FEModel* fem = GetFEModel();
FECoreKernel& fecore = FECoreKernel::GetInstance();
m_plinsolve = fecore.CreateDefaultLinearSolver(fem);
if (m_plinsolve == 0)
{
feLogError("Unknown solver type selected\n");
return false;
}
}
if (m_part.empty() || (m_part.size() == 1))
{
// Set the partitioning of the global matrix
// This is only used for debugging block solvers for problems that
// usually don't generate a block structure
if (m_force_partition > 0)
{
m_part.resize(2);
m_part[0] = m_force_partition;
m_part[1] = m_neq - m_force_partition;
}
}
if (m_part.empty() == false)
{
m_plinsolve->SetPartitions(m_part);
}
feLogInfo("Selecting linear solver %s", m_plinsolve->GetTypeStr());
Matrix_Type mtype = MatrixType();
SparseMatrix* pS = m_qnstrategy->CreateSparseMatrix(mtype);
if ((pS == 0) && (m_msymm == REAL_SYMMETRIC))
{
// oh, oh, something went wrong. It's probably because the user requested a symmetric matrix for a
// solver that wants a non-symmetric. If so, let's force a non-symmetric format.
pS = m_qnstrategy->CreateSparseMatrix(REAL_UNSYMMETRIC);
if (pS)
{
// Problem solved! Let's inform the user.
m_msymm = REAL_UNSYMMETRIC;
feLogWarning("The matrix format was changed to non-symmetric since the selected linear solver does not support a symmetric format.");
}
}
// if the sparse matrix is still zero, we have a problem
if (pS == 0)
{
feLogError("The selected linear solver does not support the requested matrix format.\nPlease select a different linear solver.");
return false;
}
// clean up the stiffness matrix if we have one
if (m_pK) delete m_pK; m_pK = 0;
// Create the stiffness matrix.
// Note that this does not construct the stiffness matrix. This
// is done later in the CreateStiffness routine.
m_pK = new FEGlobalMatrix(pS);
if (m_pK == 0)
{
feLogError("Failed allocating stiffness matrix.");
return false;
}
return true;
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::Init()
{
// choose a solution strategy
if (m_qnstrategy == nullptr)
{
m_qnstrategy = fecore_new<FENewtonStrategy>("BFGS", GetFEModel());
assert(m_qnstrategy);
if (m_qnstrategy == nullptr) return false;
}
// make sure the QN strategy knows what solver it belongs to
m_qnstrategy->SetNewtonSolver(this);
// allocate data vectors
m_R0.assign(m_neq, 0);
m_R1.assign(m_neq, 0);
m_ui.assign(m_neq, 0);
m_Ui.assign(m_neq, 0);
m_Ut.assign(m_neq, 0);
m_Fd.assign(m_neq, 0);
// allocate storage for the sparse matrix that will hold the stiffness matrix data
// we let the linear solver allocate the correct type of matrix format
if (AllocateLinearSystem() == false) return false;
// Base class initialization and validation
if (FESolver::Init() == false) return false;
// set the create stiffness matrix flag
m_breshape = true;
return true;
}
//-----------------------------------------------------------------------------
//! Clean
void FENewtonSolver::Clean()
{
if (m_pK) delete m_pK; m_pK = nullptr;
if (m_qnstrategy) m_qnstrategy->Reset();
m_Var.clear();
}
//-----------------------------------------------------------------------------
void FENewtonSolver::Serialize(DumpStream& ar)
{
FESolver::Serialize(ar);
if (m_lineSearch) m_lineSearch->Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
ar << m_neq;
ar << m_maxref;
// ar << m_qndefault;
ar << m_qnstrategy;
}
else
{
ar >> m_neq;
ar >> m_maxref;
// ar >> m_qndefault;
ar >> m_qnstrategy;
// realloc data
if (m_neq > 0 && m_qnstrategy)
{
m_R0.assign(m_neq, 0);
m_R1.assign(m_neq, 0);
m_ui.assign(m_neq, 0);
m_Fd.assign(m_neq, 0);
}
}
}
//-----------------------------------------------------------------------------
//! This function mainly calls the Quasin routine
//! and deals with exceptions that require the immediate termination of
//! quasi-Newton iterations.
bool FENewtonSolver::SolveStep()
{
bool bret;
// initialize counters
m_niter = 0; // nr of iterations
m_nrhs = 0; // nr of RHS evaluations
m_nref = 0; // nr of stiffness reformations
m_ntotref = 0;
m_naug = 0; // nr of augmentations
try
{
// let's try to call Quasin
bret = Quasin();
}
catch (FEException e)
{
if (e.level() == FEException::Error)
feLogError("%s", e.what());
else
feLogWarning("%s", e.what());
return false;
}
if (bret)
{
// print a convergence summary to the felog file
feLog("\nconvergence summary\n");
feLog(" number of iterations : %d\n", m_niter);
feLog(" number of reformations : %d\n", m_nref);
}
// if we don't want to hold on to the stiffness matrix, let's clean it up
if (m_persistMatrix == false)
{
// clean up the solver
m_plinsolve->Destroy();
// clean up the stiffness matrix
m_pK->Clear();
// make sure we recreate it in the next time step
m_breshape = true;
}
return bret;
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::Quasin()
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
// initialize counters
m_niter = 0; // nr of iterations
m_nrhs = 0; // nr of RHS evaluations
m_nref = 0; // nr of stiffness reformations
m_ntotref = 0;
// TODO: Maybe call FEQuasiNewtonStrategy::Init or something?
m_qnstrategy->m_nups = 0; // nr of stiffness updates between reformations
// do the presolve update
PrepStep();
// Initialize QN method
QNInit();
// Start the quasi-Newton loop
bool bconv = false;
do
{
feLog(" %d\n", m_niter + 1);
// solve the equations (returns line search; solution stored in m_ui)
double ls = QNSolve();
// update solution vector
for (int i = 0; i<m_neq; ++i) m_Ui[i] += ls*m_ui[i];
feLog(" Nonlinear solution status: time= %lg\n", tp.currentTime);
feLog("\tstiffness updates = %d\n", m_qnstrategy->m_nups);
feLog("\tright hand side evaluations = %d\n", m_nrhs);
feLog("\tstiffness matrix reformations = %d\n", m_nref);
if (m_lineSearch->m_LStol > 0) feLog("\tstep from line search = %lf\n", ls);
// check convergence
bconv = CheckConvergence(m_niter, m_ui, ls);
// if we did not converge, do QN update
if (bconv == false)
{
if (ls < m_lineSearch->m_LSmin)
{
// check for zero linestep size
feLogWarning("Zero linestep size. Stiffness matrix will now be reformed");
QNForceReform(true);
}
else if ((m_energyNorm.norm > m_energyNorm.maxnorm) && m_bdivreform)
{
// check for diverging
feLogWarning("Problem is diverging. Stiffness matrix will now be reformed");
m_energyNorm.maxnorm = m_energyNorm.norm;
m_energyNorm.norm0 = m_energyNorm.norm;
m_residuNorm.norm0 = m_residuNorm.norm;
for (int i = 0; i < m_solutionNorm.size(); ++i)
{
ConvergenceInfo& ci = m_solutionNorm[i];
ci.norm0 = ci.normi;
}
QNForceReform(true);
}
// do the QN update (this may also do a stiffness reformation if necessary)
bool bret = QNUpdate();
// Oh, oh, something went wrong
if (bret == false) break;
}
else if (m_baugment)
{
// do augmentations
bconv = DoAugmentations();
}
// increase iteration number
m_niter++;
// do minor iterations callbacks
fem.DoCallback(CB_MINOR_ITERS);
}
while (!bconv);
// if converged we update the total solution
if (bconv)
{
m_Ut += m_Ui;
}
return bconv;
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::CheckConvergence(int niter, const vector<double>& ui, double ls)
{
int vars = (int)m_solutionNorm.size();
// If this is the first iteration, calculate initial convergence norms
if (niter == 0)
{
// initial residual norm
m_residuNorm.norm0 = m_R0*m_R0;
// initial energy norm
m_energyNorm.norm0 = fabs(m_ui*m_R0); // why is line search not taken into account here?
m_energyNorm.maxnorm = m_energyNorm.norm0;
// calculate initial solution norms
for (int i = 0; i < vars; ++i)
{
ConvergenceInfo& c = m_solutionNorm[i];
FESolutionVariable& var = m_Var[c.nvar];
double d2 = ExtractSolutionNorm(ui, *var.m_dofs);
c.norm0 = d2; // why no linesearch?
}
}
// calculate current norms
m_residuNorm.norm = m_R1*m_R1;
m_energyNorm.norm = fabs(ls*(ui*m_R1));
for (int i = 0; i < vars; ++i)
{
ConvergenceInfo& c = m_solutionNorm[i];
FESolutionVariable& var = m_Var[c.nvar];
double d2 = ExtractSolutionNorm(ui, *var.m_dofs);
double D2 = ExtractSolutionNorm(m_Ui, *var.m_dofs);
c.normi = (d2)*(ls*ls);
c.norm = D2;
}
// check convergence
bool bconv = true;
if ((m_Rtol > 0) && (m_residuNorm.norm > m_Rtol*m_residuNorm.norm0)) bconv = false;
if ((m_Etol > 0) && (m_energyNorm.norm > m_Etol*m_energyNorm.norm0)) bconv = false;
for (int i = 0; i < vars; ++i)
{
ConvergenceInfo& c = m_solutionNorm[i];
if (c.IsConverged() == false) bconv = false;
}
// print convergence information
feLog("\tconvergence norms : INITIAL CURRENT REQUIRED\n");
feLog("\t residual %15le %15le %15le \n", m_residuNorm.norm0, m_residuNorm.norm, m_Rtol*m_residuNorm.norm0);
feLog("\t energy %15le %15le %15le \n", m_energyNorm.norm0, m_energyNorm.norm, m_Etol*m_energyNorm.norm0);
for (int i = 0; i < vars; ++i)
{
ConvergenceInfo& c = m_solutionNorm[i];
FESolutionVariable& var = m_Var[c.nvar];
const char* varName = var.m_szname;
// print the values of this field variable only
feLog("\t %-17s%15le %15le %15le \n", varName, c.norm0, c.normi, (c.tol*c.tol)*c.norm);
}
// see if we may have a small residual
if ((bconv == false) && (m_residuNorm.norm < m_Rmin))
{
// check for almost zero-residual on the first iteration
// this might be an indication that there is no load on the system
feLogWarning("No load acting on the system.");
bconv = true;
}
// see if we have exceeded the max residual
if ((bconv == false) && (m_Rmax > 0) && (m_residuNorm.norm >= m_Rmax))
{
// doesn't look like we're getting anywhere, so let's retry the time step
throw MaxResidualError();
}
return bconv;
}
//-----------------------------------------------------------------------------
//! Solve the linear system of equations.
//! x is the solution vector
//! R is the right-hand-side vector
void FENewtonSolver::SolveLinearSystem(vector<double>& x, vector<double>& R)
{
// solve the equations
if (m_plinsolve->BackSolve(x, R) == false)
throw LinearSolverFailed();
}
//-----------------------------------------------------------------------------
//! rewind solver
//! This is called when the time step failed.
void FENewtonSolver::Rewind()
{
// reset the forceReform flag so that we reform the stiffness matrix
m_bforceReform = true;
}
//-----------------------------------------------------------------------------
void FENewtonSolver::PrepStep()
{
FEModel& fem = *GetFEModel();
const FETimeInfo& tp = fem.GetTime();
// zero total DOFs
zero(m_Ui);
// apply prescribed velocities
// we save the prescribed velocity increments in the ui vector
vector<double>& ui = m_ui;
zero(ui);
int nbc = fem.BoundaryConditions();
for (int i = 0; i<nbc; ++i)
{
FEBoundaryCondition& dc = *fem.BoundaryCondition(i);
if (dc.IsActive()) dc.PrepStep(ui);
}
// intialize material point data
// NOTE: do this before the model is updated
// TODO: does it matter if the stresses are updated before
// the material point data is initialized
// update domain data
FEMesh& mesh = fem.GetMesh();
for (int i = 0; i<mesh.Domains(); ++i) mesh.Domain(i).PreSolveUpdate(tp);
// update model
fem.Update();
}
//-----------------------------------------------------------------------------
//! call this at the start of the quasi-newton loop (after PrepStep)
bool FENewtonSolver::QNInit()
{
// see if we reform at the start of every time step
bool breform = (m_breformtimestep || (m_qnstrategy->m_maxups == 0));
// if the force reform flag was set, we force a reform
// (This will be the case for the first time this is called, or when the previous time step failed)
if (m_bforceReform)
{
breform = true;
m_bforceReform = false;
}
m_qnstrategy->PreSolveUpdate();
// do the reform
// NOTE: It is important for JFNK that the matrix is reformed before the
// residual is evaluated, so do not switch these two calculations!
if (breform)
{
// do the first stiffness formation
if (m_qnstrategy->ReformStiffness() == false) return false;
}
// calculate initial residual
if (m_qnstrategy->Residual(m_R0, true) == false) return false;
// add the contribution from prescribed dofs
m_R0 += m_Fd;
// TODO: I can check here if the residual is zero.
// If it is than there is probably no force acting on the system
// if (m_R0*m_R0 < eps) bconv = true;
// double r0 = m_R0*m_R0;
// do callback (we do it here since we want the RHS to be formed as well)
GetFEModel()->DoCallback(CB_MATRIX_REFORM);
return true;
}
//-----------------------------------------------------------------------------
//! solve the equations
void FENewtonSolver::SolveEquations(std::vector<double>& u, std::vector<double>& R)
{
if (m_plinsolve->IsIterative())
{
// for the first iteration, we pass the solution of the last time step
if (m_niter == 0)
u = m_Ui;
else
u = m_up;
}
else zero(u);
GetFEModel()->DoCallback(CB_PRE_MATRIX_SOLVE);
// check for nans in the residual
double r2 = R * R;
if (ISNAN(r2))
{
FENodalDofInfo info;
FEMesh& mesh = GetFEModel()->GetMesh();
for (int i = 0; i < u.size(); ++i)
{
if (ISNAN(R[i]))
{
info = GetDOFInfoFromEquation(i);
break;
}
}
throw NANInResidualDetected(info);
}
// call the qn strategy to actually solve the equations
{
TRACK_TIME(TimerID::Timer_LinSol_Backsolve);
m_qnstrategy->SolveEquations(u, R);
}
// check for nans
double u2 = u*u;
if (ISNAN(u2))
{
FENodalDofInfo info;
FEMesh& mesh = GetFEModel()->GetMesh();
for (int i = 0; i < u.size(); ++i)
{
if (ISNAN(u[i]))
{
info = GetDOFInfoFromEquation(i);
break;
}
}
throw (NANInSolutionDetected(info));
}
// store the last solution for iterative solvers
if (m_plinsolve->IsIterative()) m_up = u;
}
//-----------------------------------------------------------------------------
double FENewtonSolver::DoLineSearch()
{
// the geometry is also updated in the line search
m_ls = 1.0;
if (m_lineSearch && (m_lineSearch->m_LStol > 0.0)) m_ls = m_lineSearch->DoLineSearch();
else
{
// Update geometry
Update(m_ui);
// calculate residual at this point
m_qnstrategy->Residual(m_R1, false);
}
// return line search
return m_ls;
}
//-----------------------------------------------------------------------------
double FENewtonSolver::QNSolve()
{
// solve linear system of equations
SolveEquations(m_ui, m_R0);
// perform a linesearch
return DoLineSearch();
}
//-----------------------------------------------------------------------------
void FENewtonSolver::QNForceReform(bool b)
{
m_bforceReform = b;
}
//-----------------------------------------------------------------------------
//! Do a QN update
bool FENewtonSolver::QNUpdate()
{
// see if the force reform flag was set
bool breform = m_bforceReform; m_bforceReform = false;
// do a QN update
if (breform == false)
{
TRACK_TIME(TimerID::Timer_QNUpdate);
if (m_qnstrategy->Update(m_ls, m_ui, m_R0, m_R1) == false)
{
// the qn update failed. Force matrix reformations
breform = true;
}
}
// zero displacement increments
// we must set this to zero before the reformation
// because we assume that the prescribed displacements are stored
// in the m_ui vector.
zero(m_ui);
// reform stiffness matrices if necessary
if (breform && m_bdoreforms)
{
// reform the matrix
if (m_qnstrategy->ReformStiffness() == false) return false;
}
// copy last calculated residual
m_R0 = m_R1;
if (breform && m_bdoreforms) GetFEModel()->DoCallback(CB_MATRIX_REFORM);
return true;
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::DoAugmentations()
{
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = fem.GetCurrentStep();
// we have converged, so let's see if the augmentations have converged as well
feLog("\n........................ augmentation # %d\n", m_naug + 1);
// do callback
fem.DoCallback(CB_AUGMENT);
// do the augmentations
bool bconv = Augment();
// update counter
++m_naug;
// we reset the reformations counter
m_nref = 0;
// If we havn't converged we prepare for the next iteration
if (!bconv)
{
// Since the Lagrange multipliers have changed, we can't just copy
// the last residual but have to recalculate the residual
// we also recalculate the stresses in case we are doing augmentations
// for incompressible materials
UpdateModel();
{
// TODO: Why is this not calling strategy->Residual?
TRACK_TIME(TimerID::Timer_Residual);
Residual(m_R0);
}
m_qnstrategy->PreSolveUpdate();
// reform the matrix if we are using full-Newton or
// force reform after augmentations
if ((m_qnstrategy->m_maxups == 0) || (m_breformAugment))
{
// TODO: Note sure how to handle a false return from ReformStiffness.
// I think this is pretty rare so I'm ignoring it for now.
// if (ReformStiffness() == false) break;
m_qnstrategy->ReformStiffness();
}
}
return bconv;
}
//! Update the state of the model
void FENewtonSolver::Update(std::vector<double>& ui)
{
{
TRACK_TIME(TimerID::Timer_Update);
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// update nodes
vector<double> U(m_Ut.size());
for (size_t i = 0; i < m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
// scatter solution to nodes
for (int i = 0; i < m_solutionNorm.size(); ++i)
{
ConvergenceInfo& ci = m_solutionNorm[i];
FESolutionVariable& var = m_Var[ci.nvar];
scatter(U, mesh, *var.m_dofs);
}
// enforce the linear constraints
// TODO: do we really have to do this? Shouldn't the algorithm
// already guarantee that the linear constraints are satisfied?
FELinearConstraintManager& LCM = fem.GetLinearConstraintManager();
if (LCM.LinearConstraints() > 0)
{
LCM.Update();
}
// make sure the prescribed velocities are fullfilled
int nbc = fem.BoundaryConditions();
for (int i = 0; i < nbc; ++i)
{
FEBoundaryCondition& dc = *fem.BoundaryCondition(i);
if (dc.IsActive()) dc.Update();
}
// update element degrees of freedom
int ndom = mesh.Domains();
for (int i = 0; i < ndom; ++i)
{
FEDomain& dom = mesh.Domain(i);
int NE = dom.Elements();
for (int j = 0; j < NE; ++j)
{
FEElement& el = dom.ElementRef(j);
if (el.m_lm >= 0) el.m_val = U[el.m_lm];
}
}
}
// update model state
GetFEModel()->Update();
}
//-----------------------------------------------------------------------------
//! Updates the current state of the model
//! NOTE: The ui vector also contains prescribed displacement increments. Also note that this
//! only works for a limited set of FEBio features (no rigid bodies or shells!).
void FENewtonSolver::Update2(const vector<double>& ui)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// total displacements
vector<double> U(m_Ut.size());
for (size_t i = 0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
// scatter solution to nodes
for (int i = 0; i < m_solutionNorm.size(); ++i)
{
ConvergenceInfo& ci = m_solutionNorm[i];
FESolutionVariable& var = m_Var[ci.nvar];
scatter(U, mesh, *var.m_dofs);
}
// Update the prescribed nodes
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.m_rid == -1)
{
vec3d dv(0, 0, 0);
for (int j = 0; j < node.m_ID.size(); ++j)
{
int nj = -node.m_ID[j] - 2; if (nj >= 0) node.set(j, node.get(j) + ui[nj]);
}
}
}
// update element degrees of freedom
int ndom = mesh.Domains();
for (int i = 0; i<ndom; ++i)
{
FEDomain& dom = mesh.Domain(i);
int NE = dom.Elements();
for (int j = 0; j < NE; ++j)
{
FEElement& el = dom.ElementRef(j);
if (el.m_lm >= 0) el.m_val = U[el.m_lm];
}
}
// update model state
GetFEModel()->Update();
}
//-----------------------------------------------------------------------------
//! Update the model
void FENewtonSolver::UpdateModel()
{
FEModel& fem = *GetFEModel();
fem.Update();
}
//-----------------------------------------------------------------------------
//! calculates the global stiffness matrix (needs to be overwritten by derived classes)
bool FENewtonSolver::StiffnessMatrix()
{
// setup the linear system
FELinearSystem LS(GetFEModel(), *m_pK, m_Fd, m_ui, (m_msymm == REAL_SYMMETRIC));
// build the stiffness matrix
return StiffnessMatrix(LS);
}
//-----------------------------------------------------------------------------
bool FENewtonSolver::StiffnessMatrix(FELinearSystem& LS)
{
assert(false);
return false;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FELogData.h | .h | 1,460 | 36 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "fecore_api.h"
// Super class for log data classes.
class FECORE_API FELogData : public FECoreBase
{
public:
FELogData(FEModel* fem);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEException.cpp | .cpp | 5,899 | 218 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEException.h"
#include "FESolver.h" // for FENodalDofInfo
#include <stdarg.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FEException::FEException(const char* msg, int level)
{
if (msg) m_what = msg;
m_level = level;
}
FEException::~FEException()
{
}
const char* FEException::what()
{
return m_what.c_str();
}
void FEException::what(const char* msg, ...)
{
// get a pointer to the argument list
va_list args;
// make the message
char sztxt[1024] = { 0 };
va_start(args, msg);
vsnprintf(sztxt, sizeof(sztxt), msg, args);
va_end(args);
m_what = sztxt;
}
//-----------------------------------------------------------------------------
int FEException::level() const
{
return m_level;
}
//-----------------------------------------------------------------------------
//! \todo implement error handling
ZeroDiagonal::ZeroDiagonal(int node, int ndof)
{
what("Zero diagonal detected. Aborting run.");
}
/*
ZeroDiagonal::ZeroDiagonal(vector<int>& l, FEM& fem)
{
// let's find what dof this equation belonges to
FEMesh& m = fem.GetMesh();
int nz = (int) l.size();
int i, j, id;
for (i=0; i<fem.m_nrb; ++i)
{
FERigidBody& rb = fem.m_RB[i];
for (j=0; j<6; ++j)
{
id = rb.m_LM[j];
if (id < -1) id = -id-2;
for (int k=0; k<nz; ++k)
{
int n = l[k];
if (id == n)
{
felog.printf("Zero diagonal on row %d.\nThis dof belongs to rigid body %d (dof %d)\n", n, i+1, j+1);
}
}
}
}
vector<EQUATION> EQT(fem.m_neq);
for (i=0; i<fem.m_neq; ++i)
{
EQUATION& q = EQT[i];
q.node = -1;
q.dof = -1;
}
for (i=0; i<m.Nodes(); ++i)
{
FENode& node = m.Node(i);
for (j=0; j<MAX_NDOFS; ++j)
{
id = node.m_ID[j];
if (id < -1) id = -id-2;
if (id != -1)
{
assert(id < fem.m_neq);
EQT[id].node = i;
EQT[id].dof = j;
}
}
}
const int NMAX = 128;
int N = (nz < NMAX? nz : NMAX), n;
for (i=0; i<N; ++i)
{
n = l[i];
EQUATION& q = EQT[n];
felog.printf("Zero diagonal on row %d. (node %d, dof %d)\n", n+1, q.node+1, q.dof+1);
}
if (nz > NMAX) felog.printf("(%d out of %d printed)\n", NMAX, nz);
// print error message
sprintf(m_szerr, "FATAL ERROR: %d zero(s) found on diagonal.", l.size());
}
*/
//=============================================================================
bool NegativeJacobian::m_bthrown = false;
int NegativeJacobian::m_maxout = 0; // output off by default
int NegativeJacobian::m_count = 0;
//-----------------------------------------------------------------------------
NegativeJacobian::NegativeJacobian(int iel, int ng, double vol, FEElement* pe)
{
m_iel = iel;
m_ng = ng;
m_vol = vol;
m_pel = pe;
m_bthrown = true;
what("Negative jacobian was detected at element %d at gauss point %d\njacobian = %lg\n", m_iel, m_ng + 1, m_vol);
}
//-----------------------------------------------------------------------------
bool NegativeJacobian::DoOutput()
{
m_count++; // we do this here because this function is called from critical sections.
bool b = (m_maxout < 0) || (m_count <= m_maxout);
return b;
}
//-----------------------------------------------------------------------------
void NegativeJacobian::clearFlag()
{
m_bthrown = false;
}
//-----------------------------------------------------------------------------
bool NegativeJacobian::IsThrown()
{
return m_bthrown;
}
int NegativeJacobian::Count()
{
return m_count;
}
void NegativeJacobian::ResetCount()
{
m_count = 0;
}
//-----------------------------------------------------------------------------
NANInResidualDetected::NANInResidualDetected(const FENodalDofInfo& ndi)
{
what("NAN detected in residual vector at index %d.\nNode id = %d, dof = %d ('%s')", ndi.m_eq, ndi.m_node, ndi.m_dof, ndi.szdof);
}
//-----------------------------------------------------------------------------
NANInSolutionDetected::NANInSolutionDetected(const FENodalDofInfo& ndi)
{
what("NAN detected in solution vector at index %d.\nNode id = %d, dof = %d ('%s')", ndi.m_eq, ndi.m_node, ndi.m_dof, ndi.szdof);
}
//-----------------------------------------------------------------------------
FEMultiScaleException::FEMultiScaleException(int eid, int gpt)
{
what("The RVE problem has failed at element %d, gauss point %d.\nAborting macro run.", eid, gpt + 1);
}
//-----------------------------------------------------------------------------
ConcentrationChangeDetected::ConcentrationChangeDetected(const FENodalDofInfo& ndi)
{
what("Sudden concentration change detected.\n");
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEFunction1D.h | .h | 6,649 | 235 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FECoreBase.h"
#include "MathObject.h"
//-----------------------------------------------------------------------------
class FEModel;
class DumpStream;
//-----------------------------------------------------------------------------
// Class that represents a 1D function
// Derived classes need to implement:
// - value(double): This evaluates the function at a particular point
// - copy() : Create a copy of the class
// - derive(double) : Calculate the derivative. This is optional, but allows implementation of more efficient algorithm, since default implements forward difference
//
class FECORE_API FEFunction1D : public FECoreBase
{
FECORE_SUPER_CLASS(FEFUNCTION1D_ID)
FECORE_BASE_CLASS(FEFunction1D);
public:
FEFunction1D(FEModel* pfem);
// serialization
void Serialize(DumpStream& ar);
// this class requires a copy member
virtual FEFunction1D* copy() = 0;
// evaluate the function at x
// must be defined by derived classes
virtual double value(double x) const = 0;
// value of first derivative of function at x
// can be overridden by derived classes.
// default implementation is a forward-difference
virtual double derive(double x) const;
virtual double deriv2(double x) const = 0;
// value of first definite integral of funciton from a to b
// can be overridden by derived classes.
// default implementation is trapezoidal rule
virtual double integrate(double a, double b) const;
virtual void Clear() {}
// invert function
virtual bool invert(const double f0, double &x);
};
//-----------------------------------------------------------------------------
// A constant function
class FECORE_API FEConstFunction : public FEFunction1D
{
public:
FEConstFunction(FEModel* fem) : FEFunction1D(fem), m_value(0.0) {}
FEFunction1D* copy() override { return new FEConstFunction(GetFEModel(), m_value); }
double value(double t) const override { return m_value; }
double derive(double t) const override { return 0.0; }
double deriv2(double t) const override { return 0.0; }
protected:
FEConstFunction(FEModel* fem, double val) : FEFunction1D(fem), m_value(val) {}
private:
double m_value;
DECLARE_FECORE_CLASS();
};
// A scale function
class FECORE_API FEScaleFunction : public FEFunction1D
{
public:
FEScaleFunction(FEModel* fem) : FEFunction1D(fem), m_scale(1.0) {}
FEScaleFunction(FEModel* fem, double s) : FEFunction1D(fem), m_scale(s) {}
FEFunction1D* copy() override { return new FEScaleFunction(GetFEModel(), m_scale); }
double value(double t) const override
{
return m_scale * t;
}
double derive(double t) const override
{
return m_scale;
}
double deriv2(double t) const override
{
return 0;
}
private:
double m_scale;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// A linear function
class FECORE_API FELinearFunction : public FEFunction1D
{
public:
FELinearFunction(FEModel* fem) : FEFunction1D(fem), m_slope(0.0), m_intercept(0.0) {}
FELinearFunction(FEModel* fem, double m, double y0) : FEFunction1D(fem), m_slope(m), m_intercept(y0) {}
FEFunction1D* copy() override { return new FELinearFunction(GetFEModel(), m_slope, m_intercept); }
double value(double t) const override
{
return m_slope*t + m_intercept;
}
double derive(double t) const override
{
return m_slope;
}
double deriv2(double t) const override
{
return 0;
}
private:
double m_slope;
double m_intercept;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// A step function
class FECORE_API FEStepFunction : public FEFunction1D
{
public:
FEStepFunction(FEModel* fem) : FEFunction1D(fem), m_x0(0.0), m_leftVal(0.0), m_rightVal(1.0) {}
FEStepFunction(FEModel* fem, double x0, double lv, double rv) : FEFunction1D(fem), m_x0(x0), m_leftVal(lv), m_rightVal(rv) {}
FEFunction1D* copy() override { return new FEStepFunction(GetFEModel(), m_x0, m_leftVal, m_rightVal); }
double value(double t) const override
{
return (t < m_x0 ? m_leftVal : m_rightVal);
}
double derive(double t) const override
{
return 0.0;
}
double deriv2(double t) const override
{
return 0.0;
}
// invert function has no unique solution
bool invert(const double f0, double &x) override { return false; }
private:
double m_x0;
double m_leftVal;
double m_rightVal;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
//! function defined via math expression
class FECORE_API FEMathFunction : public FEFunction1D
{
public:
FEMathFunction(FEModel* fem);
bool Init() override;
void Serialize(DumpStream& ar) override;
FEFunction1D* copy() override;
double value(double t) const override;
double derive(double t) const override;
double deriv2(double t) const override;
void SetMathString(const std::string& s);
private:
void evalParams(std::vector<double>& val, double t) const;
bool BuildMathExpressions();
private:
std::string m_s;
int m_ix; // index of independent variable
std::vector<FEParamValue> m_var; // list of model parameters that are used as variables in expression.
MSimpleExpression m_exp;
MSimpleExpression m_dexp;
MSimpleExpression m_d2exp;
DECLARE_FECORE_CLASS();
};
| Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.