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/FELogElemMath.cpp | .cpp | 2,174 | 71 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FELogElemMath.h"
#include "MObjBuilder.h"
FELogElemMath::FELogElemMath(FEModel* pfem) : FELogElemData(pfem)
{
}
FELogElemMath::~FELogElemMath()
{
Clear();
}
void FELogElemMath::Clear()
{
for (FELogElemData* d : m_data) delete d;
m_data.clear();
}
double FELogElemMath::value(FEElement& el)
{
std::vector<double> val(m_data.size());
for (size_t i = 0; i < m_data.size(); ++i) val[i] = m_data[i]->value(el);
return m.value_s(val);
}
bool FELogElemMath::SetExpression(const std::string& smath)
{
Clear();
MObjBuilder o;
o.setAutoVars(true);
if (!o.Create(&m, smath, false)) return false;
int nvar = m.Variables();
for (int i = 0; i < nvar; ++i)
{
MVariable& var = *m.Variable(i);
string varName = var.Name();
FELogElemData* pd = fecore_new<FELogElemData>(varName.c_str(), GetFEModel());
if (pd == nullptr) return false;
m_data.push_back(pd);
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEPrescribedDOF.cpp | .cpp | 4,161 | 136 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEPrescribedDOF.h"
#include "FENodeSet.h"
#include "DumpStream.h"
#include "FEMesh.h"
#include "log.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEPrescribedDOF, FEPrescribedNodeSet)
ADD_PARAMETER(m_scale, "scale");
ADD_PARAMETER(m_dof , "dof", 0, "$(dof_list)");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEPrescribedDOF::FEPrescribedDOF(FEModel* pfem) : FEPrescribedNodeSet(pfem)
{
m_scale = 0.0;
m_dof = -1;
}
//-----------------------------------------------------------------------------
FEPrescribedDOF::FEPrescribedDOF(FEModel* pfem, int dof, FENodeSet* nset) : FEPrescribedNodeSet(pfem)
{
m_scale = 0.0;
SetNodeSet(nset);
SetDOF(dof);
}
//-----------------------------------------------------------------------------
void FEPrescribedDOF::SetDOF(int ndof)
{
m_dof = ndof;
}
//-----------------------------------------------------------------------------
bool FEPrescribedDOF::SetDOF(const char* szdof)
{
int ndof = GetDOFIndex(szdof);
assert(ndof >= 0);
if (ndof < 0) return false;
SetDOF(ndof);
return true;
}
//-----------------------------------------------------------------------------
// Sets the displacement scale factor. An optional load curve index can be given
// of the load curve that will control the scale factor.
FEPrescribedDOF& FEPrescribedDOF::SetScale(double s, int lc)
{
m_scale = s;
if (lc >= 0)
{
AttachLoadController(&m_scale, lc);
}
return *this;
}
//-----------------------------------------------------------------------------
bool FEPrescribedDOF::Init()
{
// set the dof first before calling base class
if (m_dof < 0) return false;
SetDOFList(m_dof);
// don't forget to call the base class
if (FEPrescribedNodeSet::Init() == false) return false;
// make sure this is not a rigid node
FEMesh& mesh = GetMesh();
int NN = mesh.Nodes();
const FENodeSet& nset = *GetNodeSet();
for (size_t i = 0; i<nset.Size(); ++i)
{
int nid = nset[i];
if ((nid < 0) || (nid >= NN)) return false;
if (mesh.Node(nid).m_rid != -1)
{
feLogError("Rigid nodes cannot be prescribed.");
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
void FEPrescribedDOF::GetNodalValues(int n, std::vector<double>& val)
{
assert(val.size() == 1);
const FENodeSet& nset = *GetNodeSet();
int nid = nset[n];
const FENode& node = *nset.Node(n);
FEMaterialPoint mp;
mp.m_r0 = node.m_r0;
mp.m_index = n;
val[0] = m_scale(mp);
}
//-----------------------------------------------------------------------------
void FEPrescribedDOF::CopyFrom(FEBoundaryCondition* pbc)
{
FEPrescribedDOF* ps = dynamic_cast<FEPrescribedDOF*>(pbc); assert(ps);
m_scale = ps->m_scale;
CopyParameterListState(ps->GetParameterList());
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECoreBase.cpp | .cpp | 20,049 | 819 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FECoreBase.h"
#include "DumpStream.h"
#include "FECoreKernel.h"
#include "FEModelParam.h"
#include "log.h"
#include <sstream>
//-----------------------------------------------------------------------------
//! The constructor takes one argument, namely the SUPER_CLASS_ID which
//! defines the type of class this is. (The SUPER_CLASS_ID was introduced to
//! eliminate a lot of akward dynamic_casts.)
FECoreBase::FECoreBase(FEModel* fem) : m_fem(fem)
{
m_nID = -1;
m_pParent = 0;
m_fac = nullptr;
}
//-----------------------------------------------------------------------------
//! destructor does nothing for now.
FECoreBase::~FECoreBase()
{
ClearProperties();
}
//-----------------------------------------------------------------------------
//! return the super class id
SUPER_CLASS_ID FECoreBase::GetSuperClassID() { return (m_fac ? m_fac->GetSuperClassID() : FEINVALID_ID); }
//-----------------------------------------------------------------------------
//! return a (unique) string describing the type of this class
//! This string is used in object creation
const char* FECoreBase::GetTypeStr() { return (m_fac ? m_fac->GetTypeStr() : nullptr); }
//-----------------------------------------------------------------------------
//! Set the factory class
void FECoreBase::SetFactoryClass(const FECoreFactory* fac)
{
m_fac = fac;
}
//-----------------------------------------------------------------------------
const FECoreFactory* FECoreBase::GetFactoryClass() const
{
return m_fac;
}
//-----------------------------------------------------------------------------
//! Sets the user defined name of the component
void FECoreBase::SetName(const std::string& name)
{
m_name = name;
}
//-----------------------------------------------------------------------------
//! Return the name
const std::string& FECoreBase::GetName() const
{
return m_name;
}
//-----------------------------------------------------------------------------
//! Get the parent of this object (zero if none)
FECoreBase* FECoreBase::GetParent()
{
return m_pParent;
}
//-----------------------------------------------------------------------------
FECoreBase* FECoreBase::GetAncestor()
{
FECoreBase* mp = GetParent();
return (mp ? mp->GetAncestor() : this);
}
//-----------------------------------------------------------------------------
//! Set the parent of this class
void FECoreBase::SetParent(FECoreBase* parent) { m_pParent = parent; }
//-----------------------------------------------------------------------------
//! return the component ID
int FECoreBase::GetID() const { return m_nID; }
//-----------------------------------------------------------------------------
//! set the component ID
void FECoreBase::SetID(int nid) { m_nID = nid; }
//-----------------------------------------------------------------------------
//! Get the FE model
FEModel* FECoreBase::GetFEModel() const { return m_fem; }
//-----------------------------------------------------------------------------
void FECoreBase::SetFEModel(FEModel* fem) { m_fem = fem; }
//-----------------------------------------------------------------------------
void setParamValue(FEParam& pi, const std::string& val)
{
if (val.empty()) return;
const char* sz = val.c_str();
switch (pi.type())
{
case FE_PARAM_INT: pi.value<int>() = atoi(sz); break;
case FE_PARAM_BOOL: pi.value<bool>() = (atoi(sz) == 0 ? false : true); break;
case FE_PARAM_DOUBLE: pi.value<double>() = atof(sz); break;
default:
assert(false);
}
}
//-----------------------------------------------------------------------------
// set parameters through a class descriptor
bool FECoreBase::SetParameters(const FEClassDescriptor& cd)
{
const FEClassDescriptor::ClassVariable* root = cd.Root();
return SetParameters(*cd.Root());
}
//-----------------------------------------------------------------------------
// set parameters through a class descriptor
bool FECoreBase::SetParameters(const FEClassDescriptor::ClassVariable& cv)
{
FEParameterList& PL = GetParameterList();
for (int i=0; i<cv.Count(); ++i)
{
// get the next variable
const FEClassDescriptor::Variable* vari = cv.GetVariable(i);
// see if this parameter is defined
FEParam* pi = PL.FindFromName(vari->m_name.c_str());
if (pi)
{
const FEClassDescriptor::SimpleVariable* vi = dynamic_cast<const FEClassDescriptor::SimpleVariable*>(vari);
assert(vi);
if (vi == nullptr) return false;
// set the value
setParamValue(*pi, vi->m_val);
}
else
{
// could be a property
const FEClassDescriptor::ClassVariable* ci = dynamic_cast<const FEClassDescriptor::ClassVariable*>(vari);
assert(ci);
// find the property
FEProperty* prop = FindProperty(ci->m_name.c_str()); assert(prop);
if (prop == nullptr) return false;
// allocate a new child class
FECoreBase* pc = fecore_new<FECoreBase>(prop->GetSuperClassID(), ci->m_type.c_str(), GetFEModel()); assert(pc);
if (pc == nullptr) return false;
// assign the property
prop->SetProperty(pc);
// set the property's parameters
pc->SetParameters(*ci);
}
}
return true;
}
//-----------------------------------------------------------------------------
void FECoreBase::Serialize(DumpStream& ar)
{
// do base class first
FEParamContainer::Serialize(ar);
// serialize name
if (ar.IsShallow() == false)
{
ar & m_name;
ar & m_nID;
}
if (ar.IsShallow() == false) ar & m_pParent;
// serialize all the properties
int NP = (int)m_Prop.size();
for (int i = 0; i<NP; ++i)
{
FEProperty* prop = m_Prop[i];
prop->SetParent(this);
prop->Serialize(ar);
}
}
//-----------------------------------------------------------------------------
void FECoreBase::SaveClass(DumpStream& ar, FECoreBase* a)
{
assert(ar.IsSaving());
int classID = 0;
if (a == nullptr) { ar << classID; return; }
classID = a->GetSuperClassID();
assert(classID != FEINVALID_ID);
const char* sztype = a->GetTypeStr();
ar << classID;
ar << sztype;
}
FECoreBase* FECoreBase::LoadClass(DumpStream& ar, FECoreBase* a)
{
assert(ar.IsLoading());
int classID = 0;
ar >> classID;
if (classID == FEINVALID_ID) return nullptr;
char sztype[256] = { 0 };
ar >> sztype;
// instantiate the class
a = fecore_new<FECoreBase>(classID, sztype, &ar.GetFEModel());
assert(a);
if (a == nullptr) throw DumpStream::ReadError();
return a;
}
bool FECoreBase::ValidateParameters()
{
FEParameterList& pl = GetParameterList();
int N = pl.Parameters();
list<FEParam>::iterator pi = pl.first();
for (int i = 0; i < N; ++i, pi++)
{
FEParam& p = *pi;
if (p.is_valid() == false)
{
stringstream ss;
ss << GetName() << "." << p.name();
string paramName = ss.str();
feLogError("Invalid value for parameter: %s", paramName.c_str());
return false;
}
}
return true;
}
bool FECoreBase::Validate()
{
// validate parameters
if (!ValidateParameters()) return false;
// check properties
const int nprop = (int)m_Prop.size();
for (int i = 0; i<nprop; ++i)
{
FEProperty* pi = m_Prop[i];
if (pi)
{
if (pi->Validate() == false) return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
bool FECoreBase::Init()
{
// call init on model parameters
FEParameterList& PL = GetParameterList();
FEParamIterator it = PL.first();
for (int i = 0; i < PL.Parameters(); ++i, ++it)
{
FEParam& pi = *it;
if (pi.type() == FE_PARAM_DOUBLE_MAPPED)
{
for (int j = 0; j < pi.dim(); ++j)
{
FEParamDouble& pd = pi.value<FEParamDouble>(j);
if (pd.Init() == false)
{
feLogError("Failed to initialize parameter %s", pi.name());
return false;
}
}
}
else if (pi.type() == FE_PARAM_VEC3D_MAPPED)
{
for (int j = 0; j < pi.dim(); ++j)
{
FEParamVec3& pd = pi.value<FEParamVec3>(j);
if (pd.Init() == false)
{
feLogError("Failed to initialize parameter %s", pi.name());
return false;
}
}
}
else if (pi.type() == FE_PARAM_MAT3D_MAPPED)
{
for (int j = 0; j < pi.dim(); ++j)
{
FEParamMat3d& pd = pi.value<FEParamMat3d>(j);
if (pd.Init() == false)
{
feLogError("Failed to initialize parameter %s", pi.name());
return false;
}
}
}
}
// check the parameter ranges
if (ValidateParameters() == false) return false;
// initialize properties
const int nprop = (int)m_Prop.size();
for (int i = 0; i<nprop; ++i)
{
FEProperty* pi = m_Prop[i];
if (pi)
{
if (pi->Init() == false)
{
feLogError("The property \"%s\" failed to initialize or was not defined.", pi->GetName());
return false;
}
}
else
{
feLogError("A nullptr was set for property i");
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
void FECoreBase::AddProperty(FEProperty* pp, const char* sz, unsigned int flags)
{
pp->SetName(sz);
pp->SetLongName(sz);
pp->SetFlags(flags);
pp->SetParent(this);
m_Prop.push_back(pp);
}
//-----------------------------------------------------------------------------
void FECoreBase::RemoveProperty(int i)
{
m_Prop[i] = nullptr;
}
//-----------------------------------------------------------------------------
void FECoreBase::ClearProperties()
{
for (int i = 0; i < m_Prop.size(); ++i)
{
delete m_Prop[i];
}
m_Prop.clear();
}
//-----------------------------------------------------------------------------
int FECoreBase::Properties()
{
int N = (int)m_Prop.size();
int n = 0;
for (int i = 0; i<N; ++i) n += m_Prop[i]->size();
return n;
}
//-----------------------------------------------------------------------------
int FECoreBase::FindPropertyIndex(const char* sz)
{
int NP = (int)m_Prop.size();
for (int i = 0; i<NP; ++i)
{
const FEProperty* pm = m_Prop[i];
if (pm && (strcmp(pm->GetName(), sz) == 0)) return i;
}
return -1;
}
//-----------------------------------------------------------------------------
FEProperty* FECoreBase::FindProperty(const char* sz, bool searchChildren)
{
// first, search the class' properties
int NP = (int)m_Prop.size();
for (int i = 0; i<NP; ++i)
{
FEProperty* pm = m_Prop[i];
if (pm && (strcmp(pm->GetName(), sz) == 0)) return pm;
}
// the property, wasn't found so look into the properties' properties
if (searchChildren)
{
for (int i = 0; i < NP; ++i)
{
FEProperty* pm = m_Prop[i];
if (pm)
{
int m = pm->size();
for (int j = 0; j < m; ++j)
{
FECoreBase* pcj = pm->get(j);
if (pcj)
{
// Note: we don't search children's children!
FEProperty* pj = pcj->FindProperty(sz);
if (pj) return pj;
}
}
}
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
FECoreBase* FECoreBase::GetProperty(int n)
{
int N = (int)m_Prop.size();
int m = 0;
for (int i = 0; i<N; ++i)
{
FEProperty* pm = m_Prop[i];
int l = pm->size();
if (m + l > n) return pm->get(n - m);
m += l;
}
return 0;
}
//-----------------------------------------------------------------------------
bool FECoreBase::SetProperty(int i, FECoreBase* pb)
{
FEProperty* pm = m_Prop[i];
if (pm->IsType(pb))
{
pm->SetProperty(pb);
if (pb) pb->SetParent(this);
return true;
}
return false;
}
//-----------------------------------------------------------------------------
//! Set a property via name
bool FECoreBase::SetProperty(const char* sz, FECoreBase* pb)
{
FEProperty* prop = FindProperty(sz);
if (prop == nullptr) return false;
if (prop->IsType(pb))
{
prop->SetProperty(pb);
if (pb) pb->SetParent(this);
return true;
}
return false;
}
//-----------------------------------------------------------------------------
//! number of parameters
int FECoreBase::Parameters() const
{
return GetParameterList().Parameters();
}
//-----------------------------------------------------------------------------
FEParam* FECoreBase::FindParameter(const ParamString& s)
{
// first search the parameter list
FEParam* p = FEParamContainer::FindParameter(s);
if (p) return p;
// next, let's try the property list
int NP = (int)m_Prop.size();
for (int i = 0; i<NP; ++i)
{
// get the property
FEProperty* mp = m_Prop[i];
// see if matches
if (s == mp->GetName())
{
if (mp->IsArray())
{
// get the number of items in this property
int nsize = mp->size();
int index = s.Index();
if ((index >= 0) && (index < nsize))
{
return mp->get(index)->FindParameter(s.next());
}
else
{
int nid = s.ID();
if (nid != -1)
{
FECoreBase* pc = mp->getFromID(nid);
if (pc) return pc->FindParameter(s.next());
}
else if (s.IDString())
{
FECoreBase* c = mp->get(s.IDString());
if (c) return c->FindParameter(s.next());
}
}
}
else
{
FECoreBase* pc = mp->get(0);
return (pc ? pc->FindParameter(s.next()) : nullptr);
}
}
}
return nullptr;
}
FEParamValue FECoreBase::GetParameterValue(const ParamString& s)
{
FEParam* p = FEParamContainer::FindParameter(s);
if (p)
{
FEParamValue paramVal;
if (p->type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& v = p->value<FEParamDouble>();
if (v.isConst()) paramVal = FEParamValue(p, &v.constValue(), FE_PARAM_DOUBLE);
else paramVal = FEParamValue(p, p->data_ptr(), p->type());
}
else paramVal = FEParamValue(p, p->data_ptr(), p->type());
if (s.Index() >= 0)
{
paramVal = GetParameterComponent(paramVal, s.Index());
}
ParamString comp = s.next();
if (comp.isValid())
{
paramVal = GetParameterComponent(paramVal, comp.c_str());
}
return paramVal;
}
// next, let's try the property list
int NP = (int)m_Prop.size();
for (int i = 0; i < NP; ++i)
{
// get the property
FEProperty* mp = m_Prop[i];
// see if matches
if (s == mp->GetName())
{
if (mp->IsArray())
{
// get the number of items in this property
int nsize = mp->size();
int index = s.Index();
if ((index >= 0) && (index < nsize))
{
return mp->get(index)->GetParameterValue(s.next());
}
else
{
int nid = s.ID();
if (nid != -1)
{
FECoreBase* pc = mp->getFromID(nid);
if (pc) return pc->GetParameterValue(s.next());
}
else if (s.IDString())
{
FECoreBase* c = mp->get(s.IDString());
if (c) return c->GetParameterValue(s.next());
}
}
}
else
{
FECoreBase* pc = mp->get(0);
return (pc ? pc->GetParameterValue(s.next()) : FEParamValue());
}
}
}
return FEParamValue();
}
//-----------------------------------------------------------------------------
//! return the property (or this) that owns a parameter
FECoreBase* FECoreBase::FindParameterOwner(void* pd)
{
// see if this class is the owner of the data pointer
FEParam* p = FindParameterFromData(pd);
if (p) return this;
// it's not se let's check the properties
int NP = PropertyClasses();
for (int i = 0; i < NP; ++i)
{
FEProperty* pi = PropertyClass(i);
int n = pi->size();
for (int j = 0; j < n; ++j)
{
FECoreBase* pcj = pi->get(j);
if (pcj)
{
FECoreBase* pc = pcj->FindParameterOwner(pd);
if (pc) return pc;
}
}
}
// sorry, no luck
return nullptr;
}
//-----------------------------------------------------------------------------
//! return the number of properties defined
int FECoreBase::PropertyClasses() const
{
return (int)m_Prop.size();
}
//! return a property
FEProperty* FECoreBase::PropertyClass(int i)
{
return m_Prop[i];
}
//-----------------------------------------------------------------------------
FEProperty* FECoreBase::FindProperty(const ParamString& prop)
{
int NP = (int)m_Prop.size();
for (int i = 0; i < NP; ++i)
{
FEProperty* mp = m_Prop[i];
if (prop == mp->GetName())
{
if (mp->IsArray())
{
// get the number of items in this property
int nsize = mp->size();
int index = prop.Index();
if ((index >= 0) && (index < nsize))
{
FECoreBase* pc = mp->get(index);
if (pc)
{
ParamString next = prop.next();
if (next.count() == 0) return nullptr;
else return pc->FindProperty(next);
}
}
else
{
int nid = prop.ID();
if (nid != -1)
{
FECoreBase* pc = mp->getFromID(nid);
// TODO: What to do here?
assert(false);
}
else if (prop.IDString())
{
FECoreBase* pc = mp->get(prop.IDString());
if (pc)
{
ParamString next = prop.next();
if (next.count() == 0) return nullptr;
else return pc->FindProperty(next);
}
}
}
}
else
{
ParamString next = prop.next();
if (next.count() == 0) return mp;
else return FindProperty(next);
}
}
}
return 0;
}
//-----------------------------------------------------------------------------
FECoreBase* FECoreBase::GetProperty(const ParamString& prop)
{
int NP = (int) m_Prop.size();
for (int i=0; i<NP; ++i)
{
FEProperty* mp = m_Prop[i];
if (prop == mp->GetName())
{
if (mp->IsArray())
{
// get the number of items in this property
int nsize = mp->size();
int index = prop.Index();
if ((index >= 0) && (index < nsize))
{
FECoreBase* pc = mp->get(index);
if (pc)
{
ParamString next = prop.next();
if (next.count() == 0) return pc;
else return pc->GetProperty(next);
}
}
else
{
int nid = prop.ID();
if (nid != -1)
{
FECoreBase* pc = mp->getFromID(nid);
}
else if (prop.IDString())
{
FECoreBase* pc = mp->get(prop.IDString());
if (pc)
{
ParamString next = prop.next();
if (next.count() == 0) return pc;
else return pc->GetProperty(next);
}
}
}
}
else
{
FECoreBase* pc = mp->get(0);
ParamString next = prop.next();
if (next.count() == 0) return pc;
else return pc->GetProperty(next);
}
}
}
return 0;
}
FEProperty* FECoreBase::FindProperty(FECoreBase* pc)
{
for (int i = 0; i < PropertyClasses(); ++i)
{
FEProperty* prop = PropertyClass(i);
if (prop)
{
int N = prop->size();
for (int j = 0; j < N; ++j)
{
if (prop->get(j) == pc) return prop;
}
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
bool FECoreBase::BuildClass()
{
GetParameterList();
for (int i = 0; i < PropertyClasses(); ++i)
{
FEProperty* pp = PropertyClass(i);
int m = pp->size();
for (int j = 0; j < m; ++j)
{
FECoreBase* pj = pp->get(j);
if (pj) pj->BuildClass();
}
}
return true;
}
//-----------------------------------------------------------------------------
bool FECoreBase::UpdateParams()
{
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/Callback.h | .h | 4,387 | 100 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <list>
#include "fecore_api.h"
//-----------------------------------------------------------------------------
// Forward declarations.
class FEModel;
//-----------------------------------------------------------------------------
// callback events
#define CB_ALWAYS 0x0FFFFFFF //!< Call for all reasons
#define CB_INIT 0x00000001 //!< Call after model initialization (i.e. FEModel::Init())
#define CB_STEP_ACTIVE 0x00000002 //!< call after step was activated (i.e.
#define CB_MAJOR_ITERS 0x00000004 //!< Call at the end of each major converged iteration
#define CB_MINOR_ITERS 0x00000008 //!< Call for each minor iteration
#define CB_SOLVED 0x00000010 //!< Call at the end of FEModel::Solve
#define CB_UPDATE_TIME 0x00000020 //!< Call when time is updated and right before time step is solved (in FEAnalysis::Solve)
#define CB_AUGMENT 0x00000040 //!< The model is entering augmentations (called before Augment)
#define CB_STEP_SOLVED 0x00000080 //!< The step was solved
#define CB_MATRIX_REFORM 0x00000100 //!< stiffness matrix was reformed
#define CB_REMESH 0x00000200 //!< Called after remesh
#define CB_PRE_MATRIX_SOLVE 0x00000400 //!< Called right before matrix solve
#define CB_RESET 0x00000800 //!< Called after FEModel::Reset
#define CB_MODEL_UPDATE 0x00001000 //!< Called at the end of FEModel::Update
#define CB_TIMESTEP_SOLVED 0x00002000 //!< Called at FEAnalysis::SolveTimeStep after the solver returns.
#define CB_SERIALIZE_SAVE 0x00004000 //!< Called at the end of FEModel::Serialize when saving
#define CB_SERIALIZE_LOAD 0x00008000 //!< Called at the end of FEModel::Serialize when loading
#define CB_TIMESTEP_FAILED 0x00010000 //!< Called when the time step failed
#define CB_QUASIN_CONVERGED 0x00020000 //!< Called when Quasin is done (but before it finishes up)
#define CB_USER1 0x01000000 //!< can be used by users
typedef unsigned int FECORE_CB_WHEN;
typedef bool(*FECORE_CB_FNC)(FEModel*, unsigned int, void*);
//-----------------------------------------------------------------------------
// callback structure
struct FECORE_CALLBACK {
FECORE_CB_FNC m_pcb; // pointer to callback function
void* m_pd; // pointer to user data
FECORE_CB_WHEN m_nwhen; // when to call function
};
//-----------------------------------------------------------------------------
// class that handles callbacks
class FECORE_API CallbackHandler
{
public:
enum CBInsertPolicy
{
CB_ADD_FRONT,
CB_ADD_END
};
public:
CallbackHandler();
virtual ~CallbackHandler();
//! set callback function
void AddCallback(FECORE_CB_FNC pcb, unsigned int nwhen, void* pd, CBInsertPolicy insert = CBInsertPolicy::CB_ADD_END);
//! call the callback function
//! This function returns false if the run is to be aborted
bool DoCallback(FEModel* fem, unsigned int nevent);
//! Get the current callback reason (or zero if not inside DoCallback)
unsigned int CurrentEvent() const;
private:
std::list<FECORE_CALLBACK> m_pcb; //!< pointer to callback function
unsigned int m_event; //!< reason for current callback (or zero)
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEConstValueVec3.cpp | .cpp | 10,081 | 394 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEConstValueVec3.h"
#include "FEMaterialPoint.h"
#include "FEMeshPartition.h"
#include "FENode.h"
#include "quatd.h"
#include <assert.h>
//==================================================================================
BEGIN_FECORE_CLASS(FEConstValueVec3, FEVec3dValuator)
ADD_PARAMETER(m_val, "vector");
END_FECORE_CLASS();
FEConstValueVec3::FEConstValueVec3(FEModel* fem) : FEVec3dValuator(fem) {}
FEVec3dValuator* FEConstValueVec3::copy()
{
FEConstValueVec3* val = fecore_alloc(FEConstValueVec3, GetFEModel());
val->m_val = m_val;
return val;
}
//==================================================================================
BEGIN_FECORE_CLASS(FEMathValueVec3, FEVec3dValuator)
ADD_PARAMETER(m_expr, "math");
END_FECORE_CLASS();
FEMathValueVec3::FEMathValueVec3(FEModel* fem) : FEVec3dValuator(fem)
{
m_expr = "0,0,0";
Init();
}
//---------------------------------------------------------------------------------------
bool FEMathValueVec3::Init()
{
if (m_expr.empty()) return false;
string s[3];
const char* c = m_expr.c_str();
int n = 0;
int l = 0;
while (*c)
{
char ch = *c;
if ((ch == ',') && (l == 0))
{
n++;
if (n > 2) return false;
}
else
{
if ((ch == '(') || (ch == '[') || (ch == '{')) l++;
if ((ch == ')') || (ch == ']') || (ch == '}')) l--;
s[n].push_back(ch);
}
c++;
}
if (n != 2) return false;
return create(s[0], s[1], s[2]);
}
//---------------------------------------------------------------------------------------
bool FEMathValueVec3::create(const std::string& sx, const std::string& sy, const std::string& sz)
{
FECoreBase* pc = nullptr;
if (pc == nullptr)
{
// try to find the owner of this parameter
// First, we need the model parameter
FEModelParam* param = GetModelParam();
if (param == nullptr) return false;
// we'll need the model for this
FEModel* fem = GetFEModel();
if (fem == nullptr) return false;
// Now try to find the owner of this parameter
pc = fem->FindParameterOwner(param);
}
if (m_math[0].Init(sx, pc) == false) return false;
if (m_math[1].Init(sy, pc) == false) return false;
if (m_math[2].Init(sz, pc) == false) return false;
return true;
}
bool FEMathValueVec3::UpdateParams()
{
return Init();
}
vec3d FEMathValueVec3::operator()(const FEMaterialPoint& pt)
{
double vx = m_math[0].value(GetFEModel(), pt);
double vy = m_math[1].value(GetFEModel(), pt);
double vz = m_math[2].value(GetFEModel(), pt);
return vec3d(vx, vy, vz);
}
void FEMathValueVec3::Serialize(DumpStream& ar)
{
FEVec3dValuator::Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsLoading())
{
Init();
}
}
//---------------------------------------------------------------------------------------
FEVec3dValuator* FEMathValueVec3::copy()
{
FEMathValueVec3* newVal = fecore_alloc(FEMathValueVec3, GetFEModel());
newVal->m_math[0] = m_math[0];
newVal->m_math[1] = m_math[1];
newVal->m_math[2] = m_math[2];
return newVal;
}
//---------------------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMappedValueVec3, FEVec3dValuator)
ADD_PARAMETER(m_mapName, "map");
END_FECORE_CLASS();
FEMappedValueVec3::FEMappedValueVec3(FEModel* fem) : FEVec3dValuator(fem)
{
m_val = nullptr;
}
void FEMappedValueVec3::setDataMap(FEDataMap* val, vec3d scl)
{
m_val = val;
}
vec3d FEMappedValueVec3::operator()(const FEMaterialPoint& pt)
{
vec3d r = m_val->valueVec3d(pt);
return vec3d(r.x, r.y, r.z);
}
FEVec3dValuator* FEMappedValueVec3::copy()
{
FEMappedValueVec3* map = fecore_alloc(FEMappedValueVec3, GetFEModel());
map->m_val = m_val;
return map;
}
void FEMappedValueVec3::Serialize(DumpStream& ar)
{
FEVec3dValuator::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_val;
}
bool FEMappedValueVec3::Init()
{
if (m_val == nullptr)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
FEDataMap* map = mesh.FindDataMap(m_mapName);
if (map == nullptr) return false;
setDataMap(map);
}
return FEVec3dValuator::Init();
}
//=================================================================================================
BEGIN_FECORE_CLASS(FELocalVectorGenerator, FEVec3dValuator)
ADD_PARAMETER(m_n, 2, "local");
END_FECORE_CLASS();
FELocalVectorGenerator::FELocalVectorGenerator(FEModel* fem) : FEVec3dValuator(fem)
{
m_n[0] = m_n[1] = 0;
}
bool FELocalVectorGenerator::Init()
{
if ((m_n[0] <= 0) && (m_n[1] <= 0))
{
m_n[0] = 1;
m_n[1] = 2;
}
if ((m_n[0] <= 0) || (m_n[1] <= 0)) return false;
return FEVec3dValuator::Init();
}
vec3d FELocalVectorGenerator::operator () (const FEMaterialPoint& mp)
{
FEElement* el = mp.m_elem; assert(el);
FEMeshPartition* dom = el->GetMeshPartition();
vec3d r0 = dom->Node(el->m_lnode[m_n[0]-1]).m_r0;
vec3d r1 = dom->Node(el->m_lnode[m_n[1]-1]).m_r0;
vec3d n = r1 - r0;
n.unit();
return n;
}
FEVec3dValuator* FELocalVectorGenerator::copy()
{
FELocalVectorGenerator* map = fecore_alloc(FELocalVectorGenerator, GetFEModel());
map->m_n[0] = m_n[0];
map->m_n[1] = m_n[1];
return map;
}
//=================================================================================================
BEGIN_FECORE_CLASS(FESphericalVectorGenerator, FEVec3dValuator)
ADD_PARAMETER(m_center, "center");
ADD_PARAMETER(m_vector, "vector");
END_FECORE_CLASS();
FESphericalVectorGenerator::FESphericalVectorGenerator(FEModel* fem) : FEVec3dValuator(fem)
{
m_center = vec3d(0, 0, 0);
m_vector = vec3d(1, 0, 0);
}
bool FESphericalVectorGenerator::Init()
{
// Make sure the vector is a unit vector
m_vector.unit();
return true;
}
FEVec3dValuator* FESphericalVectorGenerator::copy()
{
FESphericalVectorGenerator* map = fecore_alloc(FESphericalVectorGenerator, GetFEModel());
map->m_center = m_center;
map->m_vector = m_vector;
return map;
}
vec3d FESphericalVectorGenerator::operator () (const FEMaterialPoint& mp)
{
vec3d a = mp.m_r0 - m_center;
a.unit();
// setup the rotation
vec3d e1(1, 0, 0);
quatd q(e1, a);
vec3d v = m_vector;
// v.unit();
q.RotateVector(v);
return v;
}
//=================================================================================================
BEGIN_FECORE_CLASS(FECylindricalVectorGenerator, FEVec3dValuator)
ADD_PARAMETER(m_center, "center");
ADD_PARAMETER(m_axis, "axis");
ADD_PARAMETER(m_vector, "vector");
END_FECORE_CLASS();
FECylindricalVectorGenerator::FECylindricalVectorGenerator(FEModel* fem) : FEVec3dValuator(fem)
{
m_center = vec3d(0, 0, 0);
m_axis = vec3d(0, 0, 1);
m_vector = vec3d(1, 0, 0);
}
bool FECylindricalVectorGenerator::Init()
{
// Make sure the axis and vector are unit vectors
m_axis.unit();
m_vector.unit();
return true;
}
vec3d FECylindricalVectorGenerator::operator () (const FEMaterialPoint& mp)
{
vec3d p = mp.m_r0 - m_center;
// find the vector to the axis
vec3d a = m_axis; a.unit();
vec3d b = p - a * (a*p);
b.unit();
// setup the rotation
vec3d e1(1, 0, 0);
quatd qz(vec3d(0, 0, 1), a);
qz.RotateVector(e1);
quatd q(e1, b);
vec3d r = m_vector;
r.unit();
q.RotateVector(r);
return r;
}
FEVec3dValuator* FECylindricalVectorGenerator::copy()
{
FECylindricalVectorGenerator* map = fecore_alloc(FECylindricalVectorGenerator, GetFEModel());
map->m_center = m_center;
map->m_axis = m_axis;
map->m_vector = m_vector;
return map;
}
//=================================================================================================
BEGIN_FECORE_CLASS(FESphericalAnglesVectorGenerator, FEVec3dValuator)
ADD_PARAMETER(m_theta, "theta");
ADD_PARAMETER(m_phi, "phi");
END_FECORE_CLASS();
FESphericalAnglesVectorGenerator::FESphericalAnglesVectorGenerator(FEModel* fem) : FEVec3dValuator(fem)
{
// equal to x-axis (1,0,0)
m_theta = 0.0;
m_phi = 90.0;
}
vec3d FESphericalAnglesVectorGenerator::operator () (const FEMaterialPoint& mp)
{
// convert from degress to radians
const double the = m_theta(mp)* PI / 180.;
const double phi = m_phi(mp)* PI / 180.;
// the fiber vector
vec3d a;
a.x = cos(the)*sin(phi);
a.y = sin(the)*sin(phi);
a.z = cos(phi);
return a;
}
FEVec3dValuator* FESphericalAnglesVectorGenerator::copy()
{
FESphericalAnglesVectorGenerator* v = fecore_alloc(FESphericalAnglesVectorGenerator, GetFEModel());
v->m_theta = m_theta;
v->m_phi = m_phi;
return v;
}
//=================================================================================================
BEGIN_FECORE_CLASS(FEUserVectorGenerator, FEVec3dValuator)
END_FECORE_CLASS();
FEUserVectorGenerator::FEUserVectorGenerator(FEModel* fem) : FEVec3dValuator(fem)
{
}
vec3d FEUserVectorGenerator::operator () (const FEMaterialPoint& mp)
{
assert(false);
return vec3d(0, 0, 0);
}
FEVec3dValuator* FEUserVectorGenerator::copy()
{
assert(false);
return fecore_alloc(FEUserVectorGenerator, GetFEModel());
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens6d.cpp | .cpp | 6,852 | 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 "tens6d.h"
//-----------------------------------------------------------------------------
double calc_6ds_comp(double K[3][3], double Ri[3], double Rj[3], int i, int j, int k, int l, int m, int n)
{
i -= 1; j -= 1; k -= 1; l -= 1; m -= 1; n -= 1;
return (1/72)*( Ri[i]*Ri[j]*K[k][l]*Rj[m]*Rj[n] + Ri[i]*Ri[j]*K[k][n]*Rj[m]*Rj[l] + Ri[i]*Ri[j]*K[k][m]*Rj[l]*Rj[n] + Ri[i]*Ri[j]*K[k][l]*Rj[n]*Rj[m] + Ri[i]*Ri[j]*K[k][m]*Rj[n]*Rj[l] + Ri[i]*Ri[j]*K[k][n]*Rj[l]*Rj[m]
+ Ri[k]*Ri[j]*K[i][l]*Rj[m]*Rj[n] + Ri[k]*Ri[j]*K[i][n]*Rj[m]*Rj[l] + Ri[k]*Ri[j]*K[i][m]*Rj[l]*Rj[n] + Ri[k]*Ri[j]*K[i][l]*Rj[n]*Rj[m] + Ri[k]*Ri[j]*K[i][m]*Rj[n]*Rj[l] + Ri[k]*Ri[j]*K[i][n]*Rj[l]*Rj[m]
+ Ri[j]*Ri[i]*K[k][l]*Rj[m]*Rj[n] + Ri[j]*Ri[i]*K[k][n]*Rj[m]*Rj[l] + Ri[j]*Ri[i]*K[k][m]*Rj[l]*Rj[n] + Ri[j]*Ri[i]*K[k][l]*Rj[n]*Rj[m] + Ri[j]*Ri[i]*K[k][m]*Rj[n]*Rj[l] + Ri[j]*Ri[i]*K[k][n]*Rj[l]*Rj[m]
+ Ri[i]*Ri[k]*K[j][l]*Rj[m]*Rj[n] + Ri[i]*Ri[k]*K[j][n]*Rj[m]*Rj[l] + Ri[i]*Ri[k]*K[j][m]*Rj[l]*Rj[n] + Ri[i]*Ri[k]*K[j][l]*Rj[n]*Rj[m] + Ri[i]*Ri[k]*K[j][m]*Rj[n]*Rj[l] + Ri[i]*Ri[k]*K[j][n]*Rj[l]*Rj[m]
+ Ri[j]*Ri[k]*K[i][l]*Rj[m]*Rj[n] + Ri[j]*Ri[k]*K[i][n]*Rj[m]*Rj[l] + Ri[j]*Ri[k]*K[i][m]*Rj[l]*Rj[n] + Ri[j]*Ri[k]*K[i][l]*Rj[n]*Rj[m] + Ri[j]*Ri[k]*K[i][m]*Rj[n]*Rj[l] + Ri[j]*Ri[k]*K[i][n]*Rj[l]*Rj[m]
+ Ri[k]*Ri[i]*K[j][l]*Rj[m]*Rj[n] + Ri[k]*Ri[i]*K[j][n]*Rj[m]*Rj[l] + Ri[k]*Ri[i]*K[j][m]*Rj[l]*Rj[n] + Ri[k]*Ri[i]*K[j][l]*Rj[n]*Rj[m] + Ri[k]*Ri[i]*K[j][m]*Rj[n]*Rj[l] + Ri[k]*Ri[i]*K[j][n]*Rj[l]*Rj[m]
+ Ri[l]*Ri[m]*K[n][i]*Rj[j]*Rj[k] + Ri[l]*Ri[m]*K[n][k]*Rj[j]*Rj[i] + Ri[l]*Ri[m]*K[n][j]*Rj[i]*Rj[k] + Ri[l]*Ri[m]*K[n][i]*Rj[k]*Rj[j] + Ri[l]*Ri[m]*K[n][j]*Rj[k]*Rj[i] + Ri[l]*Ri[m]*K[n][k]*Rj[i]*Rj[j]
+ Ri[n]*Ri[m]*K[l][i]*Rj[j]*Rj[k] + Ri[n]*Ri[m]*K[l][k]*Rj[j]*Rj[i] + Ri[n]*Ri[m]*K[l][j]*Rj[i]*Rj[k] + Ri[n]*Ri[m]*K[l][i]*Rj[k]*Rj[j] + Ri[n]*Ri[m]*K[l][j]*Rj[k]*Rj[i] + Ri[n]*Ri[m]*K[l][k]*Rj[i]*Rj[j]
+ Ri[m]*Ri[l]*K[n][i]*Rj[j]*Rj[k] + Ri[m]*Ri[l]*K[n][k]*Rj[j]*Rj[i] + Ri[m]*Ri[l]*K[n][j]*Rj[i]*Rj[k] + Ri[m]*Ri[l]*K[n][i]*Rj[k]*Rj[j] + Ri[m]*Ri[l]*K[n][j]*Rj[k]*Rj[i] + Ri[m]*Ri[l]*K[n][k]*Rj[i]*Rj[j]
+ Ri[l]*Ri[n]*K[m][i]*Rj[j]*Rj[k] + Ri[l]*Ri[n]*K[m][k]*Rj[j]*Rj[i] + Ri[l]*Ri[n]*K[m][j]*Rj[i]*Rj[k] + Ri[l]*Ri[n]*K[m][i]*Rj[k]*Rj[j] + Ri[l]*Ri[n]*K[m][j]*Rj[k]*Rj[i] + Ri[l]*Ri[n]*K[m][k]*Rj[i]*Rj[j]
+ Ri[m]*Ri[n]*K[l][i]*Rj[j]*Rj[k] + Ri[m]*Ri[n]*K[l][k]*Rj[j]*Rj[i] + Ri[m]*Ri[n]*K[l][j]*Rj[i]*Rj[k] + Ri[m]*Ri[n]*K[l][i]*Rj[k]*Rj[j] + Ri[m]*Ri[n]*K[l][j]*Rj[k]*Rj[i] + Ri[m]*Ri[n]*K[l][k]*Rj[i]*Rj[j]
+ Ri[n]*Ri[l]*K[m][i]*Rj[j]*Rj[k] + Ri[n]*Ri[l]*K[m][k]*Rj[j]*Rj[i] + Ri[n]*Ri[l]*K[m][j]*Rj[i]*Rj[k] + Ri[n]*Ri[l]*K[m][i]*Rj[k]*Rj[j] + Ri[n]*Ri[l]*K[m][j]*Rj[k]*Rj[i] + Ri[n]*Ri[l]*K[m][k]*Rj[i]*Rj[j]);
}
//-----------------------------------------------------------------------------
void calculate_e2O(tens6ds& e, double K[3][3], double Ri[3], double Rj[3] )
{
e.d[ 0] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 1, 1);
e.d[ 1] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 1, 2);
e.d[ 2] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 1, 3);
e.d[ 3] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 2, 2);
e.d[ 4] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 2, 3);
e.d[ 5] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 1, 3, 3);
e.d[ 6] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 2, 2, 2);
e.d[ 7] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 2, 2, 3);
e.d[ 8] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 2, 3, 3);
e.d [9] += calc_6ds_comp(K, Ri, Rj, 1, 1, 1, 3, 3, 3);
e.d[10] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 1, 2, 2);
e.d[11] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 1, 2, 3);
e.d[12] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 1, 3, 3);
e.d[13] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 2, 2, 2);
e.d[14] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 2, 2, 3);
e.d[15] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 2, 3, 3);
e.d[16] += calc_6ds_comp(K, Ri, Rj, 1, 1, 2, 3, 3, 3);
e.d[17] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 1, 2, 2);
e.d[18] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 1, 2, 3);
e.d[19] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 1, 3, 3);
e.d[20] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 2, 2, 2);
e.d[21] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 2, 2, 3);
e.d[22] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 2, 3, 3);
e.d[23] += calc_6ds_comp(K, Ri, Rj, 1, 1, 3, 3, 3, 3);
e.d[24] += calc_6ds_comp(K, Ri, Rj, 1, 2, 2, 1, 3, 3);
e.d[25] += calc_6ds_comp(K, Ri, Rj, 1, 2, 2, 2, 2, 2);
e.d[26] += calc_6ds_comp(K, Ri, Rj, 1, 2, 2, 2, 2, 3);
e.d[27] += calc_6ds_comp(K, Ri, Rj, 1, 2, 2, 2, 3, 3);
e.d[28] += calc_6ds_comp(K, Ri, Rj, 1, 2, 2, 3, 3, 3);
e.d[29] += calc_6ds_comp(K, Ri, Rj, 1, 2, 3, 1, 3, 3);
e.d[30] += calc_6ds_comp(K, Ri, Rj, 1, 2, 3, 2, 2, 2);
e.d[31] += calc_6ds_comp(K, Ri, Rj, 1, 2, 3, 2, 2, 3);
e.d[32] += calc_6ds_comp(K, Ri, Rj, 1, 2, 3, 2, 3, 3);
e.d[33] += calc_6ds_comp(K, Ri, Rj, 1, 2, 3, 3, 3, 3);
e.d[34] += calc_6ds_comp(K, Ri, Rj, 1, 3, 3, 2, 2, 2);
e.d[35] += calc_6ds_comp(K, Ri, Rj, 1, 3, 3, 2, 2, 3);
e.d[36] += calc_6ds_comp(K, Ri, Rj, 1, 3, 3, 2, 3, 3);
e.d[37] += calc_6ds_comp(K, Ri, Rj, 1, 3, 3, 3, 3, 3);
e.d[38] += calc_6ds_comp(K, Ri, Rj, 2, 2, 2, 2, 2, 2);
e.d[39] += calc_6ds_comp(K, Ri, Rj, 2, 2, 2, 2, 2, 3);
e.d[40] += calc_6ds_comp(K, Ri, Rj, 2, 2, 2, 2, 3, 3);
e.d[41] += calc_6ds_comp(K, Ri, Rj, 2, 2, 2, 3, 3, 3);
e.d[42] += calc_6ds_comp(K, Ri, Rj, 2, 2, 3, 2, 3, 3);
e.d[43] += calc_6ds_comp(K, Ri, Rj, 2, 2, 3, 3, 3, 3);
e.d[44] += calc_6ds_comp(K, Ri, Rj, 2, 3, 3, 3, 3, 3);
e.d[45] += calc_6ds_comp(K, Ri, Rj, 3, 3, 3, 3, 3, 3);
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens5d.hpp | .hpp | 1,722 | 48 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// NOTE: This file is automatically included from tens5d.h
// Users should not include this file manually!
// access operator
inline double tens5d::operator () (int i, int j, int k, int l, int m) const
{
int R = 3*(3*i + j) + k;
int C = 3*l + m;
return d[27*C + R];
}
// access operator
inline double& tens5d::operator () (int i, int j, int k, int l, int m)
{
int R = 3*(3*i + j) + k;
int C = 3*l + m;
return d[27*C + R];
}
| Unknown |
3D | febiosoftware/FEBio | FECore/BSpline.cpp | .cpp | 9,762 | 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) 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 "BSpline.h"
#include "matrix.h"
#include <limits>
//--------------------------------------------------------------------------------
struct BSpline::Impl
{
int korder; //! B-spline order
int ncoef; //! number of B-spline coefficients
std::vector<double> xknot; //! knot sequence
std::vector<double> coeff; //! B-spline coefficients
};
//--------------------------------------------------------------------------------
BSpline::BSpline() : im(new BSpline::Impl)
{
im->korder = 0;
im->ncoef = 0;
m_deriv = false;
}
//--------------------------------------------------------------------------------
// destructor
BSpline::~BSpline()
{
delete im;
im = nullptr;
}
//--------------------------------------------------------------------------------
// copy constructor
BSpline::BSpline(const BSpline& bs) : im(new BSpline::Impl)
{
im->korder = bs.im->korder;
im->ncoef = bs.im->ncoef;
im->xknot = bs.im->xknot;
im->coeff = bs.im->coeff;
}
//--------------------------------------------------------------------------------
void BSpline::operator = (const BSpline& bs)
{
im->korder = bs.im->korder;
im->ncoef = bs.im->ncoef;
im->xknot = bs.im->xknot;
im->coeff = bs.im->coeff;
}
//--------------------------------------------------------------------------------
// initialize B-spline, using p as control points
bool BSpline::init(int korder, const std::vector<vec2d>& p)
{
int ncoef = (int)p.size();
if (ncoef < 2) return false;
im->korder = korder;
im->ncoef = ncoef;
if (ncoef < korder) return false;
im->coeff.resize(ncoef);
// extract breakpoint sequence and spline coefficients
std::vector<double> bp(ncoef);
for (int i=0; i< ncoef; ++i) {
bp[i] = p[i].x();
im->coeff[i] = p[i].y();
}
// evaluate knot sequence from breakpoint sequence
im->xknot.resize(korder + ncoef);
int khalf;
const double eps = 10*std::numeric_limits<double>::epsilon();
double e = eps*(bp[ncoef-1] - bp[ncoef-2]);
if ((korder % 2) == 0) {
khalf = korder/2;
for (int i=0; i< korder; ++i)
im->xknot[i] = bp.front();
for (int i= korder; i< ncoef; ++i)
im->xknot[i] = bp[i-khalf];
for (int i=ncoef; i<ncoef+korder; ++i)
im->xknot[i] = bp.back() + e;
}
else {
khalf = (korder-1)/2;
for (int i=0; i<korder; ++i)
im->xknot[i] = bp.front();
for (int i=korder; i<ncoef; ++i)
im->xknot[i] = (bp[i-khalf] + bp[i-1-khalf])/2;
for (int i=ncoef; i<ncoef+korder; ++i)
im->xknot[i] = bp.back() + e;
}
return true;
}
//--------------------------------------------------------------------------------
// evaluate B-spline at x using de Boor algorithm (de Boor 1986)
double BSpline::eval(double x, int korder, const std::vector<double>& xknot,
int ncoef, const std::vector<double>& coeff) const
{
// perform binary search to locate knot interval that encloses x
int j = korder-1, jh = ncoef;
while (jh - j > 1) {
int jm = (j+jh)/2;
if ((xknot[j] <= x) && (x < xknot[jm]))
jh = jm;
else
j = jm;
}
std::vector<double> c = coeff;
double w;
for (int r=0; r<korder-1; ++r) {
for (int i=j; i>j-korder+r+1; --i) {
if (xknot[i] != xknot[i+korder-r-1])
w = (x - xknot[i])/(xknot[i+korder-r-1] - xknot[i]);
else
w = 0;
c[i] = (1-w)*c[i-1] + w*c[i];
}
}
return c[j];
}
//--------------------------------------------------------------------------------
// evaluate B-spline at x using de Boor algorithm (de Boor 1986)
double BSpline::eval(double x) const
{
return eval(x, im->korder, im->xknot, im->ncoef, im->coeff);
}
//--------------------------------------------------------------------------------
double BSpline::eval_deriv(double x) const {
if (m_deriv) return eval(x);
else return eval_nderiv(x, 1);
}
//--------------------------------------------------------------------------------
double BSpline::eval_deriv2(double x) const {
if (m_deriv) return eval_nderiv(x, 1);
else return eval_nderiv(x, 2);
}
//--------------------------------------------------------------------------------
// evaluate B-spline n-th derivative at x using de Boor algorithm (de Boor 1986)
double BSpline::eval_nderiv(double x, int n) const
{
double deriv = 0;
int korder = im->korder;
int ncoef = im->ncoef;
if (n >= korder) return deriv;
std::vector<double> coeff = im->coeff;
for (int k=1; k<=n; ++k) {
for (int i= im->ncoef-1; i>=k; --i) {
if (im->xknot[i+korder-k] > im->xknot[i]) {
coeff[i] = (korder - k)*(coeff[i] - coeff[i-1])/
(im->xknot[i+korder-k] - im->xknot[i]);
}
}
}
// extract portion of vectors
std::vector<double> xknot(im->xknot.begin() + n, im->xknot.end());
std::vector<double> doeff(coeff.begin() + n,coeff.end());
deriv = eval(x,korder-n, xknot, ncoef-n, doeff);
return deriv;
}
//--------------------------------------------------------------------------------
// evaluate B-spline blending functions at x
std::vector<double> BSpline::blending_functions(double x) const
{
int korder = im->korder;
int ncoef = im->ncoef;
std::vector<double> bsbldg(ncoef);
std::vector<std::vector<double> > d(ncoef, std::vector<double>(korder));
for (int i=0; i<ncoef; ++i) {
if ((im->xknot[i] <= x) && (x < im->xknot[i+1]))
d[i][0] = 1;
else
d[i][0] = 0;
}
double r1, r2;
for (int k=2; k<=korder; ++k) {
for (int i=0; i<ncoef; ++i) {
if (im->xknot[i+k-1] == im->xknot[i])
r1 = 0;
else
r1 = (x- im->xknot[i])*d[i][k-2]/(im->xknot[i+k-1]-im->xknot[i]);
if (im->xknot[i+k] == im->xknot[i+1])
r2 = 0;
else
r2 = (im->xknot[i+k]-x)*d[i+1][k-2]/(im->xknot[i+k]- im->xknot[i+1]);
d[i][k-1] = r1 + r2;
}
}
for (int i=0; i<ncoef; ++i)
bsbldg[i] = d[i][korder-1];
return bsbldg;
}
//--------------------------------------------------------------------------------
// fit a B-spline of order korder, with ncoef coefficients, to the points p
bool BSpline::fit(int korder, int ncoef, const std::vector<vec2d>& p)
{
// check for valid spline order
if (korder <1) return false;
// number of points to fit
int np = (int)p.size();
if (np < korder) return false;
// for an interpolation, use p.x as breakpoints to generate knot sequence
bool binit = true;
if (ncoef == np) binit = init(korder, p);
// otherwise, generate breakpoints uniformly over range of x
else {
std::vector<vec2d> q(ncoef,vec2d(0, 0));
double dx = (p[np-1].x() - p[0].x())/(ncoef-1);
for (int i=0; i<ncoef; ++i)
q[i].x() = p[0].x() + i*dx;
binit = init(korder, q);
}
if (binit == false) return binit;
// evaluate B-spline blending functions at p.x using this knot sequence
matrix wk1(np,ncoef);
for (int j=0; j<np; ++j) {
std::vector<double> bsbldg = blending_functions(p[j].x());
for (int i=0; i<ncoef; ++i) wk1(j,i) = bsbldg[i];
}
// evaluate the coefficient matrix
matrix wk2 = wk1.transpose()*wk1;
// evaluate the right-hand-side
std::vector<double> rhs(ncoef,0);
for (int k=0; k<ncoef; ++k)
for (int j=0; j<np; ++j)
rhs[k] += p[j].y()*wk1(j,k);
// solve the system of equations
wk2.solve(im->coeff, rhs);
return true;
}
//--------------------------------------------------------------------------------
// use given points as interpolation points
bool BSpline::init_interpolation(int korder, const std::vector<vec2d>& p)
{
int ncoef = (int)p.size();
return fit(korder, ncoef, p);
}
//--------------------------------------------------------------------------------
// perform spline approximation over points p, using ncoef coefficients
bool BSpline::init_approximation(int korder, int ncoef, const std::vector<vec2d>& p)
{
return fit(korder, ncoef, p);
}
| C++ |
3D | febiosoftware/FEBio | FECore/DumpStream.h | .h | 18,846 | 554 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <map>
#include <string.h>
#include "vec3d.h"
#include "mat3d.h"
#include "quatd.h"
#include "tens3d.h"
#include "tens4d.h"
#include "fecore_api.h"
#include "FECoreKernel.h"
#include "matrix.h"
//-----------------------------------------------------------------------------
class FEModel;
class matrix;
//-----------------------------------------------------------------------------
enum TypeID
{
TYPE_UNKNOWN,
TYPE_INT,
TYPE_UINT,
TYPE_FLOAT,
TYPE_DOUBLE,
TYPE_VEC2D,
TYPE_VEC3D,
TYPE_MAT2D,
TYPE_MAT3D,
TYPE_MAT3DD,
TYPE_MAT3DS,
TYPE_MAT3DA,
TYPE_QUATD,
TYPE_TENS3DS,
TYPE_TENS3DRS,
TYPE_MATRIX,
TYPE_TENS4D,
TYPE_TENS4DS,
TYPE_TENS4DMM
};
typedef unsigned char uchar;
//-----------------------------------------------------------------------------
//! A dump stream is used to serialize data to and from a data stream.
//! This is used in FEBio for running and cold restarts.
//! This is just an abstract base class. Classes must be derived from this
//! to implement the actual storage mechanism.
class FECORE_API DumpStream
{
public:
class DataBlock
{
public:
DataBlock() { m_type = TypeID::TYPE_UNKNOWN; m_pd = nullptr; }
~DataBlock() {
if (m_pd) {
switch (m_type) {
case TypeID::TYPE_INT: delete (int*) m_pd; break;
case TypeID::TYPE_UINT: delete (unsigned int*) m_pd; break;
case TypeID::TYPE_FLOAT: delete (float*) m_pd; break;
case TypeID::TYPE_DOUBLE: delete (double*) m_pd; break;
case TypeID::TYPE_VEC2D: delete (vec2d*) m_pd; break;
case TypeID::TYPE_VEC3D: delete (vec3d*) m_pd; break;
case TypeID::TYPE_MAT2D: delete (mat2d*) m_pd; break;
case TypeID::TYPE_MAT3D: delete (mat3d*) m_pd; break;
case TypeID::TYPE_MAT3DD: delete (mat3dd*) m_pd; break;
case TypeID::TYPE_MAT3DS: delete (mat3ds*) m_pd; break;
case TypeID::TYPE_MAT3DA: delete (mat3da*) m_pd; break;
case TypeID::TYPE_QUATD: delete (quatd*) m_pd; break;
case TypeID::TYPE_TENS3DS: delete (tens3ds*) m_pd; break;
case TypeID::TYPE_TENS3DRS: delete (tens3drs*) m_pd; break;
case TypeID::TYPE_MATRIX: delete (matrix*) m_pd; break;
case TypeID::TYPE_TENS4D: delete (tens4d*) m_pd; break;
case TypeID::TYPE_TENS4DS: delete (tens4ds*) m_pd; break;
case TypeID::TYPE_TENS4DMM: delete (tens4dmm*) m_pd; break;
default: break;
}
}
m_pd = nullptr;
}
int dataType() const { return m_type; }
template <typename T> T value() { return *((T*)(m_pd)); }
private:
int m_type;
void* m_pd;
friend class DumpStream;
};
public:
// This class is thrown when an error occurs reading the dumpfile
class ReadError{};
public:
//! constructor
DumpStream(FEModel& fem);
//! destructor
virtual ~DumpStream();
//! See if the stream is used for input or output
bool IsSaving() const;
//! See if the stream is used for input
bool IsLoading() const;
//! See if shallow flag is set
bool IsShallow() const;
// open the stream
virtual void Open(bool bsave, bool bshallow);
// get the FE model
FEModel& GetFEModel() { return m_fem; }
// set the write type info flag
void WriteTypeInfo(bool b);
// see if the stream has type info
bool HasTypeInfo() const;
// return total nr of bytes that was serialized
size_t bytesSerialized() const { return m_bytes_serialized; }
public:
// read the next block
bool readBlock(DataBlock& d);
public:
// These functions must be overloaded by derived classes
// and should return the number of bytes serialized
virtual size_t write(const void* pd, size_t size, size_t count) = 0;
virtual size_t read(void* pd, size_t size, size_t count) = 0;
// override function to indicate the end of stream was reached (while reading)
virtual bool EndOfStream() const = 0;
// additional function that need to be overridden
virtual void clear() = 0;
void check();
void LockPointerTable();
void UnlockPointerTable();
public:
// input-output operators (will call correct operator depending on input or output mode)
template <typename T> DumpStream& operator & (T& o);
public: // output operators
DumpStream& operator << (const char* sz);
DumpStream& operator << (char* sz);
DumpStream& operator << (const double a[3][3]);
DumpStream& operator << (std::string& s);
DumpStream& operator << (const std::string& s);
DumpStream& operator << (bool b);
DumpStream& operator << (int n);
template <typename T> DumpStream& operator << (T& o);
template <typename T> DumpStream& operator << (std::vector<T>& o);
template <typename A, typename B> DumpStream& operator << (std::map<A, B>& o);
template <typename T, std::size_t N> DumpStream& operator << (T(&a)[N]);
template <typename T> DumpStream& operator << (T* &a);
template <typename T> DumpStream& operator << (std::vector<T*>& o);
template <typename T> DumpStream& write_raw(const T& o);
public: // input operators
DumpStream& operator >> (char* sz);
DumpStream& operator >> (double a[3][3]);
DumpStream& operator >> (std::string& s);
DumpStream& operator >> (bool& b);
template <typename T> DumpStream& operator >> (T& o);
template <typename T> DumpStream& operator >> (std::vector<T>& o);
template <typename A, typename B> DumpStream& operator >> (std::map<A, B>& o);
template <typename T, std::size_t N> DumpStream& operator >> (T(&a)[N]);
template <typename T> DumpStream& operator >> (T* &a);
template <typename T> DumpStream& operator >> (std::vector<T*>& o);
template <typename T> DumpStream& read_raw(T& o);
private:
int FindPointer(void* p);
void AddPointer(void* p);
DumpStream& write_matrix(matrix& o);
DumpStream& read_matrix(matrix& o);
void writeType(uchar type)
{
m_bytes_serialized += write(&type, sizeof(type), 1);
}
uchar readType()
{
uchar type;
m_bytes_serialized += read(&type, sizeof(type), 1);
return type;
}
bool readType(uchar type)
{
uchar typeRead = readType();
assert(type == typeRead);
return (type == typeRead);
}
private:
bool m_bsave; //!< true if output stream, false for input stream
bool m_bshallow; //!< if true only shallow data needs to be serialized
bool m_btypeInfo; //!< write/read type info
FEModel& m_fem; //!< the FE Model that is being serialized
size_t m_bytes_serialized; //!< number or bytes serialized
bool m_ptr_lock;
std::map<void*, int> m_ptrOut; // used for writing
std::vector<void*> m_ptrIn; // user for reading
};
template <typename T> class typeInfo {};
template <> class typeInfo<int> { public: static uchar typeId() { return (uchar)TypeID::TYPE_INT; }};
template <> class typeInfo<unsigned int> { public: static uchar typeId() { return (uchar)TypeID::TYPE_UINT; }};
template <> class typeInfo<float> { public: static uchar typeId() { return (uchar)TypeID::TYPE_FLOAT; }};
template <> class typeInfo<double> { public: static uchar typeId() { return (uchar)TypeID::TYPE_DOUBLE; }};
template <> class typeInfo<vec2d> { public: static uchar typeId() { return (uchar)TypeID::TYPE_VEC2D; }};
template <> class typeInfo<vec3d> { public: static uchar typeId() { return (uchar)TypeID::TYPE_VEC3D; }};
template <> class typeInfo<mat2d> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MAT3D; }};
template <> class typeInfo<mat3d> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MAT3D; }};
template <> class typeInfo<mat3dd> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MAT3DD; }};
template <> class typeInfo<mat3ds> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MAT3DS; }};
template <> class typeInfo<mat3da> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MAT3DA; }};
template <> class typeInfo<quatd> { public: static uchar typeId() { return (uchar)TypeID::TYPE_QUATD; }};
template <> class typeInfo<tens3ds> { public: static uchar typeId() { return (uchar)TypeID::TYPE_TENS3DS; }};
template <> class typeInfo<tens3drs> { public: static uchar typeId() { return (uchar)TypeID::TYPE_TENS3DRS;}};
template <> class typeInfo<matrix> { public: static uchar typeId() { return (uchar)TypeID::TYPE_MATRIX; }};
template <> class typeInfo<tens4d> { public: static uchar typeId() { return (uchar)TypeID::TYPE_TENS4D; }};
template <> class typeInfo<tens4ds> { public: static uchar typeId() { return (uchar)TypeID::TYPE_TENS4DS; }};
template <> class typeInfo<tens4dmm> { public: static uchar typeId() { return (uchar)TypeID::TYPE_TENS4DMM;}};
template <typename T> DumpStream& DumpStream::write_raw(const T& o)
{
if (m_btypeInfo) writeType(typeInfo<T>::typeId());
m_bytes_serialized += write(&o, sizeof(T), 1);
return *this;
}
template <typename T> DumpStream& DumpStream::read_raw(T& o)
{
if (m_btypeInfo) readType(typeInfo<T>::typeId());
m_bytes_serialized += read(&o, sizeof(T), 1);
return *this;
}
template <typename T> inline DumpStream& DumpStream::operator & (T& o)
{
if (IsSaving()) (*this) << o; else (*this) >> o;
return *this;
}
template <> inline DumpStream& DumpStream::operator << (int& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (unsigned int& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (double& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (vec2d& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (vec3d& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (quatd& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (mat2d& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (mat3d& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (mat3ds& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (mat3dd& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (mat3da& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (tens3ds& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (tens3drs& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (matrix& o) { return write_matrix(o); }
template <> inline DumpStream& DumpStream::operator << (tens4d& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (tens4ds& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator << (tens4dmm& o) { return write_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (int& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (unsigned int& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (double& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (vec2d& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (vec3d& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (quatd& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (mat2d& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (mat3d& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (mat3ds& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (mat3dd& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (mat3da& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (tens3ds& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (tens3drs& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (matrix& o) { return read_matrix(o); }
template <> inline DumpStream& DumpStream::operator >> (tens4d& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (tens4ds& o) { return read_raw(o); }
template <> inline DumpStream& DumpStream::operator >> (tens4dmm& o) { return read_raw(o); }
template <typename T> inline DumpStream& DumpStream::operator << (T& o)
{
AddPointer((void*)&o);
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
o.Serialize(*this);
check();
return *this;
}
template <typename T> inline DumpStream& DumpStream::operator >> (T& o)
{
AddPointer((void*)&o);
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
o.Serialize(*this);
check();
return *this;
}
template <typename T> inline DumpStream& DumpStream::operator << (std::vector<T>& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
int N = (int) o.size();
m_bytes_serialized += write(&N, sizeof(int), 1);
for (int i=0; i<N; ++i) (*this) << o[i];
return *this;
}
template <typename T> inline DumpStream& DumpStream::operator >> (std::vector<T>& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
DumpStream& This = *this;
int N = 0;
m_bytes_serialized += read(&N, sizeof(int), 1);
if (N > 0)
{
o.resize(N);
for (int i = 0; i<N; ++i) (*this) >> o[i];
}
return This;
}
template <> inline DumpStream& DumpStream::operator << (std::vector<double>& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
int N = (int)o.size();
m_bytes_serialized += write(&N, sizeof(int), 1);
write(o.data(), sizeof(double), N);
return *this;
}
template <> inline DumpStream& DumpStream::operator >> (std::vector<double>& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
DumpStream& This = *this;
int N = 0;
m_bytes_serialized += read(&N, sizeof(int), 1);
if (N > 0)
{
o.resize(N);
read(o.data(), sizeof(double), N);
}
return This;
}
template <> inline DumpStream& DumpStream::operator << (std::vector<bool>& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
DumpStream& This = *this;
int N = (int) o.size();
m_bytes_serialized += write(&N, sizeof(int), 1);
for (int i=0; i<N; ++i)
{
bool b = o[i];
This << b;
}
return This;
}
template <> inline DumpStream& DumpStream::operator >> (std::vector<bool>& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
DumpStream& This = *this;
int N;
m_bytes_serialized += read(&N, sizeof(int), 1);
if (N > 0)
{
o.resize(N);
for (int i=0; i<N; ++i)
{
bool b;
This >> b;
o[i] = b;
}
}
return This;
}
template <typename A, typename B> DumpStream& DumpStream::operator << (std::map<A, B>& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
DumpStream& ar = *this;
int N = (int)o.size();
ar << N;
for (typename std::map<A, B>::iterator it = o.begin(); it != o.end(); ++it)
{
const A& a = it->first;
B& b = it->second;
ar << a << b;
}
return ar;
}
template <typename A, typename B> DumpStream& DumpStream::operator >> (std::map<A, B>& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
DumpStream& ar = *this;
int N = 0;
ar >> N;
o.clear();
for (int i=0; i<N; ++i)
{
A a;
B b;
ar >> a >> b;
o[a] = b;
}
return ar;
}
template <typename T, std::size_t N> DumpStream& DumpStream::operator << (T(&a)[N])
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
for (int i = 0; i < N; ++i) (*this) << a[i];
return *this;
}
template <typename T, std::size_t N> DumpStream& DumpStream::operator >> (T(&a)[N])
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
for (int i = 0; i < N; ++i) (*this) >> a[i];
return *this;
}
template <typename T> DumpStream& DumpStream::operator << (T* &a)
{
DumpStream& ar = *this;
// see if we already stored this pointer
int pid = FindPointer((void*)a);
ar << pid;
if (pid != -1) return ar;
// store the pointer in the table
AddPointer((void*)a);
// If we are storing a deep copy we need to store class info
// so that we can reinstantiate the class
if (ar.IsShallow() == false)
{
// store the class info
T::SaveClass(*this, a);
}
// serialize the object (assuming it has a Serialize member)
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
a->Serialize(*this);
return *this;
}
template <typename T> DumpStream& DumpStream::operator << (std::vector<T*>& o)
{
if (m_btypeInfo) writeType(TypeID::TYPE_UNKNOWN);
size_t N = o.size();
m_bytes_serialized += write(&N, sizeof(size_t), 1);
for (size_t i = 0; i < N; ++i)
{
(*this) << o[i];
}
return *this;
}
template <typename T> DumpStream& DumpStream::operator >> (T* &a)
{
DumpStream& ar = *this;
// get the pointer id
int pid;
ar >> pid;
if (pid != -1)
{
a = (T*)(m_ptrIn[pid]);
return ar;
}
// read class identifier and instatiate class
if (ar.IsShallow() == false)
{
a = dynamic_cast<T*>(T::LoadClass(ar, a));
}
// store the pointer
AddPointer((void*)a);
// serialize the object
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
a->Serialize(*this);
return *this;
}
template <typename T> DumpStream& DumpStream::operator >> (std::vector<T*>& o)
{
if (m_btypeInfo) readType(TypeID::TYPE_UNKNOWN);
size_t N = 0;
m_bytes_serialized += read(&N, sizeof(size_t), 1);
if (N > 0)
{
o.resize(N);
for (size_t i = 0; i < N; ++i)
{
(*this) >> o[i];
}
}
return *this;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/fecore_type.h | .h | 2,108 | 71 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_enum.h"
#include "fecore_api.h"
class vec2d;
class vec3d;
class mat3d;
class mat3ds;
template <typename T> struct fecoreType {};
template <> struct fecoreType<double>
{
static FEDataType type() { return FE_DOUBLE; }
static int size() { return 1; }
};
template <> struct fecoreType<vec2d>
{
static FEDataType type() { return FE_VEC2D; }
static int size() { return 2; }
};
template <> struct fecoreType<vec3d>
{
static FEDataType type() { return FE_VEC3D; }
static int size() { return 3; }
};
template <> struct fecoreType<mat3d>
{
static FEDataType type() { return FE_MAT3D; }
static int size() { return 9; }
};
template <> struct fecoreType<mat3ds>
{
static FEDataType type() { return FE_MAT3DS; }
static int size() { return 6; }
};
FECORE_API int fecore_data_size(FEDataType type);
| Unknown |
3D | febiosoftware/FEBio | FECore/tools.h | .h | 2,469 | 47 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
#include <vector>
#include <complex>
FECORE_API void linmin(double* p, double* xi, int n, double* fret, double(*fnc)(double[]));
FECORE_API void powell(double* p, double* xi, int n, double ftol, int* iter, double* fret, double(*fnc)(double[]));
FECORE_API double brent(double ax, double bx, double cx, double(*f)(double), double tol, double* xmin);
FECORE_API void mnbrak(double* ax, double* bx, double* cx, double* fa, double* fb, double* fc, double(*fnc)(double));
FECORE_API double golden(double ax, double bx, double cx, double(*f)(double), double tol, double* xmin);
FECORE_API double zbrent(double f(double, void*), double x1, double x2, double tol, void* data);
FECORE_API bool zbrac(double f(double, void*), double& x1, double& x2, void* data);
FECORE_API void solve_3x3(double A[3][3], double b[3], double x[3]);
FECORE_API bool LinearRegression(const std::vector<std::pair<double, double> >& data, std::pair<double, double>& res);
FECORE_API bool NonlinearRegression(const std::vector<std::pair<double, double> >& data, std::vector<double>& res, int func);
FECORE_API bool solvepoly(int n, std::vector<double> a, double& x, bool nwt = true);
| Unknown |
3D | febiosoftware/FEBio | FECore/DumpMemStream.cpp | .cpp | 3,663 | 132 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "DumpMemStream.h"
#include <assert.h>
#include <memory.h>
//-----------------------------------------------------------------------------
DumpMemStream::DumpMemStream(FEModel& fem) : DumpStream(fem)
{
m_pb = 0;
m_pd = 0;
m_nsize = 0;
m_nreserved = 0;
m_growsize = 16777216;
m_growcounter = 0;
Open(true, true);
}
//-----------------------------------------------------------------------------
void DumpMemStream::clear()
{
m_pd = m_pb;
m_nsize = 0;
// Since we can't read from an empty stream
// we restore write mode.
Open(true, true);
}
//-----------------------------------------------------------------------------
void DumpMemStream::Open(bool bsave, bool bshallow)
{
DumpStream::Open(bsave, bshallow);
if (m_pb) set_position(0);
}
//-----------------------------------------------------------------------------
bool DumpMemStream::EndOfStream() const
{
return (bytesSerialized() >= m_nsize);
}
//-----------------------------------------------------------------------------
DumpMemStream::~DumpMemStream()
{
delete[] m_pb;
}
//-----------------------------------------------------------------------------
void DumpMemStream::set_position(size_t l)
{
assert((l >= 0) && (l < m_nreserved));
m_pd = m_pb + l;
}
//-----------------------------------------------------------------------------
void DumpMemStream::grow_buffer(size_t l)
{
if (l <= 0) return;
if (l > m_growsize) m_growsize = l;
size_t newSize = m_nreserved + m_growsize;
char* pnew = new char[newSize];
if (m_pb)
{
memcpy(pnew, m_pb, m_nreserved);
delete [] m_pb;
}
m_pb = pnew;
m_pd = m_pb + m_nsize;
m_nreserved = newSize;
m_growsize = m_nreserved / 2;
m_growcounter++;
}
//-----------------------------------------------------------------------------
size_t DumpMemStream::write(const void* pd, size_t size, size_t count)
{
assert(IsSaving());
size_t nsize = count*size;
size_t lpos = (size_t)(m_pd - m_pb);
if (lpos + nsize > m_nreserved) grow_buffer(nsize);
memcpy(m_pd, pd, nsize);
m_pd += nsize;
lpos += nsize;
if (lpos > m_nsize) m_nsize = lpos;
return nsize;
}
//-----------------------------------------------------------------------------
size_t DumpMemStream::read(void* pd, size_t size, size_t count)
{
assert(IsSaving()==false);
size_t nsize = count*size;
memcpy(pd, m_pd, nsize);
m_pd += nsize;
return nsize;
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens3d.h | .h | 5,894 | 163 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "mat3d.h"
#include "tensor_base.h"
//-----------------------------------------------------------------------------
// The following classes are defined in this file
class tens3ds; // symmetric 3o tensor
class tens3drs; // right-conjugate symmetric 3o tensor
class tens3dls; // left-conjugate symmetric 3o tensor
class tens3d; // general 3o tensor (no symmetry)
//-----------------------------------------------------------------------------
// traits for these classes defining the number of components
template <> class tensor_traits<tens3ds > {public: enum { NNZ = 10}; };
template <> class tensor_traits<tens3drs> {public: enum { NNZ = 18}; };
template <> class tensor_traits<tens3dls> {public: enum { NNZ = 18}; };
template <> class tensor_traits<tens3d > {public: enum { NNZ = 27}; };
//-----------------------------------------------------------------------------
//! Class for 3rd order tensor with full symmetry Tijk = Tjik = Tkji = Tikj = Tkij = Tjki (only 10 out of 27 components are unique)
// We store this tensor as a 1x10 array.
// [T] = [T111 T112 T113 T122 T123 T133 T222 T223 T233 T333]
// = T0 T1 T2 T3 T4 T5 T6 T7 T8 T9
class tens3ds : public tensor_base<tens3ds>
{
public:
// constructors
tens3ds(){}
// access operator
double operator () (int i, int j, int k) const;
vec3d contractdyad1(const vec3d& v);
double tripledot(const tens3ds& H);
};
tens3ds dyad3s(const vec3d& l, const vec3d& r);
//-----------------------------------------------------------------------------
//! Class for 3rd order tensor with right-conjugate symmetry Gijk = Gikj (only 18 out of 27 components are unique)
// We store this tensor as a 1x18 array.
// [G] = [G111 G112 G113 G122 G123 G133 G211 G212 G213 G222 G223 G233 G311 G312 G313 G322 G323 G333]
// = G0 G1 G2 G3 G4 G5 G6 G7 G8 G9 G10 G11 G12 G13 G14 G15 G16 G17
class tens3drs : public tensor_base<tens3drs>
{
public:
// constructors
explicit tens3drs(double a);
tens3drs(){}
// access operator
double operator () (int i, int j, int k) const;
double& operator () (int i, int j, int k);
vec3d contractdyad1(const vec3d& v) const;
vec3d contract2s(const mat3ds& s) const;
double tripledot(const tens3drs& H) const;
vec3d contractdyad2(const vec3d& v, const vec3d& w);
tens3dls transpose();
void contractleg2(const mat3d& F, int leg);
};
tens3drs operator * (const mat3d& F, const tens3drs& t);
tens3drs dyad3rs(const vec3d& l, const vec3d& r);
tens3drs dyad3rs(const mat3d& L, const vec3d& r);
//-----------------------------------------------------------------------------
//! Class for 3rd order tensor with left-conjugate symmetry Gijk = Gjik (only 18 out of 27 components are unique)
// We store this tensor as a 1x18 array.
// [G] = [G111 G112 G113 G121 G122 G123 G131 G132 G133 G221 G222 G223 G231 G232 G233 G331 G332 G333]
// = G0 G1 G2 G3 G4 G5 G6 G7 G8 G9 G10 G11 G12 G13 G14 G15 G16 G17
class tens3dls : public tensor_base<tens3dls>
{
public:
// constructors
tens3dls(){}
tens3dls operator * (const mat3d& F) const;
tens3dls operator * (const double& f) const;
// transpose
tens3drs transpose();
vec3d trace();
tens3d generalize();
};
tens3dls dyad3ls(const mat3ds& L, const vec3d& r);
//-----------------------------------------------------------------------------
//! Class for 3rd order tensor with no symmetry (27 components)
// Due to symmetry we can store this tensor as a 1x27 array.
// [T] = [T111 T112 T113 T121 T122 T123 T131 T132 T133 T211 T212 T213 T221 T222 T223 T231 T232 T233 T311 T312 T313 T321 T322 T323 T331 T332 T333
// = T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15 T16 T17 T18 T19 T20 T21 T22 T23 T24 T25 T26
class tens3d : public tensor_base<tens3d>
{
public:
// constructors
tens3d(){}
explicit tens3d(double a);
// access operators
double operator () (int i, int j, int k) const;
double& operator () (int i, int j, int k);
// return symmetric tens3ds
tens3ds symm();
// right transpose
tens3d transposer();
//Contract by 2nd order tensor
vec3d contract2(const mat3d& s) const;
//Contract on right by vector
mat3d contract1(const vec3d& v) const;
};
tens3d operator + (const tens3dls& l, const tens3drs& r);
inline tens3d operator + (const tens3drs& r, const tens3dls& l) { return l+r; }
// The following file contains the actual definition of the class functions
#include "tens3ds.hpp"
#include "tens3drs.hpp"
#include "tens3dls.hpp"
#include "tens3d.hpp"
| Unknown |
3D | febiosoftware/FEBio | FECore/FECoreClass.cpp | .cpp | 1,427 | 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 "FECoreClass.h"
BEGIN_FECORE_CLASS(FECoreClass, FECoreBase)
END_FECORE_CLASS();
FECoreClass::FECoreClass(FEModel* fem) : FECoreBase(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/LUSolver.h | .h | 2,352 | 71 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "LinearSolver.h"
#include "DenseMatrix.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
//! LU decomposition solver
//! This solver performs an LU decomposition and uses a backsolving algorithm
//! to solve the equations.
//! This solver uses the FullMatrix class and therefore is not the preferred
//! solver. It should only be used for small problems and only when the other
//! solvers are not adequate.
class FECORE_API LUSolver : public LinearSolver
{
public:
//! constructor
LUSolver(FEModel* fem = nullptr);
//! Pre-process data
bool PreProcess() override;
//! Factor matrix
bool Factor() override;
//! solve using factored matrix
bool BackSolve(double* x, double* b) override;
//! Clean-up
void Destroy() override;
//! Create a sparse matrix
SparseMatrix* CreateSparseMatrix(Matrix_Type ntype) override;
//! Set the matrix
void SetMatrix(FECore::DenseMatrix* pA);
protected:
std::vector<int> indx; //!< indices
FECore::DenseMatrix* m_pA; //!< sparse matrix
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEBroydenStrategy.h | .h | 2,388 | 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 "matrix.h"
#include "FENewtonStrategy.h"
//-----------------------------------------------------------------------------
//! This class implements the Broyden quasi-newton strategy.
class FECORE_API FEBroydenStrategy : public FENewtonStrategy
{
public:
//! constructor
FEBroydenStrategy(FEModel* fem);
//! Initialization
bool Init() override;
//! perform a quasi-Newton udpate
bool Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1) override;
//! solve the equations
void SolveEquations(vector<double>& x, vector<double>& b) override;
//! Presolve update
virtual void PreSolveUpdate() override;
private:
// keep a pointer to the linear solver
LinearSolver* m_plinsolve; //!< pointer to linear solver
int m_neq; //!< number of equations
bool m_bnewStep;
// Broyden update vectors
matrix m_R; //!< Broyden update vector "r"
matrix m_D; //!< Broydeb update vector "delta"
vector<double> m_rho; //!< temp vectors for calculating Broyden update vectors
vector<double> m_q; //!< temp storage for q
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MObjBuilder.h | .h | 3,289 | 132 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "MathObject.h"
class MathError
{
public:
MathError(int n, const char* sz) : m_npos(n), m_szerr(sz){}
int GetPosition() { return m_npos; }
const char* GetErrorStr() { return m_szerr; }
protected:
int m_npos;
const char* m_szerr;
};
class FECORE_API MObjBuilder
{
private:
enum Token_value {
NAME, NUMBER, END,
EQUAL='=', PLUS='+', MINUS='-', MUL='*', DIV='/', MOD = '%', POW='^', FACT='!', TRANS = '\'',
LP='(', RP=')', AB = '|', LB = '[', RB = ']', LC='{', RC='}',
CONTRACT = ':',
COMMA = ',', PRINT, EQUALITY
};
public:
MObjBuilder();
bool Create(MSimpleExpression* mo, const std::string& ex, bool eval);
MathObject* Create(const std::string& ex , bool eval);
void setAutoVars(bool b) { m_autoVars = b; }
static bool Add1DFunction(const std::string& name, double (*f)(double));
protected:
MItem* create();
MItem* create_sequence();
MItem* expr();
MItem* term ();
MItem* power();
MItem* prim ();
MItem* var ();
MItem* func ();
MItem* fnc1d();
MItem* fnc2d();
MItem* fncnd();
MItem* fmat ();
MItem* fsym();
MItem* sequence();
double get_number();
void get_name(char* str);
int Position() { return (int)(m_szexpr - m_szorg); }
protected:
MItem* derive ();
MItem* replace ();
MItem* taylor ();
MItem* integrate();
MItem* expand ();
MItem* simplify ();
MItem* solve ();
MItem* collect ();
MItem* identity ();
MItem* mdiag ();
protected:
MathObject* m_po;
Token_value get_token();
Token_value curr_tok;
// read an expression
MItem* read_math();
// read a required token
void read_token(Token_value n, bool bnext = true);
// read a variable name
MVariable* read_var(bool badd = false);
// read an int
int read_int();
// read a double
double read_double();
// process string substitutions
std::string processStrings(const std::string& ex);
protected:
const char* m_szexpr, *m_szorg;
double number_value;
char string_value[256];
bool m_autoVars; // add new variables automatically
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFaceList.h | .h | 3,053 | 131 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
class FEMesh;
class FEElementList;
class FEElemElemList;
class FEEdgeList;
class FECORE_API FEFaceList
{
public:
struct FECORE_API FACE
{
int ntype; // 3 = triangle, 4 = quad
int node[4];
int nsurf; // 1 if facet is on surface
int nbr[4]; // neighbor list
bool IsEqual(int* n) const;
bool HasEdge(int a, int b) const;
};
public:
FEFaceList();
FEFaceList(const FEFaceList& faceList);
bool Create(FEMesh& mesh, FEElemElemList& ENL);
int Faces() const;
const FACE& operator [] (int i) const;
const FACE& Face(int i) const;
FEMesh* GetMesh();
// Extract the surface only
FEFaceList GetSurface() const;
// build the neighbor list
void BuildNeighbors();
protected:
FEMesh* m_mesh;
std::vector<FACE> m_faceList;
};
class FECORE_API FENodeFaceList
{
public:
FENodeFaceList();
bool Create(FEFaceList& FL);
int Faces(int node) const;
const std::vector<int>& FaceList(int node) const;
private:
std::vector<std::vector<int> > m_NFL;
};
class FECORE_API FEElementFaceList
{
public:
FEElementFaceList();
bool Create(FEElementList& elemList, FEFaceList& faceList);
int Faces(int elem) const;
const std::vector<int>& FaceList(int elem) const;
private:
std::vector<std::vector<int> > m_EFL;
};
class FECORE_API FEFaceEdgeList
{
public:
FEFaceEdgeList();
bool Create(FEFaceList& faceList, FEEdgeList& edgeList);
int Edges(int nface);
const std::vector<int>& EdgeList(int nface) const;
private:
std::vector<std::vector<int> > m_FEL;
};
class FECORE_API FENodeEdgeList
{
public:
FENodeEdgeList();
bool Create(FEEdgeList& edgeList);
const std::vector<int>& EdgeList(int node) const { return m_NEL[node]; }
private:
std::vector<std::vector<int> > m_NEL;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tens4ds.hpp | .hpp | 68,041 | 1,511 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// NOTE: This file is automatically included from tens4d.h
// Users should not include this file manually!
#include "matrix.h"
inline tens4ds::tens4ds(const double g)
{
d[ 0] =
d[ 1] = d[ 2] =
d[ 3] = d[ 4] = d[ 5] =
d[ 6] = d[ 7] = d[ 8] = d[ 9] =
d[10] = d[11] = d[12] = d[13] = d[14] =
d[15] = d[16] = d[17] = d[18] = d[19] = d[20] = g;
}
inline tens4ds::tens4ds(double m[6][6])
{
d[ 0] = m[0][0];
d[ 1] = m[0][1]; d[ 2] = m[1][1];
d[ 3] = m[0][2]; d[ 4] = m[1][2]; d[ 5] = m[2][2];
d[ 6] = m[0][3]; d[ 7] = m[1][3]; d[ 8] = m[2][3]; d[ 9] = m[3][3];
d[10] = m[0][4]; d[11] = m[1][4]; d[12] = m[2][4]; d[13] = m[3][4]; d[14] = m[4][4];
d[15] = m[0][5]; d[16] = m[1][5]; d[17] = m[2][5]; d[18] = m[3][5]; d[19] = m[4][5]; d[20] = m[5][5];
}
inline double& tens4ds::operator () (int i, int j, int k, int l)
{
const int m[3][3] = {{0,3,5},{3,1,4},{5,4,2}};
tens4ds& T = (*this);
return T(m[i][j], m[k][l]);
}
inline double tens4ds::operator () (int i, int j, int k, int l) const
{
const int m[3][3] = {{0,3,5},{3,1,4},{5,4,2}};
const tens4ds& T = (*this);
return T(m[i][j], m[k][l]);
}
inline double& tens4ds::operator () (int i, int j)
{
const int m[6] = {0, 1, 3, 6, 10, 15};
if (i<=j) return d[m[j]+i]; else return d[m[i]+j];
}
inline double tens4ds::operator () (int i, int j) const
{
const int m[6] = {0, 1, 3, 6, 10, 15};
if (i<=j) return d[m[j]+i]; else return d[m[i]+j];
}
// operator +
inline tens4ds tens4ds::operator + (const tens4ds& t) const
{
tens4ds s;
// for (int i=0; i<NNZ; i++)
// s.d[i] = d[i] + t.d[i];
s.d[ 0] = d[ 0] + t.d[ 0];
s.d[ 1] = d[ 1] + t.d[ 1];
s.d[ 2] = d[ 2] + t.d[ 2];
s.d[ 3] = d[ 3] + t.d[ 3];
s.d[ 4] = d[ 4] + t.d[ 4];
s.d[ 5] = d[ 5] + t.d[ 5];
s.d[ 6] = d[ 6] + t.d[ 6];
s.d[ 7] = d[ 7] + t.d[ 7];
s.d[ 8] = d[ 8] + t.d[ 8];
s.d[ 9] = d[ 9] + t.d[ 9];
s.d[10] = d[10] + t.d[10];
s.d[11] = d[11] + t.d[11];
s.d[12] = d[12] + t.d[12];
s.d[13] = d[13] + t.d[13];
s.d[14] = d[14] + t.d[14];
s.d[15] = d[15] + t.d[15];
s.d[16] = d[16] + t.d[16];
s.d[17] = d[17] + t.d[17];
s.d[18] = d[18] + t.d[18];
s.d[19] = d[19] + t.d[19];
s.d[20] = d[20] + t.d[20];
return s;
}
// operator -
inline tens4ds tens4ds::operator - (const tens4ds& t) const
{
tens4ds s;
// for (int i=0; i<NNZ; i++)
// s.d[i] = d[i] - t.d[i];
s.d[ 0] = d[ 0] - t.d[ 0];
s.d[ 1] = d[ 1] - t.d[ 1];
s.d[ 2] = d[ 2] - t.d[ 2];
s.d[ 3] = d[ 3] - t.d[ 3];
s.d[ 4] = d[ 4] - t.d[ 4];
s.d[ 5] = d[ 5] - t.d[ 5];
s.d[ 6] = d[ 6] - t.d[ 6];
s.d[ 7] = d[ 7] - t.d[ 7];
s.d[ 8] = d[ 8] - t.d[ 8];
s.d[ 9] = d[ 9] - t.d[ 9];
s.d[10] = d[10] - t.d[10];
s.d[11] = d[11] - t.d[11];
s.d[12] = d[12] - t.d[12];
s.d[13] = d[13] - t.d[13];
s.d[14] = d[14] - t.d[14];
s.d[15] = d[15] - t.d[15];
s.d[16] = d[16] - t.d[16];
s.d[17] = d[17] - t.d[17];
s.d[18] = d[18] - t.d[18];
s.d[19] = d[19] - t.d[19];
s.d[20] = d[20] - t.d[20];
return s;
}
// operator *
inline tens4ds tens4ds::operator * (double g) const
{
tens4ds s;
// for (int i=0; i<NNZ; i++)
// s.d[i] = g*d[i];
s.d[ 0] = g*d[ 0];
s.d[ 1] = g*d[ 1];
s.d[ 2] = g*d[ 2];
s.d[ 3] = g*d[ 3];
s.d[ 4] = g*d[ 4];
s.d[ 5] = g*d[ 5];
s.d[ 6] = g*d[ 6];
s.d[ 7] = g*d[ 7];
s.d[ 8] = g*d[ 8];
s.d[ 9] = g*d[ 9];
s.d[10] = g*d[10];
s.d[11] = g*d[11];
s.d[12] = g*d[12];
s.d[13] = g*d[13];
s.d[14] = g*d[14];
s.d[15] = g*d[15];
s.d[16] = g*d[16];
s.d[17] = g*d[17];
s.d[18] = g*d[18];
s.d[19] = g*d[19];
s.d[20] = g*d[20];
return s;
}
// operator /
inline tens4ds tens4ds::operator / (double g) const
{
tens4ds s;
// for (int i=0; i<NNZ; i++)
// s.d[i] = d[i]/g;
s.d[ 0] = d[ 0]/g;
s.d[ 1] = d[ 1]/g;
s.d[ 2] = d[ 2]/g;
s.d[ 3] = d[ 3]/g;
s.d[ 4] = d[ 4]/g;
s.d[ 5] = d[ 5]/g;
s.d[ 6] = d[ 6]/g;
s.d[ 7] = d[ 7]/g;
s.d[ 8] = d[ 8]/g;
s.d[ 9] = d[ 9]/g;
s.d[10] = d[10]/g;
s.d[11] = d[11]/g;
s.d[12] = d[12]/g;
s.d[13] = d[13]/g;
s.d[14] = d[14]/g;
s.d[15] = d[15]/g;
s.d[16] = d[16]/g;
s.d[17] = d[17]/g;
s.d[18] = d[18]/g;
s.d[19] = d[19]/g;
s.d[20] = d[20]/g;
return s;
}
// assignment operator +=
inline tens4ds& tens4ds::operator += (const tens4ds& t)
{
// for (int i=0; i<NNZ; i++)
// d[i] += t.d[i];
d[ 0] += t.d[ 0];
d[ 1] += t.d[ 1];
d[ 2] += t.d[ 2];
d[ 3] += t.d[ 3];
d[ 4] += t.d[ 4];
d[ 5] += t.d[ 5];
d[ 6] += t.d[ 6];
d[ 7] += t.d[ 7];
d[ 8] += t.d[ 8];
d[ 9] += t.d[ 9];
d[10] += t.d[10];
d[11] += t.d[11];
d[12] += t.d[12];
d[13] += t.d[13];
d[14] += t.d[14];
d[15] += t.d[15];
d[16] += t.d[16];
d[17] += t.d[17];
d[18] += t.d[18];
d[19] += t.d[19];
d[20] += t.d[20];
return (*this);
}
// assignment operator -=
inline tens4ds& tens4ds::operator -= (const tens4ds& t)
{
// for (int i=0; i<NNZ; i++)
// d[i] -= t.d[i];
d[ 0] -= t.d[ 0];
d[ 1] -= t.d[ 1];
d[ 2] -= t.d[ 2];
d[ 3] -= t.d[ 3];
d[ 4] -= t.d[ 4];
d[ 5] -= t.d[ 5];
d[ 6] -= t.d[ 6];
d[ 7] -= t.d[ 7];
d[ 8] -= t.d[ 8];
d[ 9] -= t.d[ 9];
d[10] -= t.d[10];
d[11] -= t.d[11];
d[12] -= t.d[12];
d[13] -= t.d[13];
d[14] -= t.d[14];
d[15] -= t.d[15];
d[16] -= t.d[16];
d[17] -= t.d[17];
d[18] -= t.d[18];
d[19] -= t.d[19];
d[20] -= t.d[20];
return (*this);
}
// assignment operator *=
inline tens4ds& tens4ds::operator *= (double g)
{
// for (int i=0; i<NNZ; i++)
// d[i] *= g;
d[ 0] *= g;
d[ 1] *= g;
d[ 2] *= g;
d[ 3] *= g;
d[ 4] *= g;
d[ 5] *= g;
d[ 6] *= g;
d[ 7] *= g;
d[ 8] *= g;
d[ 9] *= g;
d[10] *= g;
d[11] *= g;
d[12] *= g;
d[13] *= g;
d[14] *= g;
d[15] *= g;
d[16] *= g;
d[17] *= g;
d[18] *= g;
d[19] *= g;
d[20] *= g;
return (*this);
}
// assignment operator /=
inline tens4ds& tens4ds::operator /= (double g)
{
// for (int i=0; i<NNZ; i++)
// d[i] /= g;
d[ 0] /= g;
d[ 1] /= g;
d[ 2] /= g;
d[ 3] /= g;
d[ 4] /= g;
d[ 5] /= g;
d[ 6] /= g;
d[ 7] /= g;
d[ 8] /= g;
d[ 9] /= g;
d[10] /= g;
d[11] /= g;
d[12] /= g;
d[13] /= g;
d[14] /= g;
d[15] /= g;
d[16] /= g;
d[17] /= g;
d[18] /= g;
d[19] /= g;
d[20] /= g;
return (*this);
}
// unary operator -
inline tens4ds tens4ds::operator - () const
{
tens4ds s;
s.d[ 0] = -d[ 0];
s.d[ 1] = -d[ 1];
s.d[ 2] = -d[ 2];
s.d[ 3] = -d[ 3];
s.d[ 4] = -d[ 4];
s.d[ 5] = -d[ 5];
s.d[ 6] = -d[ 6];
s.d[ 7] = -d[ 7];
s.d[ 8] = -d[ 8];
s.d[ 9] = -d[ 9];
s.d[10] = -d[10];
s.d[11] = -d[11];
s.d[12] = -d[12];
s.d[13] = -d[13];
s.d[14] = -d[14];
s.d[15] = -d[15];
s.d[16] = -d[16];
s.d[17] = -d[17];
s.d[18] = -d[18];
s.d[19] = -d[19];
s.d[20] = -d[20];
return s;
}
// trace
// C.tr() = I:C:I
inline double tens4ds::tr() const
{
return (d[0]+d[2]+d[5]+2*(d[1]+d[3]+d[4]));
}
// intialize to zero
inline void tens4ds::zero()
{
d[0] = d[1] = d[2] = d[3] = d[4] = d[5] = d[6] = d[7] = d[8] = d[9] =
d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = d[18] = d[19] = d[20] = 0;
}
// extract 6x6 matrix
inline void tens4ds::extract(double D[6][6])
{
D[0][0] = d[0]; D[0][1] = d[1]; D[0][2] = d[3]; D[0][3] = d[6]; D[0][4] = d[10]; D[0][5] = d[15];
D[1][0] = d[1]; D[1][1] = d[2]; D[1][2] = d[4]; D[1][3] = d[7]; D[1][4] = d[11]; D[1][5] = d[16];
D[2][0] = d[3]; D[2][1] = d[4]; D[2][2] = d[5]; D[2][3] = d[8]; D[2][4] = d[12]; D[2][5] = d[17];
D[3][0] = d[6]; D[3][1] = d[7]; D[3][2] = d[8]; D[3][3] = d[9]; D[3][4] = d[13]; D[3][5] = d[18];
D[4][0] = d[10]; D[4][1] = d[11]; D[4][2] = d[12]; D[4][3] = d[13]; D[4][4] = d[14]; D[4][5] = d[19];
D[5][0] = d[15]; D[5][1] = d[16]; D[5][2] = d[17]; D[5][3] = d[18]; D[5][4] = d[19]; D[5][5] = d[20];
}
//-----------------------------------------------------------------------------
// (a dyad1s a)_ijkl = a_ij a_kl
inline tens4ds dyad1s(const mat3dd& a)
{
tens4ds c;
c.d[ 0] = a.xx()*a.xx();
c.d[ 1] = a.xx()*a.yy();
c.d[ 2] = a.yy()*a.yy();
c.d[ 3] = a.xx()*a.zz();
c.d[ 4] = a.yy()*a.zz();
c.d[ 5] = a.zz()*a.zz();
c.d[ 6] = 0.0;
c.d[ 7] = 0.0;
c.d[ 8] = 0.0;
c.d[ 9] = 0.0;
c.d[10] = 0.0;
c.d[11] = 0.0;
c.d[12] = 0.0;
c.d[13] = 0.0;
c.d[14] = 0.0;
c.d[15] = 0.0;
c.d[16] = 0.0;
c.d[17] = 0.0;
c.d[18] = 0.0;
c.d[19] = 0.0;
c.d[20] = 0.0;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad1s a)_ijkl = a_ij a_kl
inline tens4ds dyad1s(const mat3ds& a)
{
tens4ds c;
c.d[ 0] = a.xx()*a.xx();
c.d[ 1] = a.xx()*a.yy();
c.d[ 2] = a.yy()*a.yy();
c.d[ 3] = a.xx()*a.zz();
c.d[ 4] = a.yy()*a.zz();
c.d[ 5] = a.zz()*a.zz();
c.d[ 6] = a.xx()*a.xy();
c.d[ 7] = a.xy()*a.yy();
c.d[ 8] = a.xy()*a.zz();
c.d[ 9] = a.xy()*a.xy();
c.d[10] = a.xx()*a.yz();
c.d[11] = a.yy()*a.yz();
c.d[12] = a.yz()*a.zz();
c.d[13] = a.xy()*a.yz();
c.d[14] = a.yz()*a.yz();
c.d[15] = a.xx()*a.xz();
c.d[16] = a.xz()*a.yy();
c.d[17] = a.xz()*a.zz();
c.d[18] = a.xy()*a.xz();
c.d[19] = a.xz()*a.yz();
c.d[20] = a.xz()*a.xz();
return c;
}
//-----------------------------------------------------------------------------
// (a dyad1s b)_ijkl = a_ij b_kl + b_ij a_kl
inline tens4ds dyad1s(const mat3ds& a, const mat3ds& b)
{
tens4ds c;
c.d[ 0] = 2*a.xx()*b.xx();
c.d[ 1] = a.xx()*b.yy() + b.xx()*a.yy();
c.d[ 2] = 2*a.yy()*b.yy();
c.d[ 3] = a.xx()*b.zz() + b.xx()*a.zz();
c.d[ 4] = a.yy()*b.zz() + b.yy()*a.zz();
c.d[ 5] = 2*a.zz()*b.zz();
c.d[ 6] = a.xx()*b.xy() + b.xx()*a.xy();
c.d[ 7] = a.xy()*b.yy() + b.xy()*a.yy();
c.d[ 8] = a.xy()*b.zz() + b.xy()*a.zz();
c.d[ 9] = 2*a.xy()*b.xy();
c.d[10] = a.xx()*b.yz() + b.xx()*a.yz();
c.d[11] = a.yy()*b.yz() + b.yy()*a.yz();
c.d[12] = a.yz()*b.zz() + b.yz()*a.zz();
c.d[13] = a.xy()*b.yz() + b.xy()*a.yz();
c.d[14] = 2*a.yz()*b.yz();
c.d[15] = a.xx()*b.xz() + b.xx()*a.xz();
c.d[16] = a.xz()*b.yy() + b.xz()*a.yy();
c.d[17] = a.xz()*b.zz() + b.xz()*a.zz();
c.d[18] = a.xy()*b.xz() + b.xy()*a.xz();
c.d[19] = a.xz()*b.yz() + b.xz()*a.yz();
c.d[20] = 2*a.xz()*b.xz();
return c;
}
//-----------------------------------------------------------------------------
// (a dyad1s b)_ijkl = a_ij b_kl + b_ij a_kl
inline tens4ds dyad1s(const mat3dd& a, const mat3dd& b)
{
tens4ds c;
c.d[ 0] = 2*a.xx()*b.xx();
c.d[ 1] = a.xx()*b.yy() + b.xx()*a.yy();
c.d[ 2] = 2*a.yy()*b.yy();
c.d[ 3] = a.xx()*b.zz() + b.xx()*a.zz();
c.d[ 4] = a.yy()*b.zz() + b.yy()*a.zz();
c.d[ 5] = 2*a.zz()*b.zz();
c.d[ 6] = 0.0;
c.d[ 7] = 0.0;
c.d[ 8] = 0.0;
c.d[ 9] = 0.0;
c.d[10] = 0.0;
c.d[11] = 0.0;
c.d[12] = 0.0;
c.d[13] = 0.0;
c.d[14] = 0.0;
c.d[15] = 0.0;
c.d[16] = 0.0;
c.d[17] = 0.0;
c.d[18] = 0.0;
c.d[19] = 0.0;
c.d[20] = 0.0;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad1s b)_ijkl = a_ij b_kl + b_ij a_kl
inline tens4ds dyad1s(const mat3ds& a, const mat3dd& b)
{
tens4ds c;
c.d[ 0] = 2*a.xx()*b.xx();
c.d[ 1] = a.xx()*b.yy() + b.xx()*a.yy();
c.d[ 2] = 2*a.yy()*b.yy();
c.d[ 3] = a.xx()*b.zz() + b.xx()*a.zz();
c.d[ 4] = a.yy()*b.zz() + b.yy()*a.zz();
c.d[ 5] = 2*a.zz()*b.zz();
c.d[ 6] = b.xx()*a.xy();
c.d[ 7] = a.xy()*b.yy();
c.d[ 8] = a.xy()*b.zz();
c.d[ 9] = 0.0;
c.d[10] = b.xx()*a.yz();
c.d[11] = b.yy()*a.yz();
c.d[12] = a.yz()*b.zz();
c.d[13] = 0.0;
c.d[14] = 0.0;
c.d[15] = b.xx()*a.xz();
c.d[16] = a.xz()*b.yy();
c.d[17] = a.xz()*b.zz();
c.d[18] = 0.0;
c.d[19] = 0.0;
c.d[20] = 0.0;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad4s a)_ijkl = (a_ik a_jl + a_il a_jk)/2
inline tens4ds dyad4s(const mat3dd& a)
{
tens4ds c;
c.d[ 0] = a.xx()*a.xx();
c.d[ 1] = 0.0;
c.d[ 2] = a.yy()*a.yy();
c.d[ 3] = 0.0;
c.d[ 4] = 0.0;
c.d[ 5] = a.zz()*a.zz();
c.d[ 6] = 0.0;
c.d[ 7] = 0.0;
c.d[ 8] = 0.0;
c.d[ 9] = a.xx()*a.yy()/2;
c.d[10] = 0.0;
c.d[11] = 0.0;
c.d[12] = 0.0;
c.d[13] = 0.0;
c.d[14] = a.yy()*a.zz()/2;
c.d[15] = 0.0;
c.d[16] = 0.0;
c.d[17] = 0.0;
c.d[18] = 0.0;
c.d[19] = 0.0;
c.d[20] = a.xx()*a.zz()/2;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad4s a)_ijkl = (a_ik a_jl + a_il a_jk)/2
inline tens4ds dyad4s(const mat3ds& a)
{
tens4ds c;
c.d[ 0] = a.xx()*a.xx();
c.d[ 1] = a.xy()*a.xy();
c.d[ 2] = a.yy()*a.yy();
c.d[ 3] = a.xz()*a.xz();
c.d[ 4] = a.yz()*a.yz();
c.d[ 5] = a.zz()*a.zz();
c.d[ 6] = a.xx()*a.xy();
c.d[ 7] = a.xy()*a.yy();
c.d[ 8] = a.xz()*a.yz();
c.d[ 9] = (a.xx()*a.yy() + a.xy()*a.xy())/2;
c.d[10] = a.xy()*a.xz();
c.d[11] = a.yy()*a.yz();
c.d[12] = a.yz()*a.zz();
c.d[13] = (a.xy()*a.yz() + a.xz()*a.yy())/2;
c.d[14] = (a.yy()*a.zz() + a.yz()*a.yz())/2;
c.d[15] = a.xx()*a.xz();
c.d[16] = a.xy()*a.yz();
c.d[17] = a.xz()*a.zz();
c.d[18] = (a.xx()*a.yz() + a.xy()*a.xz())/2;
c.d[19] = (a.xy()*a.zz() + a.xz()*a.yz())/2;
c.d[20] = (a.xx()*a.zz() + a.xz()*a.xz())/2;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad4s b)_ijkl = (a_ik b_jl + a_il b_jk)/2 + (b_ik a_jl + b_il a_jk)/2
inline tens4ds dyad4s(const mat3ds& a, const mat3dd& b)
{
tens4ds c;
c.d[ 0] = 2*a.xx()*b.xx();
c.d[ 1] = 0.0;
c.d[ 2] = 2*a.yy()*b.yy();
c.d[ 3] = 0.0;
c.d[ 4] = 0.0;
c.d[ 5] = 2*a.zz()*b.zz();
c.d[ 6] = b.xx()*a.xy();
c.d[ 7] = a.xy()*b.yy();
c.d[ 8] = 0.0;
c.d[ 9] = (a.xx()*b.yy() + b.xx()*a.yy())/2;
c.d[10] = 0.0;
c.d[11] = b.yy()*a.yz();
c.d[12] = a.yz()*b.zz();
c.d[13] = a.xz()*b.yy()/2;
c.d[14] = (a.yy()*b.zz() + b.yy()*a.zz())/2;
c.d[15] = b.xx()*a.xz();
c.d[16] = 0.0;
c.d[17] = a.xz()*b.zz();
c.d[18] = b.xx()*a.yz()/2;
c.d[19] = a.xy()*b.zz()/2;
c.d[20] = (a.xx()*b.zz() + b.xx()*a.zz())/2;
return c;
}
//-----------------------------------------------------------------------------
// (a dyad5s b)_ijkl = (a_ik b_jl + a_il b_jk)/2 + (a_jl b_ik + a_jk b_il)/2
inline tens4ds dyad5s(const mat3ds& a, const mat3ds& b)
{
int L[21][4] = { { 0, 0, 0, 0},
{ 0, 0, 1, 1},{ 1, 1, 1, 1},
{ 0, 0, 2, 2},{ 1, 1, 2, 2},{ 2, 2, 2, 2},
{ 0, 0, 0, 1},{ 1, 1, 0, 1},{ 2, 2, 0, 1},{ 0, 1, 0, 1},
{ 0, 0, 1, 2},{ 1, 1, 1, 2},{ 2, 2, 1, 2},{ 0, 1, 1, 2},{ 1, 2, 1, 2 },
{ 0, 0, 0, 2},{ 1, 1, 0, 2},{ 2, 2, 0, 2},{ 0, 1, 0, 2},{ 1, 2, 0, 2 },{ 0, 2, 0, 2 }};
tens4ds c;
for (int n = 0; n < 21; ++n)
{
int i = L[n][0];
int j = L[n][1];
int k = L[n][2];
int l = L[n][3];
c.d[n] = 0.5*(a(i, k)*b(j, l) + a(i, l)*b(j, k)) + 0.5*(a(j, l)*b(i, k) + a(j, k)*b(i, l));
}
return c;
}
//-----------------------------------------------------------------------------
// (a dyad4s b)_ijkl = (a_ik b_jl + a_il b_jk)/2 + (b_ik a_jl + b_il a_jk)/2
inline tens4ds dyad4s(const mat3ds& a, const mat3ds& b)
{
tens4ds c;
c.d[ 0] = 2*a.xx()*b.xx();
c.d[ 1] = 2*a.xy()*b.xy();
c.d[ 2] = 2*a.yy()*b.yy();
c.d[ 3] = 2*a.xz()*b.xz();
c.d[ 4] = 2*a.yz()*b.yz();
c.d[ 5] = 2*a.zz()*b.zz();
c.d[ 6] = a.xx()*b.xy() + b.xx()*a.xy();
c.d[ 7] = a.xy()*b.yy() + b.xy()*a.yy();
c.d[ 8] = a.xz()*b.yz() + b.xz()*a.yz();
c.d[ 9] = (a.xx()*b.yy() + 2*a.xy()*b.xy() + b.xx()*a.yy())/2;
c.d[10] = a.xy()*b.xz() + b.xy()*a.xz();
c.d[11] = a.yy()*b.yz() + b.yy()*a.yz();
c.d[12] = a.yz()*b.zz() + b.yz()*a.zz();
c.d[13] = (a.xy()*b.yz() + a.xz()*b.yy() + b.xy()*a.yz() + b.xz()*a.yy())/2;
c.d[14] = (a.yy()*b.zz() + 2*a.yz()*b.yz() + b.yy()*a.zz())/2;
c.d[15] = a.xx()*b.xz() + b.xx()*a.xz();
c.d[16] = a.xy()*b.yz() + b.xy()*a.yz();
c.d[17] = a.xz()*b.zz() + b.xz()*a.zz();
c.d[18] = (a.xx()*b.yz() + a.xy()*b.xz() + b.xx()*a.yz() + b.xy()*a.xz())/2;
c.d[19] = (a.xy()*b.zz() + a.xz()*b.yz() + b.xy()*a.zz() + b.xz()*a.yz())/2;
c.d[20] = (a.xx()*b.zz() + 2*a.xz()*b.xz() + b.xx()*a.zz())/2;
return c;
}
//-----------------------------------------------------------------------------
// (a ddots b)_ijkl = a_ijmn b_mnkl + b_ijmn a_mnkl
inline tens4ds ddots(const tens4ds& a, const tens4ds& b)
{
tens4ds c;
c.d[0] = 2*(a.d[0]*b.d[0] + a.d[1]*b.d[1] + a.d[3]*b.d[3] + 2*a.d[6]*b.d[6]
+ 2*a.d[10]*b.d[10] + 2*a.d[15]*b.d[15]);
c.d[1] = a.d[0]*b.d[1] + a.d[2]*b.d[1] + a.d[1]*(b.d[0] + b.d[2]) + a.d[4]*b.d[3]
+ a.d[3]*b.d[4] + 2*a.d[7]*b.d[6] + 2*a.d[6]*b.d[7] + 2*a.d[11]*b.d[10]
+ 2*a.d[10]*b.d[11] + 2*a.d[16]*b.d[15] + 2*a.d[15]*b.d[16];
c.d[3] = a.d[4]*b.d[1] + a.d[0]*b.d[3] + a.d[5]*b.d[3] + a.d[1]*b.d[4]
+ a.d[3]*(b.d[0] + b.d[5]) + 2*a.d[8]*b.d[6] + 2*a.d[6]*b.d[8] + 2*a.d[12]*b.d[10]
+ 2*a.d[10]*b.d[12] + 2*a.d[17]*b.d[15] + 2*a.d[15]*b.d[17];
c.d[6] = a.d[7]*b.d[1] + a.d[8]*b.d[3] + a.d[0]*b.d[6] + 2*a.d[9]*b.d[6] + a.d[1]*b.d[7]
+ a.d[3]*b.d[8] + a.d[6]*(b.d[0] + 2*b.d[9]) + 2*a.d[13]*b.d[10] + 2*a.d[10]*b.d[13]
+ 2*a.d[18]*b.d[15] + 2*a.d[15]*b.d[18];
c.d[10] = a.d[11]*b.d[1] + a.d[12]*b.d[3] + 2*a.d[13]*b.d[6] + a.d[0]*b.d[10]
+ 2*a.d[14]*b.d[10] + a.d[1]*b.d[11] + a.d[3]*b.d[12] + 2*a.d[6]*b.d[13]
+ a.d[10]*(b.d[0] + 2*b.d[14]) + 2*a.d[19]*b.d[15] + 2*a.d[15]*b.d[19];
c.d[15] = a.d[16]*b.d[1] + a.d[17]*b.d[3] + 2*a.d[18]*b.d[6] + 2*a.d[19]*b.d[10]
+ a.d[0]*b.d[15] + 2*a.d[20]*b.d[15] + a.d[1]*b.d[16] + a.d[3]*b.d[17]
+ 2*a.d[6]*b.d[18] + 2*a.d[10]*b.d[19] + a.d[15]*(b.d[0] + 2*b.d[20]);
c.d[2] = 2*(a.d[1]*b.d[1] + a.d[2]*b.d[2] + a.d[4]*b.d[4] + 2*a.d[7]*b.d[7]
+ 2*a.d[11]*b.d[11] + 2*a.d[16]*b.d[16]);
c.d[4] = a.d[3]*b.d[1] + a.d[1]*b.d[3] + a.d[2]*b.d[4] + a.d[5]*b.d[4]
+ a.d[4]*(b.d[2] + b.d[5]) + 2*a.d[8]*b.d[7] + 2*a.d[7]*b.d[8] + 2*a.d[12]*b.d[11]
+ 2*a.d[11]*b.d[12] + 2*a.d[17]*b.d[16] + 2*a.d[16]*b.d[17];
c.d[7] = a.d[6]*b.d[1] + a.d[8]*b.d[4] + a.d[1]*b.d[6] + a.d[2]*b.d[7]
+ 2*a.d[9]*b.d[7] + a.d[4]*b.d[8] + a.d[7]*(b.d[2] + 2*b.d[9]) + 2*a.d[13]*b.d[11]
+ 2*a.d[11]*b.d[13] + 2*a.d[18]*b.d[16] + 2*a.d[16]*b.d[18];
c.d[11] = a.d[10]*b.d[1] + a.d[12]*b.d[4] + 2*a.d[13]*b.d[7] + a.d[1]*b.d[10]
+ a.d[2]*b.d[11] + 2*a.d[14]*b.d[11] + a.d[4]*b.d[12] + 2*a.d[7]*b.d[13]
+ a.d[11]*(b.d[2] + 2*b.d[14]) + 2*a.d[19]*b.d[16] + 2*a.d[16]*b.d[19];
c.d[16] = a.d[15]*b.d[1] + a.d[17]*b.d[4] + 2*a.d[18]*b.d[7] + 2*a.d[19]*b.d[11]
+ a.d[1]*b.d[15] + a.d[2]*b.d[16] + 2*a.d[20]*b.d[16] + a.d[4]*b.d[17]
+ 2*a.d[7]*b.d[18] + 2*a.d[11]*b.d[19] + a.d[16]*(b.d[2] + 2*b.d[20]);
c.d[5] = 2*(a.d[3]*b.d[3] + a.d[4]*b.d[4] + a.d[5]*b.d[5] + 2*a.d[8]*b.d[8]
+ 2*a.d[12]*b.d[12] + 2*a.d[17]*b.d[17]);
c.d[8] = a.d[6]*b.d[3] + a.d[7]*b.d[4] + a.d[8]*b.d[5] + a.d[3]*b.d[6]
+ a.d[4]*b.d[7] + a.d[5]*b.d[8] + 2*a.d[9]*b.d[8] + 2*a.d[8]*b.d[9] + 2*a.d[13]*b.d[12]
+ 2*a.d[12]*b.d[13] + 2*a.d[18]*b.d[17] + 2*a.d[17]*b.d[18];
c.d[12] = a.d[10]*b.d[3] + a.d[11]*b.d[4] + a.d[12]*b.d[5] + 2*a.d[13]*b.d[8]
+ a.d[3]*b.d[10] + a.d[4]*b.d[11] + a.d[5]*b.d[12] + 2*a.d[14]*b.d[12] + 2*a.d[8]*b.d[13]
+ 2*a.d[12]*b.d[14] + 2*a.d[19]*b.d[17] + 2*a.d[17]*b.d[19];
c.d[17] = a.d[15]*b.d[3] + a.d[16]*b.d[4] + a.d[17]*b.d[5] + 2*a.d[18]*b.d[8]
+ 2*a.d[19]*b.d[12] + a.d[3]*b.d[15] + a.d[4]*b.d[16] + a.d[5]*b.d[17]
+ 2*a.d[20]*b.d[17] + 2*a.d[8]*b.d[18] + 2*a.d[12]*b.d[19] + 2*a.d[17]*b.d[20];
c.d[9] = 2*(a.d[6]*b.d[6] + a.d[7]*b.d[7] + a.d[8]*b.d[8] + 2*a.d[9]*b.d[9]
+ 2*a.d[13]*b.d[13] + 2*a.d[18]*b.d[18]);
c.d[13] = a.d[10]*b.d[6] + a.d[11]*b.d[7] + a.d[12]*b.d[8] + 2*a.d[13]*b.d[9]
+ a.d[6]*b.d[10] + a.d[7]*b.d[11] + a.d[8]*b.d[12] + 2*a.d[9]*b.d[13]
+ 2*a.d[14]*b.d[13] + 2*a.d[13]*b.d[14] + 2*a.d[19]*b.d[18] + 2*a.d[18]*b.d[19];
c.d[18] = a.d[15]*b.d[6] + a.d[16]*b.d[7] + a.d[17]*b.d[8] + 2*a.d[18]*b.d[9]
+ 2*a.d[19]*b.d[13] + a.d[6]*b.d[15] + a.d[7]*b.d[16] + a.d[8]*b.d[17]
+ 2*a.d[9]*b.d[18] + 2*a.d[20]*b.d[18] + 2*a.d[13]*b.d[19] + 2*a.d[18]*b.d[20];
c.d[14] = 2*(a.d[10]*b.d[10] + a.d[11]*b.d[11] + a.d[12]*b.d[12]
+ 2*a.d[13]*b.d[13] + 2*a.d[14]*b.d[14] + 2*a.d[19]*b.d[19]);
c.d[19] = a.d[15]*b.d[10] + a.d[16]*b.d[11] + a.d[17]*b.d[12]
+ 2*a.d[18]*b.d[13] + 2*a.d[19]*b.d[14] + a.d[10]*b.d[15] + a.d[11]*b.d[16]
+ a.d[12]*b.d[17] + 2*a.d[13]*b.d[18] + 2*a.d[14]*b.d[19] + 2*a.d[20]*b.d[19] + 2*a.d[19]*b.d[20];
c.d[20] = 2*(a.d[15]*b.d[15] + a.d[16]*b.d[16] + a.d[17]*b.d[17]
+ 2*a.d[18]*b.d[18] + 2*a.d[19]*b.d[19] + 2*a.d[20]*b.d[20]);
return c;
}
//-----------------------------------------------------------------------------
// Evaluates the dyadic product C_ijkl = 0.25*(a_i * K_jk * b_l + perms.)
inline tens4ds dyad4s(const vec3d& a, const mat3d& K, const vec3d& b)
{
tens4ds c;
c(0,0) = a.x * K(0,0) * b.x;
c(1,1) = a.y * K(1,1) * b.y;
c(2,2) = a.z * K(2,2) * b.z;
c(0,1) = 0.5*(a.x * K(0,1) * b.y + a.y * K(1,0) * b.x);
c(0,2) = 0.5*(a.x * K(0,2) * b.z + a.z * K(2,0) * b.x);
c(1,2) = 0.5*(a.y * K(1,2) * b.z + a.z * K(2,1) * b.y);
c(0,3) = 0.25*(a.x * K(0,0) * b.y + a.x * K(0,1) * b.x + a.x * K(1,0) * b.x + a.y * K(0,0) * b.x);
c(0,4) = 0.25*(a.x * K(0,1) * b.z + a.x * K(0,2) * b.y + a.y * K(2,0) * b.x + a.z * K(1,0) * b.x);
c(0,5) = 0.25*(a.x * K(0,0) * b.z + a.x * K(0,2) * b.x + a.x * K(2,0) * b.x + a.z * K(0,0) * b.x);
c(1,3) = 0.25*(a.y * K(1,0) * b.y + a.y * K(1,1) * b.x + a.x * K(1,1) * b.y + a.y * K(0,1) * b.y);
c(1,4) = 0.25*(a.y * K(1,1) * b.z + a.y * K(1,2) * b.y + a.y * K(2,1) * b.y + a.z * K(1,1) * b.y);
c(1,5) = 0.25*(a.y * K(1,0) * b.z + a.y * K(1,2) * b.x + a.x * K(2,1) * b.y + a.z * K(0,1) * b.y);
c(2,3) = 0.25*(a.z * K(2,0) * b.y + a.z * K(2,1) * b.x + a.x * K(1,2) * b.z + a.y * K(0,2) * b.z);
c(2,4) = 0.25*(a.z * K(2,1) * b.z + a.z * K(2,2) * b.y + a.y * K(2,2) * b.z + a.z * K(1,2) * b.z);
c(2,5) = 0.25*(a.z * K(2,0) * b.z + a.z * K(2,2) * b.x + a.x * K(2,2) * b.z + a.z * K(0,2) * b.z);
c(3,3) = 0.25*(a.x * K(1,0) * b.y + a.x * K(1,1) * b.x + a.x * K(1,0) * b.y + a.y * K(0,0) * b.y);
c(3,4) = 0.25*(a.x * K(1,1) * b.z + a.x * K(1,2) * b.y + a.y * K(2,0) * b.y + a.z * K(1,0) * b.y);
c(3,5) = 0.25*(a.x * K(1,0) * b.z + a.x * K(1,2) * b.x + a.x * K(2,0) * b.y + a.z * K(0,0) * b.y);
c(4,4) = 0.25*(a.y * K(2,1) * b.z + a.y * K(2,2) * b.y + a.y * K(2,1) * b.z + a.z * K(1,1) * b.z);
c(4,5) = 0.25*(a.y * K(2,0) * b.z + a.y * K(2,2) * b.x + a.x * K(2,1) * b.z + a.z * K(0,1) * b.z);
c(5,5) = 0.25*(a.x * K(2,0) * b.z + a.x * K(2,2) * b.x + a.x * K(2,0) * b.z + a.z * K(0,0) * b.z);
return c;
}
//-----------------------------------------------------------------------------
// double contraction of symmetric 4th-order tensor with a symmetric 2nd-order tensor
// Aij = Dijkl Mkl
inline mat3ds tens4ds::dot(const mat3ds &m) const
{
mat3ds a;
a.xx() = d[ 0]*m.xx() + d[ 1]*m.yy() + d[ 3]*m.zz() + 2*d[ 6]*m.xy() + 2*d[10]*m.yz() + 2*d[15]*m.xz();
a.yy() = d[ 1]*m.xx() + d[ 2]*m.yy() + d[ 4]*m.zz() + 2*d[ 7]*m.xy() + 2*d[11]*m.yz() + 2*d[16]*m.xz();
a.zz() = d[ 3]*m.xx() + d[ 4]*m.yy() + d[ 5]*m.zz() + 2*d[ 8]*m.xy() + 2*d[12]*m.yz() + 2*d[17]*m.xz();
a.xy() = d[ 6]*m.xx() + d[ 7]*m.yy() + d[ 8]*m.zz() + 2*d[ 9]*m.xy() + 2*d[13]*m.yz() + 2*d[18]*m.xz();
a.yz() = d[10]*m.xx() + d[11]*m.yy() + d[12]*m.zz() + 2*d[13]*m.xy() + 2*d[14]*m.yz() + 2*d[19]*m.xz();
a.xz() = d[15]*m.xx() + d[16]*m.yy() + d[17]*m.zz() + 2*d[18]*m.xy() + 2*d[19]*m.yz() + 2*d[20]*m.xz();
return a;
}
//-----------------------------------------------------------------------------
// double contraction of symmetric 4th-order tensor with a general 2nd-order tensor
// Aij = Dijkl Mkl
inline mat3ds tens4ds::dot(const mat3d &m) const
{
mat3ds a;
a.xx() = d[ 0]*m(0,0) + d[ 1]*m(1,1) + d[ 3]*m(2,2) + d[ 6]*(m(0,1)+m(1,0)) + d[10]*(m(1,2)+m(2,1)) + d[15]*(m(0,2)+m(2,0));
a.yy() = d[ 1]*m(0,0) + d[ 2]*m(1,1) + d[ 4]*m(2,2) + d[ 7]*(m(0,1)+m(1,0)) + d[11]*(m(1,2)+m(2,1)) + d[16]*(m(0,2)+m(2,0));
a.zz() = d[ 3]*m(0,0) + d[ 4]*m(1,1) + d[ 5]*m(2,2) + d[ 8]*(m(0,1)+m(1,0)) + d[12]*(m(1,2)+m(2,1)) + d[17]*(m(0,2)+m(2,0));
a.xy() = d[ 6]*m(0,0) + d[ 7]*m(1,1) + d[ 8]*m(2,2) + d[ 9]*(m(0,1)+m(1,0)) + d[13]*(m(1,2)+m(2,1)) + d[18]*(m(0,2)+m(2,0));
a.yz() = d[10]*m(0,0) + d[11]*m(1,1) + d[12]*m(2,2) + d[13]*(m(0,1)+m(1,0)) + d[14]*(m(1,2)+m(2,1)) + d[19]*(m(0,2)+m(2,0));
a.xz() = d[15]*m(0,0) + d[16]*m(1,1) + d[17]*m(2,2) + d[18]*(m(0,1)+m(1,0)) + d[19]*(m(1,2)+m(2,1)) + d[20]*(m(0,2)+m(2,0));
return a;
}
//-----------------------------------------------------------------------------
// contraction of symmetric 4th-order tensor with a vector
// Aijk = Dijkl Ml
//
// / 0 1 3 6 10 15 \ / C0000 C0011 C0022 C0001 C0012 C0002 \
// | 2 4 7 11 16 | | C1111 C1122 C1101 C1112 C1102 |
// | 5 8 12 17 | | C2222 C2201 C2212 C2202 |
// A = | 9 13 18 | = | C0101 C0112 C0102 |
// | 14 19 | | C1212 C1202 |
// \ 20 / \ C0202 /
//
// [G] = [G111 G112 G113 G121 G122 G123 G131 G132 G133 G221 G222 G223 G231 G232 G233 G331 G332 G333]
// = G0 G1 G2 G3 G4 G5 G6 G7 G8 G9 G10 G11 G12 G13 G14 G15 G16 G17
inline tens3dls tens4ds::dot(const vec3d &m) const
{
tens3dls a;
a.d[0] = d[0]*m.x + d[6]*m.y + d[15]*m.z;
a.d[1] = d[6]*m.x + d[1]*m.y + d[10]*m.z;
a.d[2] = d[15]*m.x + d[10]*m.y + d[3]*m.z;
a.d[3] = d[6]*m.x + d[9]*m.y + d[18]*m.z;
a.d[4] = d[9]*m.x + d[7]*m.y + d[13]*m.z;
a.d[5] = d[18]*m.x + d[13]*m.y + d[8]*m.z;
a.d[6] = d[15]*m.x + d[18]*m.y + d[20]*m.z;
a.d[7] = d[18]*m.x + d[16]*m.y + d[19]*m.z;
a.d[8] = d[20]*m.x + d[19]*m.y + d[17]*m.z;
a.d[9] = d[1]*m.x + d[7]*m.y + d[16]*m.z;
a.d[10] = d[7]*m.x + d[2]*m.y + d[11]*m.z;
a.d[11] = d[16]*m.x + d[11]*m.y + d[4]*m.z;
a.d[12] = d[10]*m.x + d[13]*m.y + d[19]*m.z;
a.d[13] = d[13]*m.x + d[11]*m.y + d[14]*m.z;
a.d[14] = d[19]*m.x + d[14]*m.y + d[12]*m.z;
a.d[15] = d[3]*m.x + d[8]*m.y + d[17]*m.z;
a.d[16] = d[8]*m.x + d[4]*m.y + d[12]*m.z;
a.d[17] = d[17]*m.x + d[12]*m.y + d[5]*m.z;
return a;
}
//-----------------------------------------------------------------------------
// double contraction of symmetric 4th-order tensor with a general 2nd-order tensor (2nd kind)
// Aij = Dikjl Mkl
inline mat3ds tens4ds::dot2(const mat3d &m) const
{
mat3ds a;
a.xx() = d[ 0]*m(0,0) + d[ 9]*m(1,1) + d[20]*m(2,2) + d[ 6]*(m(0,1)+m(1,0)) + d[18]*(m(1,2)+m(2,1)) + d[15]*(m(0,2)+m(2,0));
a.yy() = d[ 9]*m(0,0) + d[ 2]*m(1,1) + d[14]*m(2,2) + d[ 7]*(m(0,1)+m(1,0)) + d[11]*(m(1,2)+m(2,1)) + d[13]*(m(0,2)+m(2,0));
a.zz() = d[20]*m(0,0) + d[14]*m(1,1) + d[ 5]*m(2,2) + d[19]*(m(0,1)+m(1,0)) + d[12]*(m(1,2)+m(2,1)) + d[17]*(m(0,2)+m(2,0));
a.xy() = d[ 6]*m(0,0) + d[ 7]*m(1,1) + d[19]*m(2,2) + d[ 1]*(m(0,1)+m(1,0)) + d[13]*(m(1,2)+m(2,1)) + d[10]*(m(0,2)+m(2,0));
a.yz() = d[18]*m(0,0) + d[11]*m(1,1) + d[12]*m(2,2) + d[13]*(m(0,1)+m(1,0)) + d[ 4]*(m(1,2)+m(2,1)) + d[ 8]*(m(0,2)+m(2,0));
a.xz() = d[15]*m(0,0) + d[13]*m(1,1) + d[17]*m(2,2) + d[10]*(m(0,1)+m(1,0)) + d[ 8]*(m(1,2)+m(2,1)) + d[ 3]*(m(0,2)+m(2,0));
return a;
}
// contraction
// Aij = c_qqij = c_ijqq
inline mat3ds tens4ds::contract() const
{
mat3ds a;
a.xx() = d[ 0] + d[ 1] + d[ 3];
a.yy() = d[ 1] + d[ 2] + d[ 4];
a.zz() = d[ 3] + d[ 4] + d[ 5];
a.xy() = d[ 6] + d[ 7] + d[ 8];
a.yz() = d[10] + d[11] + d[12];
a.xz() = d[15] + d[16] + d[17];
return a;
}
//-----------------------------------------------------------------------------
// vdotTdotv_jk = a_i T_ijkl b_l
inline mat3d vdotTdotv(const vec3d& a, const tens4ds& T, const vec3d& b)
{
return mat3d(a.x*(b.x*T.d[0] + b.y*T.d[6] + b.z*T.d[15]) + a.y*(b.x*T.d[6] + b.y*T.d[9] + b.z*T.d[18]) + a.z*(b.x*T.d[15] + b.y*T.d[18] + b.z*T.d[20]),
a.x*(b.y*T.d[1] + b.x*T.d[6] + b.z*T.d[10]) + a.y*(b.y*T.d[7] + b.x*T.d[9] + b.z*T.d[13]) + a.z*(b.y*T.d[16] + b.x*T.d[18] + b.z*T.d[19]),
a.x*(b.z*T.d[3] + b.y*T.d[10] + b.x*T.d[15]) + a.y*(b.z*T.d[8] + b.y*T.d[13] + b.x*T.d[18]) + a.z*(b.z*T.d[17] + b.y*T.d[19] + b.x*T.d[20]),
a.y*(b.x*T.d[1] + b.y*T.d[7] + b.z*T.d[16]) + a.x*(b.x*T.d[6] + b.y*T.d[9] + b.z*T.d[18]) + a.z*(b.x*T.d[10] + b.y*T.d[13] + b.z*T.d[19]),
a.y*(b.y*T.d[2] + b.x*T.d[7] + b.z*T.d[11]) + a.x*(b.y*T.d[7] + b.x*T.d[9] + b.z*T.d[13]) + a.z*(b.y*T.d[11] + b.x*T.d[13] + b.z*T.d[14]),
a.y*(b.z*T.d[4] + b.y*T.d[11] + b.x*T.d[16]) + a.x*(b.z*T.d[8] + b.y*T.d[13] + b.x*T.d[18]) + a.z*(b.z*T.d[12] + b.y*T.d[14] + b.x*T.d[19]),
a.z*(b.x*T.d[3] + b.y*T.d[8] + b.z*T.d[17]) + a.y*(b.x*T.d[10] + b.y*T.d[13] + b.z*T.d[19]) + a.x*(b.x*T.d[15] + b.y*T.d[18] + b.z*T.d[20]),
a.z*(b.y*T.d[4] + b.x*T.d[8] + b.z*T.d[12]) + a.y*(b.y*T.d[11] + b.x*T.d[13] + b.z*T.d[14]) + a.x*(b.y*T.d[16] + b.x*T.d[18] + b.z*T.d[19]),
a.z*(b.z*T.d[5] + b.y*T.d[12] + b.x*T.d[17]) + a.y*(b.z*T.d[12] + b.y*T.d[14] + b.x*T.d[19]) + a.x*(b.z*T.d[17] + b.y*T.d[19] + b.x*T.d[20]));
}
//-----------------------------------------------------------------------------
// inverse
inline tens4ds tens4ds::inverse() const
{
matrix c(6,6);
// populate c
c(0,0) = d[0];
c(1,1) = d[2];
c(2,2) = d[5];
c(3,3) = d[9];
c(4,4) = d[14];
c(5,5) = d[20];
c(0,1) = c(1,0) = d[1];
c(0,2) = c(2,0) = d[3];
c(0,3) = c(3,0) = d[6];
c(0,4) = c(4,0) = d[10];
c(0,5) = c(5,0) = d[15];
c(1,2) = c(2,1) = d[4];
c(1,3) = c(3,1) = d[7];
c(1,4) = c(4,1) = d[11];
c(1,5) = c(5,1) = d[16];
c(2,3) = c(3,2) = d[8];
c(2,4) = c(4,2) = d[12];
c(2,5) = c(5,2) = d[17];
c(3,4) = c(4,3) = d[13];
c(3,5) = c(5,3) = d[18];
c(4,5) = c(5,4) = d[19];
// invert c
matrix s = c.inverse();
// return inverse
tens4ds S;
S.d[ 0] = s(0,0);
S.d[ 2] = s(1,1);
S.d[ 5] = s(2,2);
S.d[ 9] = s(3,3);
S.d[14] = s(4,4);
S.d[20] = s(5,5);
S.d[ 1] = s(0,1);
S.d[ 3] = s(0,2);
S.d[ 6] = s(0,3);
S.d[10] = s(0,4);
S.d[15] = s(0,5);
S.d[ 4] = s(1,2);
S.d[ 7] = s(1,3);
S.d[11] = s(1,4);
S.d[16] = s(1,5);
S.d[ 8] = s(2,3);
S.d[12] = s(2,4);
S.d[17] = s(2,5);
S.d[13] = s(3,4);
S.d[18] = s(3,5);
S.d[19] = s(4,5);
return S;
}
//-----------------------------------------------------------------------------
// evaluate push/pull operation
// c_ijpq = F_ik F_jl C_klmn F_pm F_qn
inline tens4ds tens4ds::pp(const mat3d& F)
{
tens4ds c;
c.d[0] = d[0]*pow(F(0,0),4) + 4*d[6]*pow(F(0,0),3)*F(0,1) +
2*d[1]*pow(F(0,0),2)*pow(F(0,1),2) + 4*d[9]*pow(F(0,0),2)*pow(F(0,1),2) +
4*d[7]*F(0,0)*pow(F(0,1),3) + d[2]*pow(F(0,1),4) +
4*d[15]*pow(F(0,0),3)*F(0,2) + 4*d[10]*pow(F(0,0),2)*F(0,1)*F(0,2) +
8*d[18]*pow(F(0,0),2)*F(0,1)*F(0,2) + 8*d[13]*F(0,0)*pow(F(0,1),2)*F(0,2) +
4*d[16]*F(0,0)*pow(F(0,1),2)*F(0,2) + 4*d[11]*pow(F(0,1),3)*F(0,2) +
2*d[3]*pow(F(0,0),2)*pow(F(0,2),2) + 4*d[20]*pow(F(0,0),2)*pow(F(0,2),2) +
4*d[8]*F(0,0)*F(0,1)*pow(F(0,2),2) + 8*d[19]*F(0,0)*F(0,1)*pow(F(0,2),2) +
2*d[4]*pow(F(0,1),2)*pow(F(0,2),2) + 4*d[14]*pow(F(0,1),2)*pow(F(0,2),2) +
4*d[17]*F(0,0)*pow(F(0,2),3) + 4*d[12]*F(0,1)*pow(F(0,2),3) +
d[5]*pow(F(0,2),4);
c.d[1] = d[0]*pow(F(0,0),2)*pow(F(1,0),2) + d[1]*pow(F(0,1),2)*pow(F(1,0),2) +
2*d[15]*F(0,0)*F(0,2)*pow(F(1,0),2) + 2*d[10]*F(0,1)*F(0,2)*pow(F(1,0),2) +
d[3]*pow(F(0,2),2)*pow(F(1,0),2) + 4*d[9]*F(0,0)*F(0,1)*F(1,0)*F(1,1) +
2*d[7]*pow(F(0,1),2)*F(1,0)*F(1,1) + 4*d[18]*F(0,0)*F(0,2)*F(1,0)*F(1,1) +
4*d[13]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + 2*d[8]*pow(F(0,2),2)*F(1,0)*F(1,1) +
d[1]*pow(F(0,0),2)*pow(F(1,1),2) + 2*d[7]*F(0,0)*F(0,1)*pow(F(1,1),2) +
d[2]*pow(F(0,1),2)*pow(F(1,1),2) + 2*d[16]*F(0,0)*F(0,2)*pow(F(1,1),2) +
2*d[11]*F(0,1)*F(0,2)*pow(F(1,1),2) + d[4]*pow(F(0,2),2)*pow(F(1,1),2) +
2*d[6]*F(0,0)*F(1,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) +
2*d[15]*pow(F(0,0),2)*F(1,0)*F(1,2) + 4*d[18]*F(0,0)*F(0,1)*F(1,0)*F(1,2) +
2*d[16]*pow(F(0,1),2)*F(1,0)*F(1,2) + 4*d[20]*F(0,0)*F(0,2)*F(1,0)*F(1,2) +
4*d[19]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + 2*d[17]*pow(F(0,2),2)*F(1,0)*F(1,2) +
2*d[10]*pow(F(0,0),2)*F(1,1)*F(1,2) + 4*d[13]*F(0,0)*F(0,1)*F(1,1)*F(1,2) +
2*d[11]*pow(F(0,1),2)*F(1,1)*F(1,2) + 4*d[19]*F(0,0)*F(0,2)*F(1,1)*F(1,2) +
4*d[14]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + 2*d[12]*pow(F(0,2),2)*F(1,1)*F(1,2) +
d[3]*pow(F(0,0),2)*pow(F(1,2),2) + 2*d[8]*F(0,0)*F(0,1)*pow(F(1,2),2) +
d[4]*pow(F(0,1),2)*pow(F(1,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(1,2),2) +
2*d[12]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[5]*pow(F(0,2),2)*pow(F(1,2),2);
c.d[2] = d[0]*pow(F(1,0),4) + 4*d[6]*pow(F(1,0),3)*F(1,1) +
2*d[1]*pow(F(1,0),2)*pow(F(1,1),2) + 4*d[9]*pow(F(1,0),2)*pow(F(1,1),2) +
4*d[7]*F(1,0)*pow(F(1,1),3) + d[2]*pow(F(1,1),4) +
4*d[15]*pow(F(1,0),3)*F(1,2) + 4*d[10]*pow(F(1,0),2)*F(1,1)*F(1,2) +
8*d[18]*pow(F(1,0),2)*F(1,1)*F(1,2) + 8*d[13]*F(1,0)*pow(F(1,1),2)*F(1,2) +
4*d[16]*F(1,0)*pow(F(1,1),2)*F(1,2) + 4*d[11]*pow(F(1,1),3)*F(1,2) +
2*d[3]*pow(F(1,0),2)*pow(F(1,2),2) + 4*d[20]*pow(F(1,0),2)*pow(F(1,2),2) +
4*d[8]*F(1,0)*F(1,1)*pow(F(1,2),2) + 8*d[19]*F(1,0)*F(1,1)*pow(F(1,2),2) +
2*d[4]*pow(F(1,1),2)*pow(F(1,2),2) + 4*d[14]*pow(F(1,1),2)*pow(F(1,2),2) +
4*d[17]*F(1,0)*pow(F(1,2),3) + 4*d[12]*F(1,1)*pow(F(1,2),3) +
d[5]*pow(F(1,2),4);
c.d[3] = d[0]*pow(F(0,0),2)*pow(F(2,0),2) + d[1]*pow(F(0,1),2)*pow(F(2,0),2) +
2*d[15]*F(0,0)*F(0,2)*pow(F(2,0),2) + 2*d[10]*F(0,1)*F(0,2)*pow(F(2,0),2) +
d[3]*pow(F(0,2),2)*pow(F(2,0),2) + 4*d[9]*F(0,0)*F(0,1)*F(2,0)*F(2,1) +
2*d[7]*pow(F(0,1),2)*F(2,0)*F(2,1) + 4*d[18]*F(0,0)*F(0,2)*F(2,0)*F(2,1) +
4*d[13]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + 2*d[8]*pow(F(0,2),2)*F(2,0)*F(2,1) +
d[1]*pow(F(0,0),2)*pow(F(2,1),2) + 2*d[7]*F(0,0)*F(0,1)*pow(F(2,1),2) +
d[2]*pow(F(0,1),2)*pow(F(2,1),2) + 2*d[16]*F(0,0)*F(0,2)*pow(F(2,1),2) +
2*d[11]*F(0,1)*F(0,2)*pow(F(2,1),2) + d[4]*pow(F(0,2),2)*pow(F(2,1),2) +
2*d[6]*F(0,0)*F(2,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) +
2*d[15]*pow(F(0,0),2)*F(2,0)*F(2,2) + 4*d[18]*F(0,0)*F(0,1)*F(2,0)*F(2,2) +
2*d[16]*pow(F(0,1),2)*F(2,0)*F(2,2) + 4*d[20]*F(0,0)*F(0,2)*F(2,0)*F(2,2) +
4*d[19]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + 2*d[17]*pow(F(0,2),2)*F(2,0)*F(2,2) +
2*d[10]*pow(F(0,0),2)*F(2,1)*F(2,2) + 4*d[13]*F(0,0)*F(0,1)*F(2,1)*F(2,2) +
2*d[11]*pow(F(0,1),2)*F(2,1)*F(2,2) + 4*d[19]*F(0,0)*F(0,2)*F(2,1)*F(2,2) +
4*d[14]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + 2*d[12]*pow(F(0,2),2)*F(2,1)*F(2,2) +
d[3]*pow(F(0,0),2)*pow(F(2,2),2) + 2*d[8]*F(0,0)*F(0,1)*pow(F(2,2),2) +
d[4]*pow(F(0,1),2)*pow(F(2,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(2,2),2) +
2*d[12]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[5]*pow(F(0,2),2)*pow(F(2,2),2);
c.d[4] = d[0]*pow(F(1,0),2)*pow(F(2,0),2) + d[1]*pow(F(1,1),2)*pow(F(2,0),2) +
2*d[15]*F(1,0)*F(1,2)*pow(F(2,0),2) + 2*d[10]*F(1,1)*F(1,2)*pow(F(2,0),2) +
d[3]*pow(F(1,2),2)*pow(F(2,0),2) + 4*d[9]*F(1,0)*F(1,1)*F(2,0)*F(2,1) +
2*d[7]*pow(F(1,1),2)*F(2,0)*F(2,1) + 4*d[18]*F(1,0)*F(1,2)*F(2,0)*F(2,1) +
4*d[13]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[8]*pow(F(1,2),2)*F(2,0)*F(2,1) +
d[1]*pow(F(1,0),2)*pow(F(2,1),2) + 2*d[7]*F(1,0)*F(1,1)*pow(F(2,1),2) +
d[2]*pow(F(1,1),2)*pow(F(2,1),2) + 2*d[16]*F(1,0)*F(1,2)*pow(F(2,1),2) +
2*d[11]*F(1,1)*F(1,2)*pow(F(2,1),2) + d[4]*pow(F(1,2),2)*pow(F(2,1),2) +
2*d[6]*F(1,0)*F(2,0)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) +
2*d[15]*pow(F(1,0),2)*F(2,0)*F(2,2) + 4*d[18]*F(1,0)*F(1,1)*F(2,0)*F(2,2) +
2*d[16]*pow(F(1,1),2)*F(2,0)*F(2,2) + 4*d[20]*F(1,0)*F(1,2)*F(2,0)*F(2,2) +
4*d[19]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[17]*pow(F(1,2),2)*F(2,0)*F(2,2) +
2*d[10]*pow(F(1,0),2)*F(2,1)*F(2,2) + 4*d[13]*F(1,0)*F(1,1)*F(2,1)*F(2,2) +
2*d[11]*pow(F(1,1),2)*F(2,1)*F(2,2) + 4*d[19]*F(1,0)*F(1,2)*F(2,1)*F(2,2) +
4*d[14]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[12]*pow(F(1,2),2)*F(2,1)*F(2,2) +
d[3]*pow(F(1,0),2)*pow(F(2,2),2) + 2*d[8]*F(1,0)*F(1,1)*pow(F(2,2),2) +
d[4]*pow(F(1,1),2)*pow(F(2,2),2) + 2*d[17]*F(1,0)*F(1,2)*pow(F(2,2),2) +
2*d[12]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[5]*pow(F(1,2),2)*pow(F(2,2),2);
c.d[5] = d[0]*pow(F(2,0),4) + 4*d[6]*pow(F(2,0),3)*F(2,1) +
2*d[1]*pow(F(2,0),2)*pow(F(2,1),2) + 4*d[9]*pow(F(2,0),2)*pow(F(2,1),2) +
4*d[7]*F(2,0)*pow(F(2,1),3) + d[2]*pow(F(2,1),4) +
4*d[15]*pow(F(2,0),3)*F(2,2) + 4*d[10]*pow(F(2,0),2)*F(2,1)*F(2,2) +
8*d[18]*pow(F(2,0),2)*F(2,1)*F(2,2) + 8*d[13]*F(2,0)*pow(F(2,1),2)*F(2,2) +
4*d[16]*F(2,0)*pow(F(2,1),2)*F(2,2) + 4*d[11]*pow(F(2,1),3)*F(2,2) +
2*d[3]*pow(F(2,0),2)*pow(F(2,2),2) + 4*d[20]*pow(F(2,0),2)*pow(F(2,2),2) +
4*d[8]*F(2,0)*F(2,1)*pow(F(2,2),2) + 8*d[19]*F(2,0)*F(2,1)*pow(F(2,2),2) +
2*d[4]*pow(F(2,1),2)*pow(F(2,2),2) + 4*d[14]*pow(F(2,1),2)*pow(F(2,2),2) +
4*d[17]*F(2,0)*pow(F(2,2),3) + 4*d[12]*F(2,1)*pow(F(2,2),3) +
d[5]*pow(F(2,2),4);
c.d[6] = d[0]*pow(F(0,0),3)*F(1,0) + d[1]*F(0,0)*pow(F(0,1),2)*F(1,0) +
2*d[9]*F(0,0)*pow(F(0,1),2)*F(1,0) + d[7]*pow(F(0,1),3)*F(1,0) +
3*d[15]*pow(F(0,0),2)*F(0,2)*F(1,0) + 2*d[10]*F(0,0)*F(0,1)*F(0,2)*F(1,0) +
4*d[18]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[13]*pow(F(0,1),2)*F(0,2)*F(1,0) +
d[16]*pow(F(0,1),2)*F(0,2)*F(1,0) + d[3]*F(0,0)*pow(F(0,2),2)*F(1,0) +
2*d[20]*F(0,0)*pow(F(0,2),2)*F(1,0) + d[8]*F(0,1)*pow(F(0,2),2)*F(1,0) +
2*d[19]*F(0,1)*pow(F(0,2),2)*F(1,0) + d[17]*pow(F(0,2),3)*F(1,0) +
d[1]*pow(F(0,0),2)*F(0,1)*F(1,1) + 2*d[9]*pow(F(0,0),2)*F(0,1)*F(1,1) +
3*d[7]*F(0,0)*pow(F(0,1),2)*F(1,1) + d[2]*pow(F(0,1),3)*F(1,1) +
d[10]*pow(F(0,0),2)*F(0,2)*F(1,1) + 2*d[18]*pow(F(0,0),2)*F(0,2)*F(1,1) +
4*d[13]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[16]*F(0,0)*F(0,1)*F(0,2)*F(1,1) +
3*d[11]*pow(F(0,1),2)*F(0,2)*F(1,1) + d[8]*F(0,0)*pow(F(0,2),2)*F(1,1) +
2*d[19]*F(0,0)*pow(F(0,2),2)*F(1,1) + d[4]*F(0,1)*pow(F(0,2),2)*F(1,1) +
2*d[14]*F(0,1)*pow(F(0,2),2)*F(1,1) + d[12]*pow(F(0,2),3)*F(1,1) +
d[6]*pow(F(0,0),2)*(3*F(0,1)*F(1,0) + F(0,0)*F(1,1)) +
d[15]*pow(F(0,0),3)*F(1,2) + d[10]*pow(F(0,0),2)*F(0,1)*F(1,2) +
2*d[18]*pow(F(0,0),2)*F(0,1)*F(1,2) + 2*d[13]*F(0,0)*pow(F(0,1),2)*F(1,2) +
d[16]*F(0,0)*pow(F(0,1),2)*F(1,2) + d[11]*pow(F(0,1),3)*F(1,2) +
d[3]*pow(F(0,0),2)*F(0,2)*F(1,2) + 2*d[20]*pow(F(0,0),2)*F(0,2)*F(1,2) +
2*d[8]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + 4*d[19]*F(0,0)*F(0,1)*F(0,2)*F(1,2) +
d[4]*pow(F(0,1),2)*F(0,2)*F(1,2) + 2*d[14]*pow(F(0,1),2)*F(0,2)*F(1,2) +
3*d[17]*F(0,0)*pow(F(0,2),2)*F(1,2) + 3*d[12]*F(0,1)*pow(F(0,2),2)*F(1,2) +
d[5]*pow(F(0,2),3)*F(1,2);
c.d[7] = d[0]*F(0,0)*pow(F(1,0),3) + d[15]*F(0,2)*pow(F(1,0),3) +
d[1]*F(0,1)*pow(F(1,0),2)*F(1,1) + 2*d[9]*F(0,1)*pow(F(1,0),2)*F(1,1) +
d[10]*F(0,2)*pow(F(1,0),2)*F(1,1) + 2*d[18]*F(0,2)*pow(F(1,0),2)*F(1,1) +
d[1]*F(0,0)*F(1,0)*pow(F(1,1),2) + 2*d[9]*F(0,0)*F(1,0)*pow(F(1,1),2) +
3*d[7]*F(0,1)*F(1,0)*pow(F(1,1),2) + 2*d[13]*F(0,2)*F(1,0)*pow(F(1,1),2) +
d[16]*F(0,2)*F(1,0)*pow(F(1,1),2) + d[7]*F(0,0)*pow(F(1,1),3) +
d[2]*F(0,1)*pow(F(1,1),3) + d[11]*F(0,2)*pow(F(1,1),3) +
d[6]*pow(F(1,0),2)*(F(0,1)*F(1,0) + 3*F(0,0)*F(1,1)) +
3*d[15]*F(0,0)*pow(F(1,0),2)*F(1,2) + d[10]*F(0,1)*pow(F(1,0),2)*F(1,2) +
2*d[18]*F(0,1)*pow(F(1,0),2)*F(1,2) + d[3]*F(0,2)*pow(F(1,0),2)*F(1,2) +
2*d[20]*F(0,2)*pow(F(1,0),2)*F(1,2) + 2*d[10]*F(0,0)*F(1,0)*F(1,1)*F(1,2) +
4*d[18]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 4*d[13]*F(0,1)*F(1,0)*F(1,1)*F(1,2) +
2*d[16]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[8]*F(0,2)*F(1,0)*F(1,1)*F(1,2) +
4*d[19]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[13]*F(0,0)*pow(F(1,1),2)*F(1,2) +
d[16]*F(0,0)*pow(F(1,1),2)*F(1,2) + 3*d[11]*F(0,1)*pow(F(1,1),2)*F(1,2) +
d[4]*F(0,2)*pow(F(1,1),2)*F(1,2) + 2*d[14]*F(0,2)*pow(F(1,1),2)*F(1,2) +
d[3]*F(0,0)*F(1,0)*pow(F(1,2),2) + 2*d[20]*F(0,0)*F(1,0)*pow(F(1,2),2) +
d[8]*F(0,1)*F(1,0)*pow(F(1,2),2) + 2*d[19]*F(0,1)*F(1,0)*pow(F(1,2),2) +
3*d[17]*F(0,2)*F(1,0)*pow(F(1,2),2) + d[8]*F(0,0)*F(1,1)*pow(F(1,2),2) +
2*d[19]*F(0,0)*F(1,1)*pow(F(1,2),2) + d[4]*F(0,1)*F(1,1)*pow(F(1,2),2) +
2*d[14]*F(0,1)*F(1,1)*pow(F(1,2),2) + 3*d[12]*F(0,2)*F(1,1)*pow(F(1,2),2) +
d[17]*F(0,0)*pow(F(1,2),3) + d[12]*F(0,1)*pow(F(1,2),3) +
d[5]*F(0,2)*pow(F(1,2),3);
c.d[8] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[15]*F(0,2)*F(1,0)*pow(F(2,0),2) +
d[1]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[10]*F(0,2)*F(1,1)*pow(F(2,0),2) +
d[15]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[10]*F(0,1)*F(1,2)*pow(F(2,0),2) +
d[3]*F(0,2)*F(1,2)*pow(F(2,0),2) + 2*d[9]*F(0,1)*F(1,0)*F(2,0)*F(2,1) +
2*d[18]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + 2*d[9]*F(0,0)*F(1,1)*F(2,0)*F(2,1) +
2*d[7]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + 2*d[13]*F(0,2)*F(1,1)*F(2,0)*F(2,1) +
2*d[18]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + 2*d[13]*F(0,1)*F(1,2)*F(2,0)*F(2,1) +
2*d[8]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[1]*F(0,0)*F(1,0)*pow(F(2,1),2) +
d[7]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[16]*F(0,2)*F(1,0)*pow(F(2,1),2) +
d[7]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[2]*F(0,1)*F(1,1)*pow(F(2,1),2) +
d[11]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[16]*F(0,0)*F(1,2)*pow(F(2,1),2) +
d[11]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[4]*F(0,2)*F(1,2)*pow(F(2,1),2) +
d[6]*F(2,0)*(F(0,1)*F(1,0)*F(2,0) + F(0,0)*(F(1,1)*F(2,0) + 2*F(1,0)*F(2,1))) +
2*d[15]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + 2*d[18]*F(0,1)*F(1,0)*F(2,0)*F(2,2) +
2*d[20]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + 2*d[18]*F(0,0)*F(1,1)*F(2,0)*F(2,2) +
2*d[16]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + 2*d[19]*F(0,2)*F(1,1)*F(2,0)*F(2,2) +
2*d[20]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + 2*d[19]*F(0,1)*F(1,2)*F(2,0)*F(2,2) +
2*d[17]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + 2*d[10]*F(0,0)*F(1,0)*F(2,1)*F(2,2) +
2*d[13]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + 2*d[19]*F(0,2)*F(1,0)*F(2,1)*F(2,2) +
2*d[13]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[11]*F(0,1)*F(1,1)*F(2,1)*F(2,2) +
2*d[14]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + 2*d[19]*F(0,0)*F(1,2)*F(2,1)*F(2,2) +
2*d[14]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[12]*F(0,2)*F(1,2)*F(2,1)*F(2,2) +
d[3]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[8]*F(0,1)*F(1,0)*pow(F(2,2),2) +
d[17]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[8]*F(0,0)*F(1,1)*pow(F(2,2),2) +
d[4]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[12]*F(0,2)*F(1,1)*pow(F(2,2),2) +
d[17]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[12]*F(0,1)*F(1,2)*pow(F(2,2),2) +
d[5]*F(0,2)*F(1,2)*pow(F(2,2),2);
c.d[9] = d[0]*pow(F(0,0),2)*pow(F(1,0),2) + d[9]*pow(F(0,1),2)*pow(F(1,0),2) +
2*d[15]*F(0,0)*F(0,2)*pow(F(1,0),2) + 2*d[18]*F(0,1)*F(0,2)*pow(F(1,0),2) +
d[20]*pow(F(0,2),2)*pow(F(1,0),2) + 2*d[1]*F(0,0)*F(0,1)*F(1,0)*F(1,1) +
2*d[9]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + 2*d[7]*pow(F(0,1),2)*F(1,0)*F(1,1) +
2*d[10]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + 2*d[18]*F(0,0)*F(0,2)*F(1,0)*F(1,1) +
2*d[13]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + 2*d[16]*F(0,1)*F(0,2)*F(1,0)*F(1,1) +
2*d[19]*pow(F(0,2),2)*F(1,0)*F(1,1) + d[9]*pow(F(0,0),2)*pow(F(1,1),2) +
2*d[7]*F(0,0)*F(0,1)*pow(F(1,1),2) + d[2]*pow(F(0,1),2)*pow(F(1,1),2) +
2*d[13]*F(0,0)*F(0,2)*pow(F(1,1),2) + 2*d[11]*F(0,1)*F(0,2)*pow(F(1,1),2) +
d[14]*pow(F(0,2),2)*pow(F(1,1),2) +
2*d[6]*F(0,0)*F(1,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) +
2*d[15]*pow(F(0,0),2)*F(1,0)*F(1,2) + 2*d[10]*F(0,0)*F(0,1)*F(1,0)*F(1,2) +
2*d[18]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + 2*d[13]*pow(F(0,1),2)*F(1,0)*F(1,2) +
2*d[3]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + 2*d[20]*F(0,0)*F(0,2)*F(1,0)*F(1,2) +
2*d[8]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + 2*d[19]*F(0,1)*F(0,2)*F(1,0)*F(1,2) +
2*d[17]*pow(F(0,2),2)*F(1,0)*F(1,2) + 2*d[18]*pow(F(0,0),2)*F(1,1)*F(1,2) +
2*d[13]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + 2*d[16]*F(0,0)*F(0,1)*F(1,1)*F(1,2) +
2*d[11]*pow(F(0,1),2)*F(1,1)*F(1,2) + 2*d[8]*F(0,0)*F(0,2)*F(1,1)*F(1,2) +
2*d[19]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + 2*d[4]*F(0,1)*F(0,2)*F(1,1)*F(1,2) +
2*d[14]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + 2*d[12]*pow(F(0,2),2)*F(1,1)*F(1,2) +
d[20]*pow(F(0,0),2)*pow(F(1,2),2) + 2*d[19]*F(0,0)*F(0,1)*pow(F(1,2),2) +
d[14]*pow(F(0,1),2)*pow(F(1,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(1,2),2) +
2*d[12]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[5]*pow(F(0,2),2)*pow(F(1,2),2);
c.d[10] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + d[1]*pow(F(0,1),2)*F(1,0)*F(2,0) +
2*d[15]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + 2*d[10]*F(0,1)*F(0,2)*F(1,0)*F(2,0) +
d[3]*pow(F(0,2),2)*F(1,0)*F(2,0) + 2*d[9]*F(0,0)*F(0,1)*F(1,1)*F(2,0) +
d[7]*pow(F(0,1),2)*F(1,1)*F(2,0) + 2*d[18]*F(0,0)*F(0,2)*F(1,1)*F(2,0) +
2*d[13]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[8]*pow(F(0,2),2)*F(1,1)*F(2,0) +
d[15]*pow(F(0,0),2)*F(1,2)*F(2,0) + 2*d[18]*F(0,0)*F(0,1)*F(1,2)*F(2,0) +
d[16]*pow(F(0,1),2)*F(1,2)*F(2,0) + 2*d[20]*F(0,0)*F(0,2)*F(1,2)*F(2,0) +
2*d[19]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[17]*pow(F(0,2),2)*F(1,2)*F(2,0) +
2*d[9]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[7]*pow(F(0,1),2)*F(1,0)*F(2,1) +
2*d[18]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + 2*d[13]*F(0,1)*F(0,2)*F(1,0)*F(2,1) +
d[8]*pow(F(0,2),2)*F(1,0)*F(2,1) + d[1]*pow(F(0,0),2)*F(1,1)*F(2,1) +
2*d[7]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[2]*pow(F(0,1),2)*F(1,1)*F(2,1) +
2*d[16]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + 2*d[11]*F(0,1)*F(0,2)*F(1,1)*F(2,1) +
d[4]*pow(F(0,2),2)*F(1,1)*F(2,1) + d[10]*pow(F(0,0),2)*F(1,2)*F(2,1) +
2*d[13]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[11]*pow(F(0,1),2)*F(1,2)*F(2,1) +
2*d[19]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + 2*d[14]*F(0,1)*F(0,2)*F(1,2)*F(2,1) +
d[12]*pow(F(0,2),2)*F(1,2)*F(2,1) +
d[6]*F(0,0)*(2*F(0,1)*F(1,0)*F(2,0) + F(0,0)*(F(1,1)*F(2,0) + F(1,0)*F(2,1))) +
d[15]*pow(F(0,0),2)*F(1,0)*F(2,2) + 2*d[18]*F(0,0)*F(0,1)*F(1,0)*F(2,2) +
d[16]*pow(F(0,1),2)*F(1,0)*F(2,2) + 2*d[20]*F(0,0)*F(0,2)*F(1,0)*F(2,2) +
2*d[19]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[17]*pow(F(0,2),2)*F(1,0)*F(2,2) +
d[10]*pow(F(0,0),2)*F(1,1)*F(2,2) + 2*d[13]*F(0,0)*F(0,1)*F(1,1)*F(2,2) +
d[11]*pow(F(0,1),2)*F(1,1)*F(2,2) + 2*d[19]*F(0,0)*F(0,2)*F(1,1)*F(2,2) +
2*d[14]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[12]*pow(F(0,2),2)*F(1,1)*F(2,2) +
d[3]*pow(F(0,0),2)*F(1,2)*F(2,2) + 2*d[8]*F(0,0)*F(0,1)*F(1,2)*F(2,2) +
d[4]*pow(F(0,1),2)*F(1,2)*F(2,2) + 2*d[17]*F(0,0)*F(0,2)*F(1,2)*F(2,2) +
2*d[12]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[5]*pow(F(0,2),2)*F(1,2)*F(2,2);
c.d[11] = d[0]*pow(F(1,0),3)*F(2,0) + d[1]*F(1,0)*pow(F(1,1),2)*F(2,0) +
2*d[9]*F(1,0)*pow(F(1,1),2)*F(2,0) + d[7]*pow(F(1,1),3)*F(2,0) +
3*d[15]*pow(F(1,0),2)*F(1,2)*F(2,0) + 2*d[10]*F(1,0)*F(1,1)*F(1,2)*F(2,0) +
4*d[18]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[13]*pow(F(1,1),2)*F(1,2)*F(2,0) +
d[16]*pow(F(1,1),2)*F(1,2)*F(2,0) + d[3]*F(1,0)*pow(F(1,2),2)*F(2,0) +
2*d[20]*F(1,0)*pow(F(1,2),2)*F(2,0) + d[8]*F(1,1)*pow(F(1,2),2)*F(2,0) +
2*d[19]*F(1,1)*pow(F(1,2),2)*F(2,0) + d[17]*pow(F(1,2),3)*F(2,0) +
d[1]*pow(F(1,0),2)*F(1,1)*F(2,1) + 2*d[9]*pow(F(1,0),2)*F(1,1)*F(2,1) +
3*d[7]*F(1,0)*pow(F(1,1),2)*F(2,1) + d[2]*pow(F(1,1),3)*F(2,1) +
d[10]*pow(F(1,0),2)*F(1,2)*F(2,1) + 2*d[18]*pow(F(1,0),2)*F(1,2)*F(2,1) +
4*d[13]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[16]*F(1,0)*F(1,1)*F(1,2)*F(2,1) +
3*d[11]*pow(F(1,1),2)*F(1,2)*F(2,1) + d[8]*F(1,0)*pow(F(1,2),2)*F(2,1) +
2*d[19]*F(1,0)*pow(F(1,2),2)*F(2,1) + d[4]*F(1,1)*pow(F(1,2),2)*F(2,1) +
2*d[14]*F(1,1)*pow(F(1,2),2)*F(2,1) + d[12]*pow(F(1,2),3)*F(2,1) +
d[6]*pow(F(1,0),2)*(3*F(1,1)*F(2,0) + F(1,0)*F(2,1)) +
d[15]*pow(F(1,0),3)*F(2,2) + d[10]*pow(F(1,0),2)*F(1,1)*F(2,2) +
2*d[18]*pow(F(1,0),2)*F(1,1)*F(2,2) + 2*d[13]*F(1,0)*pow(F(1,1),2)*F(2,2) +
d[16]*F(1,0)*pow(F(1,1),2)*F(2,2) + d[11]*pow(F(1,1),3)*F(2,2) +
d[3]*pow(F(1,0),2)*F(1,2)*F(2,2) + 2*d[20]*pow(F(1,0),2)*F(1,2)*F(2,2) +
2*d[8]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + 4*d[19]*F(1,0)*F(1,1)*F(1,2)*F(2,2) +
d[4]*pow(F(1,1),2)*F(1,2)*F(2,2) + 2*d[14]*pow(F(1,1),2)*F(1,2)*F(2,2) +
3*d[17]*F(1,0)*pow(F(1,2),2)*F(2,2) + 3*d[12]*F(1,1)*pow(F(1,2),2)*F(2,2) +
d[5]*pow(F(1,2),3)*F(2,2);
c.d[12] = d[0]*F(1,0)*pow(F(2,0),3) + d[15]*F(1,2)*pow(F(2,0),3) +
d[1]*F(1,1)*pow(F(2,0),2)*F(2,1) + 2*d[9]*F(1,1)*pow(F(2,0),2)*F(2,1) +
d[10]*F(1,2)*pow(F(2,0),2)*F(2,1) + 2*d[18]*F(1,2)*pow(F(2,0),2)*F(2,1) +
d[1]*F(1,0)*F(2,0)*pow(F(2,1),2) + 2*d[9]*F(1,0)*F(2,0)*pow(F(2,1),2) +
3*d[7]*F(1,1)*F(2,0)*pow(F(2,1),2) + 2*d[13]*F(1,2)*F(2,0)*pow(F(2,1),2) +
d[16]*F(1,2)*F(2,0)*pow(F(2,1),2) + d[7]*F(1,0)*pow(F(2,1),3) +
d[2]*F(1,1)*pow(F(2,1),3) + d[11]*F(1,2)*pow(F(2,1),3) +
d[6]*pow(F(2,0),2)*(F(1,1)*F(2,0) + 3*F(1,0)*F(2,1)) +
3*d[15]*F(1,0)*pow(F(2,0),2)*F(2,2) + d[10]*F(1,1)*pow(F(2,0),2)*F(2,2) +
2*d[18]*F(1,1)*pow(F(2,0),2)*F(2,2) + d[3]*F(1,2)*pow(F(2,0),2)*F(2,2) +
2*d[20]*F(1,2)*pow(F(2,0),2)*F(2,2) + 2*d[10]*F(1,0)*F(2,0)*F(2,1)*F(2,2) +
4*d[18]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 4*d[13]*F(1,1)*F(2,0)*F(2,1)*F(2,2) +
2*d[16]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[8]*F(1,2)*F(2,0)*F(2,1)*F(2,2) +
4*d[19]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[13]*F(1,0)*pow(F(2,1),2)*F(2,2) +
d[16]*F(1,0)*pow(F(2,1),2)*F(2,2) + 3*d[11]*F(1,1)*pow(F(2,1),2)*F(2,2) +
d[4]*F(1,2)*pow(F(2,1),2)*F(2,2) + 2*d[14]*F(1,2)*pow(F(2,1),2)*F(2,2) +
d[3]*F(1,0)*F(2,0)*pow(F(2,2),2) + 2*d[20]*F(1,0)*F(2,0)*pow(F(2,2),2) +
d[8]*F(1,1)*F(2,0)*pow(F(2,2),2) + 2*d[19]*F(1,1)*F(2,0)*pow(F(2,2),2) +
3*d[17]*F(1,2)*F(2,0)*pow(F(2,2),2) + d[8]*F(1,0)*F(2,1)*pow(F(2,2),2) +
2*d[19]*F(1,0)*F(2,1)*pow(F(2,2),2) + d[4]*F(1,1)*F(2,1)*pow(F(2,2),2) +
2*d[14]*F(1,1)*F(2,1)*pow(F(2,2),2) + 3*d[12]*F(1,2)*F(2,1)*pow(F(2,2),2) +
d[17]*F(1,0)*pow(F(2,2),3) + d[12]*F(1,1)*pow(F(2,2),3) +
d[5]*F(1,2)*pow(F(2,2),3);
c.d[13] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[15]*F(0,2)*pow(F(1,0),2)*F(2,0) +
d[1]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + d[9]*F(0,1)*F(1,0)*F(1,1)*F(2,0) +
d[10]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[18]*F(0,2)*F(1,0)*F(1,1)*F(2,0) +
d[9]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,0) +
d[13]*F(0,2)*pow(F(1,1),2)*F(2,0) + 2*d[15]*F(0,0)*F(1,0)*F(1,2)*F(2,0) +
d[10]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + d[18]*F(0,1)*F(1,0)*F(1,2)*F(2,0) +
d[3]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + d[20]*F(0,2)*F(1,0)*F(1,2)*F(2,0) +
2*d[18]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + d[13]*F(0,1)*F(1,1)*F(1,2)*F(2,0) +
d[16]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + d[8]*F(0,2)*F(1,1)*F(1,2)*F(2,0) +
d[19]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[20]*F(0,0)*pow(F(1,2),2)*F(2,0) +
d[19]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[17]*F(0,2)*pow(F(1,2),2)*F(2,0) +
d[9]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[18]*F(0,2)*pow(F(1,0),2)*F(2,1) +
d[1]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + d[9]*F(0,0)*F(1,0)*F(1,1)*F(2,1) +
2*d[7]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + d[13]*F(0,2)*F(1,0)*F(1,1)*F(2,1) +
d[16]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[7]*F(0,0)*pow(F(1,1),2)*F(2,1) +
d[2]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[11]*F(0,2)*pow(F(1,1),2)*F(2,1) +
d[10]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + d[18]*F(0,0)*F(1,0)*F(1,2)*F(2,1) +
2*d[13]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + d[8]*F(0,2)*F(1,0)*F(1,2)*F(2,1) +
d[19]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + d[13]*F(0,0)*F(1,1)*F(1,2)*F(2,1) +
d[16]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[11]*F(0,1)*F(1,1)*F(1,2)*F(2,1) +
d[4]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[14]*F(0,2)*F(1,1)*F(1,2)*F(2,1) +
d[19]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[14]*F(0,1)*pow(F(1,2),2)*F(2,1) +
d[12]*F(0,2)*pow(F(1,2),2)*F(2,1) +
d[6]*F(1,0)*(F(0,1)*F(1,0)*F(2,0) + F(0,0)*(2*F(1,1)*F(2,0) + F(1,0)*F(2,1))) +
d[15]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[18]*F(0,1)*pow(F(1,0),2)*F(2,2) +
d[20]*F(0,2)*pow(F(1,0),2)*F(2,2) + d[10]*F(0,0)*F(1,0)*F(1,1)*F(2,2) +
d[18]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + d[13]*F(0,1)*F(1,0)*F(1,1)*F(2,2) +
d[16]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + 2*d[19]*F(0,2)*F(1,0)*F(1,1)*F(2,2) +
d[13]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[11]*F(0,1)*pow(F(1,1),2)*F(2,2) +
d[14]*F(0,2)*pow(F(1,1),2)*F(2,2) + d[3]*F(0,0)*F(1,0)*F(1,2)*F(2,2) +
d[20]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + d[8]*F(0,1)*F(1,0)*F(1,2)*F(2,2) +
d[19]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + 2*d[17]*F(0,2)*F(1,0)*F(1,2)*F(2,2) +
d[8]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + d[19]*F(0,0)*F(1,1)*F(1,2)*F(2,2) +
d[4]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + d[14]*F(0,1)*F(1,1)*F(1,2)*F(2,2) +
2*d[12]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[17]*F(0,0)*pow(F(1,2),2)*F(2,2) +
d[12]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[5]*F(0,2)*pow(F(1,2),2)*F(2,2);
c.d[14] = d[0]*pow(F(1,0),2)*pow(F(2,0),2) + d[9]*pow(F(1,1),2)*pow(F(2,0),2) +
2*d[15]*F(1,0)*F(1,2)*pow(F(2,0),2) + 2*d[18]*F(1,1)*F(1,2)*pow(F(2,0),2) +
d[20]*pow(F(1,2),2)*pow(F(2,0),2) + 2*d[1]*F(1,0)*F(1,1)*F(2,0)*F(2,1) +
2*d[9]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[7]*pow(F(1,1),2)*F(2,0)*F(2,1) +
2*d[10]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + 2*d[18]*F(1,0)*F(1,2)*F(2,0)*F(2,1) +
2*d[13]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[16]*F(1,1)*F(1,2)*F(2,0)*F(2,1) +
2*d[19]*pow(F(1,2),2)*F(2,0)*F(2,1) + d[9]*pow(F(1,0),2)*pow(F(2,1),2) +
2*d[7]*F(1,0)*F(1,1)*pow(F(2,1),2) + d[2]*pow(F(1,1),2)*pow(F(2,1),2) +
2*d[13]*F(1,0)*F(1,2)*pow(F(2,1),2) + 2*d[11]*F(1,1)*F(1,2)*pow(F(2,1),2) +
d[14]*pow(F(1,2),2)*pow(F(2,1),2) +
2*d[6]*F(1,0)*F(2,0)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) +
2*d[15]*pow(F(1,0),2)*F(2,0)*F(2,2) + 2*d[10]*F(1,0)*F(1,1)*F(2,0)*F(2,2) +
2*d[18]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[13]*pow(F(1,1),2)*F(2,0)*F(2,2) +
2*d[3]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + 2*d[20]*F(1,0)*F(1,2)*F(2,0)*F(2,2) +
2*d[8]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[19]*F(1,1)*F(1,2)*F(2,0)*F(2,2) +
2*d[17]*pow(F(1,2),2)*F(2,0)*F(2,2) + 2*d[18]*pow(F(1,0),2)*F(2,1)*F(2,2) +
2*d[13]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[16]*F(1,0)*F(1,1)*F(2,1)*F(2,2) +
2*d[11]*pow(F(1,1),2)*F(2,1)*F(2,2) + 2*d[8]*F(1,0)*F(1,2)*F(2,1)*F(2,2) +
2*d[19]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + 2*d[4]*F(1,1)*F(1,2)*F(2,1)*F(2,2) +
2*d[14]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[12]*pow(F(1,2),2)*F(2,1)*F(2,2) +
d[20]*pow(F(1,0),2)*pow(F(2,2),2) + 2*d[19]*F(1,0)*F(1,1)*pow(F(2,2),2) +
d[14]*pow(F(1,1),2)*pow(F(2,2),2) + 2*d[17]*F(1,0)*F(1,2)*pow(F(2,2),2) +
2*d[12]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[5]*pow(F(1,2),2)*pow(F(2,2),2);
c.d[15] = d[0]*pow(F(0,0),3)*F(2,0) + d[1]*F(0,0)*pow(F(0,1),2)*F(2,0) +
2*d[9]*F(0,0)*pow(F(0,1),2)*F(2,0) + d[7]*pow(F(0,1),3)*F(2,0) +
3*d[15]*pow(F(0,0),2)*F(0,2)*F(2,0) + 2*d[10]*F(0,0)*F(0,1)*F(0,2)*F(2,0) +
4*d[18]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[13]*pow(F(0,1),2)*F(0,2)*F(2,0) +
d[16]*pow(F(0,1),2)*F(0,2)*F(2,0) + d[3]*F(0,0)*pow(F(0,2),2)*F(2,0) +
2*d[20]*F(0,0)*pow(F(0,2),2)*F(2,0) + d[8]*F(0,1)*pow(F(0,2),2)*F(2,0) +
2*d[19]*F(0,1)*pow(F(0,2),2)*F(2,0) + d[17]*pow(F(0,2),3)*F(2,0) +
d[1]*pow(F(0,0),2)*F(0,1)*F(2,1) + 2*d[9]*pow(F(0,0),2)*F(0,1)*F(2,1) +
3*d[7]*F(0,0)*pow(F(0,1),2)*F(2,1) + d[2]*pow(F(0,1),3)*F(2,1) +
d[10]*pow(F(0,0),2)*F(0,2)*F(2,1) + 2*d[18]*pow(F(0,0),2)*F(0,2)*F(2,1) +
4*d[13]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[16]*F(0,0)*F(0,1)*F(0,2)*F(2,1) +
3*d[11]*pow(F(0,1),2)*F(0,2)*F(2,1) + d[8]*F(0,0)*pow(F(0,2),2)*F(2,1) +
2*d[19]*F(0,0)*pow(F(0,2),2)*F(2,1) + d[4]*F(0,1)*pow(F(0,2),2)*F(2,1) +
2*d[14]*F(0,1)*pow(F(0,2),2)*F(2,1) + d[12]*pow(F(0,2),3)*F(2,1) +
d[6]*pow(F(0,0),2)*(3*F(0,1)*F(2,0) + F(0,0)*F(2,1)) +
d[15]*pow(F(0,0),3)*F(2,2) + d[10]*pow(F(0,0),2)*F(0,1)*F(2,2) +
2*d[18]*pow(F(0,0),2)*F(0,1)*F(2,2) + 2*d[13]*F(0,0)*pow(F(0,1),2)*F(2,2) +
d[16]*F(0,0)*pow(F(0,1),2)*F(2,2) + d[11]*pow(F(0,1),3)*F(2,2) +
d[3]*pow(F(0,0),2)*F(0,2)*F(2,2) + 2*d[20]*pow(F(0,0),2)*F(0,2)*F(2,2) +
2*d[8]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + 4*d[19]*F(0,0)*F(0,1)*F(0,2)*F(2,2) +
d[4]*pow(F(0,1),2)*F(0,2)*F(2,2) + 2*d[14]*pow(F(0,1),2)*F(0,2)*F(2,2) +
3*d[17]*F(0,0)*pow(F(0,2),2)*F(2,2) + 3*d[12]*F(0,1)*pow(F(0,2),2)*F(2,2) +
d[5]*pow(F(0,2),3)*F(2,2);
c.d[16] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[15]*F(0,2)*pow(F(1,0),2)*F(2,0) +
2*d[9]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + 2*d[18]*F(0,2)*F(1,0)*F(1,1)*F(2,0) +
d[1]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,0) +
d[16]*F(0,2)*pow(F(1,1),2)*F(2,0) + 2*d[15]*F(0,0)*F(1,0)*F(1,2)*F(2,0) +
2*d[18]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + 2*d[20]*F(0,2)*F(1,0)*F(1,2)*F(2,0) +
2*d[10]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[13]*F(0,1)*F(1,1)*F(1,2)*F(2,0) +
2*d[19]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[3]*F(0,0)*pow(F(1,2),2)*F(2,0) +
d[8]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[17]*F(0,2)*pow(F(1,2),2)*F(2,0) +
d[1]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[10]*F(0,2)*pow(F(1,0),2)*F(2,1) +
2*d[9]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + 2*d[7]*F(0,1)*F(1,0)*F(1,1)*F(2,1) +
2*d[13]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[7]*F(0,0)*pow(F(1,1),2)*F(2,1) +
d[2]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[11]*F(0,2)*pow(F(1,1),2)*F(2,1) +
2*d[18]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + 2*d[16]*F(0,1)*F(1,0)*F(1,2)*F(2,1) +
2*d[19]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + 2*d[13]*F(0,0)*F(1,1)*F(1,2)*F(2,1) +
2*d[11]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + 2*d[14]*F(0,2)*F(1,1)*F(1,2)*F(2,1) +
d[8]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[4]*F(0,1)*pow(F(1,2),2)*F(2,1) +
d[12]*F(0,2)*pow(F(1,2),2)*F(2,1) +
d[6]*F(1,0)*(F(0,1)*F(1,0)*F(2,0) + F(0,0)*(2*F(1,1)*F(2,0) + F(1,0)*F(2,1))) +
d[15]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[10]*F(0,1)*pow(F(1,0),2)*F(2,2) +
d[3]*F(0,2)*pow(F(1,0),2)*F(2,2) + 2*d[18]*F(0,0)*F(1,0)*F(1,1)*F(2,2) +
2*d[13]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + 2*d[8]*F(0,2)*F(1,0)*F(1,1)*F(2,2) +
d[16]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[11]*F(0,1)*pow(F(1,1),2)*F(2,2) +
d[4]*F(0,2)*pow(F(1,1),2)*F(2,2) + 2*d[20]*F(0,0)*F(1,0)*F(1,2)*F(2,2) +
2*d[19]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + 2*d[17]*F(0,2)*F(1,0)*F(1,2)*F(2,2) +
2*d[19]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[14]*F(0,1)*F(1,1)*F(1,2)*F(2,2) +
2*d[12]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[17]*F(0,0)*pow(F(1,2),2)*F(2,2) +
d[12]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[5]*F(0,2)*pow(F(1,2),2)*F(2,2);
c.d[17] = d[0]*F(0,0)*pow(F(2,0),3) + d[15]*F(0,2)*pow(F(2,0),3) +
d[1]*F(0,1)*pow(F(2,0),2)*F(2,1) + 2*d[9]*F(0,1)*pow(F(2,0),2)*F(2,1) +
d[10]*F(0,2)*pow(F(2,0),2)*F(2,1) + 2*d[18]*F(0,2)*pow(F(2,0),2)*F(2,1) +
d[1]*F(0,0)*F(2,0)*pow(F(2,1),2) + 2*d[9]*F(0,0)*F(2,0)*pow(F(2,1),2) +
3*d[7]*F(0,1)*F(2,0)*pow(F(2,1),2) + 2*d[13]*F(0,2)*F(2,0)*pow(F(2,1),2) +
d[16]*F(0,2)*F(2,0)*pow(F(2,1),2) + d[7]*F(0,0)*pow(F(2,1),3) +
d[2]*F(0,1)*pow(F(2,1),3) + d[11]*F(0,2)*pow(F(2,1),3) +
d[6]*pow(F(2,0),2)*(F(0,1)*F(2,0) + 3*F(0,0)*F(2,1)) +
3*d[15]*F(0,0)*pow(F(2,0),2)*F(2,2) + d[10]*F(0,1)*pow(F(2,0),2)*F(2,2) +
2*d[18]*F(0,1)*pow(F(2,0),2)*F(2,2) + d[3]*F(0,2)*pow(F(2,0),2)*F(2,2) +
2*d[20]*F(0,2)*pow(F(2,0),2)*F(2,2) + 2*d[10]*F(0,0)*F(2,0)*F(2,1)*F(2,2) +
4*d[18]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 4*d[13]*F(0,1)*F(2,0)*F(2,1)*F(2,2) +
2*d[16]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[8]*F(0,2)*F(2,0)*F(2,1)*F(2,2) +
4*d[19]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[13]*F(0,0)*pow(F(2,1),2)*F(2,2) +
d[16]*F(0,0)*pow(F(2,1),2)*F(2,2) + 3*d[11]*F(0,1)*pow(F(2,1),2)*F(2,2) +
d[4]*F(0,2)*pow(F(2,1),2)*F(2,2) + 2*d[14]*F(0,2)*pow(F(2,1),2)*F(2,2) +
d[3]*F(0,0)*F(2,0)*pow(F(2,2),2) + 2*d[20]*F(0,0)*F(2,0)*pow(F(2,2),2) +
d[8]*F(0,1)*F(2,0)*pow(F(2,2),2) + 2*d[19]*F(0,1)*F(2,0)*pow(F(2,2),2) +
3*d[17]*F(0,2)*F(2,0)*pow(F(2,2),2) + d[8]*F(0,0)*F(2,1)*pow(F(2,2),2) +
2*d[19]*F(0,0)*F(2,1)*pow(F(2,2),2) + d[4]*F(0,1)*F(2,1)*pow(F(2,2),2) +
2*d[14]*F(0,1)*F(2,1)*pow(F(2,2),2) + 3*d[12]*F(0,2)*F(2,1)*pow(F(2,2),2) +
d[17]*F(0,0)*pow(F(2,2),3) + d[12]*F(0,1)*pow(F(2,2),3) +
d[5]*F(0,2)*pow(F(2,2),3);
c.d[18] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + d[9]*pow(F(0,1),2)*F(1,0)*F(2,0) +
2*d[15]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + 2*d[18]*F(0,1)*F(0,2)*F(1,0)*F(2,0) +
d[20]*pow(F(0,2),2)*F(1,0)*F(2,0) + d[1]*F(0,0)*F(0,1)*F(1,1)*F(2,0) +
d[9]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[7]*pow(F(0,1),2)*F(1,1)*F(2,0) +
d[10]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + d[18]*F(0,0)*F(0,2)*F(1,1)*F(2,0) +
d[13]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[16]*F(0,1)*F(0,2)*F(1,1)*F(2,0) +
d[19]*pow(F(0,2),2)*F(1,1)*F(2,0) + d[15]*pow(F(0,0),2)*F(1,2)*F(2,0) +
d[10]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[18]*F(0,0)*F(0,1)*F(1,2)*F(2,0) +
d[13]*pow(F(0,1),2)*F(1,2)*F(2,0) + d[3]*F(0,0)*F(0,2)*F(1,2)*F(2,0) +
d[20]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + d[8]*F(0,1)*F(0,2)*F(1,2)*F(2,0) +
d[19]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[17]*pow(F(0,2),2)*F(1,2)*F(2,0) +
d[1]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[9]*F(0,0)*F(0,1)*F(1,0)*F(2,1) +
d[7]*pow(F(0,1),2)*F(1,0)*F(2,1) + d[10]*F(0,0)*F(0,2)*F(1,0)*F(2,1) +
d[18]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + d[13]*F(0,1)*F(0,2)*F(1,0)*F(2,1) +
d[16]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[19]*pow(F(0,2),2)*F(1,0)*F(2,1) +
d[9]*pow(F(0,0),2)*F(1,1)*F(2,1) + 2*d[7]*F(0,0)*F(0,1)*F(1,1)*F(2,1) +
d[2]*pow(F(0,1),2)*F(1,1)*F(2,1) + 2*d[13]*F(0,0)*F(0,2)*F(1,1)*F(2,1) +
2*d[11]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[14]*pow(F(0,2),2)*F(1,1)*F(2,1) +
d[18]*pow(F(0,0),2)*F(1,2)*F(2,1) + d[13]*F(0,0)*F(0,1)*F(1,2)*F(2,1) +
d[16]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[11]*pow(F(0,1),2)*F(1,2)*F(2,1) +
d[8]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + d[19]*F(0,0)*F(0,2)*F(1,2)*F(2,1) +
d[4]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[14]*F(0,1)*F(0,2)*F(1,2)*F(2,1) +
d[12]*pow(F(0,2),2)*F(1,2)*F(2,1) +
d[6]*F(0,0)*(2*F(0,1)*F(1,0)*F(2,0) + F(0,0)*(F(1,1)*F(2,0) + F(1,0)*F(2,1))) +
d[15]*pow(F(0,0),2)*F(1,0)*F(2,2) + d[10]*F(0,0)*F(0,1)*F(1,0)*F(2,2) +
d[18]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[13]*pow(F(0,1),2)*F(1,0)*F(2,2) +
d[3]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + d[20]*F(0,0)*F(0,2)*F(1,0)*F(2,2) +
d[8]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[19]*F(0,1)*F(0,2)*F(1,0)*F(2,2) +
d[17]*pow(F(0,2),2)*F(1,0)*F(2,2) + d[18]*pow(F(0,0),2)*F(1,1)*F(2,2) +
d[13]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[16]*F(0,0)*F(0,1)*F(1,1)*F(2,2) +
d[11]*pow(F(0,1),2)*F(1,1)*F(2,2) + d[8]*F(0,0)*F(0,2)*F(1,1)*F(2,2) +
d[19]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + d[4]*F(0,1)*F(0,2)*F(1,1)*F(2,2) +
d[14]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[12]*pow(F(0,2),2)*F(1,1)*F(2,2) +
d[20]*pow(F(0,0),2)*F(1,2)*F(2,2) + 2*d[19]*F(0,0)*F(0,1)*F(1,2)*F(2,2) +
d[14]*pow(F(0,1),2)*F(1,2)*F(2,2) + 2*d[17]*F(0,0)*F(0,2)*F(1,2)*F(2,2) +
2*d[12]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[5]*pow(F(0,2),2)*F(1,2)*F(2,2);
c.d[19] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[15]*F(0,2)*F(1,0)*pow(F(2,0),2) +
d[9]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[18]*F(0,2)*F(1,1)*pow(F(2,0),2) +
d[15]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[18]*F(0,1)*F(1,2)*pow(F(2,0),2) +
d[20]*F(0,2)*F(1,2)*pow(F(2,0),2) + d[1]*F(0,1)*F(1,0)*F(2,0)*F(2,1) +
d[9]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + d[10]*F(0,2)*F(1,0)*F(2,0)*F(2,1) +
d[18]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + d[1]*F(0,0)*F(1,1)*F(2,0)*F(2,1) +
d[9]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[7]*F(0,1)*F(1,1)*F(2,0)*F(2,1) +
d[13]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + d[16]*F(0,2)*F(1,1)*F(2,0)*F(2,1) +
d[10]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + d[18]*F(0,0)*F(1,2)*F(2,0)*F(2,1) +
d[13]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + d[16]*F(0,1)*F(1,2)*F(2,0)*F(2,1) +
2*d[19]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[9]*F(0,0)*F(1,0)*pow(F(2,1),2) +
d[7]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[13]*F(0,2)*F(1,0)*pow(F(2,1),2) +
d[7]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[2]*F(0,1)*F(1,1)*pow(F(2,1),2) +
d[11]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[13]*F(0,0)*F(1,2)*pow(F(2,1),2) +
d[11]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[14]*F(0,2)*F(1,2)*pow(F(2,1),2) +
d[6]*F(2,0)*(F(0,1)*F(1,0)*F(2,0) + F(0,0)*(F(1,1)*F(2,0) + 2*F(1,0)*F(2,1))) +
2*d[15]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + d[10]*F(0,1)*F(1,0)*F(2,0)*F(2,2) +
d[18]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + d[3]*F(0,2)*F(1,0)*F(2,0)*F(2,2) +
d[20]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + d[10]*F(0,0)*F(1,1)*F(2,0)*F(2,2) +
d[18]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[13]*F(0,1)*F(1,1)*F(2,0)*F(2,2) +
d[8]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + d[19]*F(0,2)*F(1,1)*F(2,0)*F(2,2) +
d[3]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + d[20]*F(0,0)*F(1,2)*F(2,0)*F(2,2) +
d[8]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + d[19]*F(0,1)*F(1,2)*F(2,0)*F(2,2) +
2*d[17]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + 2*d[18]*F(0,0)*F(1,0)*F(2,1)*F(2,2) +
d[13]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + d[16]*F(0,1)*F(1,0)*F(2,1)*F(2,2) +
d[8]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + d[19]*F(0,2)*F(1,0)*F(2,1)*F(2,2) +
d[13]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + d[16]*F(0,0)*F(1,1)*F(2,1)*F(2,2) +
2*d[11]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + d[4]*F(0,2)*F(1,1)*F(2,1)*F(2,2) +
d[14]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + d[8]*F(0,0)*F(1,2)*F(2,1)*F(2,2) +
d[19]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + d[4]*F(0,1)*F(1,2)*F(2,1)*F(2,2) +
d[14]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[12]*F(0,2)*F(1,2)*F(2,1)*F(2,2) +
d[20]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[19]*F(0,1)*F(1,0)*pow(F(2,2),2) +
d[17]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[19]*F(0,0)*F(1,1)*pow(F(2,2),2) +
d[14]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[12]*F(0,2)*F(1,1)*pow(F(2,2),2) +
d[17]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[12]*F(0,1)*F(1,2)*pow(F(2,2),2) +
d[5]*F(0,2)*F(1,2)*pow(F(2,2),2);
c.d[20] = d[0]*pow(F(0,0),2)*pow(F(2,0),2) + d[9]*pow(F(0,1),2)*pow(F(2,0),2) +
2*d[15]*F(0,0)*F(0,2)*pow(F(2,0),2) + 2*d[18]*F(0,1)*F(0,2)*pow(F(2,0),2) +
d[20]*pow(F(0,2),2)*pow(F(2,0),2) + 2*d[1]*F(0,0)*F(0,1)*F(2,0)*F(2,1) +
2*d[9]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + 2*d[7]*pow(F(0,1),2)*F(2,0)*F(2,1) +
2*d[10]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + 2*d[18]*F(0,0)*F(0,2)*F(2,0)*F(2,1) +
2*d[13]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + 2*d[16]*F(0,1)*F(0,2)*F(2,0)*F(2,1) +
2*d[19]*pow(F(0,2),2)*F(2,0)*F(2,1) + d[9]*pow(F(0,0),2)*pow(F(2,1),2) +
2*d[7]*F(0,0)*F(0,1)*pow(F(2,1),2) + d[2]*pow(F(0,1),2)*pow(F(2,1),2) +
2*d[13]*F(0,0)*F(0,2)*pow(F(2,1),2) + 2*d[11]*F(0,1)*F(0,2)*pow(F(2,1),2) +
d[14]*pow(F(0,2),2)*pow(F(2,1),2) +
2*d[6]*F(0,0)*F(2,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) +
2*d[15]*pow(F(0,0),2)*F(2,0)*F(2,2) + 2*d[10]*F(0,0)*F(0,1)*F(2,0)*F(2,2) +
2*d[18]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + 2*d[13]*pow(F(0,1),2)*F(2,0)*F(2,2) +
2*d[3]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + 2*d[20]*F(0,0)*F(0,2)*F(2,0)*F(2,2) +
2*d[8]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + 2*d[19]*F(0,1)*F(0,2)*F(2,0)*F(2,2) +
2*d[17]*pow(F(0,2),2)*F(2,0)*F(2,2) + 2*d[18]*pow(F(0,0),2)*F(2,1)*F(2,2) +
2*d[13]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + 2*d[16]*F(0,0)*F(0,1)*F(2,1)*F(2,2) +
2*d[11]*pow(F(0,1),2)*F(2,1)*F(2,2) + 2*d[8]*F(0,0)*F(0,2)*F(2,1)*F(2,2) +
2*d[19]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + 2*d[4]*F(0,1)*F(0,2)*F(2,1)*F(2,2) +
2*d[14]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + 2*d[12]*pow(F(0,2),2)*F(2,1)*F(2,2) +
d[20]*pow(F(0,0),2)*pow(F(2,2),2) + 2*d[19]*F(0,0)*F(0,1)*pow(F(2,2),2) +
d[14]*pow(F(0,1),2)*pow(F(2,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(2,2),2) +
2*d[12]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[5]*pow(F(0,2),2)*pow(F(2,2),2);
return c;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/Callback.cpp | .cpp | 2,630 | 85 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "Callback.h"
//-----------------------------------------------------------------------------
CallbackHandler::CallbackHandler()
{
m_event = 0;
}
//-----------------------------------------------------------------------------
CallbackHandler::~CallbackHandler()
{
}
//-----------------------------------------------------------------------------
//! This function adds a callback routine
//
void CallbackHandler::AddCallback(FECORE_CB_FNC pcb, unsigned int nwhen, void *pd, CBInsertPolicy insert)
{
FECORE_CALLBACK cb;
cb.m_pcb = pcb;
cb.m_pd = pd;
cb.m_nwhen = nwhen;
if (insert == CBInsertPolicy::CB_ADD_END)
m_pcb.push_back(cb);
else
m_pcb.push_front(cb);
}
//-----------------------------------------------------------------------------
//! Call the callback functions.
//
bool CallbackHandler::DoCallback(FEModel* fem, unsigned int nevent)
{
m_event = nevent;
std::list<FECORE_CALLBACK>::iterator it = m_pcb.begin();
for (int i = 0; i<(int)m_pcb.size(); ++i, ++it)
{
// call the callback function
if (it->m_nwhen & nevent)
{
bool bret = (it->m_pcb)(fem, nevent, it->m_pd);
if (bret == false) return false;
}
}
m_event = 0;
return true;
}
//! Get the current callback reason (or zero if not inside DoCallback)
unsigned int CallbackHandler::CurrentEvent() const
{
return m_event;
}
| C++ |
3D | febiosoftware/FEBio | FECore/mortar.cpp | .cpp | 15,909 | 605 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <assert.h>
#include "mortar.h"
#include <math.h>
#include "FEMesh.h"
//-----------------------------------------------------------------------------
// subtract operator for POINT2D
POINT2D operator - (POINT2D a, POINT2D b)
{
POINT2D p = {a.x - b.x, a.y - b.y};
return p;
}
//-----------------------------------------------------------------------------
// dot product for POINT2D
double operator * (POINT2D a, POINT2D b)
{
return a.x*b.x + a.y*b.y;
}
//-----------------------------------------------------------------------------
// This function returns twice the area of the triangle defined by [a,b,c].
double Area2(POINT2D a, POINT2D b, POINT2D c)
{
return ((b.x - a.x)*(c.y - a.y) - (c.x - a.x)*(b.y - a.y));
}
//-----------------------------------------------------------------------------
// This function returns the sign of the area, defined by three POINT2Ds.
int AreaSign(POINT2D a, POINT2D b, POINT2D c, const double eps)
{
double d = ((b.x - a.x)*(c.y - a.y) - (c.x - a.x)*(b.y - a.y));
if (d > eps) return 1;
else if (d < -eps) return -1;
return 0;
}
//-----------------------------------------------------------------------------
// Checks collinearity of three POINT2Ds
bool Collinear(POINT2D a, POINT2D b, POINT2D c, const double eps)
{
return fabs(Area2(a, b, c)) <= eps;
}
//-----------------------------------------------------------------------------
// This function checks if c is between a, b.
// NOTE: This function assumes that the three points are collinear
bool Between(POINT2D a, POINT2D b, POINT2D c)
{
if (a.x != b.x)
{
return (((a.x <= c.x)&&(c.x <= b.x))||
((a.x >= c.x)&&(c.x >= b.x)));
}
else
{
return (((a.y <= c.y)&&(c.y <= b.y))||
((a.y >= c.y)&&(c.y >= b.y)));
}
}
//-----------------------------------------------------------------------------
// This function checks if the two segments (a,b) and (c,d) are collinear
// and if so, returns a POINT2D of intersection. The return code can be used
// to identify the intersection type
// 0 = no overlap
// 3 = overlap
// NOTE: This function assumes that the segments are parallel
int ParallelInt(POINT2D a, POINT2D b, POINT2D c, POINT2D d, POINT2D& p, const double eps)
{
// make sure POINT2Ds are collinear
if (!Collinear(a,b,c, eps)) return 0;
if (Between(a, b, c)) { p = c; return 3; }
if (Between(a, b, d)) { p = d; return 3; }
if (Between(c, d, a)) { p = a; return 3; }
if (Between(c, d, b)) { p = b; return 3; }
return 0;
}
//-----------------------------------------------------------------------------
// This function calculates the segment-segment intersection. The first segment
// is defined by POINT2Ds (a,b) and the second segment by (c,d). The intersection
// POINT2D (if it exists) is returned in p. The return code can be used to identify
// the intersection type:
// 0 = no intersection
// 1 = proper intersection
// 2 = vertex intersection (segments coincide at vertex)
// 3 = edge intersections (segments cooincide)
int SegSegInt(POINT2D a, POINT2D b, POINT2D c, POINT2D d, POINT2D& p, const double eps)
{
// return code
int nret = -1;
// calculate the denominator
double denom = a.x*(d.y - c.y) + b.x*(c.y - d.y) + d.x*(b.y - a.y) + c.x*(a.y - b.y);
// if the denominator is zero, the segments are parallel; handle separately
if (fabs(denom) <= eps) return ParallelInt(a, b, c, d, p, eps);
double num = a.x*(d.y - c.y) + c.x*(a.y - d.y) + d.x*(c.y - a.y);
if ((fabs(num)<=eps)||(num==denom)) nret = 2;
double s = num / denom;
num = -(a.x*(c.y - b.y) + b.x*(a.y - c.y) + c.x*(b.y - a.y));
if ((fabs(num)<=eps)||(num==denom)) nret = 2;
double t = num / denom;
// check for proper intersection
if ((0.0 < s)&&(s < 1.0)&&(0.0 < t)&&(t < 1.0)) nret = 1;
else if ((0.0 > s)||(s > 1.0) || (0.0 > t) || (t > 1.0)) nret = 0;
// find the intersection POINT2D
p.x = a.x + s*(b.x - a.x);
p.y = a.y + s*(b.y - a.y);
assert(nret >= 0);
return nret;
}
//-----------------------------------------------------------------------------
// See if a point is inside a (counter-clockwise) polygon
bool PointInConvexPoly(POINT2D p, POINT2D* P, int n)
{
for (int i=0; i<n; ++i)
{
int i1 = (i+1)%n;
if (Area2(P[i],P[i1],p) < 0) return false;
}
return true;
}
//-----------------------------------------------------------------------------
// see if a convex polygon P is inside the convex polygon Q
bool ConvexPolyInConvexPoly(POINT2D* P, int n, POINT2D* Q, int m)
{
for (int i=0; i<n; ++i)
{
if (PointInConvexPoly(P[i], Q, m) == false) return false;
}
return true;
}
//-----------------------------------------------------------------------------
int InOut(int inFlag, int aHB, int bHA)
{
if (aHB > 0) return -1;
else if (bHA > 0) return 1;
else return inFlag;
}
int Advance(int a, int *aa, int n)
{
(*aa)++;
return (a+1)%n;
}
//-----------------------------------------------------------------------------
// Calculates the intersection between two convex polygons
int ConvexIntersect(POINT2D* P, int n, POINT2D* Q, int m, POINT2D* R)
{
int a, b; // indices on P and Q (resp)
int a1, b1; // a-1, b-1 (resp)
POINT2D A, B; // directed edges on P, Q (resp)
int cross; // sign of z-component of A x B
int bHA, aHB; // b in H(a); a in H(b)
POINT2D O = {0,0}; // origin
POINT2D p; // intersection points
int inFlag; // -1,0,1 = InP, Unknown, InQ
int aa, ba; // number of advances on a & b indices (after 1st iter)
bool FirstPOINT2D; // is this the first POINT2D (used to initialize)
POINT2D p0; // the first POINT2D
int code; // SegSegInt return code
int nr; // number of POINT2Ds in intersection
const double eps = 1e-7;
// Initialize the variables
nr = 0;
a = 0; b = 0; aa = 0; ba = 0;
inFlag = 0; FirstPOINT2D = true;
do
{
// computation of key variables
a1 = (a + n - 1) % n;
b1 = (b + m - 1) % m;
A = P[a] - P[a1];
B = Q[b] - Q[b1];
cross = AreaSign(O, A, B, eps);
aHB = AreaSign(Q[b1], Q[b], P[a], eps);
bHA = AreaSign(P[a1], P[a], Q[b], eps);
// if A,B intersect, update inflag
code = SegSegInt(P[a1], P[a], Q[b1], Q[b], p, eps);
if ((code==1)||(code==2))
{
if ((inFlag == 0) && FirstPOINT2D)
{
aa = ba = 0;
FirstPOINT2D = false;
p0 = p;
}
R[nr++] = p;
inFlag = InOut(inFlag, aHB, bHA);
}
// --- Advance rules ---
if ((code == 3) && (A*B < 0))
{
// P,Q intersect in this edge only
break;
}
if ((cross == 0) && (aHB < 0) && (bHA < 0))
{
// printf("P,Q are disjoint\n");
break;
}
else if ((cross == 0) && (aHB == 0) && (bHA == 0))
{
if (inFlag == -1)
b = Advance(b, &ba, m);
else
a = Advance(a, &aa, n);
}
else if (cross >= 0)
{
if (bHA > 0)
{
if (inFlag == -1) R[nr++] = P[a];
a = Advance(a, &aa, n);
}
else
{
if (inFlag == 1) R[nr++] = Q[b];
b = Advance(b, &ba, m);
}
}
else // if cross < 0
{
if (aHB > 0)
{
if (inFlag == 1) R[nr++] = Q[b];
b = Advance(b, &ba, m);
}
else
{
if (inFlag == -1) R[nr++] = P[a];
a = Advance(a, &aa, n);
}
}
// Quit when both adv, indices have cycled, or one has cycled twice
}
while ( ((aa<n) || (ba < m)) && (aa < 2*n) && (ba < 2*m) );
// deal with special cases (not implemented)
if (inFlag == 0)
{
// The boundaries of P and Q do not cross
// see if one polygon is inside the other one
if (ConvexPolyInConvexPoly(P, n, Q, m))
{
// P is inside Q so copy P to R
for (int i=0; i<n; ++i) R[i] = P[i];
nr = n;
}
else if (ConvexPolyInConvexPoly(Q, m, P, n))
{
// Q is inside P so copy Q to R
for (int i=0; i<m; ++i) R[i] = Q[i];
nr = m;
}
}
return nr;
}
//-----------------------------------------------------------------------------
// This function calculates the intersection of a line and a segment. The line
// is defined by POINT2Ds (a,b) and the segment by (c,d). The intersection
// POINT2D (if it exists) is returned in p. The return code can be used to identify
// the intersection type:
// 0 = no intersection
// 1 = proper intersection
// 2 = vertex intersection (segment coincide at vertex)
// 3 = edge intersections (segment cooincide with line)
int LineSegInt(POINT2D a, POINT2D b, POINT2D c, POINT2D d, POINT2D& p, double eps)
{
// return code
int nret = -1;
// calculate the denominator
double denom = a.x*(d.y - c.y) + b.x*(c.y - d.y) + d.x*(b.y - a.y) + c.x*(a.y - b.y);
// if the denominator is zero, the segments are parallel; handle separately
if (fabs(denom) <= eps) return ParallelInt(a, b, c, d, p, eps);
double num = a.x*(d.y - c.y) + c.x*(a.y - d.y) + d.x*(c.y - a.y);
if ((fabs(num) <= eps)||(num==denom)) nret = 2;
double s = num / denom;
num = -(a.x*(c.y - b.y) + b.x*(a.y - c.y) + c.x*(b.y - a.y));
if ((fabs(num) <= eps)||(num==denom)) nret = 2;
double t = num / denom;
// check for proper intersection
if (nret == -1)
{
if ((0.0 < t) && (t < 1.0)) nret = 1;
else if ((0.0 > t) || (t > 1.0)) nret = 0;
}
// find the intersection POINT2D
p.x = a.x + s*(b.x - a.x);
p.y = a.y + s*(b.y - a.y);
assert(nret >= 0);
return nret;
}
//-----------------------------------------------------------------------------
int ConvexIntersectSH(POINT2D* P, int n, POINT2D* Q, int m, POINT2D* R)
{
// temporary buffer
POINT2D tmp[11];
// copy Q to R
for (int i=0; i<m; ++i) R[i] = Q[i];
int nr = m;
if (nr == 0) return 0;
const double eps = 1e-7;
POINT2D p;
// loop over all the edges of the clipping polygon P
for (int a=0; a<n; ++a)
{
// an edge is defined by the current point and the next one
int a1 = (a+1)%n;
// reset the tmp buffer
int ntmp = 0;
// see if the last point lies inside the edge A
// we'll use this to decide if the edges cross
int b1 = nr-1;
int b1HA = AreaSign(P[a], P[a1], R[b1], eps);
// loop over all the input points
for (int b=0; b<nr; ++b)
{
// see if this point lies inside the edge
int bHA = AreaSign(P[a], P[a1], R[b], eps);
if (bHA == 0)
{
// point b lies on the edge so just add it
tmp[ntmp++] = R[b];
}
else if (bHA > 0)
{
// point b lies inside the edge A
// so check whether an edge was crossed
if (b1HA < 0)
{
int ncode = LineSegInt(P[a],P[a1],R[b1],R[b], p, eps);
assert((ncode==1)||(ncode==2));
// add intersection point
tmp[ntmp++] = p;
}
// add point b
tmp[ntmp++] = R[b];
}
else if (bHA < 0)
{
// point b lies outside edge, but we still may have an intersection
if (b1HA > 0)
{
int ncode = LineSegInt(P[a],P[a1],R[b1],R[b], p, eps);
assert((ncode==1)||(ncode==2));
// add intersection point
tmp[ntmp++] = p;
}
}
// advance
b1 = b;
b1HA = bHA;
}
// copy tmp buffer to output buffer
for (int i=0; i<ntmp; i++) R[i] = tmp[i];
nr = ntmp;
// if we did not add any points, the polygons do not intersect
if (nr == 0) break;
}
return nr;
}
double tri_area(vec3d r[3])
{
return ((r[1]-r[0])^(r[2]-r[0])).norm()*0.5;
}
bool CalculateMortarIntersection(FESurface& ss, FESurface& ms, int k, int l, Patch& patch)
{
// clear the patch
patch.Clear();
// get the surface elements
FESurfaceElement& es = ss.Element(k);
FESurfaceElement& em = ms.Element(l);
// get the nodal coordinates
const int M = FEElement::MAX_NODES;
vec3d rs[M], rm[M];
int ns = es.Nodes(), nm = em.Nodes();
for (int i=0; i<ns; ++i) rs[i] = ss.Node(es.m_lnode[i]).m_rt;
for (int i=0; i<nm; ++i) rm[i] = ms.Node(em.m_lnode[i]).m_rt;
// setup an orthonormal coordinate system
vec3d c = rs[0];
vec3d e1 = rs[ 1] - rs[0]; e1.unit();
vec3d e2 = rs[ns-1] - rs[0]; e2.unit();
vec3d e3 = e1^e2; e3.unit();
e2 = e3^e1;
// project all points onto this plane
POINT2D P[M], Q[M], R[M];
for (int i=0; i<ns; ++i)
{
vec3d r = rs[i] - c;
vec3d q = r - e3*(r*e3);
P[i].x = q*e1;
P[i].y = q*e2;
}
// now we do the nodes
// Note that we loop backwards since the element will
// in general have opposite winding
for (int i=0; i<nm; ++i)
{
vec3d r = rm[nm-i-1] - c;
vec3d q = r - e3*(r*e3);
Q[i].x = q*e1;
Q[i].y = q*e2;
}
// now we calculate the intersection
int nr = ConvexIntersectSH(P, ns, Q, nm, R);
/* if (nr > 0)
{
for (int i=0; i<nr; ++i)
{
POINT2D& r = R[i];
vec3d x = e1*r.x + e2*r.y + c;
double qr, qs;
vec3d ps = ss.ProjectToSurface(es, x, qr, qs);
const double eps = 1e-4;
if ((qr < -eps) || (qs < -eps) || (qr+qs > 1+eps))
{
// error
int a = 0;
}
vec3d pm = ms.ProjectToSurface(em, x, qr, qs);
if ((qr < -eps) || (qs < -eps) || (qr+qs > 1+eps))
{
// error
int a = 0;
}
}
}
*/
if (nr >= 3)
{
// evaluate the center of the patch
POINT2D d;
d.x = d.y = 0;
for (int k=0; k<nr; ++k)
{
d.x += R[k].x;
d.y += R[k].y;
}
d.x /= nr; d.y /= nr;
// the center point is always the same
vec3d r[3];
r[0] = e1*d.x + e2*d.y + c;
// calculate the other patch points
for (int k=0; k<nr; ++k)
{
int k1 = (k+1)%nr;
r[1] = e1*R[k ].x + e2*R[k ].y + c;
r[2] = e1*R[k1].x + e2*R[k1].y + c;
patch.Add(r);
}
}
// return
return (patch.Empty() == false);
}
void CalculateMortarSurface(FESurface& ss, FESurface& ms, MortarSurface& mortar)
{
// loop over all non-mortar facets
int NSF = ss.Elements();
int NMF = ms.Elements();
for (int i=0; i<NSF; ++i)
{
// get the non-mortar surface element
FESurfaceElement& se = ss.Element(i);
// loop over all the mortar surface elements
for (int j=0; j<NMF; ++j)
{
// get the next surface element
FESurfaceElement& me = ms.Element(j);
// calculate the patch of triangles, representing the intersection
// of the non-mortar facet with the mortar facet
Patch patch(i,j);
CalculateMortarIntersection(ss, ms, i, j, patch);
mortar.AddPatch(patch);
}
}
}
bool ExportMortar(MortarSurface& mortar, const char* szfile)
{
FILE* fp = fopen(szfile, "wt");
if (fp == 0) return false;
fprintf(fp, "solid %s\n", "mortar");
int NP = mortar.Patches();
for (int i=0; i<NP; ++i)
{
Patch& patch = mortar.GetPatch(i);
int np = patch.Size();
for (int j=0; j<np; j++)
{
Patch::FACET& tri = patch.Facet(j);
vec3d e1 = tri.r[1] - tri.r[0];
vec3d e2 = tri.r[2] - tri.r[0];
vec3d n = e1^e2; n.unit();
fprintf(fp, "facet normal %g %g %g\n", n.x, n.y, n.z);
fprintf(fp, "outer loop\n");
for (int k=0; k<3; ++k)
{
vec3d& r = tri.r[k];
fprintf(fp, "vertex %g %g %g\n", r.x, r.y, r.z);
}
fprintf(fp, "endloop\n");
fprintf(fp, "endfacet\n");
}
}
fprintf(fp, "endsolid\n");
fclose(fp);
return true;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECoreTask.h | .h | 1,975 | 54 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
//-----------------------------------------------------------------------------
class FEModel;
//-----------------------------------------------------------------------------
// The FECoreTask class is the base class for all tasks.
// A task is simply the highest level module which defines what the code will do.
class FECORE_API FECoreTask : public FECoreBase
{
FECORE_SUPER_CLASS(FETASK_ID)
FECORE_BASE_CLASS(FECoreTask)
public:
FECoreTask(FEModel* fem);
virtual ~FECoreTask(void);
//! initialize the task
//! make sure to call FEModel::Init at some point
virtual bool Init(const char* szfile) = 0;
//! Run the task.
virtual bool Run() = 0;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/ad.h | .h | 15,132 | 628 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "tens4d.h"
#include "quatd.h"
#include "fecore_api.h"
#include <functional>
namespace ad {
struct number {
double r, dr;
number() : r(0.0), dr(0.0) {}
number(double v, double dv = 0) : r(v), dr(dv) {}
void operator = (const double& a) { r = a; dr = 0.0; }
};
// negation
inline number operator - (const number& a)
{
return number(-a.r, -a.dr);
}
// addition
inline number operator + (const number& a, const number& b)
{
return number(a.r + b.r, a.dr + b.dr);
}
inline number operator + (double a, const number& b)
{
return number(a + b.r, b.dr);
}
inline number operator + (const number& a, double b)
{
return number(a.r + b, a.dr);
}
// subtraction
inline number operator - (const number& a, const number& b)
{
return number(a.r - b.r, a.dr - b.dr);
}
inline number operator - (double a, const number& b)
{
return number(a - b.r, -b.dr);
}
inline number operator - (const number& a, double b)
{
return number(a.r - b, a.dr);
}
// multiplication
inline number operator * (const number& a, const number& b)
{
return number(a.r * b.r, a.dr * b.r + a.r * b.dr);
}
inline number operator * (double a, const number& b)
{
return number(a * b.r, a * b.dr);
}
inline number operator * (const number& a, double b)
{
return number(a.r * b, a.dr * b);
}
// division
inline number operator / (const number& a, const number& b)
{
return number(a.r / b.r, (a.dr - a.r * b.dr / b.r) / b.r);
}
inline number operator / (double a, const number& b)
{
return number(a / b.r, -a * b.dr / (b.r * b.r));
}
inline number operator / (const number& a, double b)
{
return number(a.r / b, a.dr / b);
}
// math functions
inline number log(const number& a)
{
return number(::log(a.r), a.dr / a.r);
}
inline number sqrt(const number& a)
{
double s = ::sqrt(a.r);
return number(s, 0.5 * a.dr / s);
}
inline number exp(const number& a)
{
double e = ::exp(a.r);
return number(e, e * a.dr);
}
inline number pow(const number& a, double e)
{
if (e == 0.0) return number(1.0);
double b = ::pow(a.r, e - 1.0);
return number(a.r * b, e * b * a.dr);
}
inline number sin(const number& a)
{
return number(::sin(a.r), ::cos(a.r) * a.dr);
}
inline number cos(const number& a)
{
return number(::cos(a.r), -::sin(a.r) * a.dr);
}
inline number cosh(const number& a)
{
return number(::cosh(a.r), ::sinh(a.r) * a.dr);
}
inline number sinh(const number& a)
{
return number(::sinh(a.r), ::cosh(a.r) * a.dr);
}
struct vec3d
{
number x, y, z;
vec3d() {}
vec3d(const ::vec3d& a) : x(a.x), y(a.y), z(a.z) {}
vec3d(double a, double b, double c) : x(a), y(b), z(c) {}
vec3d(const number& a, const number& b, const number& c) : x(a), y(b), z(c) {}
::vec3d values() const { return ::vec3d(x.r, y.r, z.r); }
::vec3d partials() const { return ::vec3d(x.dr, y.dr, z.dr); }
number& operator [] (size_t n) { return (&x)[n]; }
number length() const { return sqrt(x * x + y * y + z * z); }
};
inline number operator * (const vec3d& a, const vec3d& b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
inline vec3d operator * (double a, const vec3d& b)
{
return vec3d(a * b.x, a * b.y, a * b.z);
}
inline vec3d operator * (const number& a, const vec3d& b)
{
return vec3d(a * b.x, a * b.y, a * b.z);
}
inline vec3d operator * (const vec3d& a, double b)
{
return vec3d(a.x * b, a.y * b, a.z * b);
}
inline vec3d operator * (const vec3d& a, const number& b)
{
return vec3d(a.x * b, a.y * b, a.z * b);
}
inline vec3d operator + (const vec3d& a, const vec3d& b)
{
return vec3d(a.x + b.x, a.y + b.y, a.z + b.z);
}
inline vec3d operator - (const vec3d& a, const vec3d& b)
{
return vec3d(a.x - b.x, a.y - b.y, a.z - b.z);
}
inline vec3d operator - (const vec3d& a)
{
return vec3d(-a.x, -a.y, -a.z);
}
inline vec3d cross(const vec3d& a, const vec3d& b)
{
return vec3d(a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x);
}
// alternative cross product operator.
// Make sure to include parentheses when using this operator since ^ has a lower precedence than some other operators.
// e.g. use (a ^ b) * c instead of a ^ b * c
inline vec3d operator ^ (const vec3d& a, const vec3d& b)
{
return cross(a, b);
}
FECORE_API double Evaluate(std::function<number(ad::vec3d&)> W, const ::vec3d& a);
FECORE_API::vec3d Grad(std::function<number(ad::vec3d&)> W, const ::vec3d& a);
FECORE_API::mat3d Grad(std::function<ad::vec3d(ad::vec3d&)> F, const ::vec3d& a);
struct mat3d
{
number m[3][3];
number* operator [] (size_t n) { return m[n]; }
const number* operator [] (size_t n) const { return m[n]; }
mat3d() {}
mat3d(const ::mat3d& A)
{
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j) m[i][j] = A[i][j];
}
mat3d(const number& a11, const number& a12, const number& a13,
const number& a21, const number& a22, const number& a23,
const number& a31, const number& a32, const number& a33)
{
m[0][0] = a11; m[0][1] = a12; m[0][2] = a13;
m[1][0] = a21; m[1][1] = a22; m[1][2] = a23;
m[2][0] = a31; m[2][1] = a32; m[2][2] = a33;
}
mat3d(double d)
{
m[0][0].r = d; m[0][1].r = 0.0; m[0][2].r = 0.0;
m[1][0].r = 0.0; m[1][1].r = d; m[1][2].r = 0.0;
m[2][0].r = 0.0; m[2][1].r = 0.0; m[2][2].r = d;
}
::mat3d values() const
{
return ::mat3d(m[0][0].r, m[0][1].r, m[0][2].r,
m[1][0].r, m[1][1].r, m[1][2].r,
m[2][0].r, m[2][1].r, m[2][2].r);
}
::mat3d partials() const
{
return ::mat3d(m[0][0].dr, m[0][1].dr, m[0][2].dr,
m[1][0].dr, m[1][1].dr, m[1][2].dr,
m[2][0].dr, m[2][1].dr, m[2][2].dr);
}
};
inline mat3d operator * (const mat3d& A, const mat3d& B)
{
mat3d C(0.0);
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 3; ++k)
C[i][j] = C[i][j] + A[i][k] * B[k][j];
return C;
}
inline vec3d operator * (const mat3d& A, const vec3d& v)
{
return vec3d(
A[0][0] * v.x + A[0][1] * v.y + A[0][2] * v.z,
A[1][0] * v.x + A[1][1] * v.y + A[1][2] * v.z,
A[2][0] * v.x + A[2][1] * v.y + A[2][2] * v.z
);
}
inline mat3d dyad(const vec3d& a)
{
return mat3d(
a.x * a.x, a.x * a.y, a.x * a.z,
a.y * a.x, a.y * a.y, a.y * a.z,
a.z * a.x, a.z * a.y, a.z * a.z
);
}
inline mat3d dyad(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
);
}
struct mat3ds
{
// This enumeration can be used to remember the order
// in which the components are stored.
enum {
XX = 0,
XY = 1,
YY = 2,
XZ = 3,
YZ = 4,
ZZ = 5
};
number m[6]; // {xx,xy,yy,xz,yz,zz}
number& operator [] (size_t n) { return m[n]; }
mat3ds() {}
mat3ds(
const number& xx,
const number& yy,
const number& zz,
const number& xy,
const number& yz,
const number& xz)
{
m[XX] = xx;
m[YY] = yy;
m[ZZ] = zz;
m[XY] = xy;
m[YZ] = yz;
m[XZ] = xz;
}
mat3ds(const ::mat3ds& C)
{
m[0] = C.xx();
m[1] = C.xy();
m[2] = C.yy();
m[3] = C.xz();
m[4] = C.yz();
m[5] = C.zz();
}
mat3ds(double d)
{
m[XX].r = d;
m[YY].r = d;
m[ZZ].r = d;
}
number& xx() { return m[XX]; }
number& yy() { return m[YY]; }
number& zz() { return m[ZZ]; }
number& xy() { return m[XY]; }
number& yz() { return m[YZ]; }
number& xz() { return m[XZ]; }
const number& xx() const { return m[XX]; }
const number& yy() const { return m[YY]; }
const number& zz() const { return m[ZZ]; }
const number& xy() const { return m[XY]; }
const number& yz() const { return m[YZ]; }
const number& xz() const { return m[XZ]; }
::mat3ds values() const
{
return ::mat3ds(m[XX].r, m[YY].r, m[ZZ].r, m[XY].r, m[YZ].r, m[XZ].r);
}
::mat3ds partials() const
{
return ::mat3ds(m[XX].dr, m[YY].dr, m[ZZ].dr, m[XY].dr, m[YZ].dr, m[XZ].dr);
}
// functions
number tr() const { return m[XX] + m[YY] + m[ZZ]; }
number det() const {
return (m[XX] * (m[YY] * m[ZZ] - m[YZ] * m[YZ])
+ m[XY] * (m[YZ] * m[XZ] - m[ZZ] * m[XY])
+ m[XZ] * (m[XY] * m[YZ] - m[YY] * m[XZ]));
}
// double contraction
number dotdot(const mat3ds& B) const
{
const number* n = B.m;
return m[XX] * n[XX] + m[YY] * n[YY] + m[ZZ] * n[ZZ] + 2.0 * (m[XY] * n[XY] + m[YZ] * n[YZ] + m[XZ] * n[XZ]);
}
mat3ds inverse() const
{
number Di = 1.0 / det();
return mat3ds(
Di * (m[YY] * m[ZZ] - m[YZ] * m[YZ]),
Di * (m[XX] * m[ZZ] - m[XZ] * m[XZ]),
Di * (m[XX] * m[YY] - m[XY] * m[XY]),
Di * (m[XZ] * m[YZ] - m[XY] * m[ZZ]),
Di * (m[XY] * m[XZ] - m[XX] * m[YZ]),
Di * (m[XY] * m[YZ] - m[YY] * m[XZ]));
}
// return the square
mat3ds sqr() const
{
return mat3ds(
m[XX] * m[XX] + m[XY] * m[XY] + m[XZ] * m[XZ],
m[XY] * m[XY] + m[YY] * m[YY] + m[YZ] * m[YZ],
m[XZ] * m[XZ] + m[YZ] * m[YZ] + m[ZZ] * m[ZZ],
m[XX] * m[XY] + m[XY] * m[YY] + m[XZ] * m[YZ],
m[XY] * m[XZ] + m[YY] * m[YZ] + m[YZ] * m[ZZ],
m[XX] * m[XZ] + m[XY] * m[YZ] + m[XZ] * m[ZZ]
);
}
};
// arithmetic operations
inline mat3ds operator + (const mat3ds& A, const mat3ds& B)
{
return mat3ds(
A.xx() + B.xx(),
A.yy() + B.yy(),
A.zz() + B.zz(),
A.xy() + B.xy(),
A.yz() + B.yz(),
A.xz() + B.xz()
);
}
inline mat3ds operator - (const mat3ds& A, const mat3ds& B)
{
return mat3ds(
A.xx() - B.xx(),
A.yy() - B.yy(),
A.zz() - B.zz(),
A.xy() - B.xy(),
A.yz() - B.yz(),
A.xz() - B.xz()
);
}
inline mat3ds operator * (const mat3ds& A, double b)
{
return mat3ds(
A.xx() * b,
A.yy() * b,
A.zz() * b,
A.xy() * b,
A.yz() * b,
A.xz() * b
);
}
inline mat3ds operator * (double a, const mat3ds& B)
{
return mat3ds(
B.xx() * a,
B.yy() * a,
B.zz() * a,
B.xy() * a,
B.yz() * a,
B.xz() * a
);
}
inline mat3ds operator * (const mat3ds& A, const number& b)
{
return mat3ds(
A.xx() * b,
A.yy() * b,
A.zz() * b,
A.xy() * b,
A.yz() * b,
A.xz() * b
);
}
FECORE_API double Evaluate(std::function<number(mat3ds& C)> W, const ::mat3ds& C);
FECORE_API::mat3ds Derive(std::function<number(mat3ds& C)> W, const ::mat3ds& C);
FECORE_API::tens4ds Derive(std::function<mat3ds(mat3ds& C)> S, const ::mat3ds& C);
}
// This namespace contains classes and functions that can be used to evaluate directional
// derivatives for vec3d and quatd variables automatically.
// To use this, first create some variables, either dd::vec3d or dd::quat3d.
// For example,
//
// dd::vec3d r(1,0,0);
// dd::quatd q(1,0,0);
//
// then, create functions using these variables. For example,
//
// auto F = [&]() {
// ::vec3d z0(0, 1, 0);
// return r + q*z0;
// };
//
// Make sure to capture by reference!
// Finally, to evaluate the directional derivatives:
//
// mat3d dFr = dd::D(F, r);
// mat3d dFq = dd::D(F, q);
//
namespace dd {
// this class defines a number that can be used in calculations.
// Never initialize directly. Instead, use vec3d operators to construct numbers.
// For example.
// dd::vec3d r(1,0,0);
// dd::number l = dd::sqrt(r*r);
struct number {
double v = 0;
::vec3d dv = ::vec3d(0.0, 0.0, 0.0);
};
inline dd::number operator - (double a, const dd::number& n)
{
return { a - n.v, -n.dv };
}
inline dd::number operator * (double a, const dd::number& n)
{
return { a * n.v, n.dv * a };
}
inline dd::number operator * (const dd::number& n, double a)
{
return { a * n.v, n.dv * a };
}
inline dd::number operator / (double a, const dd::number& n)
{
return { a / n.v, n.dv * (-a / (n.v * n.v)) };
}
inline dd::number sqrt(const dd::number& a)
{
return { ::sqrt(a.v), a.dv * (0.5 / ::sqrt(a.v)) };
};
// represents vector variables.
struct vec3d {
::vec3d v = ::vec3d(0, 0, 0);
::mat3d dv = ::mat3d(0.0);
void activate(bool b) { dv = (b ? ::mat3d::identity() : ::mat3d(0.0)); }
vec3d(::vec3d a) : v(a), dv(::mat3d(0.0)) {}
vec3d(::vec3d a, ::mat3d da) : v(a), dv(da) {}
vec3d(double x, double y, double z) : v(::vec3d(x, y, z)), dv(::mat3d(0.0)) {}
};
inline dd::number operator * (const dd::vec3d& a, const dd::vec3d& b)
{
return dd::number{ a.v * b.v, b.dv.transpose() * a.v + a.dv.transpose() * b.v };
}
inline dd::vec3d operator * (const dd::vec3d& r, const dd::number& a)
{
return { r.v * a.v, (r.v & a.dv) + r.dv*a.v };
}
inline dd::vec3d operator - (const dd::vec3d& a)
{
return { -a.v, -a.dv };
}
inline dd::vec3d operator + (const dd::vec3d& a, const dd::vec3d& b)
{
return { a.v + b.v, a.dv + b.dv };
}
inline dd::vec3d operator - (const dd::vec3d& a, const dd::vec3d& b)
{
return { a.v - b.v, a.dv - b.dv };
}
inline dd::vec3d operator ^ (const dd::vec3d& a, const dd::vec3d& b)
{
::mat3da ahat(a.v);
::mat3da bhat(b.v);
return { (a.v ^ b.v), ahat * b.dv - bhat * a.dv };
}
inline dd::vec3d operator * (const dd::vec3d& a, double s)
{
return { a.v * s, a.dv * s };
}
// represents rotational variables
struct quatd {
::quatd q;
::mat3d dq;
quatd(::quatd r) { q = r; dq = ::mat3d(0.0); }
quatd(::vec3d r) { q = ::quatd(r); dq = ::mat3d(0.0); }
quatd(double x, double y, double z) { q = ::quatd(::vec3d(x,y,z)); dq = ::mat3d(0.0); }
quatd(double x, double y, double z, double w) { q = ::quatd(x,y,z,w); dq = ::mat3d(0.0); }
void activate(bool b) { dq = (b ? ::mat3d::identity() : ::mat3d(0.0)); }
dd::vec3d operator * (const ::vec3d& a)
{
::vec3d qa = q * a;
return { qa, ::mat3da(-qa) * dq };
}
};
// Use this function to return the directional derivative of "F" w.r.t. "r".
template <typename T>
::mat3d D(std::function<dd::vec3d()> F, T& r)
{
r.activate(true);
::mat3d dF = F().dv;
r.activate(false);
return dF;
}
}
| Unknown |
3D | febiosoftware/FEBio | FECore/FEModelComponent.h | .h | 2,991 | 75 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "FETimeInfo.h"
//-----------------------------------------------------------------------------
//! forward declaration of the FEModel class.
//! All classes inherited from FEModelComponent should take the model as a parameter
//! to the constructor.
class FENodeSet;
class FEMesh;
class FESolver;
//-----------------------------------------------------------------------------
//! This class serves as a base class for many of the FECore classes. It defines
//! activation and deactivation functions which are used in multi-step analyses to determine which
//! components are active during an analysis.
//! A model component is basically anything that affects the state of a model.
//! For instance, boundary conditions, loads, contact definitions, etc.
class FECORE_API FEModelComponent : public FECoreBase
{
public:
//! constructor
FEModelComponent(FEModel* fem);
//! destructor
virtual ~FEModelComponent();
//-----------------------------------------------------------------------------------
//! Update the component
//! This is called whenever the model is updated, i.e. the primary variables were updated.
virtual void Update();
public: // some convenience functions (to pull data from FEModel without the need to include)
double CurrentTime() const;
double CurrentTimeIncrement() const;
double GetGlobalConstant(const char* sz) const;
int GetDOFIndex(const char* szvar, int n) const;
int GetDOFIndex(const char* szdof) const;
const FETimeInfo& GetTimeInfo() const;
FESolver* GetSolver();
void AttachLoadController(const char* szparam, int lc);
void AttachLoadController(void* pd, int lc);
//! Get the model's mesh
FEMesh& GetMesh();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FECorePlot.cpp | .cpp | 20,777 | 757 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FECorePlot.h"
#include "FEMaterial.h"
#include "FESolidDomain.h"
#include "FEModelParam.h"
#include "FEBodyLoad.h"
#include "FENodalLoad.h"
#include "FEPlotData.h"
#include "FESurface.h"
#include "FEMaterialPointProperty.h"
#include "writeplot.h"
#include "FESurfaceLoad.h"
#include "FEDomainMap.h"
#include "FEModel.h"
#include "FEPIDController.h"
#include "FEDataMap.h"
//-----------------------------------------------------------------------------
FEPlotParameter::FEPlotParameter(FEModel* pfem) : FEPlotData(pfem)
{
m_index = 0;
SetStorageFormat(FMT_MULT);
m_mat = 0;
m_dom = 0;
m_surf = 0;
}
//-----------------------------------------------------------------------------
// This plot field requires a filter which defines the material name and
// the material parameter in the format [materialname.parametername].
bool FEPlotParameter::SetFilter(const char* sz)
{
// store the filter for serialization
m_filter = sz;
// find the parameter
ParamString ps(sz);
m_param = GetFEModel()->GetParameterValue(ps);
if (m_param.isValid() == false) return false;
FEParam* param = m_param.param();
if (param == 0) return false;
FECoreBase* pc = dynamic_cast<FECoreBase*>(param->parent());
if (pc == nullptr) return false;
switch (m_param.type())
{
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble& p = m_param.value<FEParamDouble>();
// check for materials first
if (dynamic_cast<FEMaterial*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_mat = dynamic_cast<FEMaterial*>(pc); m_mat = dynamic_cast<FEMaterial*>(m_mat->GetAncestor()); }
else
{
FEItemList* itemList = p.GetItemList();
if (itemList == 0)
{
// for some classes, the item list can be empty
if (dynamic_cast<FEBodyLoad*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEBodyLoad*>(pc))->GetDomainList(); }
// else if (dynamic_cast<FESurfaceLoad*>(pc)) { SetRegionType(FE_REGION_SURFACE); m_surf = dynamic_cast<FESurfaceLoad*>(pc)->GetSurface().GetFacetSet(); }
else if (dynamic_cast<FENodalLoad*>(pc)) SetRegionType(FE_REGION_NODE);
else return false;
}
else
{
if (dynamic_cast<FENodeSet*>(itemList)) SetRegionType(FE_REGION_NODE);
else if (dynamic_cast<FEFacetSet*>(itemList)) { SetRegionType(FE_REGION_SURFACE); m_surf = dynamic_cast<FEFacetSet*>(itemList); }
else if (dynamic_cast<FEElementSet*>(itemList)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEElementSet*>(itemList))->GetDomainList(); }
else return false;
}
}
SetVarType(PLT_FLOAT);
}
break;
case FE_PARAM_VEC3D_MAPPED:
{
FEParamVec3& p = m_param.value<FEParamVec3>();
FEItemList* itemList = p.GetItemList();
if (itemList == 0)
{
// for material parameters, the item list can be empty
if (dynamic_cast<FEMaterial*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_mat = dynamic_cast<FEMaterial*>(pc); m_mat = dynamic_cast<FEMaterial*>(m_mat->GetAncestor()); }
else if (dynamic_cast<FEBodyLoad*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEBodyLoad*>(pc))->GetDomainList(); }
else return false;
}
else
{
if (dynamic_cast<FENodeSet*>(itemList)) SetRegionType(FE_REGION_NODE);
else if (dynamic_cast<FEFacetSet*>(itemList)) { SetRegionType(FE_REGION_SURFACE); m_surf = dynamic_cast<FEFacetSet*>(itemList); }
else if (dynamic_cast<FEElementSet*>(itemList)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEElementSet*>(itemList))->GetDomainList(); }
else return false;
}
SetVarType(PLT_VEC3F);
}
break;
case FE_PARAM_MAT3D_MAPPED:
{
FEParamMat3d& p = m_param.value<FEParamMat3d>();
FEItemList* itemList = p.GetItemList();
if (itemList == 0)
{
// for material parameters, the item list can be empty
if (dynamic_cast<FEMaterial*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_mat = dynamic_cast<FEMaterial*>(pc); m_mat = dynamic_cast<FEMaterial*>(m_mat->GetAncestor()); }
else if (dynamic_cast<FEBodyLoad*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEBodyLoad*>(pc))->GetDomainList(); }
else return false;
}
else
{
if (dynamic_cast<FENodeSet*>(itemList)) SetRegionType(FE_REGION_NODE);
else if (dynamic_cast<FEFacetSet*>(itemList)) { SetRegionType(FE_REGION_SURFACE); m_surf = dynamic_cast<FEFacetSet*>(itemList); }
else if (dynamic_cast<FEElementSet*>(itemList)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEElementSet*>(itemList))->GetDomainList(); }
else return false;
}
SetStorageFormat(FMT_ITEM);
SetVarType(PLT_MAT3F);
}
break;
case FE_PARAM_MAT3DS_MAPPED:
{
FEParamMat3ds& p = m_param.value<FEParamMat3ds>();
FEItemList* itemList = p.GetItemList();
if (itemList == 0)
{
// for material parameters, the item list can be empty
if (dynamic_cast<FEMaterial*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_mat = dynamic_cast<FEMaterial*>(pc); m_mat = dynamic_cast<FEMaterial*>(m_mat->GetAncestor()); }
else if (dynamic_cast<FEBodyLoad*>(pc)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEBodyLoad*>(pc))->GetDomainList(); }
else return false;
}
else
{
if (dynamic_cast<FENodeSet*>(itemList)) SetRegionType(FE_REGION_NODE);
else if (dynamic_cast<FEFacetSet*>(itemList)) { SetRegionType(FE_REGION_SURFACE); m_surf = dynamic_cast<FEFacetSet*>(itemList); }
else if (dynamic_cast<FEElementSet*>(itemList)) { SetRegionType(FE_REGION_DOMAIN); m_dom = &(dynamic_cast<FEElementSet*>(itemList))->GetDomainList(); }
else return false;
}
SetStorageFormat(FMT_ITEM);
SetVarType(PLT_MAT3FS);
}
break;
case FE_PARAM_DOUBLE:
{
if (dynamic_cast<FEMaterial*>(pc))
{
m_mat = dynamic_cast<FEMaterial*>(pc->GetAncestor());
SetRegionType(FE_REGION_DOMAIN);
SetStorageFormat(FMT_REGION);
}
else if (dynamic_cast<FESurfaceLoad*>(pc))
{
FESurfaceLoad* psl = dynamic_cast<FESurfaceLoad*>(pc);
SetRegionType(FE_REGION_SURFACE);
SetStorageFormat(FMT_REGION);
m_surf = psl->GetSurface().GetFacetSet();
}
else return false;
}
break;
case FE_PARAM_VEC3D:
{
if (dynamic_cast<FEMaterial*>(pc))
{
m_mat = dynamic_cast<FEMaterial*>(pc->GetAncestor());
SetRegionType(FE_REGION_DOMAIN);
SetStorageFormat(FMT_REGION);
}
else if (dynamic_cast<FEBodyLoad*>(pc))
{
SetRegionType(FE_REGION_DOMAIN);
SetStorageFormat(FMT_REGION);
m_dom = &(dynamic_cast<FEBodyLoad*>(pc))->GetDomainList();
}
else if (dynamic_cast<FESurfaceLoad*>(pc))
{
FESurfaceLoad* psl = dynamic_cast<FESurfaceLoad*>(pc);
SetRegionType(FE_REGION_SURFACE);
SetStorageFormat(FMT_REGION);
m_surf = psl->GetSurface().GetFacetSet();
}
else return false;
SetVarType(PLT_VEC3F);
}
break;
case FE_PARAM_MATERIALPOINT:
{
FEMaterialPointProperty& prop = m_param.value<FEMaterialPointProperty>();
m_mat = dynamic_cast<FEMaterial*>(pc->GetAncestor());
if (m_mat == nullptr) return false;
SetRegionType(FE_REGION_DOMAIN);
switch (prop.dataType())
{
case FE_DOUBLE: SetVarType(PLT_FLOAT); break;
case FE_VEC3D: SetVarType(PLT_VEC3F); break;
case FE_MAT3D: SetVarType(PLT_MAT3F); break;
default:
return false;
}
}
break;
default:
assert(false);
return false;
break;
}
return true;
}
//-----------------------------------------------------------------------------
void FEPlotParameter::Serialize(DumpStream& ar)
{
FEPlotData::Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsSaving())
ar << m_filter;
else
{
string filter;
ar >> filter;
SetFilter(filter.c_str());
}
}
//-----------------------------------------------------------------------------
// The Save function stores the material parameter data to the plot file.
bool FEPlotParameter::Save(FEDomain& dom, FEDataStream& a)
{
if (m_param.isValid() == false) return false;
FEParam* param = m_param.param();
if ((m_param.type() == FE_PARAM_DOUBLE_MAPPED) ||
(m_param.type() == FE_PARAM_VEC3D_MAPPED ) ||
(m_param.type() == FE_PARAM_MAT3D_MAPPED ) ||
(m_param.type() == FE_PARAM_MAT3DS_MAPPED))
{
FEModelParam& map = m_param.value<FEModelParam>();
if (m_dom == nullptr)
{
if ((m_mat == nullptr) || (dom.GetMaterial() != m_mat))
return false;
}
else if (m_dom->IsMember(&dom) == false) return false;
FESolidDomain& sd = dynamic_cast<FESolidDomain&>(dom);
if (m_param.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& mapDouble = dynamic_cast<FEParamDouble&>(map);
FEMappedValue* val = dynamic_cast<FEMappedValue*>(mapDouble.valuator());
if (val)
{
FEDomainMap* map = dynamic_cast<FEDomainMap*>(val->dataMap()); assert(map);
if (map->StorageFormat() == FMT_MULT)
{
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
FEElement& e = dom.ElementRef(i);
int ne = e.Nodes();
vector<double> sn(ne);
for (int j = 0; j < ne; ++j)
{
sn[j] = map->value<double>(i, j);
}
// push data to archive
for (int j = 0; j < ne; ++j) a << sn[j];
}
return true;
}
}
writeNodalProjectedElementValues<double>(sd, a, mapDouble);
}
else if (m_param.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& mapVec3 = dynamic_cast<FEParamVec3&>(map);
writeNodalProjectedElementValues<vec3d>(sd, a, mapVec3);
}
else if (m_param.type() == FE_PARAM_MAT3D_MAPPED)
{
FEParamMat3d& mapMat3 = dynamic_cast<FEParamMat3d&>(map);
writeElementValue<mat3d>(sd, a, mapMat3);
}
else if (m_param.type() == FE_PARAM_MAT3DS_MAPPED)
{
FEParamMat3ds& mapMat3 = dynamic_cast<FEParamMat3ds&>(map);
writeElementValue<mat3ds>(sd, a, mapMat3);
}
else return false;
return true;
}
else if (m_param.type() == FE_PARAM_DOUBLE)
{
if (dom.GetMaterial() == m_mat)
{
double val = m_param.value<double>();
a << val;
return true;
}
}
else if (m_param.type() == FE_PARAM_VEC3D)
{
if (m_dom && (m_dom->IsMember(&dom)))
{
vec3d val = m_param.value<vec3d>();
a << val;
return true;
}
else if (dom.GetMaterial() == m_mat)
{
vec3d val = m_param.value<vec3d>();
a << val;
return true;
}
else return false;
}
else if (m_param.type() == FE_PARAM_MATERIALPOINT)
{
if (dom.GetMaterial() == m_mat)
{
FEMaterialPointProperty& prop = m_param.value<FEMaterialPointProperty>();
switch (prop.dataType())
{
case FE_DOUBLE: writeNodalProjectedElementValues<double>(dom, a, [&](const FEMaterialPoint& mp) {
FEMaterialPoint& mp_noconst = const_cast<FEMaterialPoint&>(mp);
double d;
prop.get(mp_noconst, d);
return d;
});
break;
case FE_VEC3D: writeNodalProjectedElementValues<vec3d>(dom, a, [&](const FEMaterialPoint& mp) {
FEMaterialPoint& mp_noconst = const_cast<FEMaterialPoint&>(mp);
vec3d d;
prop.get(mp_noconst, d);
return d;
});
break;
case FE_MAT3D: writeNodalProjectedElementValues<mat3d>(dom, a, [&](const FEMaterialPoint& mp) {
FEMaterialPoint& mp_noconst = const_cast<FEMaterialPoint&>(mp);
mat3d d;
prop.get(mp_noconst, d);
return d;
});
break;
default:
return false;
}
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// The Save function stores the material parameter data to the plot file.
bool FEPlotParameter::Save(FESurface& dom, FEDataStream& a)
{
if (m_param.isValid() == false) return false;
FEFacetSet* surf = dom.GetFacetSet();
if (m_surf != surf) return false;
if (m_param.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& map = m_param.value<FEParamDouble>();
writeNodalProjectedElementValues<double>(dom, a, map);
}
else if (m_param.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& map = m_param.value<FEParamVec3>();
writeNodalProjectedElementValues<vec3d>(dom, a, map);
}
else if (m_param.type() == FE_PARAM_DOUBLE)
{
a << m_param.value<double>();
}
else if (m_param.type() == FE_PARAM_VEC3D)
{
a << m_param.value<vec3d>();
}
else return false;
return true;
}
//-----------------------------------------------------------------------------
bool FEPlotParameter::Save(FEMesh& mesh, FEDataStream& a)
{
if (m_param.isValid() == false) return false;
if (m_param.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& map = m_param.value<FEParamDouble>();
FENodeSet* nset = dynamic_cast<FENodeSet*>(map.GetItemList());
if (nset)
writeNodalValues<double>(*nset, a, map);
else
{
writeNodalValues<double>(mesh, a, [&](const FENode& node) {
FEMaterialPoint mp;
mp.m_r0 = node.m_r0;
mp.m_index = -1;
double v = map(mp);
return v;
});
}
return true;
}
else if (m_param.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& map = m_param.value<FEParamVec3>();
FENodeSet* nset = dynamic_cast<FENodeSet*>(map.GetItemList());
if (nset == 0) return false;
// write the nodal values
writeNodalValues<vec3d>(*nset, a, map);
return true;
}
return false;
}
//-----------------------------------------------------------------------------
FEPlotPIDController::FEPlotPIDController(FEModel* pfem) : FEPlotGlobalData(pfem, PLT_ARRAY)
{
m_pid = nullptr;
SetArraySize(3);
std::vector<std::string> names;
names.push_back("measurement");
names.push_back("error");
names.push_back("output");
SetArrayNames(names);
}
bool FEPlotPIDController::SetFilter(const char* sz)
{
if (sz == nullptr) return false;
FEModel* fem = GetFEModel(); assert(fem);
if (fem == nullptr) return false;
for (int i = 0; i < fem->LoadControllers(); ++i)
{
FEPIDController* pid = dynamic_cast<FEPIDController*>(fem->GetLoadController(i));
if (pid && (pid->GetName() == string(sz)))
{
m_pid = pid;
return true;
}
}
m_pid = nullptr;
return false;
}
bool FEPlotPIDController::Save(FEDataStream& a)
{
if (m_pid == nullptr) return false;
a << m_pid->GetParameterValue();
a << m_pid->GetError();
a << m_pid->Value();
return true;
}
//=============================================================================
//-----------------------------------------------------------------------------
FEPlotMeshData::FEPlotMeshData(FEModel* pfem) : FEPlotData(pfem)
{
m_map = nullptr;
m_dom = nullptr;
}
//-----------------------------------------------------------------------------
// This plot field requires a filter which defines the material name and
// the material parameter in the format [materialname.parametername].
bool FEPlotMeshData::SetFilter(const char* sz)
{
// store the filter for serialization
m_filter = sz;
// find the map
m_map = GetFEModel()->GetMesh().FindDataMap(sz);
if (m_map == nullptr) return false;
switch (m_map->DataMapType())
{
case FE_DOMAIN_MAP:
{
FEDomainMap* map = dynamic_cast<FEDomainMap*>(m_map); assert(map);
FEDataType dataType = map->DataType();
SetRegionType(FE_REGION_DOMAIN);
SetStorageFormat((Storage_Fmt)map->StorageFormat());
if (map->StorageFormat() == FMT_MATPOINTS) SetStorageFormat(FMT_MULT);
switch (dataType)
{
case FE_DOUBLE: SetVarType(PLT_FLOAT); break;
case FE_VEC3D : SetVarType(PLT_VEC3F); break;
case FE_MAT3D : SetVarType(PLT_MAT3F); break;
default:
assert(false);
return false;
}
const FEElementSet* set = map->GetElementSet();
if (set == nullptr) return false;
m_dom = &(set->GetDomainList());
}
break;
default:
assert(false);
return false;
}
return true;
}
//-----------------------------------------------------------------------------
void FEPlotMeshData::Serialize(DumpStream& ar)
{
FEPlotData::Serialize(ar);
if (ar.IsShallow()) return;
if (ar.IsSaving())
ar << m_filter;
else
{
string filter;
ar >> filter;
SetFilter(filter.c_str());
}
}
//-----------------------------------------------------------------------------
// The Save function stores the material parameter data to the plot file.
bool FEPlotMeshData::Save(FEDomain& dom, FEDataStream& a)
{
FEDomainMap* map = dynamic_cast<FEDomainMap*>(m_map);
if (map == nullptr) return false;
if (m_dom == nullptr) return false;
if (m_dom->IsMember(&dom))
{
if (StorageFormat() == FMT_NODE)
{
if (DataType() == PLT_FLOAT)
{
int n = dom.Nodes();
for (int i = 0; i < n; ++i)
{
int m = dom.NodeIndex(i);
double v = map->NodalValue(m);
a << v;
}
return true;
}
}
else if (StorageFormat() == FMT_ITEM)
{
if (DataType() == PLT_FLOAT)
{
int n = dom.Elements();
for (int i = 0; i < n; ++i)
{
FEElement& el = dom.ElementRef(i);
FEMaterialPoint mp;
mp.m_elem = ⪙
mp.m_index = 0;
double v = map->value(mp);
a << v;
}
return true;
}
}
else if (StorageFormat() == FMT_MULT)
{
if (DataType() == PLT_FLOAT)
{
int n = dom.Elements();
for (int i = 0; i < n; ++i)
{
FEElement& el = dom.ElementRef(i);
for (int j = 0; j < el.Nodes(); ++j)
{
double v = map->value<double>(i, j);
a << v;
}
}
return true;
}
else if (DataType() == PLT_VEC3F)
{
int n = dom.Elements();
for (int i = 0; i < n; ++i)
{
FEElement& el = dom.ElementRef(i);
for (int j = 0; j < el.Nodes(); ++j)
{
vec3d v = map->value<vec3d>(i, j);
a << v;
}
}
return true;
}
}
else if (map->StorageFormat() == FMT_MATPOINTS)
{
// Note that for this map type, the plot format was changed to FMT_MULT
if (DataType() == PLT_FLOAT)
{
int NE = dom.Elements();
double vi[FEElement::MAX_INTPOINTS] = { 0 };
double vn[FEElement::MAX_NODES] = { 0 };
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom.ElementRef(i);
for (int j = 0; j < el.GaussPoints(); ++j)
{
FEMaterialPoint mp;
mp.m_elem = ⪙
mp.m_index = j;
vi[j] = map->value(mp);
}
el.project_to_nodes(vi, vn);
for (int j=0; j<el.Nodes(); ++j)
a << vn[j];
}
return true;
}
}
}
return false;
}
//-----------------------------------------------------------------------------
// The Save function stores the material parameter data to the plot file.
bool FEPlotMeshData::Save(FESurface& dom, FEDataStream& a)
{
return false;
}
//-----------------------------------------------------------------------------
bool FEPlotMeshData::Save(FEMesh& mesh, FEDataStream& a)
{
return false;
}
FEPlotFieldVariable::FEPlotFieldVariable(FEModel* pfem) : FEPlotNodeData(pfem, Var_Type::PLT_FLOAT, Storage_Fmt::FMT_ITEM)
{
}
bool FEPlotFieldVariable::SetFilter(const char* sz)
{
DOFS& dofs = GetFEModel()->GetDOFS();
int nvar = dofs.GetVariableIndex(sz);
if (nvar == -1) return false;
dofs.GetDOFList(sz, m_dofs);
int vartype = dofs.GetVariableType(nvar);
switch (vartype)
{
case VAR_SCALAR: SetVarType(PLT_FLOAT); break;
case VAR_VEC3 : SetVarType(PLT_VEC3F); break;
case VAR_ARRAY :
{
SetVarType(Var_Type::PLT_ARRAY);
SetArraySize(m_dofs.size());
vector<string> dofNames;
for (int i = 0; i < m_dofs.size(); ++i) dofNames.push_back(dofs.GetDOFName(nvar, i));
SetArrayNames(dofNames);
}
break;
default:
return false;
}
return true;
}
bool FEPlotFieldVariable::Save(FEMesh& mesh, FEDataStream& a)
{
if (m_dofs.empty()) return false;
for (int i = 0; i < mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
for (int j = 0; j < m_dofs.size(); ++j)
{
a << node.get(m_dofs[j]);
}
}
return true;
}
void FEPlotFieldVariable::Serialize(DumpStream& ar)
{
FEPlotNodeData::Serialize(ar);
ar & m_dofs;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEEdge.cpp | .cpp | 5,356 | 207 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEEdge.h"
#include "FEMesh.h"
//-----------------------------------------------------------------------------
FEEdge::FEEdge(FEModel* fem) : FEMeshPartition(FE_DOMAIN_EDGE, fem)
{
}
//-----------------------------------------------------------------------------
FEEdge::~FEEdge()
{
}
//-----------------------------------------------------------------------------
FENodeList FEEdge::GetNodeList()
{
FEMesh* pm = GetMesh();
FENodeList set(pm);
vector<int> tag(pm->Nodes(), 0);
for (int i = 0; i<Elements(); ++i)
{
FELineElement& el = Element(i);
int ne = el.Nodes();
for (int j = 0; j<ne; ++j)
{
if (tag[el.m_node[j]] == 0)
{
set.Add(el.m_node[j]);
tag[el.m_node[j]] = 1;
}
}
}
return set;
}
//-----------------------------------------------------------------------------
bool FEEdge::Init()
{
// make sure that there is an edge defined
if (Elements() == 0) return false;
// get the mesh to which this edge belongs
FEMesh& mesh = *GetMesh();
// This array is used to keep tags on each node
vector<int> tag; tag.assign(mesh.Nodes(), -1);
// let's find all nodes the edge needs
int nn = 0;
int ne = Elements();
for (int i=0; i<ne; ++i)
{
FELineElement& el = Element(i);
el.SetLocalID(i);
for (int j=0; j<el.Nodes(); ++j)
{
// get the global node number
int m = el.m_node[j];
// create a local node number
if (tag[m] == -1) tag[m] = nn++;
// set the local node number
el.m_lnode[j] = tag[m];
}
}
// allocate node index table
m_Node.resize(nn);
// fill the node index table
for (int i=0; i<mesh.Nodes(); ++i)
{
if (tag[i] >= 0)
{
m_Node[tag[i]] = i;
}
}
return true;
}
//-----------------------------------------------------------------------------
void FEEdge::Create(int nelems, int elemType)
{
m_Elem.resize(nelems);
for (int i = 0; i < nelems; ++i)
{
FELineElement& el = m_Elem[i];
el.SetLocalID(i);
el.SetMeshPartition(this);
}
if (elemType != -1)
{
for (int i = 0; i < nelems; ++i) m_Elem[i].SetType(elemType);
CreateMaterialPointData();
}
}
//-----------------------------------------------------------------------------
bool FEEdge::Create(FESegmentSet& es)
{
return Create(es, FE_LINE2G1);
}
//-----------------------------------------------------------------------------
bool FEEdge::Create(FESegmentSet& es, int elemType)
{
FEMesh& m = *GetMesh();
int NN = m.Nodes();
// count nr of segments
int nsegs = es.Segments();
// allocate storage for faces
Create(nsegs);
// read segments
for (int i = 0; i < nsegs; ++i)
{
FELineElement& el = Element(i);
FESegmentSet::SEGMENT& si = es.Segment(i);
if (si.ntype == 2) el.SetType(elemType);
else return false;
int N = el.Nodes(); assert(N == si.ntype);
for (int j = 0; j < N; ++j) el.m_node[j] = si.node[j];
}
CreateMaterialPointData();
return true;
}
//-----------------------------------------------------------------------------
void FEEdge::CreateMaterialPointData()
{
for (int i = 0; i < Elements(); ++i)
{
FELineElement& el = m_Elem[i];
int nint = el.GaussPoints();
el.ClearData();
for (int n = 0; n < nint; ++n)
{
FELineMaterialPoint* pt = dynamic_cast<FELineMaterialPoint*>(CreateMaterialPoint());
assert(pt);
el.SetMaterialPointData(pt, n);
}
}
}
//-----------------------------------------------------------------------------
// Create material point data for this surface
FEMaterialPoint* FEEdge::CreateMaterialPoint()
{
return new FELineMaterialPoint;
}
//-----------------------------------------------------------------------------
void FEEdge::GetNodalCoordinates(FELineElement& el, vec3d* rt)
{
FEMesh& mesh = *GetMesh();
int neln = el.Nodes();
for (int j = 0; j < neln; ++j) rt[j] = mesh.Node(el.m_node[j]).m_rt;
}
//-----------------------------------------------------------------------------
void FEEdge::GetReferenceNodalCoordinates(FELineElement& el, vec3d* rt)
{
FEMesh& mesh = *GetMesh();
int neln = el.Nodes();
for (int j = 0; j < neln; ++j) rt[j] = mesh.Node(el.m_node[j]).m_r0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/matrix.h | .h | 10,006 | 350 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <memory.h>
#include <vector>
#include "fecore_api.h"
#include "mat3d.h"
//-----------------------------------------------------------------------------
//! General purpose matrix class.
class FECORE_API matrix
{
public:
//! constructor
matrix() : m_nr(0), m_nc(0), m_nsize(0), m_pd(nullptr), m_pr(nullptr) {}
//! constructor
matrix(int nr, int nc);
//! copy constructor
matrix(const matrix& m);
//! constructor
matrix(const mat3d& m);
//! move constructor
matrix(matrix&& m);
//! assignment operator
matrix& operator = (const matrix& m);
//! move assigment operator
matrix& operator = (matrix&& m);
//! assignment operator
matrix& operator = (const mat3d& m);
//! Matrix reallocation
void resize(int nr, int nc);
//! destructor
~matrix() { clear(); }
//! access operator
double * operator [] (int l) { return m_pr[l]; }
const double* operator [] (int l) const { return m_pr[l]; }
double& operator () (int i, int j) { return m_pr[i][j]; }
double operator () (int i, int j) const { return m_pr[i][j]; }
operator double** () { return m_pr; }
int rows () const { return m_nr; }
int columns() const { return m_nc; }
void zero() { memset(m_pd, 0, sizeof(double)*m_nsize); }
//! matrix transpose
matrix transpose() const;
//! matrix inversion
matrix inverse();
//! matrix inverse using SVD
matrix svd_inverse();
//! matrix operators
matrix operator *(double a) const;
matrix operator * (const matrix& m) const;
matrix operator + (const matrix& m) const;
matrix operator - (const matrix& m) const;
matrix& operator += (const matrix& m);
matrix& operator -= (const matrix& m);
matrix& operator *=(double g)
{
for (int i=0; i<m_nsize; ++i) m_pd[i] *= g;
return *this;
}
matrix operator * (const vec3d& v) const;
// calculate the LU decomposition
// note that this modifies the matrix
void lufactor(std::vector<int>& indx);
// solve using the lu factor calculated with lufactor
void lusolve(std::vector<double>& b, std::vector<int>& indx);
// solve the linear system Ax=b
void solve(std::vector<double>& x, const std::vector<double>& b);
bool lsq_solve(std::vector<double>& x, std::vector<double>& b);
bool eigen_vectors(matrix& Eigen, std::vector<double>& eigen_values);
// infinity-norm
double inf_norm();
void mult(std::vector<double>& x, std::vector<double>& y);
void mult(const matrix& m, std::vector<double>& x, std::vector<double>& y);
void mult_transpose(std::vector<double>& x, std::vector<double>& y);
void mult_transpose_self(matrix& AAt);
public:
void set(int i, int j, const mat3d& a);
void add(int i, int j, const mat3ds& a);
void add(int i, int j, const mat3da& a);
void add(int i, int j, const mat3dd& a);
void add(int i, int j, const mat3d& a);
void add(int i, int j, const matrix& a);
void add(int i, int j, const vec3d& a);
void add_symm(int i, int j, const mat3d& a);
void add_symm(int i, int j, const vec3d& a);
void adds(int i, int j, const matrix& m, double s);
void adds(const matrix& m, double s);
void sub(int i, int j, const mat3ds& a);
void sub(int i, int j, const mat3da& a);
void sub(int i, int j, const mat3dd& a);
void sub(int i, int j, const mat3d& a);
void sub(int i, int j, const matrix& a);
void get(int i, int j, mat3d& a) const;
// copy-lower-triangular
// make the matrix symmetric by copying the lower triangular part
void copy_lt()
{
assert(m_nr==m_nc);
if (m_nr != m_nc) return;
for (int i=0; i<m_nr; ++i)
{
for (int j=i+1; j<m_nr; ++j)
{
m_pr[i][j] = m_pr[j][i];
}
}
}
// copy-upper-triangular
// make the matrix symmetric by copying the upper triangular part
void copy_ut()
{
assert(m_nr==m_nc);
if (m_nr != m_nc) return;
for (int i=0; i<m_nr; ++i)
{
for (int j=i+1; j<m_nr; ++j)
{
m_pr[j][i] = m_pr[i][j];
}
}
}
// extract a matrix block
// the returned matrix will have the dimensions rows x cols
// if the matrix doesn't fit in this matrix, the missing entries will be set to zero
void get(int i, int j, int rows, int cols, matrix& A) const;
// fill a matrix
void fill(int i, int j, int rows, int cols, double val);
private:
void alloc(int nr, int nc);
void clear();
protected:
double** m_pr; // pointer to rows
double* m_pd; // matrix elements
int m_nr; // nr of rows
int m_nc; // nr of columns
int m_nsize; // size of matrix (ie. total nr of elements = nr*nc)
};
std::vector<double> FECORE_API operator / (std::vector<double>& b, matrix& m);
std::vector<double> FECORE_API operator * (matrix& m, std::vector<double>& b);
matrix FECORE_API outer_product(std::vector<double>& a);
inline void matrix::set(int i, int j, const mat3d& a)
{
m_pr[i][j] = a(0,0); m_pr[i][j+1] = a(0,1); m_pr[i][j+2] = a(0,2); i++;
m_pr[i][j] = a(1,0); m_pr[i][j+1] = a(1,1); m_pr[i][j+2] = a(1,2); i++;
m_pr[i][j] = a(2,0); m_pr[i][j+1] = a(2,1); m_pr[i][j+2] = a(2,2);
}
inline void matrix::add(int i, int j, const mat3ds& a)
{
m_pr[i][j] += a.xx(); m_pr[i][j+1] += a.xy(); m_pr[i][j+2] += a.xz(); i++;
m_pr[i][j] += a.xy(); m_pr[i][j+1] += a.yy(); m_pr[i][j+2] += a.yz(); i++;
m_pr[i][j] += a.xz(); m_pr[i][j+1] += a.yz(); m_pr[i][j+2] += a.zz();
}
inline void matrix::add(int i, int j, const mat3da& a)
{
m_pr[i][j+1] += a.xy(); m_pr[i][j+2] += a.xz(); i++;
m_pr[i][j ] -= a.xy(); m_pr[i][j+2] += a.yz(); i++;
m_pr[i][j ] -= a.xz(); m_pr[i][j+1] -= a.yz();
}
inline void matrix::add(int i, int j, const mat3dd& a)
{
m_pr[i][j ] += a.diag(0); i++;
m_pr[i][j+1] += a.diag(1); i++;
m_pr[i][j+2] += a.diag(2);
}
inline void matrix::add(int i, int j, const mat3d& a)
{
m_pr[i][j] += a(0,0); m_pr[i][j+1] += a(0,1); m_pr[i][j+2] += a(0,2); i++;
m_pr[i][j] += a(1,0); m_pr[i][j+1] += a(1,1); m_pr[i][j+2] += a(1,2); i++;
m_pr[i][j] += a(2,0); m_pr[i][j+1] += a(2,1); m_pr[i][j+2] += a(2,2);
}
inline void matrix::add_symm(int i, int j, const mat3d& a)
{
m_pr[i ][j] += a(0, 0); m_pr[i ][j + 1] += a(0, 1); m_pr[i ][j + 2] += a(0, 2);
m_pr[i+1][j] += a(1, 0); m_pr[i+1][j + 1] += a(1, 1); m_pr[i+1][j + 2] += a(1, 2);
m_pr[i+2][j] += a(2, 0); m_pr[i+2][j + 1] += a(2, 1); m_pr[i+2][j + 2] += a(2, 2);
m_pr[j ][i] += a(0, 0); m_pr[j ][i + 1] += a(1, 0); m_pr[j ][i + 2] += a(2, 0);
m_pr[j+1][i] += a(0, 1); m_pr[j+1][i + 1] += a(1, 1); m_pr[j+1][i + 2] += a(2, 1);
m_pr[j+2][i] += a(0, 2); m_pr[j+2][i + 1] += a(1, 2); m_pr[j+2][i + 2] += a(2, 2);
}
inline void matrix::add_symm(int i, int j, const vec3d& a)
{
m_pr[i ][j] += a.x;
m_pr[i+1][j] += a.y;
m_pr[i+2][j] += a.z;
m_pr[j][i ] += a.x;
m_pr[j][i+1] += a.y;
m_pr[j][i+2] += a.z;
}
inline void matrix::sub(int i, int j, const mat3ds& a)
{
m_pr[i][j] -= a.xx(); m_pr[i][j+1] -= a.xy(); m_pr[i][j+2] -= a.xz(); i++;
m_pr[i][j] -= a.xy(); m_pr[i][j+1] -= a.yy(); m_pr[i][j+2] -= a.yz(); i++;
m_pr[i][j] -= a.xz(); m_pr[i][j+1] -= a.yz(); m_pr[i][j+2] -= a.zz();
}
inline void matrix::sub(int i, int j, const mat3da& a)
{
m_pr[i][j+1] -= a.xy(); m_pr[i][j+2] -= a.xz(); i++;
m_pr[i][j ] += a.xy(); m_pr[i][j+2] -= a.yz(); i++;
m_pr[i][j ] += a.xz(); m_pr[i][j+1] += a.yz();
}
inline void matrix::sub(int i, int j, const mat3dd& a)
{
m_pr[i][j ] -= a.diag(0); i++;
m_pr[i][j+1] -= a.diag(1); i++;
m_pr[i][j+2] -= a.diag(2);
}
inline void matrix::sub(int i, int j, const mat3d& a)
{
m_pr[i][j] -= a(0,0); m_pr[i][j+1] -= a(0,1); m_pr[i][j+2] -= a(0,2); i++;
m_pr[i][j] -= a(1,0); m_pr[i][j+1] -= a(1,1); m_pr[i][j+2] -= a(1,2); i++;
m_pr[i][j] -= a(2,0); m_pr[i][j+1] -= a(2,1); m_pr[i][j+2] -= a(2,2);
}
inline void matrix::sub(int i, int j, const matrix& m)
{
int mr = m.rows();
int mc = m.columns();
for (int r = 0; r < mr; ++r)
for (int c = 0; c < mc; ++c)
m_pr[i + r][j + c] -= m[r][c];
}
inline void matrix::get(int i, int j, mat3d& a) const
{
a[0][0] = m_pr[i ][j]; a[0][1] = m_pr[i ][j+1]; a[0][2] = m_pr[i ][j+2];
a[1][0] = m_pr[i+1][j]; a[1][1] = m_pr[i+1][j+1]; a[1][2] = m_pr[i+1][j+2];
a[2][0] = m_pr[i+2][j]; a[2][1] = m_pr[i+2][j+1]; a[2][2] = m_pr[i+2][j+2];
}
//! move constructor
inline matrix::matrix(matrix&& m)
{
m_nr = m.m_nr;
m_nc = m.m_nc;
m_pd = m.m_pd;
m_pr = m.m_pr;
m.m_pr = nullptr;
m.m_pd = nullptr;
}
//! move assigment operator
inline matrix& matrix::operator = (matrix&& m)
{
if (this != &m)
{
if (m_pd) delete[] m_pd;
if (m_pr) delete[] m_pr;
m_nr = m.m_nr;
m_nc = m.m_nc;
m_pd = m.m_pd;
m_pr = m.m_pr;
m.m_pr = nullptr;
m.m_pd = nullptr;
}
return *this;
}
// Calculate the covariance of a matrix.
// The rows represent the observations, and the columns represent random variables.
// The returned covariance matrix is an ncol x ncol matrix.
matrix FECORE_API covariance(const matrix& a);
| Unknown |
3D | febiosoftware/FEBio | FECore/FEInitialCondition.cpp | .cpp | 5,368 | 188 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEInitialCondition.h"
#include "DumpStream.h"
#include "FEMaterialPoint.h"
#include "FENode.h"
#include "FEModel.h"
FEInitialCondition::FEInitialCondition(FEModel* pfem) : FEStepComponent(pfem)
{
}
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FENodalIC, FEInitialCondition)
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FENodalIC::FENodalIC(FEModel* fem) : FEInitialCondition(fem), m_dofs(fem)
{
m_nodeSet = nullptr;
}
//-----------------------------------------------------------------------------
// set the nodeset for this component
void FENodalIC::SetNodeSet(FENodeSet* nset)
{
m_nodeSet = nset;
}
//-----------------------------------------------------------------------------
// get the node set
FENodeSet* FENodalIC::GetNodeSet()
{
return m_nodeSet;
}
//-----------------------------------------------------------------------------
// set the list of degrees of freedom
void FENodalIC::SetDOFList(const FEDofList& dofList)
{
m_dofs = dofList;
}
//-----------------------------------------------------------------------------
bool FENodalIC::Init()
{
if (m_nodeSet == nullptr) return false;
return FEInitialCondition::Init();
}
//-----------------------------------------------------------------------------
void FENodalIC::Activate()
{
FEStepComponent::Activate();
if (m_dofs.IsEmpty()) return;
int dofs = (int)m_dofs.Size();
std::vector<double> val(dofs, 0.0);
int N = (int)m_nodeSet->Size();
for (int i = 0; i<N; ++i)
{
FENode& node = *m_nodeSet->Node(i);
// get the nodal values
GetNodalValues(i, val);
for (int j = 0; j < dofs; ++j)
{
node.set(m_dofs[j], val[j]);
}
}
}
//-----------------------------------------------------------------------------
// serialization
void FENodalIC::Serialize(DumpStream& ar)
{
FEStepComponent::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofs;
ar & m_nodeSet;
}
//======================================================================================
BEGIN_FECORE_CLASS(FEInitialDOF, FENodalIC)
ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list)");
ADD_PARAMETER(m_data, "value");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEInitialDOF::FEInitialDOF(FEModel* pfem) : FENodalIC(pfem)
{
m_dof = -1;
m_data = 0.0;
}
//-----------------------------------------------------------------------------
FEInitialDOF::FEInitialDOF(FEModel* fem, int ndof, FENodeSet* nset) : FENodalIC(fem)
{
SetDOF(ndof);
SetNodeSet(nset);
m_data = 0.0;
}
//-----------------------------------------------------------------------------
void FEInitialDOF::SetDOF(int ndof) { m_dof = ndof; }
//-----------------------------------------------------------------------------
bool FEInitialDOF::SetDOF(const char* szdof)
{
FEModel* fem = GetFEModel();
int ndof = fem->GetDOFIndex(szdof);
assert(ndof >= 0);
if (ndof < 0) return false;
SetDOF(ndof);
return true;
}
//-----------------------------------------------------------------------------
bool FEInitialDOF::Init()
{
if (FENodalIC::Init() == false) return false;
if (m_dof == -1) return false;
FEDofList dofs(GetFEModel());
if (dofs.AddDof(m_dof) == false) return false;
SetDOFList(dofs);
return true;
}
//-----------------------------------------------------------------------------
void FEInitialDOF::Serialize(DumpStream& ar)
{
FEInitialCondition::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dof;
}
//-----------------------------------------------------------------------------
void FEInitialDOF::SetValue(double v)
{
m_data = v;
}
//-----------------------------------------------------------------------------
// return the values for node i
void FEInitialDOF::GetNodalValues(int inode, std::vector<double>& val)
{
assert(val.size() == 1);
const FENodeSet& nset = *GetNodeSet();
int nid = nset[inode];
const FENode& node = *nset.Node(inode);
FEMaterialPoint mp;
mp.m_r0 = node.m_r0;
mp.m_index = inode;
val[0] = m_data(mp);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENNQuery.cpp | .cpp | 8,556 | 436 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENNQuery.h"
#include "FESurface.h"
#include <stdlib.h>
#include "FEMesh.h"
using namespace std;
int cmp_node(const void* e1, const void* e2)
{
FENNQuery::NODE& n1 = *((FENNQuery::NODE*)e1);
FENNQuery::NODE& n2 = *((FENNQuery::NODE*)e2);
return (n1.d1 > n2.d1 ? 1 : -1);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
FENNQuery::FENNQuery(FESurface* ps)
{
m_ps = ps;
}
FENNQuery::~FENNQuery()
{
}
//-----------------------------------------------------------------------------
void FENNQuery::Init()
{
assert(m_ps);
int i;
vec3d r0, r;
int N = m_ps->Nodes();
// pick a random point as pivot
r0 = m_q1 = m_ps->Node(0).m_rt;
// find the farthest node of this node
double dmax = 0, d;
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_rt;
d = (r - r0)*(r - r0);
if (d > dmax)
{
m_q1 = r;
dmax = d;
}
}
// let's find the farthest node of this node
r0 = m_q2 = m_q1;
dmax = 0;
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_rt;
d = (r - r0)*(r - r0);
if (d > dmax)
{
m_q2 = r;
dmax = d;
}
}
// create the BK-"tree"
m_bk.resize(N);
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_rt;
m_bk[i].i = i;
m_bk[i].r = r;
m_bk[i].d1 = (m_q1 - r)*(m_q1 - r);
m_bk[i].d2 = (m_q2 - r)*(m_q2 - r);
}
// sort the tree
qsort(&m_bk[0], N, sizeof(NODE), cmp_node);
// set the initial search item
m_imin = 0;
}
//-----------------------------------------------------------------------------
void FENNQuery::InitReference()
{
assert(m_ps);
int i;
vec3d r0, r;
int N = m_ps->Nodes();
// pick a random point as pivot
r0 = m_q1 = m_ps->Node(0).m_r0;
// find the furtest node of this node
double dmax = 0, d;
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_r0;
d = (r - r0)*(r - r0);
if (d > dmax)
{
m_q1 = r;
dmax = d;
}
}
// let's find the furthest node of this node
r0 = m_q2 = m_q1;
dmax = 0;
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_r0;
d = (r - r0)*(r - r0);
if (d > dmax)
{
m_q2 = r;
dmax = d;
}
}
// create the BK-"tree"
m_bk.resize(N);
for (i=0; i<N; ++i)
{
r = m_ps->Node(i).m_r0;
m_bk[i].i = i;
m_bk[i].r = r;
m_bk[i].d1 = (m_q1 - r)*(m_q1 - r);
m_bk[i].d2 = (m_q2 - r)*(m_q2 - r);
}
// sort the tree
qsort(&m_bk[0], N, sizeof(NODE), cmp_node);
// set the initial search item
m_imin = 0;
}
//-----------------------------------------------------------------------------
int FENNQuery::Find(vec3d x)
{
int m_i0 = -1;
double rmin1, rmin2, rmax1, rmax2;
double rmin1s, rmin2s, rmax1s, rmax2s;
double d, d1, d2, dmin;
vec3d r;
// set the initial search radii
d1 = sqrt((m_q1 - x)*(m_q1 - x));
rmin1 = 0;
rmax1 = 2*d1;
d2 = sqrt((m_q2 - x)*(m_q2 - x));
rmin2 = 0;
rmax2 = 2*d2;
// check the last found item
int imin = m_imin;
r = m_ps->Node(imin).m_rt;
dmin = (r - x)*(r - x);
d = sqrt(dmin);
// adjust search radii
if (d1 - d > rmin1) rmin1 = d1 - d;
if (d1 + d < rmax1) rmax1 = d1 + d;
rmin1s = rmin1*rmin1;
rmax1s = rmax1*rmax1;
if (d2 - d > rmin2) rmin2 = d2 - d;
if (d2 + d < rmax2) rmax2 = d2 + d;
rmin2s = rmin2*rmin2;
rmax2s = rmax2*rmax2;
// find the first item that satisfies d(i, q1) >= rmin1
int i0 = FindRadius(rmin1s);
for (int i=i0; i<(int) m_bk.size(); ++i)
{
NODE& n = m_bk[i];
if (n.d1 <= rmax1s)
{
if ((n.d2 >= rmin2s) && (n.d2 <= rmax2s))
{
r = n.r;
d = (r - x)*(r - x);
if (d < dmin)
{
dmin = d;
d = sqrt(dmin);
imin = n.i;
// if (d1 - d > rmin1) rmin1 = d1 - d;
if (d1 + d < rmax1) rmax1 = d1 + d;
// rmin1s = rmin1*rmin1;
rmax1s = rmax1*rmax1;
if (d2 - d > rmin2) rmin2 = d2 - d;
if (d2 + d < rmax2) rmax2 = d2 + d;
rmin2s = rmin2*rmin2;
rmax2s = rmax2*rmax2;
}
}
}
else break;
}
/*
// do it the hard way
int imin = 0;
r = m_ps->Node(imin).m_rt;
double d0 = (r - x)*(r - x);
for (i=0; i<m_ps->Nodes(); ++i)
{
r = m_ps->Node(i).m_rt;
d = (r - x)*(r - x);
if (d < d0)
{
d0 = d;
imin = i;
}
}
assert(imin == m_imin);
*/
#pragma omp critical
m_imin = imin;
return imin;
}
//-----------------------------------------------------------------------------
int FENNQuery::FindReference(vec3d x)
{
int m_i0 = -1;
double rmin1, rmin2, rmax1, rmax2;
double rmin1s, rmin2s, rmax1s, rmax2s;
double d, d1, d2, dmin;
vec3d r;
// set the initial search radii
d1 = sqrt((m_q1 - x)*(m_q1 - x));
rmin1 = 0;
rmax1 = 2*d1;
d2 = sqrt((m_q2 - x)*(m_q2 - x));
rmin2 = 0;
rmax2 = 2*d2;
// check the last found item
r = m_ps->Node(m_imin).m_r0;
dmin = (r - x)*(r - x);
d = sqrt(dmin);
// adjust search radii
if (d1 - d > rmin1) rmin1 = d1 - d;
if (d1 + d < rmax1) rmax1 = d1 + d;
rmin1s = rmin1*rmin1;
rmax1s = rmax1*rmax1;
if (d2 - d > rmin2) rmin2 = d2 - d;
if (d2 + d < rmax2) rmax2 = d2 + d;
rmin2s = rmin2*rmin2;
rmax2s = rmax2*rmax2;
// find the first item that satisfies d(i, q1) >= rmin1
int i0 = FindRadius(rmin1s);
for (int i=i0; i<(int) m_bk.size(); ++i)
{
NODE& n = m_bk[i];
if (n.d1 <= rmax1s)
{
if ((n.d2 >= rmin2s) && (n.d2 <= rmax2s))
{
r = n.r;
d = (r - x)*(r - x);
if (d < dmin)
{
dmin = d;
d = sqrt(dmin);
m_imin = n.i;
// if (d1 - d > rmin1) rmin1 = d1 - d;
if (d1 + d < rmax1) rmax1 = d1 + d;
// rmin1s = rmin1*rmin1;
rmax1s = rmax1*rmax1;
if (d2 - d > rmin2) rmin2 = d2 - d;
if (d2 + d < rmax2) rmax2 = d2 + d;
rmin2s = rmin2*rmin2;
rmax2s = rmax2*rmax2;
}
}
}
else break;
}
/*
// do it the hard way
int imin = 0;
r = m_ps->Node(imin).m_r0;
double d0 = (r - x)*(r - x);
for (int i=0; i<m_ps->Nodes(); ++i)
{
r = m_ps->Node(i).m_r0;
d = (r - x)*(r - x);
if (d < d0)
{
d0 = d;
imin = i;
}
}
// assert(imin == m_imin);
*/
return m_imin;
}
//-----------------------------------------------------------------------------
int FENNQuery::FindRadius(double r)
{
int N = (int)m_bk.size();
int L = N - 1;
int i0 = 0;
int i1 = L;
if (m_bk[i1].d1 < r) return N;
int i = i1 / 2;
do
{
if (m_bk[i].d1 < r)
{
i0 = i;
if (m_bk[i+1].d1 >= r) { ++i; break; }
}
else
{
i1 = i;
if ((i==0) || (m_bk[i-1].d1 < r)) break;
}
i = (i1 + i0) / 2;
}
while(i0 != i1);
return i;
}
//-----------------------------------------------------------------------------
int findNeirestNeighbors(const std::vector<vec3d>& point, const vec3d& x, int k, std::vector<int>& closestNodes)
{
int N0 = (int) point.size();
if (N0 < k) k = N0;
vector<double> dist(k, 0.0);
closestNodes.resize(k);
int n = 0;
for (int i = 0; i < N0; ++i)
{
vec3d ri = point[i] - x;
double L2 = ri*ri;
if (n == 0)
{
closestNodes[0] = i;
dist[0] = L2;
n++;
}
else if (L2 <= dist[n - 1])
{
int m;
for (m = 0; m < n; ++m)
{
if (L2 <= dist[m])
{
break;
}
}
if (n < k) n++;
for (int l = n - 1; l > m; l--)
{
closestNodes[l] = closestNodes[l - 1];
dist[l] = dist[l - 1];
}
closestNodes[m] = i;
dist[m] = L2;
}
else if (n < k)
{
closestNodes[n] = i;
dist[n] = L2;
n++;
}
}
return n;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENodeList.h | .h | 2,284 | 70 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "fecore_api.h"
#include <vector>
//-----------------------------------------------------------------------------
class FEMesh;
class FENode;
class DumpStream;
//-----------------------------------------------------------------------------
// Defines an array of node indices.
class FECORE_API FENodeList
{
public:
FENodeList(FEMesh* mesh = nullptr);
FENodeList(const FENodeList& nodeList);
FENodeList& operator = (const FENodeList& nodeList);
int Size() const;
void Add(int n);
void Add(const std::vector<int>& nodeList);
void Add(const FENodeList& nodeList);
void Clear();
int operator[](int n) const { return m_nodes[n]; }
FENode* Node(int i);
const FENode* Node(int i) const;
void Serialize(DumpStream& ar);
FEMesh* GetMesh() { return m_mesh; }
// returns the local index from a global (mesh based) node index,
// or -1 if the node is not part of the set.
int GlobalToLocalID(int globalId) const;
private:
FEMesh* m_mesh;
std::vector<int> m_nodes;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/CSRMatrix.h | .h | 2,802 | 88 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
// This class represents a sparse matrix in the row-compressed format (3-array format)
class FECORE_API CSRMatrix
{
public:
// default constructor
CSRMatrix();
// create a matrix of given size
CSRMatrix(int rows, int cols, int noffset = 0);
// copy constructor
CSRMatrix(const CSRMatrix& A);
// Create matrix
void create(int nr, int nc, int noffset = 0);
// assignment operator
void operator = (const CSRMatrix& A);
// return row count
int rows() const { return m_nr; }
// return columns count
int cols() const { return m_nc; }
// return number of nonzeroes
int nonzeroes() const { return (int) m_values.size(); }
// set the value, inserting it if necessary
void set(int i, int j, double val);
// get a value
double operator () (int i, int j) const;
// see if a matrix entry was allocated
bool isAlloc(int i, int j) const;
public:
// matrix-vector multiplication: A.x = r
void multv(const std::vector<double>& x, std::vector<double>& r);
void multv(const double* x, double* r);
public:
std::vector<double>& values() { return m_values; }
std::vector<int>& indices() { return m_columns; }
std::vector<int>& pointers() { return m_rowIndex; }
private:
int m_nr; // number of rows
int m_nc; // number of columns
int m_offset; // offset (0 or 1)
std::vector<int> m_rowIndex; // start of row in columns array
std::vector<int> m_columns; // columns of non-zero entries
std::vector<double> m_values; // values of matrix
};
| Unknown |
3D | febiosoftware/FEBio | FECore/writeplot.cpp | .cpp | 9,100 | 372 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "writeplot.h"
#include "FESPRProjection.h"
void writeMaxElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<double(const FEMaterialPoint& mp)> fnc)
{
int NE = dom.Elements();
std::vector<double> v(NE);
#pragma omp parallel for shared(v)
for (int i = 0; i < NE; ++i) {
FEElement& el = dom.ElementRef(i);
double s = 0.0;
for (int j = 0; j < el.GaussPoints(); ++j)
{
double sj = fnc(*el.GetMaterialPoint(j));
if ((sj > s) || (j == 0)) s = sj;
}
v[i] = s;
}
for (int i = 0; i < NE; ++i)
ar << v[i];
}
void writeSPRElementValue(FESolidDomain& dom, FEDataStream& ar, std::function<double(const FEMaterialPoint&)> fnc, int interpolOrder)
{
int NN = dom.Nodes();
int NE = dom.Elements();
// build the element data array
vector< vector<double> > ED;
ED.resize(NE);
for (int i = 0; i < NE; ++i)
{
FESolidElement& e = dom.Element(i);
int nint = e.GaussPoints();
ED[i].assign(nint, 0.0);
}
// this array will store the results
FESPRProjection map(dom, interpolOrder);
vector<double> val;
// fill the ED array
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
double v = fnc(mp);
ED[i][j] = v;
}
}
// project to nodes
map.Project(ED, val);
// copy results to archive
for (int i = 0; i < NN; ++i)
{
ar.push_back((float)val[i]);
}
}
//-------------------------------------------------------------------------------------------------
void writeSPRElementValueVectorDouble(FESolidDomain& dom, FEDataStream& ar, std::function<std::vector<double>(const FEMaterialPoint&)> fnc, int interpolOrder, int n_fields)
{
// get all nodes and elements
int NN = dom.Nodes();
int NE = dom.Elements();
// build the element data array
vector<vector< vector<double> > > ED(n_fields);
// for each component
for (int n = 0; n < n_fields; ++n)
{
// fill element data. for each element add the number of gauss points in the element.
ED[n].resize(NE);
for (int i = 0; i < NE; ++i)
{
FESolidElement& e = dom.Element(i);
int nint = e.GaussPoints();
ED[n][i].assign(nint, 0.0);
}
}
// this array will store the results
FESPRProjection map(dom, interpolOrder);
vector<vector<double> >val(n_fields);
// fill the ED array
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
vector<double> v = fnc(mp);
// loop over all solutes components
for (int n = 0; n < n_fields; ++n)
{
ED[n][i][j] = v[n];
}
}
}
// project to nodes
// loop over stress components
for (int n = 0; n < n_fields; ++n)
{
map.Project(ED[n], val[n]);
}
// copy results to archive
for (int i_node = 0; i_node < NN; ++i_node)
{
for (int i_field = 0; i_field < n_fields; ++i_field)
ar.push_back((float)val[i_field][i_node]);
}
}
void writeSPRElementValueMat3dd(FESolidDomain& dom, FEDataStream& ar, std::function<mat3dd(const FEMaterialPoint&)> fnc, int interpolOrder)
{
int NN = dom.Nodes();
int NE = dom.Elements();
// build the element data array
vector< vector<double> > ED[3];
ED[0].resize(NE);
ED[1].resize(NE);
ED[2].resize(NE);
for (int i = 0; i<NE; ++i)
{
FESolidElement& e = dom.Element(i);
int nint = e.GaussPoints();
ED[0][i].assign(nint, 0.0);
ED[1][i].assign(nint, 0.0);
ED[2][i].assign(nint, 0.0);
}
// this array will store the results
FESPRProjection map(dom, interpolOrder);
vector<double> val[3];
// fill the ED array
for (int i = 0; i < NE; ++i)
{
FESolidElement& el = dom.Element(i);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
mat3dd v = fnc(mp);
ED[0][i][j] = v.diag(0);
ED[1][i][j] = v.diag(1);
ED[2][i][j] = v.diag(2);
}
}
// project to nodes
map.Project(ED[0], val[0]);
map.Project(ED[1], val[1]);
map.Project(ED[2], val[2]);
// copy results to archive
for (int i = 0; i<NN; ++i)
{
ar.push_back((float)val[0][i]);
ar.push_back((float)val[1][i]);
ar.push_back((float)val[2][i]);
}
}
//-------------------------------------------------------------------------------------------------
void writeSPRElementValueMat3ds(FESolidDomain& dom, FEDataStream& ar, std::function<mat3ds(const FEMaterialPoint&)> fnc, int interpolOrder)
{
const int LUT[6][2] = { { 0,0 },{ 1,1 },{ 2,2 },{ 0,1 },{ 1,2 },{ 0,2 } };
int NN = dom.Nodes();
int NE = dom.Elements();
// build the element data array
vector< vector<double> > ED[6];
for (int n = 0; n < 6; ++n)
{
ED[n].resize(NE);
for (int i = 0; i < NE; ++i)
{
FESolidElement& e = dom.Element(i);
int nint = e.GaussPoints();
ED[n][i].assign(nint, 0.0);
}
}
// this array will store the results
FESPRProjection map(dom, interpolOrder);
vector<double> val[6];
// fill the ED array
for (int i = 0; i<NE; ++i)
{
FESolidElement& el = dom.Element(i);
int nint = el.GaussPoints();
for (int j = 0; j<nint; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
mat3ds s = fnc(mp);
// loop over stress components
for (int n = 0; n < 6; ++n)
{
ED[n][i][j] = s(LUT[n][0], LUT[n][1]);
}
}
}
// project to nodes
// loop over stress components
for (int n = 0; n<6; ++n)
{
map.Project(ED[n], val[n]);
}
// copy results to archive
for (int i = 0; i<NN; ++i)
{
ar.push_back((float)val[0][i]);
ar.push_back((float)val[1][i]);
ar.push_back((float)val[2][i]);
ar.push_back((float)val[3][i]);
ar.push_back((float)val[4][i]);
ar.push_back((float)val[5][i]);
}
}
void ProjectToNodes(FEDomain& dom, vector<double>& nodeVals, function<double(FEMaterialPoint& mp)> f)
{
// temp storage
double si[FEElement::MAX_INTPOINTS];
double sn[FEElement::MAX_NODES];
// allocate nodeVals and create valence array (tag)
int NN = dom.Nodes();
vector<int> tag(NN, 0);
nodeVals.assign(NN, 0.0);
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
FEElement& e = dom.ElementRef(i);
int ne = e.Nodes();
int ni = e.GaussPoints();
// get the integration point values
for (int k = 0; k < ni; ++k)
{
FEMaterialPoint& mp = *e.GetMaterialPoint(k);
double v = f(mp);
si[k] = v;
}
// project to nodes
e.project_to_nodes(si, sn);
for (int j = 0; j < ne; ++j)
{
nodeVals[e.m_lnode[j]] += sn[j];
tag[e.m_lnode[j]]++;
}
}
for (int i = 0; i < NN; ++i)
{
if (tag[i] > 0) nodeVals[i] /= (double)tag[i];
}
}
void writeRelativeError(FEDomain& dom, FEDataStream& a, function<double(FEMaterialPoint& mp)> f)
{
int NE = dom.Elements();
int NN = dom.Nodes();
// calculate the recovered nodal values
vector<double> sn(NN);
ProjectToNodes(dom, sn, f);
// find the min and max values
double smin = 1e99, smax = -1e99;
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom.ElementRef(i);
int ni = el.GaussPoints();
for (int j = 0; j < ni; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
double sj = f(mp);
if (sj < smin) smin = sj;
if (sj > smax) smax = sj;
}
}
if (fabs(smin - smax) < 1e-12) smax++;
// calculate errors
double ev[FEElement::MAX_NODES];
for (int i = 0; i < NE; ++i)
{
FEElement& el = dom.ElementRef(i);
int ne = el.Nodes();
int ni = el.GaussPoints();
// get the nodal values
for (int j = 0; j < ne; ++j)
{
ev[j] = sn[el.m_lnode[j]];
}
// evaluate element error
double max_err = 0;
for (int j = 0; j < ni; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
double sj = f(mp);
double snj = el.Evaluate(ev, j);
double err = fabs(sj - snj) / (smax - smin);
if (err > max_err) max_err = err;
}
a << max_err;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMathController.h | .h | 1,711 | 54 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FELoadController.h"
#include "MathObject.h"
#include <vector>
#include <string>
class FEMathController : public FELoadController
{
public:
FEMathController(FEModel* fem);
bool Init() override;
protected:
double GetValue(double time) override;
private:
std::vector<std::string> m_var;
std::string m_math;
MSimpleExpression m_val;
std::vector<FEParamValue> m_param;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESolidDomain.h | .h | 13,154 | 296 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDomain.h"
#include "FEDofList.h"
#include "FELinearSystem.h"
#include "FESolidElement.h"
//-----------------------------------------------------------------------------
// This typedef defines a surface integrand.
// It evaluates the function at surface material point mp, and returns the value
// it the val vector. The size of the vector is determined by the field variable
// that is being integrated and is already set when the integrand is called.
// This is used in the FESurface::LoadVector function.
typedef std::function<void(FEMaterialPoint& mp, int node_a, std::vector<double>& val)> FEVolumeVectorIntegrand;
typedef std::function<void(FEMaterialPoint& mp, int node_a, int node_b, matrix& val)> FEVolumeMatrixIntegrand;
//-----------------------------------------------------------------------------
//! abstract base class for 3D volumetric elements
class FECORE_API FESolidDomain : public FEDomain
{
FECORE_SUPER_CLASS(FESOLIDDOMAIN_ID)
FECORE_BASE_CLASS(FESolidDomain)
public:
//! constructor
FESolidDomain(FEModel* pfem);
//! create storage for elements
bool Create(int nsize, FE_Element_Spec espec) override;
//! return nr of elements
int Elements() const override;
//! initialize element data
bool Init() override;
//! reset data (overridden from FEDomain)
void Reset() override;
//! copy data from another domain (overridden from FEDomain)
void CopyFrom(FEMeshPartition* pd) override;
//! element access
FESolidElement& Element(int n);
FEElement& ElementRef(int n) override { return m_Elem[n]; }
const FEElement& ElementRef(int n) const override { return m_Elem[n]; }
int GetElementType() const { return m_Elem[0].Type(); }
int GetElementShape() const { return m_Elem[0].Shape(); }
FE_Element_Spec GetElementSpec() const;
//! find the element in which point y lies
FESolidElement* FindElement(const vec3d& y, double r[3]);
//! find the element in which point y lies (reference configuration)
FESolidElement* FindReferenceElement(const vec3d& y, double r[3]);
//! Project a point to an element and return natural coordinates
void ProjectToElement(FESolidElement& el, const vec3d& p, double r[3]);
//! Project a point to an element in the reference frame and return natural coordinates
//! returns true if the point lies in the element
bool ProjectToReferenceElement(FESolidElement& el, const vec3d& p, double r[3]);
//! Calculate deformation gradient at integration point n
double defgrad(FESolidElement& el, mat3d& F, int n);
double defgrad(FESolidElement& el, mat3d& F, int n, vec3d* r);
//! Calculate deformation gradient at integration point n
double defgrad(FESolidElement& el, mat3d& F, double r, double s, double t);
//! Calculate deformation gradient at integration point n at previous time
double defgradp(FESolidElement& el, mat3d& F, int n);
//! Calculate GradJ at integration point n at current time
vec3d GradJ(FESolidElement& el, int n);
//! Calculate GradJ at integration point n at prev time
vec3d GradJp(FESolidElement& el, int n);
//! Calculate GradJ at integration point n at current time
tens3dls Gradb(FESolidElement& el, int n);
//! Calculate GradJ at integration point n at prev time
tens3dls Gradbp(FESolidElement& el, int n);
//! calculate inverse jacobian matrix w.r.t. reference frame
double invjac0(const FESolidElement& el, double J[3][3], int n);
//! calculate inverse jacobian matrix w.r.t. reference frame
double invjac0(const FESolidElement& el, double J[3][3], double r, double s, double t);
//! calculate inverse jacobian matrix w.r.t. reference frame
double invjac0(const FESolidElement& el, double r, double s, double t, mat3d& J);
//! calculate inverse jacobian matrix w.r.t. current frame
double invjact(FESolidElement& el, double J[3][3], int n);
double invjact(FESolidElement& el, double J[3][3], int n, const vec3d* r);
//! calculate inverse jacobian matrix w.r.t. reference frame
double invjact(FESolidElement& el, double J[3][3], double r, double s, double t);
//! calculate inverse jacobian matrix w.r.t. intermediate frame
double invjact(FESolidElement& el, double J[3][3], int n, const double alpha);
//! calculate inverse jacobian matrix w.r.t. previous time
double invjactp(FESolidElement& el, double J[3][3], int n);
//! calculate gradient of function at integration points
vec3d gradient(FESolidElement& el, double* fn, int n);
vec3d gradient(FESolidElement& el, int order, double* fn, int n);
//! calculate gradient of function at integration points
vec3d gradient(FESolidElement& el, vector<double>& fn, int n);
//! calculate spatial gradient of vector function at integration points
mat3d gradient(FESolidElement& el, vec3d* fn, int n);
//! calculate gradient of function at integration points at intermediate time
vec3d gradient(FESolidElement& el, vector<double>& fn, int n, const double alpha);
//! calculate spatial gradient of vector function at integration points at intermediate time
mat3d gradient(FESolidElement& el, vec3d* fn, int n, const double alpha);
//! calculate spatial gradient of vector function at integration points
//! at previous time
mat3d gradientp(FESolidElement& el, vec3d* fn, int n);
//! calculate spatial gradient of vector function at integration points
tens3dls gradient(FESolidElement& el, mat3ds* fn, int n);
//! calculate spatial gradient of vector function at integration points
//! at previous time
tens3dls gradientp(FESolidElement& el, mat3ds* fn, int n);
//! calculate material gradient of scalar function at integration points
vec3d Gradient(FESolidElement& el, double* fn, int n);
//! calculate material gradient of scalar function at integration points
vec3d Gradient(FESolidElement& el, vector<double>& fn, int n);
//! calculate material gradient of vector function at integration points
mat3d Gradient(FESolidElement& el, vec3d* fn, int n);
//! calculate material gradient of vector function at integration points
tens3dls Gradient(FESolidElement& el, mat3ds* fn, int n);
//! calculate jacobian in reference frame
double detJ0(FESolidElement& el, int n);
//! calculate jacobian in current frame
double detJt(FESolidElement& el, int n);
//! calculate jacobian in current frame
double detJt(FESolidElement& el, int n, const double alpha);
//! calculates covariant basis vectors in reference configuration at an integration point
void CoBaseVectors0(FESolidElement& el, int j, vec3d g[3]);
//! calculates covariant basis vectors at an integration point
void CoBaseVectors(FESolidElement& el, int j, vec3d g[3]);
//! calculates covariant basis vectors at an integration point
void CoBaseVectors(FESolidElement& el, int j, vec3d g[3], const double alpha);
//! calculates contravariant basis vectors in reference configuration at an integration point
void ContraBaseVectors0(FESolidElement& el, int j, vec3d g[3]);
//! calculates contravariant basis vectors at an integration point
void ContraBaseVectors(FESolidElement& el, int j, vec3d g[3]);
//! calculates contravariant basis vectors at an integration point
void ContraBaseVectors(FESolidElement& el, int j, vec3d g[3], const double alpha);
//! calculates parametric derivatives of covariant basis vectors at an integration point
void CoBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3]);
//! calculates parametric derivatives of covariant basis vectors at an integration point
void CoBaseVectorDerivatives0(FESolidElement& el, int j, vec3d dg[3][3]);
//! calculates parametric derivatives of covariant basis vectors at an integration point
void CoBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3], const double alpha);
//! calculates parametric derivatives of contravariant basis vectors at an integration point
void ContraBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3]);
//! calculates parametric derivatives of contravariant basis vectors at an integration point
void ContraBaseVectorDerivatives0(FESolidElement& el, int j, vec3d dg[3][3]);
//! calculates parametric derivatives of contravariant basis vectors at an integration point
void ContraBaseVectorDerivatives(FESolidElement& el, int j, vec3d dg[3][3], const double alpha);
//! calculate the laplacian of a vector function at an integration point
vec3d lapvec(FESolidElement& el, vec3d* fn, int n);
//! calculate the gradient of the divergence of a vector function at an integration point
vec3d gradivec(FESolidElement& el, vec3d* fn, int n);
//! calculate the transpose of the gradient of the shape function gradients at an integration point
void gradTgradShape(FESolidElement& el, int j, vector<mat3d>& mn);
//! calculate spatial gradient of shapefunctions at integration point (returns Jacobian determinant)
double ShapeGradient(FESolidElement& el, int n, vec3d* GradH);
//! calculate spatial gradient of shapefunctions at integration point (returns Jacobian determinant)
double ShapeGradient(FESolidElement& el, int n, vec3d* GradH, const double alpha);
//! calculate spatial gradient of shapefunctions at integration point in reference frame (returns Jacobian determinant)
double ShapeGradient0(FESolidElement& el, int n, vec3d* GradH);
//! calculate spatial gradient of shapefunctions at integration point (returns Jacobian determinant)
double ShapeGradient(FESolidElement& el, double r, double s, double t, vec3d* GradH);
//! calculate spatial gradient of shapefunctions at integration point in reference frame (returns Jacobian determinant)
double ShapeGradient0(FESolidElement& el, double r, double s, double t, vec3d* GradH);
//! calculate the volume of an element in reference frame
double Volume(FESolidElement& el);
//! calculate the volume of an element in current frame
double CurrentVolume(FESolidElement& el);
public:
//! get the current nodal coordinates
void GetCurrentNodalCoordinates(const FESolidElement& el, vec3d* rt);
void GetCurrentNodalCoordinates(const FESolidElement& el, vec3d* rt, double alpha);
//! get the reference nodal coordinates
void GetReferenceNodalCoordinates(const FESolidElement& el, vec3d* r0);
//! get the nodal coordinates at previous state
void GetPreviousNodalCoordinates(const FESolidElement& el, vec3d* rp);
public:
//! loop over elements
void ForEachSolidElement(std::function<void(FESolidElement& el)> f);
//! return the degrees of freedom of an element for this domain
virtual int GetElementDofs(FESolidElement& el);
public:
// Evaluate an integral over the domain and assemble into global load vector
virtual void LoadVector(
FEGlobalVector& R, // the global vector to assembe the load vector in
const FEDofList& dofList, // the degree of freedom list
FEVolumeVectorIntegrand f // the actual integrand function
);
//! Evaluate the stiffness matrix of a load
virtual void LoadStiffness(
FELinearSystem& LS, // The solver does the assembling
const FEDofList& dofList_a, // The degree of freedom list of node a
const FEDofList& dofList_b, // The degree of freedom list of node b
FEVolumeMatrixIntegrand f // the matrix function to evaluate
);
protected:
vector<FESolidElement> m_Elem; //!< array of elements
FE_Element_Spec m_elemSpec; //!< the element spec
FEDofList m_dofU;
FEDofList m_dofSU;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MMatrix.h | .h | 4,807 | 126 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "MItem.h"
//-----------------------------------------------------------------------------
class MMatrix;
typedef MItem* (*FUNCMATPTR )(const MMatrix& A);
typedef MItem* (*FUNCMAT2PTR)(const MMatrix& A, const MMatrix& B);
//-----------------------------------------------------------------------------
// Matrix class
class MMatrix : public MItem
{
public:
MMatrix();
~MMatrix();
void Create(int nrow, int ncol);
public:
MItem* copy() const override;
MItem* Item(int i, int j) { return m_d[i][j]; }
const MItem* Item(int i, int j) const { return m_d[i][j]; }
std::vector<MItem*>& operator [] (int n) { return m_d[n]; }
const std::vector<MItem*>& operator [] (int n) const { return m_d[n]; }
MItem* operator () (int i, int j) { return m_d[i][j]->copy(); }
const MItem* operator () (int i, int j) const { return m_d[i][j]->copy(); }
int rows () const { return m_nrow; }
int columns() const { return m_ncol; }
protected:
std::vector< std::vector<MItem*> > m_d;
int m_nrow;
int m_ncol;
};
//-----------------------------------------------------------------------------
// function of matrices
class MFuncMat : public MUnary
{
public:
MFuncMat(FUNCMATPTR pf, const std::string& s, MItem* pi) : MUnary(pi, MFMAT), m_name(s), m_pf(pf) {}
MItem* copy() const override { return new MFuncMat(m_pf, m_name, m_pi->copy()); }
const std::string& Name() { return m_name; }
FUNCMATPTR funcptr() const { return m_pf; }
protected:
std::string m_name;
FUNCMATPTR m_pf;
};
//-----------------------------------------------------------------------------
// function of 2 matrices
class MFuncMat2 : public MBinary
{
public:
MFuncMat2(FUNCMAT2PTR pf, const std::string& s, MItem* pl, MItem* pr) : MBinary(pl, pr, MFMAT2), m_name(s), m_pf(pf) {}
MItem* copy() const override { return new MFuncMat2(m_pf, m_name, m_pleft->copy(), m_pright->copy()); }
const std::string& Name() { return m_name; }
FUNCMAT2PTR funcptr() const { return m_pf; }
protected:
std::string m_name;
FUNCMAT2PTR m_pf;
};
inline MMatrix* mmatrix (MItem* pi) { return static_cast<MMatrix *>(pi); }
inline MFuncMat* mfncmat (MItem* pi) { return static_cast<MFuncMat *>(pi); }
inline MFuncMat2* mfncmat2(MItem* pi) { return static_cast<MFuncMat2*>(pi); }
inline const MMatrix* mmatrix (const MItem* pi) { return static_cast<const MMatrix *>(pi); }
inline const MFuncMat* mfncmat (const MItem* pi) { return static_cast<const MFuncMat *>(pi); }
inline const MFuncMat2* mfncmat2(const MItem* pi) { return static_cast<const MFuncMat2*>(pi); }
inline const MMatrix* mmatrix (const MITEM& i) { return static_cast<const MMatrix *>(i.ItemPtr()); }
inline const MFuncMat* mfncmat (const MITEM& i) { return static_cast<const MFuncMat *>(i.ItemPtr()); }
inline const MFuncMat2* mfncmat2(const MITEM& i) { return static_cast<const MFuncMat2*>(i.ItemPtr()); }
//-----------------------------------------------------------------------------
// Matrix operations
MMatrix* operator + (const MMatrix& A, const MMatrix& B);
MMatrix* operator - (const MMatrix& A, const MMatrix& B);
MMatrix* operator * (const MMatrix& A, const MITEM& n);
MMatrix* operator / (const MMatrix& A, const MITEM& n);
MMatrix* operator * (const MMatrix& A, const MMatrix& B);
MItem* matrix_transpose (const MMatrix& A);
MItem* matrix_trace (const MMatrix& A);
MItem* matrix_determinant(const MMatrix& A);
MItem* matrix_inverse (const MMatrix& A);
MItem* matrix_contract(const MMatrix& A, const MMatrix& B);
MMatrix* matrix_identity(int n);
| Unknown |
3D | febiosoftware/FEBio | FECore/quatd.h | .h | 8,596 | 354 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include "mat3d.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
//! This class implements a quaternion.
class FECORE_API quatd
{
public:
//! Default constructor - creates identity quaternion (0, 0, 0, 1)
quatd() { x = y = z = 0.0; w = 1.0; }
//! Constructor from rotation angle and axis vector
quatd( const double angle, vec3d v)
{
w = (double) cos(angle * 0.5);
double sina = (double) sin(angle * 0.5);
v.unit();
x = v.x*sina;
y = v.y*sina;
z = v.z*sina;
}
//! Constructor from rotation vector (magnitude is angle, direction is axis)
quatd(vec3d v)
{
double angle = v.unit();
w = (double) cos(angle * 0.5);
double sina = (double) sin(angle * 0.5);
x = v.x*sina;
y = v.y*sina;
z = v.z*sina;
}
//! Constructor from two vectors - creates rotation from v1 to v2
quatd (const vec3d& v1, const vec3d& v2)
{
vec3d n = v1^v2;
n.unit();
double d = v1*v2;
double sina = (double) sqrt((1.0-d)*0.5);
double cosa = (double) sqrt((1.0+d)*0.5);
w = cosa;
x = n.x*sina;
y = n.y*sina;
z = n.z*sina;
}
//! Constructor from four components
quatd(const double qx, const double qy, const double qz, const double qw = 1.0)
{
w = qw;
x = qx;
y = qy;
z = qz;
}
//! Constructor from rotation matrix
quatd(const mat3d& a);
//! Inequality comparison operator
bool operator != (const quatd& q) const { return ((x!=q.x) || (y!=q.y) || (z!=q.z) || (w!=q.w)); }
//! Equality comparison operator
bool operator == (const quatd& q) const { return ((x == q.x) && (y == q.y) && (z == q.z) && (w == q.w)); }
//! Unary negation operator
quatd operator - () { return quatd(-x, -y, -z, -w); }
//! Quaternion addition operator
quatd operator + (const quatd& q) const
{
return quatd(x + q.x, y + q.y, z + q.z, w + q.w);
}
//! Quaternion subtraction operator
quatd operator - (const quatd& q) const
{
return quatd(x - q.x, y - q.y, z - q.z, w - q.w);
}
//! Quaternion addition assignment operator
quatd& operator += (const quatd& q)
{
x += q.x;
y += q.y;
z += q.z;
w += q.w;
return *this;
}
//! Quaternion subtraction assignment operator
quatd& operator -= (const quatd& q)
{
x -= q.x;
y -= q.y;
z -= q.z;
w -= q.w;
return *this;
}
//! Quaternion multiplication operator
quatd operator * (const quatd& q) const
{
double qw = w*q.w - x*q.x - y*q.y - z*q.z;
double qx = w*q.x + x*q.w + y*q.z - z*q.y;
double qy = w*q.y + y*q.w + z*q.x - x*q.z;
double qz = w*q.z + z*q.w + x*q.y - y*q.x;
return quatd(qx, qy, qz, qw);
}
//! Quaternion multiplication assignment operator
quatd& operator *= (const quatd& q)
{
double qw = w*q.w - x*q.x - y*q.y - z*q.z;
double qx = w*q.x + x*q.w + y*q.z - z*q.y;
double qy = w*q.y + y*q.w + z*q.x - x*q.z;
double qz = w*q.z + z*q.w + x*q.y - y*q.x;
x = qx;
y = qy;
z = qz;
w = qw;
return *this;
}
//! Scalar multiplication operator
quatd operator*(const double a) const
{
return quatd(x*a, y*a, z*a, w*a);
}
//! Scalar division operator
quatd operator / (const double a) const
{
return quatd(x/a, y/a, z/a, w/a);
}
//! Scalar division assignment operator
quatd& operator /= (const double a)
{
x /= a;
y /= a;
z /= a;
w /= a;
return *this;
}
//! Return the conjugate of the quaternion
quatd Conjugate() const { return quatd(-x, -y, -z, w); }
//! Return the norm (squared magnitude) of the quaternion
double Norm() const { return w*w + x*x + y*y + z*z; }
//! Normalize the quaternion to unit length
void MakeUnit()
{
double N = (double) sqrt(w*w + x*x + y*y + z*z);
if (N != 0)
{
x /= N;
y /= N;
z /= N;
w /= N;
}
else w = 1.f;
}
//! Return the inverse of the quaternion
quatd Inverse() const
{
double N = w*w + x*x + y*y + z*z;
if (N == 0.0) return quatd(x, y, z, w);
else return quatd(-x/N, -y/N, -z/N, w/N);
}
//! Calculate dot product with another quaternion
double DotProduct(const quatd& q) const
{
return w*q.w + x*q.x + y*q.y + z*q.z;
}
//! Get the normalized rotation axis vector
vec3d GetVector() const
{
vec3d r(x,y,z);
r.unit();
return r;
}
//! Get the rotation vector (axis scaled by angle)
vec3d GetRotationVector() const
{
vec3d r(x,y,z);
r.unit();
double a = GetAngle();
return r*a;
}
//! Get the rotation angle in radians
double GetAngle() const
{
vec3d r(x,y,z);
double sha = r.unit();
double cha = w;
return (double)(atan2(sha,cha)*2.0);
}
//! Rotate a vector using this quaternion (in-place, for unit quaternions only)
void RotateVector(vec3d& v) const
{
if ((w == 0) || ((x==0) && (y==0) && (z==0))) return;
// v*q^-1
double qw = v.x*x + v.y*y + v.z*z;
double qx = v.x*w - v.y*z + v.z*y;
double qy = v.y*w - v.z*x + v.x*z;
double qz = v.z*w - v.x*y + v.y*x;
// q* (v* q^-1)
v.x = w*qx + x*qw + y*qz - z*qy;
v.y = w*qy + y*qw + z*qx - x*qz;
v.z = w*qz + z*qw + x*qy - y*qx;
}
//! Vector rotation operator (for unit quaternions only)
vec3d operator * (const vec3d& r) const
{
vec3d n = r;
// v*q^-1
double qw = n.x*x + n.y*y + n.z*z;
double qx = n.x*w - n.y*z + n.z*y;
double qy = n.y*w - n.z*x + n.x*z;
double qz = n.z*w - n.x*y + n.y*x;
// q* (v* q^-1)
n.x = w*qx + x*qw + y*qz - z*qy;
n.y = w*qy + y*qw + z*qx - x*qz;
n.z = w*qz + z*qw + x*qy - y*qx;
return n;
}
//! Rotate vector using raw pointer arrays
void RotateVectorP(double* v, double* r) const
{
double qw = v[0]*x + v[1]*y + v[2]*z;
double qx = v[0]*w - v[1]*z + v[2]*y;
double qy = v[1]*w - v[2]*x + v[0]*z;
double qz = v[2]*w - v[0]*y + v[1]*x;
r[0] = w*qx + x*qw + y*qz - z*qy;
r[1] = w*qy + y*qw + z*qx - x*qz;
r[2] = w*qz + z*qw + x*qy - y*qx;
}
//! Convert a quaternion to a rotation matrix
mat3d RotationMatrix() const
{
return mat3d(
w*w + x*x - y*y - z*z,
2.0*(x*y - w*z),
2.0*(x*z + w*y),
2.0*(x*y + w*z),
w*w - x*x + y*y - z*z,
2.0*(y*z - w*x),
2.0*(x*z - w*y),
2.0*(y*z + w*x),
w*w - x*x - y*y + z*z);
}
//! Calculate dot product between two quaternions
static double dot(quatd &q1, quatd &q2)
{ return q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; }
//! Linear interpolation between two quaternions
static quatd lerp(quatd &q1, quatd &q2, const double t)
{ quatd q = (q1*(1.0-t) + q2*t); q.MakeUnit(); return q; }
//! Spherical linear interpolation between two quaternions
static quatd slerp(quatd &q1, quatd &q2, const double t);
//! Set quaternion from XYZ Euler angles (roll, pitch, yaw in radians)
void SetEuler(double x, double y, double z);
//! Get XYZ Euler angles from quaternion (roll, pitch, yaw in radians)
void GetEuler(double& x, double& y, double& z) const;
public:
//! X component of quaternion
double x, y, z, w;
};
//! Scalar multiplication operator (scalar * quaternion)
inline quatd operator * (const double a, const quatd& q)
{
return q*a;
}
//! Convert euler-angles to a rotation matrix
FECORE_API mat3d euler2rot(double l[3]);
//! Convert a rotation matrix to euler angles
FECORE_API void rot2euler(const mat3d& m, double l[3]);
//! Extract euler angles from a quaternion
FECORE_API void quat2euler(const quatd& q, double l[3]); | Unknown |
3D | febiosoftware/FEBio | FECore/Preconditioner.h | .h | 2,776 | 86 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "SparseMatrix.h"
#include "LinearSolver.h"
//-----------------------------------------------------------------------------
class CRSSparseMatrix;
class CompactMatrix;
//-----------------------------------------------------------------------------
// Preconditioner class is a special type of linear solver that should only be
// used as a preconditioner for iterative linear solvers
class FECORE_API Preconditioner : public LinearSolver
{
FECORE_BASE_CLASS(Preconditioner)
public:
Preconditioner(FEModel* fem) : LinearSolver(fem), m_A(nullptr) {}
bool Create(SparseMatrix* A)
{
if (SetSparseMatrix(A) == false) return false;
if (PreProcess() == false) return false;
if (Factor() == false) return false;
return true;
}
bool SetSparseMatrix(SparseMatrix* M) override { m_A = M; return true; }
SparseMatrix* GetSparseMatrix() { return m_A; }
SparseMatrix* CreateSparseMatrix(Matrix_Type ntype) override { return nullptr; }
private:
SparseMatrix* m_A;
};
//-----------------------------------------------------------------------------
class FECORE_API DiagonalPreconditioner : public Preconditioner
{
public:
DiagonalPreconditioner(FEModel* fem);
// take square root of diagonal entries
void CalculateSquareRoot(bool b);
public:
// create a preconditioner for a sparse matrix
bool Factor() override;
// apply to vector P x = y
bool BackSolve(double* x, double* y) override;
private:
vector<double> m_D;
bool m_bsqr; // Take square root
};
| Unknown |
3D | febiosoftware/FEBio | FECore/CompactSymmMatrix.cpp | .cpp | 11,614 | 475 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "CompactSymmMatrix.h"
using namespace std;
//-----------------------------------------------------------------------------
//! constructor
CompactSymmMatrix::CompactSymmMatrix(int offset) : CompactMatrix(offset)
{
}
//-----------------------------------------------------------------------------
bool CompactSymmMatrix::mult_vector(double* x, double* r)
{
// get row count
int N = Rows();
int M = Columns();
// zero result vector
for (int j = 0; j<N; ++j) r[j] = 0.0;
// loop over all columns
for (int j = 0; j<M; ++j)
{
double* pv = m_pd + m_ppointers[j] - m_offset;
int* pi = m_pindices + m_ppointers[j] - m_offset;
int n = m_ppointers[j + 1] - m_ppointers[j];
// add off-diagonal elements
for (int i = 1; i<n - 7; i += 8)
{
// add lower triangular element
r[pi[i ] - m_offset] += pv[i ] * x[j];
r[pi[i + 1] - m_offset] += pv[i + 1] * x[j];
r[pi[i + 2] - m_offset] += pv[i + 2] * x[j];
r[pi[i + 3] - m_offset] += pv[i + 3] * x[j];
r[pi[i + 4] - m_offset] += pv[i + 4] * x[j];
r[pi[i + 5] - m_offset] += pv[i + 5] * x[j];
r[pi[i + 6] - m_offset] += pv[i + 6] * x[j];
r[pi[i + 7] - m_offset] += pv[i + 7] * x[j];
}
for (int i = 0; i<(n - 1) % 8; ++i)
r[pi[n - 1 - i] - m_offset] += pv[n - 1 - i] * x[j];
// add diagonal element
double rj = pv[0] * x[j];
// add upper-triangular elements
for (int i = 1; i<n - 7; i += 8)
{
// add upper triangular element
rj += pv[i ] * x[pi[i ] - m_offset];
rj += pv[i + 1] * x[pi[i + 1] - m_offset];
rj += pv[i + 2] * x[pi[i + 2] - m_offset];
rj += pv[i + 3] * x[pi[i + 3] - m_offset];
rj += pv[i + 4] * x[pi[i + 4] - m_offset];
rj += pv[i + 5] * x[pi[i + 5] - m_offset];
rj += pv[i + 6] * x[pi[i + 6] - m_offset];
rj += pv[i + 7] * x[pi[i + 7] - m_offset];
}
for (int i = 0; i<(n - 1) % 8; ++i)
rj += pv[n - 1 - i] * x[pi[n - 1 - i] - m_offset];
r[j] += rj;
}
return true;
}
//-----------------------------------------------------------------------------
void CompactSymmMatrix::Create(SparseMatrixProfile& mp)
{
// TODO: we should probably enforce that the matrix is square
int nr = mp.Rows();
int nc = mp.Columns();
assert(nr==nc);
// allocate pointers to column offsets
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 a0 = a[j].start;
int a1 = a[j].end;
// only grab lower-triangular
if (a1 >= i)
{
if (a0 < i) a0 = i;
int asize = a1 - a0 + 1;
nsize += asize;
pointers[i] += asize;
}
}
}
// allocate indices which store row index for each matrix element
int* pindices = new int[nsize];
int m = 0;
for (int i = 0; i <= nc; ++i)
{
int n = pointers[i];
pointers[i] = m;
m += n;
}
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++)
{
int a0 = a[j].start;
int a1 = a[j].end;
// only grab lower-triangular
if (a1 >= i)
{
if (a0 < i) a0 = i;
for (int k = a0; k <= a1; ++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);
}
//-----------------------------------------------------------------------------
// this sort function is defined in qsort.cpp
void qsort(int n, const int* arr, int* indx);
//-----------------------------------------------------------------------------
//! This function assembles the local stiffness matrix
//! into the global stiffness matrix which is in compact column storage
//!
void CompactSymmMatrix::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 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];
int M0 = m;
while ((M0>N0) && (LM[P[M0 - 1]] == J)) M0--;
for (int k = M0; 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 CompactSymmMatrix::Assemble(const matrix& ke, const vector<int>& LMi, const vector<int>& LMj)
{
const int N = ke.rows();
const int M = ke.columns();
int* indices = Indices();
int* pointers = Pointers();
double* values = Values();
for (int i = 0; i<N; ++i)
{
int I = LMi[i];
for (int j = 0; j<M; ++j)
{
int J = LMj[j];
// only add values to lower-diagonal part of stiffness matrix
if ((I >= J) && (J >= 0))
{
double* pv = values + (pointers[J] - m_offset);
int* pi = indices + (pointers[J] - m_offset);
int l = pointers[J + 1] - pointers[J];
for (int n = 0; n<l; ++n)
if (pi[n] - m_offset == I)
{
#pragma omp atomic
pv[n] += ke[i][j];
break;
}
}
}
}
}
//-----------------------------------------------------------------------------
//! add a matrix item
void CompactSymmMatrix::add(int i, int j, double v)
{
// only add to lower triangular part
// since FEBio only works with the upper triangular part
// we have to swap the indices
i ^= j; j ^= i; i ^= j;
if (j <= i)
{
double* pd = m_pd + (m_ppointers[j] - m_offset);
int* pi = m_pindices + m_ppointers[j];
pi -= m_offset;
i += 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);
}
}
//-----------------------------------------------------------------------------
//! check fo a matrix item
bool CompactSymmMatrix::check(int i, int j)
{
// only the lower-triangular part is stored, so swap indices if necessary
if (i<j) { i ^= j; j ^= i; i ^= j; }
// only add to lower triangular part
if (j <= i)
{
int* pi = m_pindices + m_ppointers[j];
pi -= 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;
}
//-----------------------------------------------------------------------------
//! set matrix item
void CompactSymmMatrix::set(int i, int j, double v)
{
if (j <= i)
{
int* pi = m_pindices + m_ppointers[j];
pi -= m_offset;
int l = m_ppointers[j + 1] - m_ppointers[j];
for (int n = 0; n<l; ++n)
if (pi[n] == i + m_offset)
{
int k = m_ppointers[j] + n;
k -= m_offset;
#pragma omp critical (CSM_set)
m_pd[k] = v;
return;
}
assert(false);
}
}
//-----------------------------------------------------------------------------
//! get a matrix item
double CompactSymmMatrix::get(int i, int j)
{
// only the lower-triangular part is stored, so swap indices if necessary
if (i<j) { i ^= j; j ^= i; i ^= j; }
int *pi = m_pindices + m_ppointers[j], k;
pi -= m_offset;
int l = m_ppointers[j + 1] - m_ppointers[j];
for (int n = 0; n<l; ++n)
if (pi[n] == i + m_offset)
{
k = m_ppointers[j] + n;
k -= m_offset;
return m_pd[k];
}
return 0;
}
//-----------------------------------------------------------------------------
double CompactSymmMatrix::infNorm() const
{
// get the matrix size
const int N = Rows();
// keep track of row sums
vector<double> rowSums(N, 0.0);
// 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];
double ri = 0.0;
for (int i = 0; i < n; ++i)
{
int irow = pr[i] - m_offset;
double vij = fabs(pv[i]);
ri += vij;
if (irow != j) rowSums[irow] += vij;
}
rowSums[j] += ri;
}
// find the largest row sum
double rmax = rowSums[0];
for (int i = 1; i < N; ++i)
{
if (rowSums[i] > rmax) rmax = rowSums[i];
}
return rmax;
}
//-----------------------------------------------------------------------------
double CompactSymmMatrix::oneNorm() const
{
// get the matrix size
const int NR = Rows();
const int NC = Columns();
// keep track of col sums
vector<double> colSums(NC, 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)
{
int irow = pr[i] - m_offset;
double vij = fabs(pv[i]);
cj += vij;
if (irow != j) colSums[irow] += vij;
}
colSums[j] += cj;
}
// find the largest row sum
double rmax = colSums[0];
for (int i = 1; i < NC; ++i)
{
if (colSums[i] > rmax) rmax = colSums[i];
}
return rmax;
}
//-----------------------------------------------------------------------------
void CompactSymmMatrix::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];
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECoreBase.h | .h | 7,279 | 250 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEParameterList.h"
#include "fecore_enum.h"
#include "FEProperty.h"
#include "ClassDescriptor.h"
#include <string>
//-----------------------------------------------------------------------------
class FECoreFactory;
class FEModel;
//-----------------------------------------------------------------------------
//! Base class for most classes in FECore library and the base class for all
//! classes that can be registered with the framework.
class FECORE_API FECoreBase : public FEParamContainer
{
public:
//! constructor
FECoreBase(FEModel* fem);
//! destructor
virtual ~FECoreBase();
//! set class name
void SetName(const std::string& name);
//! get the class' name
const std::string& GetName() const;
//! data serialization
void Serialize(DumpStream& ar) override;
//! Initialization
virtual bool Init();
//! validates all properties and parameters recursively
bool Validate() override;
//! validate parameters only
bool ValidateParameters();
//! call this after the parameters are changed
virtual bool UpdateParams();
public:
//! return the super class id
SUPER_CLASS_ID GetSuperClassID();
//! return a (unique) string describing the type of this class
//! This string is used in object creation
const char* GetTypeStr();
// Build the class' parameter and property list
bool BuildClass();
public:
//! number of parameters
int Parameters() const;
//! return a parameter
virtual FEParam* FindParameter(const ParamString& s) override;
virtual FEParamValue GetParameterValue(const ParamString& paramString);
//! return the property (or this) that owns a parameter
FECoreBase* FindParameterOwner(void* pd);
public: // interface for getting/setting properties
//! get the number of properties
int Properties();
//! Set a property
bool SetProperty(int nid, FECoreBase* pm);
//! Set a property via name
bool SetProperty(const char* sz, FECoreBase* pm);
//! return a property
virtual FECoreBase* GetProperty(int i);
//! find a property index ( returns <0 for error)
int FindPropertyIndex(const char* szname);
//! return a property (class)
FEProperty* FindProperty(const char* sz, bool searchChildren = false);
FEProperty* FindProperty(const ParamString& prop);
FEProperty* FindProperty(FECoreBase* pc);
//! return a property from a paramstring
FECoreBase* GetProperty(const ParamString& prop);
//! return the number of properties defined
int PropertyClasses() const;
//! return a property
FEProperty* PropertyClass(int i);
public:
//! Get the parent of this object (zero if none)
FECoreBase* GetParent();
//! Get the ancestor of this class (this if none)
FECoreBase* GetAncestor();
//! Set the parent of this class
void SetParent(FECoreBase* parent);
//! return the component ID
int GetID() const;
//! set the component ID
void SetID(int nid);
//! Get the FE model
FEModel* GetFEModel() const;
//! set the FEModel of this class (use with caution!)
void SetFEModel(FEModel* fem);
static void SaveClass(DumpStream& ar, FECoreBase* p);
static FECoreBase* LoadClass(DumpStream& ar, FECoreBase* p);
// set parameters through a class descriptor
bool SetParameters(const FEClassDescriptor& cd);
bool SetParameters(const FEClassDescriptor::ClassVariable& cv);
public:
//! Add a property
//! Call this in the constructor of derived classes to
//! build the property list
void AddProperty(FEProperty* pp, const char* sz, unsigned int flags = FEProperty::Required);
void RemoveProperty(int i);
void ClearProperties();
public:
template <class T> T* ExtractProperty(bool extractSelf = true);
protected:
// Set the factory class
void SetFactoryClass(const FECoreFactory* fac);
public:
const FECoreFactory* GetFactoryClass() const;
private:
std::string m_name; //!< user defined name of component
FECoreBase* m_pParent; //!< pointer to "parent" object (if any) (NOTE: only used by materials)
FEModel* m_fem; //!< the model this class belongs to
vector<FEProperty*> m_Prop; //!< list of properties
private:
int m_nID; //!< component ID
const FECoreFactory* m_fac; //!< factory class that instantiated this class
friend class FECoreFactory;
};
// include template property definitions
#include "FEPropertyT.h"
template <class T> FEProperty* AddClassProperty(FECoreBase* pc, T* pp, const char* sz)
{
FEFixedPropertyT<T>* prop = new FEFixedPropertyT<T>(pp);
prop->SetDefaultType(sz);
pc->AddProperty(prop, sz, FEProperty::Fixed);
return prop;
}
template <class T> FEProperty* AddClassProperty(FECoreBase* pc, std::vector<T>* pp, const char* sz)
{
FEFixedVecPropertyT<T>* prop = new FEFixedVecPropertyT<T>(pp);
prop->SetDefaultType(sz);
pc->AddProperty(prop, sz, FEProperty::Fixed);
return prop;
}
template <class T> FEProperty* AddClassProperty(FECoreBase* pc, T** pp, const char* sz, unsigned int flags = FEProperty::Required)
{
FEPropertyT<T>* prop = new FEPropertyT<T>(pp);
if (prop->GetSuperClassID() == FECLASS_ID) prop->SetDefaultType(sz);
pc->AddProperty(prop, sz, flags);
return prop;
}
template <class T> FEProperty* AddClassProperty(FECoreBase* pc, std::vector<T*>* pp, const char* sz, unsigned int flags = FEProperty::Required)
{
FEVecPropertyT<T>* prop = new FEVecPropertyT<T>(pp);
if (prop->GetSuperClassID() == FECLASS_ID) prop->SetDefaultType(sz);
pc->AddProperty(prop, sz, flags);
return prop;
}
#define ADD_PROPERTY(theProp, ...) AddClassProperty(this, &theProp, __VA_ARGS__)
#define FECORE_SUPER_CLASS(a) public: static SUPER_CLASS_ID superClassID() { return a; }
//#define REGISTER_SUPER_CLASS(theClass, a) SUPER_CLASS_ID theClass::superClassID() { return a;}
template <class T> T* FECoreBase::ExtractProperty(bool extractSelf)
{
if (extractSelf)
{
if (dynamic_cast<T*>(this)) return dynamic_cast<T*>(this);
}
int NC = Properties();
for (int i = 0; i < NC; i++)
{
FECoreBase* pci = GetProperty(i);
if (pci)
{
T* pc = pci->ExtractProperty<T>();
if (pc) return pc;
}
}
return nullptr;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/SurfaceDataRecord.h | .h | 2,198 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "DataRecord.h"
class FESurface;
//-----------------------------------------------------------------------------
//! Base class for surface log data
class FECORE_API FELogSurfaceData : public FELogData
{
FECORE_SUPER_CLASS(FELOGSURFACEDATA_ID)
FECORE_BASE_CLASS(FELogSurfaceData);
public:
FELogSurfaceData(FEModel* fem) : FELogData(fem) {}
virtual ~FELogSurfaceData() {}
virtual double value(FESurface& surface) = 0;
};
//-----------------------------------------------------------------------------
class FECORE_API FESurfaceDataRecord : public DataRecord
{
public:
FESurfaceDataRecord(FEModel* pfem);
double Evaluate(int item, int ndata) override;
void SetData(const char* sz) override;
void SetSurface(int surfIndex);
void SelectAllItems() override;
int Size() const override;
private:
vector<FELogSurfaceData*> m_Data;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tens4dms.hpp | .hpp | 10,539 | 336 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// NOTE: This file is automatically included from tens4d.h
// Users should not include this file manually!
#include "matrix.h"
inline tens4dms::tens4dms(const double g)
{
for (int i = 0; i < NNZ; i++)
d[i] = g;
}
inline tens4dms::tens4dms(double m[9][9])
{
d[ 0] = m[0][0];
d[ 1] = m[0][1]; d[ 2] = m[1][1];
d[ 3] = m[0][2]; d[ 4] = m[1][2]; d[ 5] = m[2][2];
d[ 6] = m[0][3]; d[ 7] = m[1][3]; d[ 8] = m[2][3]; d[ 9] = m[3][3];
d[10] = m[0][4]; d[11] = m[1][4]; d[12] = m[2][4]; d[13] = m[3][4]; d[14] = m[4][4];
d[15] = m[0][5]; d[16] = m[1][5]; d[17] = m[2][5]; d[18] = m[3][5]; d[19] = m[4][5]; d[20] = m[5][5];
d[21] = m[0][6]; d[22] = m[1][6]; d[23] = m[2][6]; d[24] = m[3][6]; d[25] = m[4][6]; d[26] = m[5][6]; d[27] = m[6][6];
d[28] = m[0][7]; d[29] = m[1][7]; d[30] = m[2][7]; d[31] = m[3][7]; d[32] = m[4][7]; d[33] = m[5][7]; d[34] = m[6][7]; d[35] = m[7][7];
d[36] = m[0][8]; d[37] = m[1][8]; d[38] = m[2][8]; d[39] = m[3][8]; d[40] = m[4][8]; d[41] = m[5][8]; d[42] = m[6][8]; d[43] = m[7][8]; d[44] = m[8][8];
}
inline double& tens4dms::operator () (int i, int j, int k, int l)
{
const int m[3][3] = {{0,3,5},{6,1,4},{8,7,2}};
tens4dms& T = (*this);
return T(m[i][j], m[k][l]);
}
inline double tens4dms::operator () (int i, int j, int k, int l) const
{
const int m[3][3] = {{0,3,5},{6,1,4},{8,7,2}};
const tens4dms& T = (*this);
return T(m[i][j], m[k][l]);
}
inline double& tens4dms::operator () (int i, int j)
{
const int m[9] = {0, 1, 3, 6, 10, 15, 21, 28, 36};
if (i<=j) return d[m[j]+i]; else return d[m[i]+j];
}
inline double tens4dms::operator () (int i, int j) const
{
const int m[9] = {0, 1, 3, 6, 10, 15, 21, 28, 36};
if (i<=j) return d[m[j]+i]; else return d[m[i]+j];
}
// operator +
inline tens4dms tens4dms::operator + (const tens4dms& t) const
{
tens4dms s;
for (int i=0; i<NNZ; i++)
s.d[i] = d[i] + t.d[i];
return s;
}
// operator -
inline tens4dms tens4dms::operator - (const tens4dms& t) const
{
tens4dms s;
for (int i=0; i<NNZ; i++)
s.d[i] = d[i] - t.d[i];
return s;
}
// operator *
inline tens4dms tens4dms::operator * (double g) const
{
tens4dms s;
for (int i=0; i<NNZ; i++)
s.d[i] = g*d[i];
return s;
}
// operator /
inline tens4dms tens4dms::operator / (double g) const
{
tens4dms s;
for (int i=0; i<NNZ; i++)
s.d[i] = d[i]/g;
return s;
}
// assignment operator +=
inline tens4dms& tens4dms::operator += (const tens4dms& t)
{
for (int i=0; i<NNZ; i++)
d[i] += t.d[i];
return (*this);
}
// assignment operator -=
inline tens4dms& tens4dms::operator -= (const tens4dms& t)
{
for (int i=0; i<NNZ; i++)
d[i] -= t.d[i];
return (*this);
}
// assignment operator *=
inline tens4dms& tens4dms::operator *= (double g)
{
for (int i=0; i<NNZ; i++)
d[i] *= g;
return (*this);
}
// assignment operator /=
inline tens4dms& tens4dms::operator /= (double g)
{
for (int i=0; i<NNZ; i++)
d[i] /= g;
return (*this);
}
// unary operator -
inline tens4dms tens4dms::operator - () const
{
tens4dms s;
for (int i = 0; i < NNZ; i++)
s.d[i] = -d[i];
return s;
}
// trace
// C.tr() = I:C:I
// No need to change the trace operation because major symmetry still applies
inline double tens4dms::tr() const
{
return (d[0]+d[2]+d[5]+2*(d[1]+d[3]+d[4]));
}
// intialize to zero
inline void tens4dms::zero()
{
for (int i = 0; i < NNZ; i++)
d[i] = 0;
}
// extract 9x9 matrix
inline void tens4dms::extract(double D[9][9])
{
D[0][0] = d[0]; D[0][1] = d[1]; D[0][2] = d[3]; D[0][3] = d[6]; D[0][4] = d[10]; D[0][5] = d[15]; D[0][6] = d[21]; D[0][7] = d[28]; D[0][8] = d[36];
D[1][0] = d[1]; D[1][1] = d[2]; D[1][2] = d[4]; D[1][3] = d[7]; D[1][4] = d[11]; D[1][5] = d[16]; D[1][6] = d[22]; D[1][7] = d[29]; D[1][8] = d[37];
D[2][0] = d[3]; D[2][1] = d[4]; D[2][2] = d[5]; D[2][3] = d[8]; D[2][4] = d[12]; D[2][5] = d[17]; D[2][6] = d[23]; D[2][7] = d[30]; D[2][8] = d[38];
D[3][0] = d[6]; D[3][1] = d[7]; D[3][2] = d[8]; D[3][3] = d[9]; D[3][4] = d[13]; D[3][5] = d[18]; D[3][6] = d[24]; D[3][7] = d[31]; D[3][8] = d[39];
D[4][0] = d[10]; D[4][1] = d[11]; D[4][2] = d[12]; D[4][3] = d[13]; D[4][4] = d[14]; D[4][5] = d[19]; D[4][6] = d[25]; D[4][7] = d[32]; D[4][8] = d[40];
D[5][0] = d[15]; D[5][1] = d[16]; D[5][2] = d[17]; D[5][3] = d[18]; D[5][4] = d[19]; D[5][5] = d[20]; D[5][6] = d[26]; D[5][7] = d[33]; D[5][8] = d[41];
D[6][0] = d[21]; D[6][1] = d[22]; D[6][2] = d[23]; D[6][3] = d[24]; D[6][4] = d[25]; D[6][5] = d[26]; D[6][6] = d[27]; D[6][7] = d[34]; D[6][8] = d[42];
D[7][0] = d[28]; D[7][1] = d[29]; D[7][2] = d[30]; D[7][3] = d[31]; D[7][4] = d[32]; D[7][5] = d[33]; D[7][6] = d[34]; D[7][7] = d[35]; D[7][8] = d[43];
D[8][0] = d[36]; D[8][1] = d[37]; D[8][2] = d[38]; D[8][3] = d[39]; D[8][4] = d[40]; D[8][5] = d[41]; D[8][6] = d[42]; D[8][7] = d[43]; D[8][8] = d[44];
}
// compute the super symmetric (major and minor symmetric) component of the tensor
// Sijkl = (1/4)*(Cijkl + Cijlk + Cjikl + Cjilk)
inline tens4ds tens4dms::supersymm() const
{
tens4ds s;
s.d[0] = d[0]; s.d[1] = d[1]; s.d[3] = d[3]; s.d[6] = (d[6] + d[21])/2.; s.d[10] = (d[10] + d[28])/2.; s.d[15] = (d[15] + d[36])/2.;
s.d[2] = d[2]; s.d[4] = d[4]; s.d[7] = (d[7] + d[22])/2.; s.d[11] = (d[11] + d[29])/2.; s.d[16] = (d[16] + d[37])/2.;
s.d[5] = d[5]; s.d[8] = (d[8] + d[23])/2.; s.d[12] = (d[12] + d[30])/2.; s.d[17] = (d[17] + d[38])/2.;
s.d[9] = (d[9] + 2.*d[24] + d[27])/4.; s.d[13] = (d[13] + d[31] + d[25] + d[34])/4.; s.d[18] = (d[18] + d[39] + d[26] + d[42])/4.;
s.d[14] = (d[14] + 2.*d[32] + d[35])/4.; s.d[19] = (d[19] + d[40] + d[33] + d[43])/4.;
s.d[20] = (d[20] + 2.*d[41] + d[44])/4.;
return s;
}
//-----------------------------------------------------------------------------
// (a dyad1s a)_ijkl = a_ij a_kl
inline tens4dms dyad1ms(const mat3d& a)
{
tens4dms c;
c.d[ 0] = a(0,0)*a(0,0);
c.d[ 1] = a(0,0)*a(1,1);
c.d[ 3] = a(0,0)*a(2,2);
c.d[ 6] = a(0,0)*a(0,1);
c.d[10] = a(0,0)*a(1,2);
c.d[15] = a(0,0)*a(0,2);
c.d[21] = a(0,0)*a(1,0);
c.d[28] = a(0,0)*a(2,1);
c.d[36] = a(0,0)*a(2,0);
c.d[ 2] = a(1,1)*a(1,1);
c.d[ 4] = a(1,1)*a(2,2);
c.d[ 7] = a(1,1)*a(0,1);
c.d[11] = a(1,1)*a(1,2);
c.d[16] = a(1,1)*a(0,2);
c.d[22] = a(1,1)*a(1,0);
c.d[29] = a(1,1)*a(2,1);
c.d[37] = a(1,1)*a(2,0);
c.d[ 5] = a(2,2)*a(2,2);
c.d[ 8] = a(2,2)*a(0,1);
c.d[12] = a(2,2)*a(1,2);
c.d[17] = a(2,2)*a(0,2);
c.d[23] = a(2,2)*a(1,0);
c.d[30] = a(2,2)*a(2,1);
c.d[38] = a(2,2)*a(2,0);
c.d[ 9] = a(0,1)*a(0,1);
c.d[13] = a(0,1)*a(1,2);
c.d[18] = a(0,1)*a(0,2);
c.d[24] = a(0,1)*a(1,0);
c.d[31] = a(0,1)*a(2,1);
c.d[39] = a(0,1)*a(2,0);
c.d[14] = a(1,2)*a(1,2);
c.d[19] = a(1,2)*a(0,2);
c.d[25] = a(1,2)*a(1,0);
c.d[32] = a(1,2)*a(2,1);
c.d[40] = a(1,2)*a(2,0);
c.d[20] = a(0,2)*a(0,2);
c.d[26] = a(0,2)*a(1,0);
c.d[33] = a(0,2)*a(2,1);
c.d[41] = a(0,2)*a(2,0);
c.d[27] = a(1,0)*a(1,0);
c.d[34] = a(1,0)*a(2,1);
c.d[42] = a(1,0)*a(2,0);
c.d[35] = a(2,1)*a(2,1);
c.d[43] = a(2,1)*a(2,0);
c.d[44] = a(2,0)*a(2,0);
return c;
}
//-----------------------------------------------------------------------------
// (a dyad1s b)_ijkl = a_ij b_kl + b_ij a_kl
inline tens4dms dyad1ms(const mat3d& a, const mat3d& b)
{
tens4dms c;
c.d[0] = 2*a(0,0)*b(0,0);
c.d[1] = a(0,0)*b(1,1) + b(0,0)*a(1,1);
c.d[3] = a(0,0)*b(2,2) + b(0,0)*a(2,2);
c.d[6] = a(0,0)*b(0,1) + b(0,0)*a(0,1);
c.d[10] = a(0,0)*b(1,2) + b(0,0)*a(1,2);
c.d[15] = a(0,0)*b(0,2) + b(0,0)*a(0,2);
c.d[21] = a(0,0)*b(1,0) + b(0,0)*a(1,0);
c.d[28] = a(0,0)*b(2,1) + b(0,0)*a(2,1);
c.d[36] = a(0,0)*b(2,0) + b(0,0)*a(2,0);
c.d[2] = 2*a(1,1)*b(1,1);
c.d[4] = a(1,1)*b(2,2) + b(1,1)*a(2,2);
c.d[7] = a(1,1)*b(0,1) + b(1,1)*a(0,1);
c.d[11] = a(1,1)*b(1,2) + b(1,1)*a(1,2);
c.d[16] = a(1,1)*b(0,2) + b(1,1)*a(0,2);
c.d[22] = a(1,1)*b(1,0) + b(1,1)*a(1,0);
c.d[29] = a(1,1)*b(2,1) + b(1,1)*a(2,1);
c.d[37] = a(1,1)*b(2,0) + b(1,1)*a(2,0);
c.d[5] = 2*a(2,2)*b(2,2);
c.d[8] = a(2,2)*b(0,1) + b(2,2)*a(0,1);
c.d[12] = a(2,2)*b(1,2) + b(2,2)*a(1,2);
c.d[17] = a(2,2)*b(0,2) + b(2,2)*a(0,2);
c.d[23] = a(2,2)*b(1,0) + b(2,2)*a(1,0);
c.d[30] = a(2,2)*b(2,1) + b(2,2)*a(2,1);
c.d[38] = a(2,2)*b(2,0) + b(2,2)*a(2,0);
c.d[9] = 2*a(0,1)*b(0,1);
c.d[13] = a(0,1)*b(1,2) + b(0,1)*a(1,2);
c.d[18] = a(0,1)*b(0,2) + b(0,1)*a(0,2);
c.d[24] = a(0,1)*b(1,0) + b(0,1)*a(1,0);
c.d[31] = a(0,1)*b(2,1) + b(0,1)*a(2,1);
c.d[39] = a(0,1)*b(2,0) + b(0,1)*a(2,0);
c.d[14] = 2*a(1,2)*b(1,2);
c.d[19] = a(1,2)*b(0,2) + b(1,2)*a(0,2);
c.d[25] = a(1,2)*b(1,0) + b(1,2)*a(1,0);
c.d[32] = a(1,2)*b(2,1) + b(1,2)*a(2,1);
c.d[40] = a(1,2)*b(2,0) + b(1,2)*a(2,0);
c.d[20] = 2*a(0,2)*b(0,2);
c.d[26] = a(0,2)*b(1,0) + b(0,2)*a(1,0);
c.d[33] = a(0,2)*b(2,1) + b(0,2)*a(2,1);
c.d[41] = a(0,2)*b(2,0) + b(0,2)*a(2,0);
c.d[27] = 2*a(1,0)*b(1,0);
c.d[34] = a(1,0)*b(2,1) + b(1,0)*a(2,1);
c.d[42] = a(1,0)*b(2,0) + b(1,0)*a(2,0);
c.d[35] = 2*a(2,1)*b(2,1);
c.d[43] = a(2,1)*b(2,0) + b(2,1)*a(2,0);
c.d[44] = 2*a(2,0)*b(2,0);
return c;
}
| Unknown |
3D | febiosoftware/FEBio | FECore/mat3d.hpp | .hpp | 34,786 | 1,203 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// NOTE: This file is automatically included from mat3d.h
// Users should not include this file manually!
//-----------------------------------------------------------------------------
// class mat3dd : class describing diagonal 3D matrices of doubles
//-----------------------------------------------------------------------------
// constructor
inline mat3dd::mat3dd(double a) { d[0] = d[1] = d[2] = a; }
inline mat3dd::mat3dd(double a0, double a1, double a2) { d[0] = a0; d[1] = a1; d[2] = a2; }
// assignment operators
inline mat3dd& mat3dd::operator = (const mat3dd& m) { d[0] = m.d[0]; d[1] = m.d[1]; d[2] = m.d[2]; return (*this); }
inline mat3dd& mat3dd::operator = (double a) { d[0] = d[1] = d[2] = a; return (*this); }
// access operators
inline double mat3dd::operator () (int i, int j) const { return (i==j? d[i] : 0); }
inline double& mat3dd::diag(int i) { return d[i]; }
inline const double& mat3dd::diag(int i) const { return d[i]; }
// arithmetic operators
inline mat3dd mat3dd::operator + (const mat3dd& m) const { return mat3dd(d[0]+m.d[0],d[1]+m.d[1],d[2]+m.d[2]);}
inline mat3dd mat3dd::operator - (const mat3dd& m) const { return mat3dd(d[0]-m.d[0],d[1]-m.d[1],d[2]-m.d[2]);}
inline mat3dd mat3dd::operator * (const mat3dd& m) const { return mat3dd(d[0]*m.d[0],d[1]*m.d[1],d[2]*m.d[2]);}
inline mat3dd mat3dd::operator * (double a) const { return mat3dd(d[0]*a, d[1]*a, d[2]*a); }
inline mat3dd mat3dd::operator / (double a) const { a = 1./a; return mat3dd(d[0]*a, d[1]*a, d[2]*a); }
inline mat3dd mat3dd::operator - () const { return mat3dd(-d[0], -d[1], -d[2]); }
// arithmetic operators with mat3ds
inline mat3ds mat3dd::operator + (const mat3ds& m) const
{
return mat3ds(
d[0]+m.m[mat3ds::XX],
d[1]+m.m[mat3ds::YY],
d[2]+m.m[mat3ds::ZZ],
m.m[mat3ds::XY],
m.m[mat3ds::YZ],
m.m[mat3ds::XZ]
);
}
inline mat3ds mat3dd::operator - (const mat3ds& m) const
{
return mat3ds(
d[0]-m.m[mat3ds::XX],
d[1]-m.m[mat3ds::YY],
d[2]-m.m[mat3ds::ZZ],
-m.m[mat3ds::XY],
-m.m[mat3ds::YZ],
-m.m[mat3ds::XZ]
);
}
inline mat3ds mat3dd::operator * (const mat3ds& m) const
{
return mat3ds(
d[0]*m.m[mat3ds::XX],
d[1]*m.m[mat3ds::YY],
d[2]*m.m[mat3ds::ZZ],
d[0]*m.m[mat3ds::XY],
d[1]*m.m[mat3ds::YZ],
d[0]*m.m[mat3ds::XZ]
);
}
// arithmetic operators for mat3d
inline mat3d mat3dd::operator + (const mat3d& m) const
{
return mat3d(d[0]+m.d[0][0], m.d[0][1], m.d[0][2],
m.d[1][0], d[1]+m.d[1][1], m.d[1][2],
m.d[2][0], m.d[2][1], d[2]+m.d[2][2]);
}
inline mat3d mat3dd::operator - (const mat3d& m) const
{
return mat3d(d[0]-m.d[0][0], -m.d[0][1], -m.d[0][2],
-m.d[1][0], d[1]-m.d[1][1], -m.d[1][2],
-m.d[2][0], -m.d[2][1], d[2]-m.d[2][2]);
}
inline mat3d mat3dd::operator * (const mat3d& m) const
{
return mat3d(d[0]*m.d[0][0], d[0]*m.d[0][1], d[0]*m.d[0][2],
d[1]*m.d[1][0], d[1]*m.d[1][1], d[1]*m.d[1][2],
d[2]*m.d[2][0], d[2]*m.d[2][1], d[2]*m.d[2][2]);
}
// arithmetic operators for mat3da
inline mat3d mat3dd::operator + (const mat3da& m) const
{
return mat3d( d[0], m.d[0], m.d[2],
-m.d[0], d[1], m.d[1],
-m.d[2], -m.d[1], d[2]);
}
inline mat3d mat3dd::operator - (const mat3da& m) const
{
return mat3d( d[0],-m.d[0], -m.d[2],
m.d[0], d[1], -m.d[1],
m.d[2], m.d[1], d[2]);
}
inline mat3d mat3dd::operator *(const mat3da& m) const
{
return mat3d( 0, d[0]*m.d[0], d[0]*m.d[2],
-d[1]*m.d[0], 0, d[1]*m.d[1],
-d[2]*m.d[2], -d[2]*m.d[1], 0);
}
// arithmetic assignment operators
inline mat3dd& mat3dd::operator += (const mat3dd& m) { d[0] += m.d[0]; d[1] += m.d[1]; d[2] += m.d[2]; return (*this); }
inline mat3dd& mat3dd::operator -= (const mat3dd& m) { d[0] -= m.d[0]; d[1] -= m.d[1]; d[2] -= m.d[2]; return (*this); }
inline mat3dd& mat3dd::operator *= (const mat3dd& m) { d[0] *= m.d[0]; d[1] *= m.d[1]; d[2] *= m.d[2]; return (*this); }
inline mat3dd& mat3dd::operator *= (double a) { d[0] *= a; d[1] *= a; d[2] *= a; return (*this); }
inline mat3dd& mat3dd::operator /= (double a) { a = 1./a; d[0] *= a; d[1] *= a; d[2] *= a; return (*this); }
// matrix-vector multiplication
inline vec3d mat3dd::operator * (const vec3d& r) const { return vec3d(r.x*d[0], r.y*d[1], r.z*d[2]); }
// trace
inline double mat3dd::tr() const { return d[0]+d[1]+d[2]; }
// determinant
inline double mat3dd::det() const { return d[0]*d[1]*d[2]; }
//-----------------------------------------------------------------------------
// class mat3ds : this class describes a symmetric 3D matrix of doubles
//-----------------------------------------------------------------------------
// constructor
inline mat3ds::mat3ds(double a)
{
m[XX] = a;
m[XY] = a;
m[YY] = a;
m[XZ] = a;
m[YZ] = a;
m[ZZ] = a;
}
inline mat3ds::mat3ds(double xx, double yy, double zz, double xy, double yz, double xz)
{
m[XX] = xx;
m[XY] = xy;
m[YY] = yy;
m[XZ] = xz;
m[YZ] = yz;
m[ZZ] = zz;
}
inline mat3ds::mat3ds(const mat3dd& d)
{
m[XX] = d.d[0];
m[YY] = d.d[1];
m[ZZ] = d.d[2];
m[XY] = m[YZ] = m[XZ] = 0.;
}
inline mat3ds::mat3ds(const mat3ds& d)
{
m[0] = d.m[0];
m[1] = d.m[1];
m[2] = d.m[2];
m[3] = d.m[3];
m[4] = d.m[4];
m[5] = d.m[5];
}
// access operator
inline double& mat3ds::operator ()(int i, int j)
{
const int n[] = {0, 1, 3};
return (i<=j? m[n[j]+i] : m[n[i]+j]);
}
// access operator for const objects
inline const double& mat3ds::operator ()(int i, int j) const
{
const int n[] = {0, 1, 3};
return (i<=j? m[n[j]+i] : m[n[i]+j]);
}
// operator + for mat3dd objects
inline mat3ds mat3ds::operator + (const mat3dd& d) const
{
return mat3ds(m[XX]+d.d[0], m[YY]+d.d[1], m[ZZ]+d.d[2], m[XY], m[YZ], m[XZ]);
}
// operator - for mat3dd objects
inline mat3ds mat3ds::operator - (const mat3dd& d) const
{
return mat3ds(m[XX]-d.d[0], m[YY]-d.d[1], m[ZZ]-d.d[2], m[XY], m[YZ], m[XZ]);
}
// operator * for mat3dd objects
inline mat3ds mat3ds::operator * (const mat3dd& d) const
{
return mat3ds(m[XX]*d.d[0], m[YY]*d.d[1], m[ZZ]*d.d[2], m[XY]*d.d[1], m[YZ]*d.d[2], m[XZ]*d.d[2]);
}
// operator +
inline mat3ds mat3ds::operator +(const mat3ds& t) const
{
return mat3ds(m[XX]+t.m[XX], m[YY]+t.m[YY], m[ZZ]+t.m[ZZ], m[XY]+t.m[XY], m[YZ]+t.m[YZ],m[XZ]+t.m[XZ]);
}
// operator -
inline mat3ds mat3ds::operator -(const mat3ds& t) const
{
return mat3ds(m[XX]-t.m[XX], m[YY]-t.m[YY], m[ZZ]-t.m[ZZ], m[XY]-t.m[XY], m[YZ]-t.m[YZ],m[XZ]-t.m[XZ]);
}
// operator *
inline mat3d mat3ds::operator *(const mat3ds& t) const
{
return mat3d(
m[XX] * t.m[XX] + m[XY] * t.m[XY] + m[XZ] * t.m[XZ],
m[XX] * t.m[XY] + m[XY] * t.m[YY] + m[XZ] * t.m[YZ],
m[XX] * t.m[XZ] + m[XY] * t.m[YZ] + m[XZ] * t.m[ZZ],
m[XY] * t.m[XX] + m[YY] * t.m[XY] + m[YZ] * t.m[XZ],
m[XY] * t.m[XY] + m[YY] * t.m[YY] + m[YZ] * t.m[YZ],
m[XY] * t.m[XZ] + m[YY] * t.m[YZ] + m[YZ] * t.m[ZZ],
m[XZ] * t.m[XX] + m[YZ] * t.m[XY] + m[ZZ] * t.m[XZ],
m[XZ] * t.m[XY] + m[YZ] * t.m[YY] + m[ZZ] * t.m[YZ],
m[XZ] * t.m[XZ] + m[YZ] * t.m[YZ] + m[ZZ] * t.m[ZZ]
);
}
// operator *
inline mat3ds mat3ds::operator * (double g) const
{
return mat3ds(m[XX]*g, m[YY]*g, m[ZZ]*g, m[XY]*g, m[YZ]*g, m[XZ]*g);
}
// operator /
inline mat3ds mat3ds::operator / (double g) const
{
g = 1.0/g;
return mat3ds(m[XX]*g, m[YY]*g, m[ZZ]*g, m[XY]*g, m[YZ]*g, m[XZ]*g);
}
// operator + for mat3d objects
inline mat3d mat3ds::operator + (const mat3d& d) const
{
return mat3d(m[XX]+d.d[0][0], m[XY]+d.d[0][1], m[XZ]+d.d[0][2],
m[XY]+d.d[1][0], m[YY]+d.d[1][1], m[YZ]+d.d[1][2],
m[XZ]+d.d[2][0], m[YZ]+d.d[2][1], m[ZZ]+d.d[2][2]);
}
// operator - for mat3d objects
inline mat3d mat3ds::operator - (const mat3d& d) const
{
return mat3d(m[XX]-d.d[0][0], m[XY]-d.d[0][1], m[XZ]-d.d[0][2],
m[XY]-d.d[1][0], m[YY]-d.d[1][1], m[YZ]-d.d[1][2],
m[XZ]-d.d[2][0], m[YZ]-d.d[2][1], m[ZZ]-d.d[2][2]);
}
// operator * for mat3d objects
inline mat3d mat3ds::operator * (const mat3d& d) const
{
return mat3d(d.d[0][0]*m[XX] + d.d[1][0]*m[XY] + d.d[2][0]*m[XZ],
d.d[0][1]*m[XX] + d.d[1][1]*m[XY] + d.d[2][1]*m[XZ],
d.d[0][2]*m[XX] + d.d[1][2]*m[XY] + d.d[2][2]*m[XZ],
d.d[0][0]*m[XY] + d.d[1][0]*m[YY] + d.d[2][0]*m[YZ],
d.d[0][1]*m[XY] + d.d[1][1]*m[YY] + d.d[2][1]*m[YZ],
d.d[0][2]*m[XY] + d.d[1][2]*m[YY] + d.d[2][2]*m[YZ],
d.d[0][0]*m[XZ] + d.d[1][0]*m[YZ] + d.d[2][0]*m[ZZ],
d.d[0][1]*m[XZ] + d.d[1][1]*m[YZ] + d.d[2][1]*m[ZZ],
d.d[0][2]*m[XZ] + d.d[1][2]*m[YZ] + d.d[2][2]*m[ZZ]);
}
// operator + for mat3da objects
inline mat3d mat3ds::operator + (const mat3da& d) const
{
return mat3d(m[XX] , m[XY]+d.xy(), m[XZ]+d.xz(),
m[XY]-d.xy(), m[YY] , m[YZ]+d.yz(),
m[XZ]-d.xz(), m[YZ]-d.yz(), m[ZZ] );
}
// operator - for mat3da objects
inline mat3d mat3ds::operator - (const mat3da& d) const
{
return mat3d(m[XX] , m[XY]-d.xy(), m[XZ]-d.xz(),
m[XY]+d.xy(), m[YY] , m[YZ]-d.yz(),
m[XZ]+d.xz(), m[YZ]+d.yz(), m[ZZ] );
}
// operator * for mat3d objects
inline mat3d mat3ds::operator * (const mat3da& d) const
{
return mat3d(
-d.xy()*m[XY]-d.xz()*m[XZ],d.xy()*m[XX]-d.yz()*m[XZ],d.xz()*m[XX]+d.yz()*m[XY],
-d.xy()*m[YY]-d.xz()*m[YZ],d.xy()*m[XY]-d.yz()*m[YZ],d.xz()*m[XY]+d.yz()*m[YY],
-d.xy()*m[YZ]-d.xz()*m[ZZ],d.xy()*m[XZ]-d.yz()*m[ZZ],d.xz()*m[XZ]+d.yz()*m[YZ]
);
}
// unary operator -
inline mat3ds mat3ds::operator - () const
{
return mat3ds(-m[XX], -m[YY], -m[ZZ], -m[XY], -m[YZ], -m[XZ]);
}
// assignment operator +=
inline mat3ds& mat3ds::operator += (const mat3ds& t)
{
m[XX] += t.m[XX]; m[YY] += t.m[YY]; m[ZZ] += t.m[ZZ];
m[XY] += t.m[XY]; m[YZ] += t.m[YZ]; m[XZ] += t.m[XZ];
return (*this);
}
// assignment operator -=
inline mat3ds& mat3ds::operator -= (const mat3ds& t)
{
m[XX] -= t.m[XX]; m[YY] -= t.m[YY]; m[ZZ] -= t.m[ZZ];
m[XY] -= t.m[XY]; m[YZ] -= t.m[YZ]; m[XZ] -= t.m[XZ];
return (*this);
}
// assignment operator *=
inline mat3ds& mat3ds::operator *= (const mat3ds& t)
{
double xx = m[XX]*t.m[XX]+m[XY]*t.m[XY]+m[XZ]*t.m[XZ];
double yy = m[XY]*t.m[XY]+m[YY]*t.m[YY]+m[YZ]*t.m[YZ];
double zz = m[XZ]*t.m[XZ]+m[YZ]*t.m[YZ]+m[ZZ]*t.m[ZZ];
double xy = m[XX]*t.m[XY]+m[XY]*t.m[YY]+m[XZ]*t.m[YZ];
double yz = m[XY]*t.m[XZ]+m[YY]*t.m[YZ]+m[YZ]*t.m[ZZ];
double xz = m[XX]*t.m[XZ]+m[XY]*t.m[YZ]+m[XZ]*t.m[ZZ];
m[XX] = xx; m[YY] = yy; m[ZZ] = zz;
m[XY] = xy; m[YZ] = yz; m[XZ] = xz;
return (*this);
}
// assignment operator *=
inline mat3ds& mat3ds::operator *= (double g)
{
m[XX] *= g; m[YY] *= g; m[ZZ] *= g;
m[XY] *= g; m[YZ] *= g; m[XZ] *= g;
return (*this);
}
// assignment operator /=
inline mat3ds& mat3ds::operator /= (double g)
{
g = 1./g;
m[XX] *= g; m[YY] *= g; m[ZZ] *= g;
m[XY] *= g; m[YZ] *= g; m[XZ] *= g;
return (*this);
}
// arithmetic assignment operators for mat3dd
inline mat3ds& mat3ds::operator += (const mat3dd& d)
{
m[XX] += d.d[0];
m[YY] += d.d[1];
m[ZZ] += d.d[2];
return (*this);
}
inline mat3ds& mat3ds::operator -= (const mat3dd& d)
{
m[XX] -= d.d[0];
m[YY] -= d.d[1];
m[ZZ] -= d.d[2];
return (*this);
}
// matrix-vector multiplication
inline vec3d mat3ds::operator* (const vec3d& r) const
{
return vec3d(
r.x*m[XX]+r.y*m[XY]+r.z*m[XZ],
r.x*m[XY]+r.y*m[YY]+r.z*m[YZ],
r.x*m[XZ]+r.y*m[YZ]+r.z*m[ZZ]
);
}
// comparison
inline bool mat3ds::operator == (const mat3ds& d)
{
return (
(m[XX] == d.m[XX]) &&
(m[XY] == d.m[XY]) &&
(m[YY] == d.m[YY]) &&
(m[XZ] == d.m[XZ]) &&
(m[YZ] == d.m[YZ]) &&
(m[ZZ] == d.m[ZZ]));
}
// trace
inline double mat3ds::tr() const
{
return m[XX]+m[YY]+m[ZZ];
}
// determinant
inline double mat3ds::det() const
{
return (m[XX]*(m[YY]*m[ZZ] - m[YZ]*m[YZ])
+ m[XY]*(m[YZ]*m[XZ] - m[ZZ]*m[XY])
+ m[XZ]*(m[XY]*m[YZ] - m[YY]*m[XZ]));
}
// zero
inline void mat3ds::zero()
{
m[0] = m[1] = m[2] = m[3] = m[4] = m[5] = 0;
}
// unit tensor
inline void mat3ds::unit()
{
m[XX] = m[YY] = m[ZZ] = 1.0;
m[XY] = m[YZ] = m[XZ] = 0.0;
}
// deviator
inline mat3ds mat3ds::dev() const
{
double t = (m[XX]+m[YY]+m[ZZ])/3.0;
return mat3ds(m[XX]-t, m[YY]-t, m[ZZ]-t, m[XY], m[YZ], m[XZ]);
}
// isotropic part
inline mat3ds mat3ds::iso() const
{
double t = (m[XX]+m[YY]+m[ZZ])/3.0;
return mat3ds(t, t, t, 0, 0, 0);
}
// return the square
inline mat3ds mat3ds::sqr() const
{
return mat3ds(
m[XX] * m[XX] + m[XY] * m[XY] + m[XZ] * m[XZ],
m[XY] * m[XY] + m[YY] * m[YY] + m[YZ] * m[YZ],
m[XZ] * m[XZ] + m[YZ] * m[YZ] + m[ZZ] * m[ZZ],
m[XX] * m[XY] + m[XY] * m[YY] + m[XZ] * m[YZ],
m[XY] * m[XZ] + m[YY] * m[YZ] + m[YZ] * m[ZZ],
m[XX] * m[XZ] + m[XY] * m[YZ] + m[XZ] * m[ZZ]
);
}
// inverse
inline mat3ds mat3ds::inverse() const
{
double D = det();
assert(D != 0);
D = 1/D;
return mat3ds(D*(m[YY]*m[ZZ]-m[YZ]*m[YZ]),
D*(m[XX]*m[ZZ]-m[XZ]*m[XZ]),
D*(m[XX]*m[YY]-m[XY]*m[XY]),
D*(m[XZ]*m[YZ]-m[XY]*m[ZZ]),
D*(m[XY]*m[XZ]-m[XX]*m[YZ]),
D*(m[XY]*m[YZ]-m[YY]*m[XZ]));
}
// invert
inline double mat3ds::invert(mat3ds& Ai)
{
double D = det();
if (D != 0) {
double Di = 1/D;
Ai = mat3ds(Di*(m[YY]*m[ZZ]-m[YZ]*m[YZ]),
Di*(m[XX]*m[ZZ]-m[XZ]*m[XZ]),
Di*(m[XX]*m[YY]-m[XY]*m[XY]),
Di*(m[XZ]*m[YZ]-m[XY]*m[ZZ]),
Di*(m[XY]*m[XZ]-m[XX]*m[YZ]),
Di*(m[XY]*m[YZ]-m[YY]*m[XZ]));
}
return D;
}
// L2-norm
inline double mat3ds::norm() const
{
double D = m[XX]*m[XX] + m[YY]*m[YY] + m[ZZ]*m[ZZ] + 2*(m[XY]*m[XY] + m[YZ]*m[YZ] + m[XZ]*m[XZ]);
return sqrt(D);
}
// double contraction
inline double mat3ds::dotdot(const mat3ds& B) const
{
const double* n = B.m;
return m[XX]*n[XX] + m[YY]*n[YY] + m[ZZ]*n[ZZ] + 2.0*(m[XY]*n[XY] + m[YZ]*n[YZ] + m[XZ]*n[XZ]);
}
// Effective or von-mises value
inline double mat3ds::effective_norm() const
{
double vm;
vm = m[XX] * m[XX] + m[YY] * m[YY] + m[ZZ] * m[ZZ];
vm -= m[XX] * m[YY] + m[YY] * m[ZZ] + m[XX] * m[ZZ];
vm += 3 * (m[XY] * m[XY] + m[YZ] * m[YZ] + m[XZ] * m[XZ]);
vm = sqrt(vm >= 0.0 ? vm : 0.0);
return vm;
}
//-----------------------------------------------------------------------------
// class mat3da : anti-symmetric 3D matrix of doubles
//-----------------------------------------------------------------------------
// constructors
inline mat3da::mat3da(double xy, double yz, double xz)
{
d[0] = xy; d[1] = yz; d[2] = xz;
}
// calculates the antisymmetric matrix from a vector such that for any b,
// A.b = a x b where A = mat3da(a).
inline mat3da::mat3da(const vec3d& a)
{
d[0] = -a.z; d[1] = -a.x; d[2] = a.y;
}
// access operator
inline double mat3da::operator ()(int i, int j) const
{
return (i==j? 0 : (i<j? d[((j-1)<<1)-i] : -d[((i-1)<<1)-j]));
}
// scalar multiplication
inline mat3da mat3da::operator * (double g) const
{
return mat3da(d[0]*g, d[1]*g, d[2]*g);
}
inline mat3da mat3da::operator + (const mat3da& a)
{
return mat3da(d[0]+a.d[0], d[1]+a.d[1], d[2]+a.d[2]);
}
inline mat3da mat3da::operator - (const mat3da& a)
{
return mat3da(d[0]-a.d[0], d[1]-a.d[1], d[2]-a.d[2]);
}
inline mat3da mat3da::operator - () const
{
return mat3da(-d[0], -d[1], -d[2]);
}
inline mat3da mat3da::transpose() const
{
return mat3da(-d[0], -d[1], -d[2]);
}
// matrix multiplication
inline mat3d mat3da::operator * (const mat3d& m)
{
return mat3d(
d[0]*m.d[1][0] + d[2]*m.d[2][0], d[0]*m.d[1][1] + d[2]*m.d[2][1], d[0]*m.d[1][2] + d[2]*m.d[2][2],
-d[0]*m.d[0][0] + d[1]*m.d[2][0], -d[0]*m.d[0][1] + d[1]*m.d[2][1], -d[0]*m.d[0][2] + d[1]*m.d[2][2],
-d[2]*m.d[0][0] - d[1]*m.d[1][0], -d[2]*m.d[0][1] - d[1]*m.d[1][1], -d[2]*m.d[0][2] - d[1]*m.d[1][2]
);
}
inline mat3d mat3da::operator + (const mat3ds& a) const
{
return mat3d(
a.xx(),a.xy()+xy(),a.xz()+xz(),
a.xy()-xy(),a.yy(),a.yz()+yz(),
a.xz()-xz(),a.yz()-yz(),a.zz()
);
}
inline mat3d mat3da::operator - (const mat3ds& a) const
{
return mat3d(
-a.xx(),-a.xy()+xy(),-a.xz()+xz(),
-a.xy()-xy(),-a.yy(),-a.yz()+yz(),
-a.xz()-xz(),-a.yz()-yz(),-a.zz()
);
}
inline vec3d mat3da::operator * (const vec3d& a)
{
return vec3d(
d[0] * a.y + d[2] * a.z, \
-d[0] * a.x + d[1] * a.z, \
-d[2] * a.x - d[1] * a.y);
}
//-----------------------------------------------------------------------------
// class mat3d : general 3D matrix of doubles
//-----------------------------------------------------------------------------
// constructors
inline mat3d::mat3d(double a)
{
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;
}
inline mat3d::mat3d(double a00, double a01, double a02,
double a10, double a11, double a12,
double a20, double a21, double 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;
}
inline mat3d::mat3d(double m[3][3])
{
d[0][0] = m[0][0]; d[0][1] = m[0][1]; d[0][2] = m[0][2];
d[1][0] = m[1][0]; d[1][1] = m[1][1]; d[1][2] = m[1][2];
d[2][0] = m[2][0]; d[2][1] = m[2][1]; d[2][2] = m[2][2];
}
inline mat3d::mat3d(double a[9])
{
d[0][0] = a[0]; d[0][1] = a[1]; d[0][2] = a[2];
d[1][0] = a[3]; d[1][1] = a[4]; d[1][2] = a[5];
d[2][0] = a[6]; d[2][1] = a[7]; d[2][2] = a[8];
}
inline mat3d::mat3d(const mat3dd& m)
{
d[0][0] = m.d[0]; d[1][1] = m.d[1]; d[2][2] = m.d[2];
d[0][1] = d[1][0] = 0;
d[1][2] = d[2][1] = 0;
d[0][2] = d[2][0] = 0;
}
inline mat3d::mat3d(const mat3ds& m)
{
d[0][0] = m.m[mat3ds::XX];
d[1][1] = m.m[mat3ds::YY];
d[2][2] = m.m[mat3ds::ZZ];
d[0][1] = d[1][0] = m.m[mat3ds::XY];
d[1][2] = d[2][1] = m.m[mat3ds::YZ];
d[0][2] = d[2][0] = m.m[mat3ds::XZ];
}
inline mat3d::mat3d(const mat3da& m)
{
d[0][0] = d[1][1] = d[2][2] = 0;
d[0][1] = m.d[0]; d[1][0] = -m.d[0];
d[1][2] = m.d[1]; d[2][1] = -m.d[1];
d[0][2] = m.d[2]; d[2][0] = -m.d[2];
}
inline mat3d::mat3d(const mat2d& m)
{
d[0][0] = m(0,0); d[0][1] = m(0,1); d[0][2] = 0.0;
d[1][0] = m(1,0); d[1][1] = m(1,1); d[1][2] = 0.0;
d[2][0] = d[2][1] = 0.0;
d[2][2] = 0.0; // Should I set this to 1.0 instead? that way det(), inverse() etc. remain valid for the mat3d
}
inline mat3d::mat3d(const vec3d& e1, const vec3d& e2, const vec3d& e3)
{
d[0][0] = e1.x; d[0][1] = e2.x; d[0][2] = e3.x;
d[1][0] = e1.y; d[1][1] = e2.y; d[1][2] = e3.y;
d[2][0] = e1.z; d[2][1] = e2.z; d[2][2] = e3.z;
}
inline mat3d::mat3d(const vec3d& a, const vec3d& b)
{
vec3d e1(a);
vec3d e3 = a ^ b;
vec3d e2 = e3 ^ e1;
// normalize
e1.unit();
e2.unit();
e3.unit();
// set the value
d[0][0] = e1.x; d[0][1] = e2.x; d[0][2] = e3.x;
d[1][0] = e1.y; d[1][1] = e2.y; d[1][2] = e3.y;
d[2][0] = e1.z; d[2][1] = e2.z; d[2][2] = e3.z;
}
// assignment operators
inline mat3d& mat3d::operator = (const mat3dd& m)
{
d[0][0] = m.d[0];
d[1][1] = m.d[1];
d[2][2] = m.d[2];
d[0][1] = d[1][0] = 0;
d[1][2] = d[2][1] = 0;
d[0][2] = d[2][0] = 0;
return (*this);
}
inline mat3d& mat3d::operator = (const mat3ds& m)
{
d[0][0] = m.m[mat3ds::XX];
d[1][1] = m.m[mat3ds::YY];
d[2][2] = m.m[mat3ds::ZZ];
d[0][1] = d[1][0] = m.m[mat3ds::XY];
d[1][2] = d[2][1] = m.m[mat3ds::YZ];
d[0][2] = d[2][0] = m.m[mat3ds::XZ];
return (*this);
}
inline mat3d& mat3d::operator = (const double m[3][3])
{
d[0][0] = m[0][0]; d[0][1] = m[0][1]; d[0][2] = m[0][2];
d[1][0] = m[1][0]; d[1][1] = m[1][1]; d[1][2] = m[1][2];
d[2][0] = m[2][0]; d[2][1] = m[2][1]; d[2][2] = m[2][2];
return (*this);
}
inline mat3d& mat3d::operator = (const mat3d& m)
{
d[0][0] = m.d[0][0]; d[0][1] = m.d[0][1]; d[0][2] = m.d[0][2];
d[1][0] = m.d[1][0]; d[1][1] = m.d[1][1]; d[1][2] = m.d[1][2];
d[2][0] = m.d[2][0]; d[2][1] = m.d[2][1]; d[2][2] = m.d[2][2];
return (*this);
}
// access operator
inline double& mat3d::operator () (int i, int j) { return d[i][j]; }
inline const double& mat3d::operator () (int i, int j) const { return d[i][j]; }
inline double* mat3d::operator [] (int i) { return d[i]; }
inline const double* mat3d::operator [] (int i) const { return d[i]; }
// arithmetic operators
inline mat3d mat3d::operator + (const mat3d& m) const
{
return mat3d( d[0][0]+m.d[0][0], d[0][1]+m.d[0][1], d[0][2]+m.d[0][2],
d[1][0]+m.d[1][0], d[1][1]+m.d[1][1], d[1][2]+m.d[1][2],
d[2][0]+m.d[2][0], d[2][1]+m.d[2][1], d[2][2]+m.d[2][2]);
}
inline mat3d mat3d::operator - (const mat3d& m) const
{
return mat3d( d[0][0]-m.d[0][0], d[0][1]-m.d[0][1], d[0][2]-m.d[0][2],
d[1][0]-m.d[1][0], d[1][1]-m.d[1][1], d[1][2]-m.d[1][2],
d[2][0]-m.d[2][0], d[2][1]-m.d[2][1], d[2][2]-m.d[2][2]);
}
inline mat3d mat3d::operator * (const mat3d& m) const
{
return mat3d(d[0][0]*m.d[0][0]+d[0][1]*m.d[1][0]+d[0][2]*m.d[2][0],
d[0][0]*m.d[0][1]+d[0][1]*m.d[1][1]+d[0][2]*m.d[2][1],
d[0][0]*m.d[0][2]+d[0][1]*m.d[1][2]+d[0][2]*m.d[2][2],
d[1][0]*m.d[0][0]+d[1][1]*m.d[1][0]+d[1][2]*m.d[2][0],
d[1][0]*m.d[0][1]+d[1][1]*m.d[1][1]+d[1][2]*m.d[2][1],
d[1][0]*m.d[0][2]+d[1][1]*m.d[1][2]+d[1][2]*m.d[2][2],
d[2][0]*m.d[0][0]+d[2][1]*m.d[1][0]+d[2][2]*m.d[2][0],
d[2][0]*m.d[0][1]+d[2][1]*m.d[1][1]+d[2][2]*m.d[2][1],
d[2][0]*m.d[0][2]+d[2][1]*m.d[1][2]+d[2][2]*m.d[2][2]);
}
inline mat3d mat3d::operator * (double a) const
{
return mat3d(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);
}
inline mat3d mat3d::operator / (double a) const
{
a = 1./a;
return mat3d(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);
}
// arithmetic operators for mat3dd
inline mat3d mat3d::operator + (const mat3dd& m) const
{
return mat3d( d[0][0]+m.d[0], d[0][1], d[0][2],
d[1][0], d[1][1]+m.d[1], d[1][2],
d[2][0], d[2][1], d[2][2]+m.d[2]);
}
inline mat3d mat3d::operator - (const mat3dd& m) const
{
return mat3d( d[0][0]-m.d[0], d[0][1], d[0][2],
d[1][0], d[1][1]-m.d[1], d[1][2],
d[2][0], d[2][1], d[2][2]-m.d[2]);
}
inline mat3d mat3d::operator * (const mat3dd& m) const
{
return mat3d( d[0][0]*m.d[0], d[0][1]*m.d[1], d[0][2]*m.d[2],
d[1][0]*m.d[0], d[1][1]*m.d[1], d[1][2]*m.d[2],
d[2][0]*m.d[0], d[2][1]*m.d[1], d[2][2]*m.d[2]);
}
// arithmetic operators for mat3ds
inline mat3d mat3d::operator + (const mat3ds& m) const
{
return mat3d(d[0][0]+m.m[m.XX], d[0][1]+m.m[m.XY], d[0][2]+m.m[m.XZ],
d[1][0]+m.m[m.XY], d[1][1]+m.m[m.YY], d[1][2]+m.m[m.YZ],
d[2][0]+m.m[m.XZ], d[2][1]+m.m[m.YZ], d[2][2]+m.m[m.ZZ]);
}
inline mat3d mat3d::operator - (const mat3ds& m) const
{
return mat3d(d[0][0]-m.m[m.XX], d[0][1]-m.m[m.XY], d[0][2]-m.m[m.XZ],
d[1][0]-m.m[m.XY], d[1][1]-m.m[m.YY], d[1][2]-m.m[m.YZ],
d[2][0]-m.m[m.XZ], d[2][1]-m.m[m.YZ], d[2][2]-m.m[m.ZZ]);
}
inline mat3d mat3d::operator * (const mat3ds& m) const
{
return mat3d(
d[0][0]*m.m[m.XX] + d[0][1]*m.m[m.XY] + d[0][2]*m.m[m.XZ],
d[0][0]*m.m[m.XY] + d[0][1]*m.m[m.YY] + d[0][2]*m.m[m.YZ],
d[0][0]*m.m[m.XZ] + d[0][1]*m.m[m.YZ] + d[0][2]*m.m[m.ZZ],
d[1][0]*m.m[m.XX] + d[1][1]*m.m[m.XY] + d[1][2]*m.m[m.XZ],
d[1][0]*m.m[m.XY] + d[1][1]*m.m[m.YY] + d[1][2]*m.m[m.YZ],
d[1][0]*m.m[m.XZ] + d[1][1]*m.m[m.YZ] + d[1][2]*m.m[m.ZZ],
d[2][0]*m.m[m.XX] + d[2][1]*m.m[m.XY] + d[2][2]*m.m[m.XZ],
d[2][0]*m.m[m.XY] + d[2][1]*m.m[m.YY] + d[2][2]*m.m[m.YZ],
d[2][0]*m.m[m.XZ] + d[2][1]*m.m[m.YZ] + d[2][2]*m.m[m.ZZ]);
}
// arithmetic assignment operators
inline mat3d& mat3d::operator += (const mat3d& m)
{
d[0][0] += m.d[0][0]; d[0][1] += m.d[0][1]; d[0][2] += m.d[0][2];
d[1][0] += m.d[1][0]; d[1][1] += m.d[1][1]; d[1][2] += m.d[1][2];
d[2][0] += m.d[2][0]; d[2][1] += m.d[2][1]; d[2][2] += m.d[2][2];
return (*this);
}
inline mat3d& mat3d::operator -= (const mat3d& m)
{
d[0][0] -= m.d[0][0]; d[0][1] -= m.d[0][1]; d[0][2] -= m.d[0][2];
d[1][0] -= m.d[1][0]; d[1][1] -= m.d[1][1]; d[1][2] -= m.d[1][2];
d[2][0] -= m.d[2][0]; d[2][1] -= m.d[2][1]; d[2][2] -= m.d[2][2];
return (*this);
}
inline mat3d& mat3d::operator *= (const mat3d& m)
{
double d00 = d[0][0]*m.d[0][0]+d[0][1]*m.d[1][0]+d[0][2]*m.d[2][0];
double d01 = d[0][0]*m.d[0][1]+d[0][1]*m.d[1][1]+d[0][2]*m.d[2][1];
double d02 = d[0][0]*m.d[0][2]+d[0][1]*m.d[1][2]+d[0][2]*m.d[2][2];
double d10 = d[1][0]*m.d[0][0]+d[1][1]*m.d[1][0]+d[1][2]*m.d[2][0];
double d11 = d[1][0]*m.d[0][1]+d[1][1]*m.d[1][1]+d[1][2]*m.d[2][1];
double d12 = d[1][0]*m.d[0][2]+d[1][1]*m.d[1][2]+d[1][2]*m.d[2][2];
double d20 = d[2][0]*m.d[0][0]+d[2][1]*m.d[1][0]+d[2][2]*m.d[2][0];
double d21 = d[2][0]*m.d[0][1]+d[2][1]*m.d[1][1]+d[2][2]*m.d[2][1];
double d22 = d[2][0]*m.d[0][2]+d[2][1]*m.d[1][2]+d[2][2]*m.d[2][2];
d[0][0] = d00; d[0][1] = d01; d[0][2] = d02;
d[1][0] = d10; d[1][1] = d11; d[1][2] = d12;
d[2][0] = d20; d[2][1] = d21; d[2][2] = d22;
return (*this);
}
inline mat3d& mat3d::operator *= (double a)
{
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;
return (*this);
}
inline mat3d& mat3d::operator /= (double a)
{
a = 1./a;
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;
return (*this);
}
// arithmetic assignment operators for mat3dd
inline mat3d& mat3d::operator += (const mat3dd& m)
{
d[0][0] += m.d[0];
d[1][1] += m.d[1];
d[2][2] += m.d[2];
return (*this);
}
inline mat3d& mat3d::operator -= (const mat3dd& m)
{
d[0][0] -= m.d[0];
d[1][1] -= m.d[1];
d[2][2] -= m.d[2];
return (*this);
}
inline mat3d& mat3d::operator *= (const mat3dd& m)
{
d[0][0] *= m.d[0]; d[0][1] *= m.d[1]; d[0][2] *= m.d[2];
d[1][0] *= m.d[0]; d[1][1] *= m.d[1]; d[1][2] *= m.d[2];
d[2][0] *= m.d[0]; d[2][1] *= m.d[1]; d[2][2] *= m.d[2];
return (*this);
}
// arithmetic operators for mat3ds
inline mat3d& mat3d::operator += (const mat3ds& m)
{
d[0][0] += m.m[m.XX]; d[0][1] += m.m[m.XY]; d[0][2] += m.m[m.XZ];
d[1][0] += m.m[m.XY]; d[1][1] += m.m[m.YY]; d[1][2] += m.m[m.YZ];
d[2][0] += m.m[m.XZ]; d[2][1] += m.m[m.YZ]; d[2][2] += m.m[m.ZZ];
return (*this);
}
inline mat3d& mat3d::operator -= (const mat3ds& m)
{
d[0][0] -= m.m[m.XX]; d[0][1] -= m.m[m.XY]; d[0][2] -= m.m[m.XZ];
d[1][0] -= m.m[m.XY]; d[1][1] -= m.m[m.YY]; d[1][2] -= m.m[m.YZ];
d[2][0] -= m.m[m.XZ]; d[2][1] -= m.m[m.YZ]; d[2][2] -= m.m[m.ZZ];
return (*this);
}
inline mat3d& mat3d::operator *= (const mat3ds& m)
{
double d00 = d[0][0]*m.m[m.XX]+d[0][1]*m.m[m.XY]+d[0][2]*m.m[m.XZ];
double d01 = d[0][0]*m.m[m.XY]+d[0][1]*m.m[m.YY]+d[0][2]*m.m[m.YZ];
double d02 = d[0][0]*m.m[m.XZ]+d[0][1]*m.m[m.YZ]+d[0][2]*m.m[m.ZZ];
double d10 = d[1][0]*m.m[m.XX]+d[1][1]*m.m[m.XY]+d[1][2]*m.m[m.XZ];
double d11 = d[1][0]*m.m[m.XY]+d[1][1]*m.m[m.YY]+d[1][2]*m.m[m.YZ];
double d12 = d[1][0]*m.m[m.XZ]+d[1][1]*m.m[m.YZ]+d[1][2]*m.m[m.ZZ];
double d20 = d[2][0]*m.m[m.XX]+d[2][1]*m.m[m.XY]+d[2][2]*m.m[m.XZ];
double d21 = d[2][0]*m.m[m.XY]+d[2][1]*m.m[m.YY]+d[2][2]*m.m[m.YZ];
double d22 = d[2][0]*m.m[m.XZ]+d[2][1]*m.m[m.YZ]+d[2][2]*m.m[m.ZZ];
d[0][0] = d00; d[0][1] = d01; d[0][2] = d02;
d[1][0] = d10; d[1][1] = d11; d[1][2] = d12;
d[2][0] = d20; d[2][1] = d21; d[2][2] = d22;
return (*this);
}
// matrix-vector multiplication
inline vec3d mat3d::operator * (const vec3d& r) const
{
return vec3d(d[0][0]*r.x+d[0][1]*r.y+d[0][2]*r.z,
d[1][0]*r.x+d[1][1]*r.y+d[1][2]*r.z,
d[2][0]*r.x+d[2][1]*r.y+d[2][2]*r.z);
}
// determinant
inline double mat3d::det() const
{
return (d[0][0]*(d[1][1]*d[2][2] - d[1][2]*d[2][1])
+ d[0][1]*(d[1][2]*d[2][0] - d[2][2]*d[1][0])
+ d[0][2]*(d[1][0]*d[2][1] - d[1][1]*d[2][0]));
}
// trace
inline double mat3d::trace() const { return d[0][0]+d[1][1]+d[2][2]; }
inline void mat3d::unit()
{
d[0][0] = d[1][1] = d[2][2] = 1;
d[0][1] = d[1][0] = 0;
d[0][2] = d[2][0] = 0;
d[1][2] = d[2][1] = 0;
}
// zero the matrix
inline void mat3d::zero()
{
d[0][0] = d[0][1] = d[0][2] = 0;
d[1][0] = d[1][1] = d[1][2] = 0;
d[2][0] = d[2][1] = d[2][2] = 0;
}
// return a column vector from the matrix
inline vec3d mat3d::col(int j) const
{
return vec3d(d[0][j], d[1][j], d[2][j]);
}
// return a row vector from the matrix
inline vec3d mat3d::row(int j) const
{
return vec3d(d[j][0], d[j][1], d[j][2]);
}
// set the column of the matrix
inline void mat3d::setCol(int i, const vec3d& a)
{
d[0][i] = a.x;
d[1][i] = a.y;
d[2][i] = a.z;
}
// set the row of the matrix
inline void mat3d::setRow(int i, const vec3d& a)
{
d[i][0] = a.x;
d[i][1] = a.y;
d[i][2] = a.z;
}
// return the symmetric matrix 0.5*(A+A^T)
inline mat3ds mat3d::sym() const
{
return mat3ds(
d[0][0],
d[1][1],
d[2][2],
0.5*(d[0][1]+d[1][0]),
0.5*(d[1][2]+d[2][1]),
0.5*(d[0][2]+d[2][0]));
}
// return the anti-symmetric matrix 0.5*(A - A^T)
inline mat3da mat3d::skew() const
{
return mat3da(
0.5*(d[0][1] - d[1][0]),
0.5*(d[1][2] - d[2][1]),
0.5*(d[0][2] - d[2][0]));
}
// return the inverse matrix
inline mat3d mat3d::inverse() const
{
double D = det();
assert(D != 0);
D = 1/D;
return mat3d(D*(d[1][1]*d[2][2] - d[1][2]*d[2][1]),
D*(d[0][2]*d[2][1] - d[0][1]*d[2][2]),
D*(d[0][1]*d[1][2] - d[1][1]*d[0][2]),
D*(d[1][2]*d[2][0] - d[1][0]*d[2][2]),
D*(d[0][0]*d[2][2] - d[0][2]*d[2][0]),
D*(d[0][2]*d[1][0] - d[0][0]*d[1][2]),
D*(d[1][0]*d[2][1] - d[1][1]*d[2][0]),
D*(d[0][1]*d[2][0] - d[0][0]*d[2][1]),
D*(d[0][0]*d[1][1] - d[0][1]*d[1][0]));
}
// return the inverse matrix
inline bool mat3d::invert()
{
double D = det();
if (D == 0) return false;
D = 1.0 / D;
// calculate conjugate Matrix
double mi[3][3];
mi[0][0] = (d[1][1] * d[2][2] - d[1][2] * d[2][1]);
mi[0][1] = -(d[1][0] * d[2][2] - d[1][2] * d[2][0]);
mi[0][2] = (d[1][0] * d[2][1] - d[1][1] * d[2][0]);
mi[1][0] = -(d[0][1] * d[2][2] - d[0][2] * d[2][1]);
mi[1][1] = (d[0][0] * d[2][2] - d[0][2] * d[2][0]);
mi[1][2] = -(d[0][0] * d[2][1] - d[0][1] * d[2][0]);
mi[2][0] = (d[0][1] * d[1][2] - d[0][2] * d[1][1]);
mi[2][1] = -(d[0][0] * d[1][2] - d[0][2] * d[1][0]);
mi[2][2] = (d[0][0] * d[1][1] - d[0][1] * d[1][0]);
// divide by det and transpose
d[0][0] = mi[0][0] * D; d[1][0] = mi[0][1] * D; d[2][0] = mi[0][2] * D;
d[0][1] = mi[1][0] * D; d[1][1] = mi[1][1] * D; d[2][1] = mi[1][2] * D;
d[0][2] = mi[2][0] * D; d[1][2] = mi[2][1] * D; d[2][2] = mi[2][2] * D;
return true;
}
// return the transpose matrix
inline mat3d mat3d::transpose() const
{
return mat3d(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]);
}
// return the transposed inverse matrix
inline mat3d mat3d::transinv() const
{
double D = det();
assert(D != 0);
D = 1/D;
return mat3d(D*(d[1][1]*d[2][2] - d[1][2]*d[2][1]), // xx
D*(d[1][2]*d[2][0] - d[1][0]*d[2][2]), // yx
D*(d[1][0]*d[2][1] - d[1][1]*d[2][0]), // zx
D*(d[0][2]*d[2][1] - d[0][1]*d[2][2]), // xy
D*(d[0][0]*d[2][2] - d[0][2]*d[2][0]), // yy
D*(d[0][1]*d[2][0] - d[0][0]*d[2][1]), // zy
D*(d[0][1]*d[1][2] - d[1][1]*d[0][2]), // xz
D*(d[0][2]*d[1][0] - d[0][0]*d[1][2]), // yz
D*(d[0][0]*d[1][1] - d[0][1]*d[1][0])); // zz
}
// calculate the skew symmetric matrix from a vector
inline void mat3d::skew(const vec3d& v)
{
d[0][0] = 0; d[0][1] = -v.z; d[0][2] = v.y;
d[1][0] = v.z; d[1][1] = 0; d[1][2] = -v.x;
d[2][0] = -v.y; d[2][1] = v.x; d[2][2] = 0;
}
// calculate the one-norm (max of absolute column-sum)
inline double mat3d::norm() const
{
double s, sc;
sc = fabs(d[0][0]) + fabs(d[1][0]) + fabs(d[2][0]); s = sc;
sc = fabs(d[0][1]) + fabs(d[1][1]) + fabs(d[2][1]); if (sc > s) s = sc;
sc = fabs(d[0][2]) + fabs(d[1][2]) + fabs(d[2][2]); if (sc > s) s = sc;
return s;
}
// double contraction
inline double mat3d::dotdot(const mat3d& T) const
{
return (T.d[0][0]*d[0][0] + T.d[0][1]*d[0][1] + T.d[0][2]*d[0][2] + T.d[1][0]*d[1][0] + T.d[1][1]*d[1][1] + T.d[1][2]*d[1][2] + T.d[2][0]*d[2][0] + T.d[2][1]*d[2][1] + T.d[2][2]*d[2][2]);
}
// return the inverse matrix
inline bool mat3f::invert()
{
float D = d[0][0] * (d[1][1] * d[2][2] - d[1][2] * d[2][1])
+ d[0][1] * (d[1][2] * d[2][0] - d[2][2] * d[1][0])
+ d[0][2] * (d[1][0] * d[2][1] - d[1][1] * d[2][0]);
if (D == 0.f) return false;
D = 1.f / D;
// calculate conjugate Matrix
float mi[3][3];
mi[0][0] = (d[1][1] * d[2][2] - d[1][2] * d[2][1]);
mi[0][1] = -(d[1][0] * d[2][2] - d[1][2] * d[2][0]);
mi[0][2] = (d[1][0] * d[2][1] - d[1][1] * d[2][0]);
mi[1][0] = -(d[0][1] * d[2][2] - d[0][2] * d[2][1]);
mi[1][1] = (d[0][0] * d[2][2] - d[0][2] * d[2][0]);
mi[1][2] = -(d[0][0] * d[2][1] - d[0][1] * d[2][0]);
mi[2][0] = (d[0][1] * d[1][2] - d[0][2] * d[1][1]);
mi[2][1] = -(d[0][0] * d[1][2] - d[0][2] * d[1][0]);
mi[2][2] = (d[0][0] * d[1][1] - d[0][1] * d[1][0]);
// divide by det and transpose
d[0][0] = mi[0][0] * D; d[1][0] = mi[0][1] * D; d[2][0] = mi[0][2] * D;
d[0][1] = mi[1][0] * D; d[1][1] = mi[1][1] * D; d[2][1] = mi[1][2] * D;
d[0][2] = mi[2][0] * D; d[1][2] = mi[2][1] * D; d[2][2] = mi[2][2] * D;
return true;
}
//-----------------------------------------------------------------------------
inline void mat3d::exp(const vec3d& v)
{
double l = v.norm();
if (l == 0.0) *this = mat3d::identity();
else
{
double a = 0.5 * (tan(0.5 * l) / (0.5 * l));
vec3d w = v * a;
mat3da S(w);
mat3d S2 = S * S;
mat3dd I(1.0);
mat3d E = I + (S2 + S) * (2.0 / (1.0 + w.norm2()));
*this = E;
}
}
| Unknown |
3D | febiosoftware/FEBio | FECore/CompactMatrix.cpp | .cpp | 3,633 | 143 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "CompactMatrix.h"
#include <assert.h>
//=============================================================================
// CompactMatrix
//=============================================================================
//-----------------------------------------------------------------------------
CompactMatrix::CompactMatrix(int offset)
{
m_pd = 0;
m_pindices = 0;
m_ppointers = 0;
m_offset = offset;
m_bdel = false;
}
//-----------------------------------------------------------------------------
CompactMatrix::~CompactMatrix()
{
Clear();
}
//-----------------------------------------------------------------------------
void CompactMatrix::Zero()
{
memset(m_pd, 0, m_nsize*sizeof(double));
}
//-----------------------------------------------------------------------------
void CompactMatrix::Clear()
{
if (m_bdel)
{
if (m_pd) delete [] m_pd;
if (m_pindices) delete [] m_pindices;
if (m_ppointers) delete [] m_ppointers;
}
m_pd = 0;
m_pindices = 0;
m_ppointers = 0;
SparseMatrix::Clear();
}
//-----------------------------------------------------------------------------
void CompactMatrix::alloc(int nr, int nc, int nz, double* pv, int* pi, int* pp, bool bdel)
{
Clear();
m_pd = pv;
m_pindices = pi;
m_ppointers = pp;
m_bdel = bdel;
m_nrow = nr;
m_ncol = nc;
m_nsize = nz;
int nn = (isRowBased() ? nr : nc) + 1;
}
//-----------------------------------------------------------------------------
//! calculate bandwidth of matrix
int CompactMatrix::bandWidth()
{
int NR = Rows();
int NC = Columns();
int kmax = 0;
if (isRowBased())
{
for (int i = 0; i < NR; ++i)
{
int* pi = m_pindices + (m_ppointers[i] - m_offset);
int n = m_ppointers[i + 1] - m_ppointers[i];
for (int k = 0; k < n; ++k)
{
int j = pi[k] - m_offset;
if (abs(j - i) > kmax) kmax = abs(j - i);
}
}
}
else
{
for (int j = 0; j < NC; ++j)
{
int* pj = m_pindices + (m_ppointers[j] - m_offset);
int n = m_ppointers[j + 1] - m_ppointers[j];
for (int k = 0; k < n; ++k)
{
int i = pj[k] - m_offset;
if (abs(j - i) > kmax) kmax = abs(j - i);
}
}
}
return kmax;
}
size_t CompactMatrix::actualNonZeroes()
{
size_t NNZ = NonZeroes();
size_t nnz = 0;
double* v = Values();
for (size_t i = 0; i < NNZ; ++i)
{
if (v[i] != 0.0) nnz++;
}
return nnz;
}
| C++ |
3D | febiosoftware/FEBio | FECore/SkylineSolver.h | .h | 1,960 | 62 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "LinearSolver.h"
#include "SkylineMatrix.h"
#include "fecore_api.h"
//-----------------------------------------------------------------------------
//! Implements a linear solver that uses a skyline format
class FECORE_API SkylineSolver : public LinearSolver
{
public:
//! constructor
SkylineSolver(FEModel* fem);
//! Preprocess
bool PreProcess() override;
//! Factor matrix
bool Factor() override;
//! Backsolve the linear system
bool BackSolve(double* x, double* b) override;
//! Clean up
void Destroy() override;
//! Create a sparse matrix
SparseMatrix* CreateSparseMatrix(Matrix_Type ntype) override;
private:
SkylineMatrix* m_pA;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEModifiedNewtonStrategy.h | .h | 1,982 | 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 "matrix.h"
#include "vector.h"
#include "LinearSolver.h"
#include "FENewtonStrategy.h"
//-----------------------------------------------------------------------------
class FECORE_API FEModifiedNewtonStrategy : public FENewtonStrategy
{
public:
//! constructor
FEModifiedNewtonStrategy(FEModel* fem);
//! New initialization method
bool Init() override;
//! perform a BFGS udpate
bool Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1) override;
//! solve the equations
void SolveEquations(vector<double>& x, vector<double>& b) override;
public:
// keep a pointer to the linear solver
LinearSolver* m_plinsolve; //!< pointer to linear solver
};
| Unknown |
3D | febiosoftware/FEBio | FECore/writeplot.h | .h | 14,536 | 371 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEMesh.h"
#include "FESurface.h"
#include "FEDataStream.h"
#include "FESolidDomain.h"
#include <FEBioMech/FESSIShellDomain.h>
#include "FEDomainParameter.h"
#include "fecore_api.h"
#include <functional>
//=================================================================================================
template <class T> void writeNodalValues(FEMesh& mesh, FEDataStream& ar, std::function<T(const FENode& node)> f)
{
for (int i = 0; i<mesh.Nodes(); ++i) ar << f(mesh.Node(i));
}
//=================================================================================================
template <class T> void writeNodalValues(FEMeshPartition& dom, FEDataStream& ar, std::function<T(int)> f)
{
for (int i = 0; i<dom.Nodes(); ++i) ar << f(i);
}
//=================================================================================================
template <class T> void writeElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<T(int nface)> f)
{
for (int i = 0; i<dom.Elements(); ++i) ar << f(i);
}
//=================================================================================================
template <class T> void writeNodalValues(FENodeSet& nset, FEDataStream& ar, std::function<T (const FEMaterialPoint&)> var)
{
FEMesh& mesh = *nset.GetMesh();
vector<T> data(mesh.Nodes(), T(0.0));
FEMaterialPoint mp;
for (int i = 0; i < nset.Size(); ++i) {
FENode& node = mesh.Node(nset[i]);
mp.m_r0 = node.m_r0;
mp.m_index = i;
data[nset[i]] = var(mp);
}
ar << data;
}
//=================================================================================================
template <class T> void writeIntegratedElementValue(FESurface& surf, FEDataStream& ar, std::function<T(const FEMaterialPoint& mp)> fnc)
{
T s(0.0);
for (int i = 0; i<surf.Elements(); ++i) {
FESurfaceElement& el = surf.Element(i);
double* w = el.GaussWeights();
for (int j = 0; j<el.GaussPoints(); ++j) s += fnc(*el.GetMaterialPoint(j))*w[j];
}
ar << s;
}
//=================================================================================================
template <class T> void writeElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint& mp)> fnc)
{
int NE = dom.Elements();
std::vector<T> v(NE);
#pragma omp parallel for shared(v)
for (int i = 0; i<NE; ++i) {
FEElement& el = dom.ElementRef(i);
v[i] = fnc(*el.GetMaterialPoint(0));
}
for (int i = 0; i < NE; ++i)
ar << v[i];
}
//=================================================================================================
void FECORE_API writeMaxElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<double(const FEMaterialPoint& mp)> fnc);
//=================================================================================================
template <class T> void writeAverageElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint& mp)> fnc)
{
int NE = dom.Elements();
std::vector<T> v(NE);
#pragma omp parallel for shared(v)
for (int i = 0; i<NE; ++i) {
FEElement& el = dom.ElementRef(i);
T s(0.0);
for (int j = 0; j<el.GaussPoints(); ++j) s += fnc(*el.GetMaterialPoint(j));
v[i] = s / (double)el.GaussPoints();
}
for (int i=0; i<NE; ++i)
ar << v[i];
}
//=================================================================================================
template <class T> void writeAverageElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<T(FEElement& el, int ip)> fnc)
{
for (int i = 0; i<dom.Elements(); ++i) {
FEElement& el = dom.ElementRef(i);
T s(0.0);
for (int j = 0; j<el.GaussPoints(); ++j) s += fnc(el, j);
ar << s / (double) el.GaussPoints();
}
}
//=================================================================================================
template <class Tin, class Tout> void writeAverageElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<Tin(const FEMaterialPoint&)> fnc, std::function<Tout(const Tin& m)> flt)
{
for (int i = 0; i<dom.Elements(); ++i) {
FEElement& el = dom.ElementRef(i);
Tin s(0.0);
for (int j = 0; j<el.GaussPoints(); ++j) s += fnc(*el.GetMaterialPoint(j));
ar << flt(s / (double) el.GaussPoints());
}
}
//=================================================================================================
template <class Tin, class Tout> void writeAverageElementValue(FEMeshPartition& dom, FEDataStream& ar, std::function<Tin(FEElement& el, int ip)> fnc, std::function<Tout(const Tin& m)> flt)
{
for (int i = 0; i<dom.Elements(); ++i) {
FEElement& el = dom.ElementRef(i);
Tin s(0.0);
for (int j = 0; j<el.GaussPoints(); ++j) s += fnc(el, j);
ar << flt(s / (double)el.GaussPoints());
}
}
//=================================================================================================
template <class T> void writeAverageElementValue(FEMeshPartition& dom, FEDataStream& ar, FEDomainParameter* var)
{
for (int i = 0; i<dom.Elements(); ++i) {
FEElement& el = dom.ElementRef(i);
T s(0.0);
for (int j = 0; j < el.GaussPoints(); ++j)
{
FEParamValue v = var->value(*el.GetMaterialPoint(j));
s += v.value<T>();
}
ar << s / (double)el.GaussPoints();
}
}
//=================================================================================================
template <class T> void writeIntegratedElementValue(FESolidDomain& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint& mp)> fnc)
{
for (int i = 0; i<dom.Elements(); ++i) {
FESolidElement& el = dom.Element(i);
double* gw = el.GaussWeights();
T ew(0.0);
for (int j = 0; j<el.GaussPoints(); ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
ew += fnc(mp)*dom.detJ0(el, j)*gw[j];
}
ar << ew;
}
}
//=================================================================================================
template <class T> void writeNodalProjectedElementValues(FEMeshPartition& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint&)> var)
{
// temp storage
T si[FEElement::MAX_INTPOINTS];
T sn[FEElement::MAX_NODES];
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i<NE; ++i)
{
FEElement& e = dom.ElementRef(i);
int ne = e.Nodes();
int ni = e.GaussPoints();
// get the integration point values
for (int k = 0; k<ni; ++k)
{
FEMaterialPoint& mp = *e.GetMaterialPoint(k);
T s = var(mp);
si[k] = s;
}
// project to nodes
e.project_to_nodes(si, sn);
// push data to archive
for (int j = 0; j<ne; ++j) ar << sn[j];
}
}
//=================================================================================================
template <class T> void writeShellElementValues(FEMeshPartition& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint&)> var, bool bbot)
{
// accepts only shell elements
if (dynamic_cast<FESSIShellDomain*>(&dom)) {
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i<NE; ++i)
{
FEElement& e = dom.ElementRef(i);
int ne = e.Nodes();
int ni = e.GaussPoints();
int NI = ni;
int NS = 1;
if (e.Type() == FE_SHELL_QUAD4G8) { NS = 2; }
else if (e.Type() == FE_SHELL_QUAD4G12) { NS = 3; }
else if (e.Type() == FE_SHELL_QUAD8G18) { NS = 2; }
else if (e.Type() == FE_SHELL_QUAD8G27) { NS = 3; }
else if (e.Type() == FE_SHELL_TRI3G6) { NS = 2; }
else if (e.Type() == FE_SHELL_TRI6G14) { NS = 2; }
else if (e.Type() == FE_SHELL_TRI6G21) { NS = 3; }
if (NS == 1) return; // no valid way to project to front or back
NI = ni/NS;
std::vector<double> gt = dynamic_cast<FEShellElementTraits*>(e.GetTraits())->gt;
// get the integration point values
T d; d.zero();
for (int k = 0; k<NI; ++k)
{
switch (NS) {
case 2:
{
FEMaterialPoint& mpt = *e.GetMaterialPoint(k + NI);
FEMaterialPoint& mpb = *e.GetMaterialPoint(k);
T st = var(mpt);
T sb = var(mpb);
double tt = gt[k + NI];
double tb = gt[k];
T s;
if (bbot)
s = (st - sb)*((-1-tb)/(tt-tb)) + sb;
else
s = (st - sb)*((1-tb)/(tt-tb)) + sb;
d += s;
}
break;
case 3:
{
FEMaterialPoint& mpt = *e.GetMaterialPoint(k + 2*NI);
FEMaterialPoint& mpm = *e.GetMaterialPoint(k + NI);
FEMaterialPoint& mpb = *e.GetMaterialPoint(k);
T st = var(mpt);
T sm = var(mpm);
T sb = var(mpb);
double tt = gt[k + 2*NI];
double tm = gt[k + NI];
double tb = gt[k];
T s;
if (bbot)
s = (-(sm*(1 + tb)*(tb - tt)*(1 + tt)) +
(1 + tm)*(st*(1 + tb)*(tb - tm) + sb*(tm - tt)*(1 + tt)))/
((tb - tm)*(tb - tt)*(tm - tt));
else
s = ((-1 + tm)*(st*(-1 + tb)*(tb - tm) + sb*(tm - tt)*(-1 + tt)) -
sm*(-1 + tb)*(tb - tt)*(-1 + tt))/((tb - tm)*(tb - tt)*(tm - tt));
d += s;
}
break;
}
}
d /= NI;
// push data to archive
ar << d;
}
}
}
//=================================================================================================
template <class T> void writeShellNodalProjectedElementValues(FEMeshPartition& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint&)> var, bool bbot)
{
// temp storage
T si[FEElement::MAX_INTPOINTS];
T sn[FEElement::MAX_NODES];
// loop over all elements
int NE = dom.Elements();
for (int i = 0; i<NE; ++i)
{
FEElement& e = dom.ElementRef(i);
if ((e.Type() == FE_SHELL_QUAD4G4) || (e.Type() == FE_SHELL_TRI3G3)) return; // no valid way to project to front or back
int ne = e.Nodes();
int ni = e.GaussPoints();
int nvln = dynamic_cast<FEShellElementTraits*>(e.GetTraits())->m_nvln;
// get the integration point values
for (int k = 0; k<ni; ++k)
{
FEMaterialPoint& mp = *e.GetMaterialPoint(k);
T s = var(mp);
si[k] = s;
}
// project to nodes
e.project_to_nodes(si, sn);
// push data to archive
for (int j = 0; j<nvln/2; ++j) (bbot) ? (ar << sn[j]) : (ar << sn[j+nvln/2]);
}
}
//=================================================================================================
template <class T> void writeNodalProjectedElementValues(FESurface& dom, FEDataStream& ar, std::function<T(const FEMaterialPoint&)> var)
{
T gi[FEElement::MAX_INTPOINTS];
T gn[FEElement::MAX_NODES];
// loop over all the elements in the domain
int NE = dom.Elements();
for (int i = 0; i < NE; ++i)
{
// get the element and loop over its integration points
// we only calculate the element's average
// but since most material parameters can only defined
// at the element level, this should get the same answer
FESurfaceElement& e = dom.Element(i);
int nint = e.GaussPoints();
int neln = e.Nodes();
for (int j = 0; j < nint; ++j)
{
// get the material point data for this integration point
FEMaterialPoint& mp = *e.GetMaterialPoint(j);
gi[j] = var(mp);
}
e.FEElement::project_to_nodes(gi, gn);
// store the result
for (int j = 0; j < neln; ++j) ar << gn[j];
}
}
//-----------------------------------------------------------------------------
// helper functions for writing SPR projected element values
// TODO: I needed to give these functions a different name because of the implicit conversion between mat3ds and mat3dd
FECORE_API void writeSPRElementValue(FESolidDomain& dom, FEDataStream& ar, std::function<double(const FEMaterialPoint&)> fnc, int interpolOrder = -1);
FECORE_API void writeSPRElementValueVectorDouble(FESolidDomain& dom, FEDataStream& ar, std::function<std::vector<double>(const FEMaterialPoint&)> fnc, int interpolOrder = -1, int n_fields = -1);
FECORE_API void writeSPRElementValueMat3dd(FESolidDomain& dom, FEDataStream& ar, std::function<mat3dd(const FEMaterialPoint&)> fnc, int interpolOrder = -1);
FECORE_API void writeSPRElementValueMat3ds(FESolidDomain& dom, FEDataStream& ar, std::function<mat3ds(const FEMaterialPoint&)> fnc, int interpolOrder = -1);
// Helper functions for mapping data
FECORE_API void ProjectToNodes(FEDomain& dom, vector<double>& nodeVals, function<double(FEMaterialPoint& mp)> f);
FECORE_API void writeRelativeError(FEDomain& dom, FEDataStream& a, function<double(FEMaterialPoint& mp)> f);
| Unknown |
3D | febiosoftware/FEBio | FECore/FEClosestPointProjection.h | .h | 3,091 | 88 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FESurface.h"
#include "FENNQuery.h"
#include "FEElemElemList.h"
#include "FENodeElemList.h"
//-----------------------------------------------------------------------------
// This class can be used to find the closest point projection of a point
// onto a surface.
class FECORE_API FEClosestPointProjection
{
public:
//! constructor
FEClosestPointProjection(FESurface& s);
//! Initialization
bool Init();
//! Project a point onto surface
FESurfaceElement* Project(const vec3d& x, vec3d& q, vec2d& r);
//! Project a node onto a surface
FESurfaceElement* Project(int n, vec3d& q, vec2d& r);
//! Project a point of a surface element onto a surface
FESurfaceElement* Project(FESurfaceElement* pse, int intgrPoint, vec3d& q, vec2d& r);
public:
//! Set the projection tolerance
void SetTolerance(double t) { m_tol = t; }
//! get the projection tolerance
double GetTolerance() { return m_tol; }
//! Set the search radius (used in self-projection)
void SetSearchRadius(double s) { m_rad = s; }
//! set if the projection should handle special cases
void HandleSpecialCases(bool b) { m_bspecial = b; }
//! set if boundary projections are allowed
void AllowBoundaryProjections(bool b) { m_projectBoundary = b; }
private:
bool ContainsElement(FESurfaceElement* el);
FESurfaceElement* ProjectSpecial(int closestPoint, const vec3d& x, vec3d& q, vec2d& r);
protected:
double m_tol; //!< projection tolerance
double m_rad; //!< search radius
bool m_bspecial; //!< try to handle special cases
bool m_projectBoundary; //!< allow boundary projections
protected:
FESurface& m_surf; //!< reference to surface
FENNQuery m_SNQ; //!< used to find the nearest neighbour
FENodeElemList m_NEL; //!< node-element tree
FEElemElemList m_EEL; //!< element neighbor list
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FENodalBC.h | .h | 1,674 | 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 "FEBoundaryCondition.h"
#include "fecore_api.h"
class FENodeSet;
class FECORE_API FENodalBC : public FEBoundaryCondition
{
FECORE_BASE_CLASS(FENodalBC)
public:
FENodalBC(FEModel* fem);
// Set the node set
void SetNodeSet(FENodeSet* nodeSet);
// Get the node set
FENodeSet* GetNodeSet();
void Serialize(DumpStream& ar) override;
private:
FENodeSet* m_nodeSet;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogData.cpp | .cpp | 1,356 | 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.*/
#include "FELogData.h"
FELogData::FELogData(FEModel* fem) : FECoreBase(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDomainMap.cpp | .cpp | 14,211 | 586 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEDomainMap.h"
#include "FEMesh.h"
#include "DumpStream.h"
#include "mathalg.h"
//-----------------------------------------------------------------------------
FEDomainMap::FEDomainMap() : FEDataMap(FE_DOMAIN_MAP)
{
m_maxElemNodes = 0;
}
//-----------------------------------------------------------------------------
FEDomainMap::FEDomainMap(FEDataType dataType, Storage_Fmt format) : FEDataMap(FE_DOMAIN_MAP, dataType)
{
m_fmt = format;
m_maxElemNodes = 0;
}
//-----------------------------------------------------------------------------
FEDomainMap::FEDomainMap(const FEDomainMap& map) : FEDataMap(map)
{
m_name = map.m_name;
m_maxElemNodes = map.m_maxElemNodes;
}
//-----------------------------------------------------------------------------
FEDomainMap& FEDomainMap::operator = (const FEDomainMap& map)
{
FEDataArray::operator=(map);
m_name = map.m_name;
m_maxElemNodes = map.m_maxElemNodes;
return *this;
}
//-----------------------------------------------------------------------------
// return the item list associated with this map
FEItemList* FEDomainMap::GetItemList()
{
return m_elset;
}
//-----------------------------------------------------------------------------
bool FEDomainMap::Create(FEElementSet* ps, double val)
{
m_elset = ps;
int NE = ps->Elements();
FEMesh* mesh = ps->GetMesh();
m_maxElemNodes = 0;
if (m_fmt == FMT_MULT)
{
for (int i = 0; i < NE; ++i)
{
FEElement& el = *mesh->FindElementFromID((*ps)[i]);
int ne = el.Nodes();
if (ne > m_maxElemNodes) m_maxElemNodes = ne;
}
return resize(NE*m_maxElemNodes, val);
}
else if (m_fmt == FMT_ITEM)
{
m_maxElemNodes = 1;
return resize(NE, val);
}
else if (m_fmt == FMT_NODE)
{
FENodeList nodeList = ps->GetNodeList();
int nodes = nodeList.Size();
// find min, max index
m_imin = mesh->Nodes();
int imax = -1;
for (int i = 0; i < nodes; ++i)
{
int nid = nodeList[i];
if (nid < m_imin) m_imin = nid;
if (nid > imax) imax = nid;
}
// build lookup table
m_NLT.resize(imax - m_imin + 1, -1);
for (int i = 0; i < nodes; ++i)
{
int nid = nodeList[i];
m_NLT[nid - m_imin] = i;
}
return resize(nodes, val);
}
else if (m_fmt == FMT_MATPOINTS)
{
for (int i = 0; i < NE; ++i)
{
FEElement& el = *mesh->FindElementFromID((*ps)[i]);
int ne = el.GaussPoints();
if (ne > m_maxElemNodes) m_maxElemNodes = ne;
}
return resize(NE*m_maxElemNodes, val);
}
else return false;
}
//-----------------------------------------------------------------------------
void FEDomainMap::setValue(int n, double v)
{
if (m_fmt == FMT_MULT)
{
int index = n*m_maxElemNodes;
for (int i = 0; i < m_maxElemNodes; ++i) set<double>(index + i, v);
}
else if (m_fmt == FMT_ITEM)
{
set<double>(n, v);
}
else if (m_fmt == FMT_NODE)
{
set<double>(n, v);
}
}
//-----------------------------------------------------------------------------
void FEDomainMap::setValue(int n, const vec2d& v)
{
if (m_fmt == FMT_MULT)
{
int index = n*m_maxElemNodes;
for (int i = 0; i < m_maxElemNodes; ++i) set<vec2d>(index + i, v);
}
else if (m_fmt == FMT_ITEM)
{
set<vec2d>(n, v);
}
else if (m_fmt == FMT_NODE)
{
set<vec2d>(n, v);
}
}
//-----------------------------------------------------------------------------
void FEDomainMap::setValue(int n, const vec3d& v)
{
if ((m_fmt == FMT_MULT) || (m_fmt == FMT_MATPOINTS))
{
int index = n*m_maxElemNodes;
for (int i = 0; i < m_maxElemNodes; ++i) set<vec3d>(index + i, v);
}
else if (m_fmt == FMT_ITEM)
{
set<vec3d>(n, v);
}
else if (m_fmt == FMT_NODE)
{
set<vec3d>(n, v);
}
}
//-----------------------------------------------------------------------------
void FEDomainMap::setValue(int n, const mat3d& v)
{
if ((m_fmt == FMT_MULT) || (m_fmt == FMT_MATPOINTS))
{
int index = n*m_maxElemNodes;
for (int i = 0; i < m_maxElemNodes; ++i) set<mat3d>(index + i, v);
}
else if (m_fmt == FMT_ITEM)
{
set<mat3d>(n, v);
}
else if (m_fmt == FMT_NODE)
{
set<mat3d>(n, v);
}
}
//-----------------------------------------------------------------------------
void FEDomainMap::setValue(int n, const mat3ds& v)
{
if ((m_fmt == FMT_MULT) || (m_fmt == FMT_MATPOINTS))
{
int index = n * m_maxElemNodes;
for (int i = 0; i < m_maxElemNodes; ++i) set<mat3ds>(index + i, v);
}
else if (m_fmt == FMT_ITEM)
{
set<mat3ds>(n, v);
}
else if (m_fmt == FMT_NODE)
{
set<mat3ds>(n, v);
}
}
//-----------------------------------------------------------------------------
void FEDomainMap::fillValue(double v)
{
set<double>(v);
}
//-----------------------------------------------------------------------------
void FEDomainMap::fillValue(const vec2d& v)
{
set<vec2d>(v);
}
//-----------------------------------------------------------------------------
void FEDomainMap::fillValue(const vec3d& v)
{
set<vec3d>(v);
}
//-----------------------------------------------------------------------------
void FEDomainMap::fillValue(const mat3d& v)
{
set<mat3d>(v);
}
//-----------------------------------------------------------------------------
void FEDomainMap::fillValue(const mat3ds& v)
{
set<mat3ds>(v);
}
//-----------------------------------------------------------------------------
void FEDomainMap::Serialize(DumpStream& ar)
{
FEDataArray::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_maxElemNodes;
ar & m_name;
ar & m_elset;
ar & m_fmt;
ar & m_NLT;
ar & m_imin;
}
//-----------------------------------------------------------------------------
//! get the value at a material point
double FEDomainMap::value(const FEMaterialPoint& pt)
{
// get the element this material point is in
FEElement* pe = pt.m_elem;
assert(pe);
// see if this element belongs to the element set
assert(m_elset);
int lid = m_elset->GetLocalIndex(*pe);
assert((lid >= 0));
double v = 0.0;
if (m_fmt == FMT_MULT)
{
// get shape functions
double* H = pe->H(pt.m_index);
int ne = pe->Nodes();
for (int i = 0; i < ne; ++i)
{
double vi = value<double>(lid, i);
v += vi*H[i];
}
}
else if (m_fmt == FMT_NODE)
{
// get shape functions
double* H = pe->H(pt.m_index);
int ne = pe->Nodes();
for (int i = 0; i < ne; ++i)
{
int n = pe->m_node[i];
int m = m_NLT[n - m_imin];
double vi = value<double>(0, m);
v += vi * H[i];
}
}
else if (m_fmt == FMT_ITEM)
{
v = get<double>(lid);
}
else if (m_fmt == FMT_MATPOINTS)
{
v = value<double>(lid, pt.m_index);
}
else { assert(false); }
return v;
}
//-----------------------------------------------------------------------------
//! get the value at a material point
vec3d FEDomainMap::valueVec3d(const FEMaterialPoint& pt)
{
// get the element this material point is in
FEElement* pe = pt.m_elem;
assert(pe);
// see if this element belongs to the element set
assert(m_elset);
int lid = m_elset->GetLocalIndex(*pe);
assert((lid >= 0));
vec3d v(0, 0, 0);
if (m_fmt == FMT_MULT)
{
// get shape functions
double* H = pe->H(pt.m_index);
int ne = pe->Nodes();
for (int i = 0; i < ne; ++i)
{
vec3d vi = value<vec3d>(lid, i);
v += vi*H[i];
}
}
else if (m_fmt == FMT_ITEM)
{
return get<vec3d>(lid);
}
return v;
}
//-----------------------------------------------------------------------------
//! get the value at a material point
mat3d FEDomainMap::valueMat3d(const FEMaterialPoint& pt)
{
assert(DataType() == FEDataType::FE_MAT3D);
// get the element this material point is in
FEElement* pe = pt.m_elem;
assert(pe);
// see if this element belongs to the element set
assert(m_elset);
int lid = m_elset->GetLocalIndex(*pe);
assert((lid >= 0));
mat3d Q;
if (m_fmt == FMT_ITEM)
{
Q = get<mat3d>(lid);
}
else if (m_fmt == FMT_MATPOINTS)
{
Q = value<mat3d>(lid, pt.m_index);
}
else { assert(false); }
return Q;
}
//-----------------------------------------------------------------------------
//! get the value at a material point
mat3ds FEDomainMap::valueMat3ds(const FEMaterialPoint& pt)
{
assert(DataType() == FEDataType::FE_MAT3DS);
// get the element this material point is in
FEElement* pe = pt.m_elem;
assert(pe);
// see if this element belongs to the element set
assert(m_elset);
int lid = m_elset->GetLocalIndex(*pe);
assert((lid >= 0));
mat3ds Q;
if (m_fmt == FMT_ITEM)
{
Q = get<mat3ds>(lid);
}
else if (m_fmt == FMT_NODE)
{
// calculate shape function values
double* w = pe->H(pt.m_index);
mat3ds Qi[FEElement::MAX_NODES];
int ne = pe->Nodes();
for (int i = 0; i < ne; ++i)
{
int nid = pe->m_node[i];
int lid = m_NLT[nid] - m_imin;
assert((lid >= 0) && (lid < DataCount()));
Qi[i] = get<mat3ds>(lid);
}
// weighted average
Q = weightedAverageStructureTensor(Qi, w, ne);
}
else if (m_fmt == FMT_MATPOINTS)
{
return value<mat3ds>(lid, pt.m_index);
}
return Q;
}
//-----------------------------------------------------------------------------
double FEDomainMap::NodalValue(int nid)
{
if (StorageFormat() != FMT_NODE) { assert(false); return 0.0; }
int m = m_NLT[nid - m_imin];
double v = value<double>(0, m);
return v;
}
//-----------------------------------------------------------------------------
// merge with another map
bool FEDomainMap::Merge(FEDomainMap& map)
{
// make sure the type and format are the same
if (map.DataType() != DataType()) return false;
if (map.StorageFormat() != map.StorageFormat()) return false;
// get the two element sets
FEElementSet* set1 = m_elset;
const FEElementSet* set2 = map.GetElementSet();
assert(set1->GetMesh() == set2->GetMesh());
// create a new element set
// TODO: should we add it to the mesh? I think we probably have to for remeshing
FEElementSet* elset = new FEElementSet(set1->GetMesh());
elset->Add(*set1);
elset->Add(*set2);
// reallocate the data array
int oldElems = set1->Elements();
int newElems = elset->Elements();
if (StorageFormat() == FMT_MULT)
{
if (DataType() == FE_DOUBLE)
{
// get the max element nodes
int maxElemNodes = m_maxElemNodes;
if (map.m_maxElemNodes > maxElemNodes) maxElemNodes = map.m_maxElemNodes;
Realloc(newElems, maxElemNodes);
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
int n = set2->Element(i).Nodes();
for (int j = 0; j < n; ++j)
{
double v = map.value<double>(i, j);
setValue<double>(oldElems + i, j, v);
}
}
}
else if (DataType() == FE_VEC3D)
{
// get the max element nodes
int maxElemNodes = m_maxElemNodes;
if (map.m_maxElemNodes > maxElemNodes) maxElemNodes = map.m_maxElemNodes;
Realloc(newElems, maxElemNodes);
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
int n = set2->Element(i).Nodes();
for (int j = 0; j < n; ++j)
{
vec3d v = map.value<vec3d>(i, j);
setValue<vec3d>(oldElems + i, j, v);
}
}
}
else assert(false);
}
else if (StorageFormat() == FMT_MATPOINTS)
{
assert(DataType() == FE_DOUBLE);
// get the max element nodes
int maxElemNodes = m_maxElemNodes;
if (map.m_maxElemNodes > maxElemNodes) maxElemNodes = map.m_maxElemNodes;
Realloc(newElems, maxElemNodes);
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
int n = set2->Element(i).GaussPoints();
for (int j = 0; j < n; ++j)
{
double v = map.value<double>(i, j);
setValue<double>(oldElems + i, j, v);
}
}
}
else if (StorageFormat() == FMT_ITEM)
{
realloc(newElems);
switch (DataType())
{
case FE_DOUBLE:
{
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
double v = map.get<double>(i);
set<double>(oldElems + i, v);
}
}
break;
case FE_VEC3D:
{
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
vec3d v = map.get<vec3d>(i);
set<vec3d>(oldElems + i, v);
}
}
break;
case FE_MAT3D:
{
// set the new values of the map
for (int i = 0; i < set2->Elements(); ++i)
{
mat3d v = map.get<mat3d>(i);
set<mat3d>(oldElems + i, v);
}
}
break;
default:
assert(false);
}
}
m_elset = elset;
return true;
}
//-----------------------------------------------------------------------------
void FEDomainMap::Realloc(int newElemSize, int newMaxElemNodes)
{
int oldMaxElemNodes = m_maxElemNodes;
assert(newMaxElemNodes >= oldMaxElemNodes);
if (newMaxElemNodes == oldMaxElemNodes) realloc(newElemSize*newMaxElemNodes);
else
{
FEDomainMap oldData(*this);
m_maxElemNodes = newMaxElemNodes;
realloc(newElemSize*newMaxElemNodes);
FEElementSet* set = m_elset;
for (int i = 0; i < set->Elements(); ++i)
{
int n = set->Element(i).Nodes();
if (StorageFormat() == FMT_MATPOINTS) n = set->Element(i).GaussPoints();
for (int j = 0; j < n; ++j)
{
double v = oldData.get<double>(i*oldMaxElemNodes + j);
setValue<double>(i, j, v);
}
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/ad.cpp | .cpp | 2,878 | 101 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "ad.h"
double ad::Evaluate(std::function<ad::number(vec3d&)> W, const ::vec3d& a)
{
ad::vec3d da(a);
return W(da).r;
}
::vec3d ad::Grad(std::function<ad::number(vec3d&)> W, const ::vec3d& a)
{
ad::vec3d da(a);
da.x.dr = 1; da.y.dr = 0; da.z.dr = 0; double dx = W(da).dr;
da.x.dr = 0; da.y.dr = 1; da.z.dr = 0; double dy = W(da).dr;
da.x.dr = 0; da.y.dr = 0; da.z.dr = 1; double dz = W(da).dr;
return ::vec3d(dx, dy, dz);
}
::mat3d ad::Grad(std::function<ad::vec3d(ad::vec3d&)> F, const ::vec3d& a)
{
ad::vec3d da(a);
double D[3][3] = { 0 };
for (int i = 0; i < 3; ++i)
{
da[i].dr = 1;
::vec3d Fi = F(da).partials();
da[i].dr = 0;
D[0][i] = Fi.x;
D[1][i] = Fi.y;
D[2][i] = Fi.z;
}
return ::mat3d(D);
}
double ad::Evaluate(std::function<ad::number(ad::mat3ds& C)> W, const ::mat3ds& C)
{
ad::mat3ds dC(C);
return W(dC).r;
}
::mat3ds ad::Derive(std::function<ad::number(ad::mat3ds& C)> W, const ::mat3ds& C)
{
ad::mat3ds dC(C);
double S[6] = { 0.0 };
for (int i = 0; i < 6; ++i)
{
dC[i].dr = 1;
S[i] = W(dC).dr;
dC[i].dr = 0;
}
return ::mat3ds(S[0], S[2], S[5], 0.5 * S[1], 0.5 * S[4], 0.5 * S[3]);
}
::tens4ds ad::Derive(std::function<mat3ds(mat3ds& C)> S, const ::mat3ds& C)
{
ad::mat3ds dC(C);
constexpr int l[6] = { 0, 2, 5, 1, 4, 3 };
double D[6][6] = { 0 };
for (int i = 0; i < 6; ++i)
{
int n = l[i];
dC[n].dr = 1;
::mat3ds Si = S(dC).partials();
dC[n].dr = 0;
D[0][i] = Si.xx();
D[1][i] = Si.yy();
D[2][i] = Si.zz();
D[3][i] = 0.5 * Si.xy();
D[4][i] = 0.5 * Si.yz();
D[5][i] = 0.5 * Si.xz();
}
return tens4ds(D);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FESolidElement.cpp | .cpp | 3,730 | 110 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FESolidElement.h"
#include "DumpStream.h"
//=================================================================================================
// FESolidElement
//=================================================================================================
//-----------------------------------------------------------------------------
FESolidElement::FESolidElement(const FESolidElement& el)
{
// set the traits of the element
if (el.m_pT) { SetTraits(el.m_pT); m_State = el.m_State; }
// copy base class data
m_mat = el.m_mat;
m_nID = el.m_nID;
m_lid = el.m_lid;
m_node = el.m_node;
m_lnode = el.m_lnode;
m_lm = el.m_lm;
m_val = el.m_val;
m_status = el.m_status;
}
FESolidElement& FESolidElement::operator = (const FESolidElement& el)
{
// set the traits of the element
if (el.m_pT) { SetTraits(el.m_pT); m_State = el.m_State; }
// copy base class data
m_mat = el.m_mat;
m_nID = el.m_nID;
m_lid = el.m_lid;
m_node = el.m_node;
m_lnode = el.m_lnode;
m_lm = el.m_lm;
m_val = el.m_val;
m_status = el.m_status;
return (*this);
}
void FESolidElement::SetTraits(FEElementTraits* pt)
{
FEElement::SetTraits(pt);
int ni = GaussPoints();
m_J0i.resize(ni);
}
vec3d FESolidElement::evaluate(vec3d* v, double r, double s, double t) const
{
double H[FEElement::MAX_NODES];
shape_fnc(H, r, s, t);
int neln = Nodes();
vec3d p(0, 0, 0);
for (int i = 0; i<neln; ++i) p += v[i] * H[i];
return p;
}
double FESolidElement::evaluate(double* v, double r, double s, double t) const
{
double H[FEElement::MAX_NODES];
shape_fnc(H, r, s, t);
int neln = Nodes();
double p = 0.0;
for (int i = 0; i<neln; ++i) p += v[i] * H[i];
return p;
}
double* FESolidElement::Gr(int order, int n) const { return (order >= 0 ? ((FESolidElementTraits*)(m_pT))->m_Gr_p[order][n] : ((FESolidElementTraits*)(m_pT))->m_Gr[n]); } // shape function derivative to r
double* FESolidElement::Gs(int order, int n) const { return (order >= 0 ? ((FESolidElementTraits*)(m_pT))->m_Gs_p[order][n] : ((FESolidElementTraits*)(m_pT))->m_Gs[n]); } // shape function derivative to s
double* FESolidElement::Gt(int order, int n) const { return (order >= 0 ? ((FESolidElementTraits*)(m_pT))->m_Gt_p[order][n] : ((FESolidElementTraits*)(m_pT))->m_Gt[n]); } // shape function derivative to t
void FESolidElement::Serialize(DumpStream& ar)
{
FEElement::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_J0i;
ar & m_bitfc;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMat3dsValuator.h | .h | 2,917 | 100 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEValuator.h"
class FEDataMap;
//---------------------------------------------------------------------------------------
// Base class for evaluating vec3d parameters
class FECORE_API FEMat3dsValuator : public FEValuator
{
FECORE_SUPER_CLASS(FEMAT3DSVALUATOR_ID)
FECORE_BASE_CLASS(FEMat3dsValuator)
public:
FEMat3dsValuator(FEModel* fem) : FEValuator(fem) {};
virtual mat3ds operator()(const FEMaterialPoint& pt) = 0;
virtual FEMat3dsValuator* copy() = 0;
virtual bool isConst() { return false; }
virtual mat3ds* constValue() { return nullptr; }
};
//-----------------------------------------------------------------------------
// A constant valuator
class FECORE_API FEConstValueMat3ds : public FEMat3dsValuator
{
public:
FEConstValueMat3ds(FEModel* fem);
FEMat3dsValuator* copy() override;
mat3ds 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)
mat3ds* constValue() override { return &m_val; }
mat3ds& value() { return m_val; }
private:
mat3ds m_val;
DECLARE_FECORE_CLASS();
};
//---------------------------------------------------------------------------------------
class FECORE_API FEMappedValueMat3ds : public FEMat3dsValuator
{
public:
FEMappedValueMat3ds(FEModel* fem);
void setDataMap(FEDataMap* val);
mat3ds operator()(const FEMaterialPoint& pt) override;
FEMat3dsValuator* copy() override;
void Serialize(DumpStream& ar) override;
private:
std::string m_mapName;
private:
FEDataMap* m_val;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMeshAdaptorCriterion.cpp | .cpp | 3,261 | 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 "FEMeshAdaptorCriterion.h"
#include "FEMeshAdaptor.h"
#include "FEModel.h"
#include "FEMesh.h"
#include <algorithm>
//=============================================================================
void FEMeshAdaptorSelection::Sort(FEMeshAdaptorSelection::SortFlag sortFlag)
{
if (sortFlag == SORT_DECREASING)
{
std::sort(m_itemList.begin(), m_itemList.end(), [](Item& e1, Item& e2) {
return (e1.m_elemValue > e2.m_elemValue);
});
}
else
{
std::sort(m_itemList.begin(), m_itemList.end(), [](Item& e1, Item& e2) {
return (e1.m_elemValue < e2.m_elemValue);
});
}
}
//=============================================================================
BEGIN_FECORE_CLASS(FEMeshAdaptorCriterion, FEModelComponent)
END_FECORE_CLASS();
FEMeshAdaptorCriterion::FEMeshAdaptorCriterion(FEModel* fem) : FEModelComponent(fem)
{
}
// return a list of elements that satisfy the criterion
FEMeshAdaptorSelection FEMeshAdaptorCriterion::GetElementSelection(FEElementSet* elemSet)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// allocate iterator
FEElementIterator it(&mesh, elemSet);
// loop over elements
FEMeshAdaptorSelection selectedElements;
for (;it.isValid(); ++it)
{
FEElement& el = *it;
if (el.isActive())
{
// evaluate element average
double elemVal = 0;
bool bvalid = GetElementValue(el, elemVal);
if (bvalid)
{
int nid = el.GetID();
selectedElements.push_back(nid, elemVal);
}
}
}
return selectedElements;
}
bool FEMeshAdaptorCriterion::GetElementValue(FEElement& el, double& value)
{
value = 0.0;
int ni = el.GaussPoints(), nv = 0;
for (int i = 0; i < ni; ++i)
{
double vali = 0.0;
bool b = GetMaterialPointValue(*el.GetMaterialPoint(i), vali);
if (b) { value += vali; nv++; }
}
if (nv > 0)
{
value /= (double)nv;
return true;
}
else return false;
}
bool FEMeshAdaptorCriterion::GetMaterialPointValue(FEMaterialPoint& mp, double& elemVal)
{
return false;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FECoreKernel.cpp | .cpp | 24,192 | 875 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FECoreKernel.h"
#include "LinearSolver.h"
#include "Timer.h"
#include "FEModule.h"
#include <stdarg.h>
#include "log.h"
using namespace std;
//-----------------------------------------------------------------------------
FECoreKernel* FECoreKernel::m_pKernel = 0;
//-----------------------------------------------------------------------------
FECoreKernel& FECoreKernel::GetInstance()
{
if (m_pKernel == 0) m_pKernel = new FECoreKernel;
return *m_pKernel;
}
//-----------------------------------------------------------------------------
// This function is used by plugins to make sure that the plugin and the executable
// are using the same kernel
void FECoreKernel::SetInstance(FECoreKernel* pkernel)
{
m_pKernel = pkernel;
}
//-----------------------------------------------------------------------------
const char* FECoreKernel::SuperClassString(unsigned int sid)
{
FECoreKernel& fecore = GetInstance();
if (fecore.m_sidMap.find(sid) != fecore.m_sidMap.end())
return fecore.m_sidMap[sid];
else
return nullptr;
}
//-----------------------------------------------------------------------------
std::map<unsigned int, const char*> FECoreKernel::GetSuperClassMap()
{
FECoreKernel& fecore = GetInstance();
return fecore.m_sidMap;
}
//-----------------------------------------------------------------------------
#define ADD_SUPER_CLASS(a) m_sidMap[a] = #a
FECoreKernel::FECoreKernel()
{
m_activeModule = -1;
m_alloc_id = 0;
m_next_alloc_id = 1;
m_nspec = -1;
m_default_solver = nullptr;
m_bshowDeprecationWarning = true;
// build the super class ID table
ADD_SUPER_CLASS(FEINVALID_ID);
ADD_SUPER_CLASS(FEOBJECT_ID);
ADD_SUPER_CLASS(FETASK_ID);
ADD_SUPER_CLASS(FESOLVER_ID);
ADD_SUPER_CLASS(FEMATERIAL_ID);
ADD_SUPER_CLASS(FEMATERIALPROP_ID);
ADD_SUPER_CLASS(FEDISCRETEMATERIAL_ID);
ADD_SUPER_CLASS(FELOAD_ID);
ADD_SUPER_CLASS(FENLCONSTRAINT_ID);
ADD_SUPER_CLASS(FEPLOTDATA_ID);
ADD_SUPER_CLASS(FEANALYSIS_ID);
ADD_SUPER_CLASS(FESURFACEINTERFACE_ID);
ADD_SUPER_CLASS(FELOGNODEDATA_ID);
ADD_SUPER_CLASS(FELOGFACEDATA_ID);
ADD_SUPER_CLASS(FELOGELEMDATA_ID);
ADD_SUPER_CLASS(FELOGOBJECTDATA_ID);
ADD_SUPER_CLASS(FELOGDOMAINDATA_ID);
ADD_SUPER_CLASS(FELOGNLCONSTRAINTDATA_ID);
ADD_SUPER_CLASS(FELOGSURFACEDATA_ID);
ADD_SUPER_CLASS(FELOGMODELDATA_ID);
ADD_SUPER_CLASS(FEBC_ID);
ADD_SUPER_CLASS(FEGLOBALDATA_ID);
ADD_SUPER_CLASS(FECALLBACK_ID);
ADD_SUPER_CLASS(FESOLIDDOMAIN_ID);
ADD_SUPER_CLASS(FESHELLDOMAIN_ID);
ADD_SUPER_CLASS(FEBEAMDOMAIN_ID);
ADD_SUPER_CLASS(FEDISCRETEDOMAIN_ID);
ADD_SUPER_CLASS(FEDOMAIN2D_ID);
ADD_SUPER_CLASS(FESURFACE_ID);
ADD_SUPER_CLASS(FEEDGE_ID);
ADD_SUPER_CLASS(FEIC_ID);
ADD_SUPER_CLASS(FEMESHDATAGENERATOR_ID);
ADD_SUPER_CLASS(FELOADCONTROLLER_ID);
ADD_SUPER_CLASS(FEMODEL_ID);
ADD_SUPER_CLASS(FESCALARVALUATOR_ID);
ADD_SUPER_CLASS(FEVEC3DVALUATOR_ID);
ADD_SUPER_CLASS(FEMAT3DVALUATOR_ID);
ADD_SUPER_CLASS(FEMAT3DSVALUATOR_ID);
ADD_SUPER_CLASS(FEFUNCTION1D_ID);
ADD_SUPER_CLASS(FELINEARSOLVER_ID);
ADD_SUPER_CLASS(FEMESHADAPTOR_ID);
ADD_SUPER_CLASS(FEMESHADAPTORCRITERION_ID);
ADD_SUPER_CLASS(FENEWTONSTRATEGY_ID);
ADD_SUPER_CLASS(FETIMECONTROLLER_ID);
ADD_SUPER_CLASS(FEEIGENSOLVER_ID);
ADD_SUPER_CLASS(FEDATARECORD_ID);
ADD_SUPER_CLASS(FECLASS_ID);
}
//-----------------------------------------------------------------------------
// Generate a allocator ID
int FECoreKernel::GenerateAllocatorID()
{
return m_next_alloc_id++;
}
//-----------------------------------------------------------------------------
FECoreFactory* FECoreKernel::SetDefaultSolverType(const char* sztype)
{
FECoreFactory* fac = FindFactoryClass(FELINEARSOLVER_ID, sztype);
if (fac) m_default_solver_type = sztype;
return fac;
}
//-----------------------------------------------------------------------------
void FECoreKernel::SetDefaultSolver(FEClassDescriptor* linsolve)
{
delete m_default_solver;
m_default_solver = linsolve;
if (linsolve)
{
m_default_solver_type = linsolve->ClassType();
}
else
{
m_default_solver_type.clear();
}
}
//-----------------------------------------------------------------------------
//! get the linear solver type
const char* FECoreKernel::GetLinearSolverType() const
{
return m_default_solver_type.c_str();
}
//-----------------------------------------------------------------------------
LinearSolver* FECoreKernel::CreateDefaultLinearSolver(FEModel* fem)
{
if (m_default_solver == nullptr)
{
const char* sztype = m_default_solver_type.c_str();
FECoreFactory* fac = FindFactoryClass(FELINEARSOLVER_ID, sztype);
return (LinearSolver*)CreateInstance(fac, fem);
}
else
{
return (LinearSolver*)Create(FELINEARSOLVER_ID, fem, *m_default_solver);
}
}
//-----------------------------------------------------------------------------
void FECoreKernel::RegisterFactory(FECoreFactory* ptf)
{
unsigned int activeID = 0;
if (m_activeModule != -1)
{
FEModule& activeModule = *m_modules[m_activeModule];
activeID = activeModule.GetModuleID();
}
// see if the name already exists
for (int i=0; i<m_Fac.size(); ++i)
{
FECoreFactory* pfi = m_Fac[i];
if ((pfi->GetSuperClassID() == ptf->GetSuperClassID()) &&
(strcmp(pfi->GetTypeStr(), ptf->GetTypeStr()) == 0))
{
// A feature with the same is already registered.
// We need to check the module to see if this would create an ambiguity
unsigned int modId = pfi->GetModuleID();
// If the same feature is defined in the active module,
// then this feature will replace the existing one.
if ((modId == activeID) && (pfi->GetSpecID() == ptf->GetSpecID()))
{
fprintf(stderr, "WARNING: \"%s\" feature is redefined\n", ptf->GetTypeStr());
m_Fac[i] = ptf;
return;
}
}
}
// it doesn't so add it
ptf->SetModuleID(activeID);
ptf->SetAllocatorID(m_alloc_id);
m_Fac.push_back(ptf);
}
//-----------------------------------------------------------------------------
bool FECoreKernel::UnregisterFactory(FECoreFactory* ptf)
{
for (vector<FECoreFactory*>::iterator it = m_Fac.begin(); it != m_Fac.end(); ++it)
{
FECoreFactory* pfi = *it;
if (pfi == ptf)
{
m_Fac.erase(it);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
//! unregister factories from allocator
void FECoreKernel::UnregisterFactories(int alloc_id)
{
for (vector<FECoreFactory*>::iterator it = m_Fac.begin(); it != m_Fac.end();)
{
FECoreFactory* pfi = *it;
if (pfi->GetAllocatorID() == alloc_id)
{
it = m_Fac.erase(it);
}
else ++it;
}
}
//! unregister modules from allocator
void FECoreKernel::UnregisterModules(int alloc_id)
{
for (vector<FEModule*>::iterator it = m_modules.begin(); it != m_modules.end();)
{
FEModule* pfi = *it;
int alloc = pfi->GetAllocID();
if (pfi->GetAllocID() == alloc_id)
{
it = m_modules.erase(it);
}
else ++it;
}
}
//-----------------------------------------------------------------------------
//! set the current allocator ID
void FECoreKernel::SetAllocatorID(int alloc_id)
{
m_alloc_id = alloc_id;
}
//-----------------------------------------------------------------------------
//! Create an object. An object is created by specifying the super-class id
//! and the type-string.
FECoreBase* FECoreKernel::Create(int superClassID, const char* sztype, FEModel* pfem)
{
FECoreFactory* fac = FindFactoryClass(superClassID, sztype);
if (fac == nullptr) return nullptr;
return CreateInstance(fac, pfem);
}
//-----------------------------------------------------------------------------
//! Create an object. An object is created by specifying the super-class id
//! and the type-string.
FECoreBase* FECoreKernel::Create(int superClassID, const char* sztype, const char* szmod, FEModel* pfem)
{
FECoreFactory* fac = FindFactoryClass(superClassID, sztype, szmod);
if (fac == nullptr) return nullptr;
return CreateInstance(fac, pfem);
}
//-----------------------------------------------------------------------------
//! Create an object. An object is created by specifying the super-class id
//! and the type-string.
FECoreBase* FECoreKernel::Create(const char* szbase, const char* sztype, FEModel* pfem)
{
if (szbase == nullptr) return nullptr;
if (sztype == nullptr) return nullptr;
unsigned int activeID = 0;
vector<int> moduleDepends;
if (m_activeModule != -1)
{
FEModule& activeModule = *m_modules[m_activeModule];
activeID = activeModule.GetModuleID();
moduleDepends = activeModule.GetDependencies();
}
// first check active module
if ((activeID > 0) || (activeID == 0))
{
std::vector<FECoreFactory*>::iterator pf;
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (strcmp(pfac->GetBaseClassName(), szbase) == 0) {
// see if we can match module first
unsigned int mid = pfac->GetModuleID();
if ((mid == activeID) || (mid == 0))
{
// see if the type name matches
if ((strcmp(pfac->GetTypeStr(), sztype) == 0))
{
// check the spec (TODO: What is this for?)
int nspec = pfac->GetSpecID();
if ((nspec == -1) || (m_nspec <= nspec))
{
return CreateInstance(pfac, pfem);
}
}
}
}
}
}
// check dependencies in order in which they are defined
std::vector<FECoreFactory*>::iterator pf;
for (int i = 0; i < moduleDepends.size(); ++i)
{
unsigned modId = moduleDepends[i];
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (strcmp(pfac->GetBaseClassName(), szbase) == 0) {
// see if we can match module first
unsigned int mid = pfac->GetModuleID();
if ((mid == 0) || (mid == modId))
{
// see if the type name matches
if ((strcmp(pfac->GetTypeStr(), sztype) == 0))
{
// check the spec (TODO: What is this for?)
int nspec = pfac->GetSpecID();
if ((nspec == -1) || (m_nspec <= nspec))
{
return CreateInstance(pfac, pfem);
}
}
}
}
}
}
return 0;
}
//-----------------------------------------------------------------------------
//! Create a specific class
FECoreBase* FECoreKernel::CreateClass(const char* szclassName, FEModel* fem)
{
std::vector<FECoreFactory*>::iterator pf;
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
const char* szfacName = pfac->GetClassName();
if (szfacName && (strcmp(szfacName, szclassName) == 0))
{
return CreateInstance(pfac, fem);
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! Create a class from a class descriptor
FECoreBase* FECoreKernel::Create(int superClassID, FEModel* pfem, const FEClassDescriptor& cd)
{
const FEClassDescriptor::ClassVariable* root = cd.Root();
FECoreBase* pc = (FECoreBase*)Create(superClassID, root->m_type.c_str(), pfem);
if (pc == nullptr) return nullptr;
pc->SetParameters(cd);
return pc;
}
//-----------------------------------------------------------------------------
bool FECoreKernel::IsModuleActive(int moduleID)
{
if (moduleID <= 0) return true;
if (m_activeModule < 0) return false;
FEModule* mod = GetActiveModule();
if (mod == nullptr) return false;
if (mod->GetModuleID() == moduleID) return true;
std::vector<int> deps = mod->GetDependencies();
for (int i = 0; i < deps.size(); ++i)
{
if (deps[i] == moduleID) return true;
}
return false;
}
//-----------------------------------------------------------------------------
FECoreBase* FECoreKernel::CreateInstance(const FECoreFactory* fac, FEModel* fem)
{
FECoreBase* pc = fac->CreateInstance(fem);
int nspec = fac->GetSpecID();
if (m_bshowDeprecationWarning && (nspec != -1) && fem)
{
if (nspec == FECORE_EXPERIMENTAL)
{
feLogWarningEx(fem, "\"%s\" is considered experimental!", fac->GetTypeStr());
}
else
{
int n1 = FECORE_SPEC_MAJOR(nspec);
int n2 = FECORE_SPEC_MINOR(nspec);
feLogWarningEx(fem, "\"%s\" is deprecated in spec %d.%d!", fac->GetTypeStr(), n1, n2);
}
}
return pc;
}
//-----------------------------------------------------------------------------
int FECoreKernel::Count(SUPER_CLASS_ID sid)
{
int N = 0;
std::vector<FECoreFactory*>::iterator pf;
for (pf=m_Fac.begin(); pf!= m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (pfac->GetSuperClassID() == sid) N++;
}
return N;
}
//-----------------------------------------------------------------------------
void FECoreKernel::List(SUPER_CLASS_ID sid)
{
std::vector<FECoreFactory*>::iterator pf;
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (pfac->GetSuperClassID() == sid) fprintf(stdout, "%s\n", pfac->GetTypeStr());
}
}
//-----------------------------------------------------------------------------
int FECoreKernel::FactoryClasses()
{
return (int) m_Fac.size();
}
//-----------------------------------------------------------------------------
const FECoreFactory* FECoreKernel::GetFactoryClass(int i)
{
if ((i < 0) || (i >= m_Fac.size())) return nullptr;
else return m_Fac[i];
}
//-----------------------------------------------------------------------------
//! return a factory class
const FECoreFactory* FECoreKernel::GetFactoryClass(int classID, int i)
{
int n = 0;
for (int j = 0; j < m_Fac.size(); ++j)
{
FECoreFactory* fac = m_Fac[j];
if (fac->GetSuperClassID() == classID)
{
if (i == n) return fac;
n++;
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! return a factory class
int FECoreKernel::GetFactoryIndex(int superClassId, const char* sztype)
{
FEModule* mod = GetActiveModule();
if (mod == nullptr) return -1;
for (int j = 0; j < m_Fac.size(); ++j)
{
FECoreFactory* fac = m_Fac[j];
int modId = fac->GetModuleID();
// check the super-class first
if (fac->GetSuperClassID() == superClassId)
{
// check the string name
if (strcmp(sztype, fac->GetTypeStr()) == 0)
{
// make sure it's part of the active module
if ((modId == 0) || (mod->HasDependent(modId))) return j;
}
}
}
return -1;
}
//-----------------------------------------------------------------------------
FECoreFactory* FECoreKernel::FindFactoryClass(int superID, const char* sztype)
{
if (sztype == nullptr) return nullptr;
unsigned int activeID = 0;
vector<int> moduleDepends;
if (m_activeModule != -1)
{
FEModule& activeModule = *m_modules[m_activeModule];
activeID = activeModule.GetModuleID();
moduleDepends = activeModule.GetDependencies();
}
// first check active module
if ((activeID > 0) || (activeID == 0))
{
std::vector<FECoreFactory*>::iterator pf;
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (pfac->GetSuperClassID() == superID) {
// see if we can match module first
unsigned int mid = pfac->GetModuleID();
if ((mid == activeID) || (mid == 0))
{
// see if the type name matches
if ((strcmp(pfac->GetTypeStr(), sztype) == 0))
{
// check the spec (TODO: What is this for?)
int nspec = pfac->GetSpecID();
if ((nspec == -1) || (m_nspec <= nspec))
{
return pfac;
}
}
}
}
}
}
// check dependencies in order in which they are defined
std::vector<FECoreFactory*>::iterator pf;
for (int i = 0; i < moduleDepends.size(); ++i)
{
unsigned modId = moduleDepends[i];
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (pfac->GetSuperClassID() == superID) {
// see if we can match module first
unsigned int mid = pfac->GetModuleID();
if ((mid == 0) || (mid == modId))
{
// see if the type name matches
if ((strcmp(pfac->GetTypeStr(), sztype) == 0))
{
// check the spec (TODO: What is this for?)
int nspec = pfac->GetSpecID();
if ((nspec == -1) || (m_nspec <= nspec))
{
return pfac;
}
}
}
}
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
FECoreFactory* FECoreKernel::FindFactoryClass(int superID, const char* sztype, const char* szmod)
{
if (sztype == nullptr) return nullptr;
int modId = FindModuleID(szmod);
if (modId == -1) return nullptr;
std::vector<FECoreFactory*>::iterator pf;
for (pf = m_Fac.begin(); pf != m_Fac.end(); ++pf)
{
FECoreFactory* pfac = *pf;
if (pfac->GetSuperClassID() == superID) {
// see if we can match module first
unsigned int mid = pfac->GetModuleID();
if (mid == modId)
{
// see if the type name matches
if ((strcmp(pfac->GetTypeStr(), sztype) == 0))
{
// check the spec (TODO: What is this for?)
int nspec = pfac->GetSpecID();
if ((nspec == -1) || (m_nspec <= nspec))
{
return pfac;
}
}
}
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! set the active module
bool FECoreKernel::SetActiveModule(const char* szmod)
{
// See if user want to deactivate modules
if (szmod == 0)
{
m_activeModule = -1;
return true;
}
// see if the module exists or not
for (size_t i=0; i<m_modules.size(); ++i)
{
FEModule& mi = *m_modules[i];
if (strcmp(mi.GetName(), szmod) == 0)
{
m_activeModule = (int) i;
return true;
}
}
// couldn't find it
m_activeModule = -1;
return false;
}
//-----------------------------------------------------------------------------
bool FECoreKernel::SetActiveModule(int moduleId)
{
if (moduleId < 0) return false;
if (GetActiveModuleID() == moduleId) return true;
// see if the module exists or not
for (size_t i = 0; i < m_modules.size(); ++i)
{
FEModule& mi = *m_modules[i];
if (mi.GetModuleID() == moduleId)
{
m_activeModule = (int)i;
return true;
}
}
// couldn't find it
m_activeModule = -1;
return false;
}
//-----------------------------------------------------------------------------
// return the active module's ID
int FECoreKernel::GetActiveModuleID()
{
if (m_activeModule == -1) return -1;
return m_modules[m_activeModule]->GetModuleID();
}
//-----------------------------------------------------------------------------
FEModule* FECoreKernel::GetActiveModule()
{
if (m_activeModule == -1) return nullptr;
return m_modules[m_activeModule];
}
//-----------------------------------------------------------------------------
//! count modules
int FECoreKernel::Modules() const
{
return (int)m_modules.size();
}
//-----------------------------------------------------------------------------
//! create a module
bool FECoreKernel::CreateModule(const char* szmod, const char* description)
{
FEModule* mod = new FEModule();
return CreateModule(mod, szmod, description);
}
//-----------------------------------------------------------------------------
//! create a module
bool FECoreKernel::CreateModule(FEModule* pmodule, const char* szmod, const char* description)
{
assert(pmodule);
if (pmodule == nullptr) return false;
m_activeModule = -1;
if (szmod == 0) return false;
// see if this module already exist
if (SetActiveModule(szmod) == false)
{
// The module does not exist, so let's add it.
unsigned int newID = (unsigned int)m_modules.size() + 1;
pmodule->SetName(szmod);
pmodule->SetID(newID);
pmodule->SetDescription(description);
pmodule->SetAllocID(m_alloc_id);
m_modules.push_back(pmodule);
// make this the active module
m_activeModule = (int)m_modules.size() - 1;
}
else return false;
return true;
}
//-----------------------------------------------------------------------------
//! Get a module
const char* FECoreKernel::GetModuleName(int i) const
{
if ((i<0) || (i >= m_modules.size())) return nullptr;
return m_modules[i]->GetName();
}
const char* FECoreKernel::GetModuleDescription(int i) const
{
if ((i < 0) || (i >= m_modules.size())) return nullptr;
return m_modules[i]->GetDescription();
}
int FECoreKernel::GetModuleStatus(int i) const
{
if ((i < 0) || (i >= m_modules.size())) return -1;
return m_modules[i]->GetStatus();
}
int FECoreKernel::GetModuleAllocatorID(int i) const
{
if ((i < 0) || (i >= m_modules.size())) return -1;
return m_modules[i]->GetAllocID();
}
int FECoreKernel::FindModuleID(const char* szmodule) const
{
if (szmodule == 0) return -1;
for (size_t i = 0; i<m_modules.size(); ++i)
{
FEModule& mi = *m_modules[i];
if (strcmp(mi.GetName(), szmodule) == 0) return mi.GetModuleID();
}
return -1;
}
//! Get a module
const char* FECoreKernel::GetModuleNameFromId(int id) const
{
for (size_t n = 0; n < m_modules.size(); ++n)
{
const FEModule& mod = *m_modules[n];
if (mod.GetModuleID() == id) return mod.GetName();
}
return 0;
}
//! Get a module's dependencies
vector<int> FECoreKernel::GetModuleDependencies(int i) const
{
vector<int> md;
if ((i >= 0) && (i < m_modules.size()))
{
md = m_modules[i]->GetDependencies();
}
return md;
}
//-----------------------------------------------------------------------------
//! set the spec ID. Features with a matching spec ID will be preferred
//! set spec ID to -1 to stop caring
void FECoreKernel::SetSpecID(int nspec)
{
m_nspec = nspec;
}
//-----------------------------------------------------------------------------
//! set a dependency on a module
bool FECoreKernel::AddModuleDependency(const char* szmodule)
{
if (m_activeModule == -1) return false;
FEModule& activeModule = *m_modules[m_activeModule];
if (szmodule == 0)
{
// clear dependencies
activeModule.ClearDependencies();
return true;
}
// find the module
for (size_t i = 0; i<m_modules.size(); ++i)
{
FEModule& mi = *m_modules[i];
if (strcmp(mi.GetName(), szmodule) == 0)
{
// add the module to the active module's dependency list
activeModule.AddDependency(mi);
return true;
}
}
// oh, oh, couldn't find it
return false;
}
//-----------------------------------------------------------------------------
//! Register a new domain class
void FECoreKernel::RegisterDomain(FEDomainFactory* pf, bool pushFront)
{
if (pushFront)
m_Dom.insert(m_Dom.begin(), pf);
else
m_Dom.push_back(pf);
}
//-----------------------------------------------------------------------------
FEDomain* FECoreKernel::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat)
{
for (int i=0; i<(int)m_Dom.size(); ++i)
{
FEDomain* pdom = m_Dom[i]->CreateDomain(spec, pm, pmat);
if (pdom != 0) return pdom;
}
return 0;
}
//-----------------------------------------------------------------------------
FEDomain* FECoreKernel::CreateDomainExplicit(int superClass, const char* sztype, FEModel* fem)
{
FEDomain* domain = (FEDomain*)Create(superClass, sztype, fem);
return domain;
}
//-----------------------------------------------------------------------------
void FECoreKernel::ShowDeprecationWarnings(bool b)
{
m_bshowDeprecationWarning = b;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMeshAdaptor.h | .h | 2,554 | 67 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEStepComponent.h"
#include <functional>
//-----------------------------------------------------------------------------
// forward declarations
class FEModel;
class FEElement;
class FEMaterialPoint;
class FEElementSet;
class FEMeshAdaptorCriterion;
//-----------------------------------------------------------------------------
// Base class for all mesh adaptors
class FECORE_API FEMeshAdaptor : public FEStepComponent
{
FECORE_SUPER_CLASS(FEMESHADAPTOR_ID)
FECORE_BASE_CLASS(FEMeshAdaptor);
public:
FEMeshAdaptor(FEModel* fem);
void SetElementSet(FEElementSet* elemSet);
FEElementSet* GetElementSet();
// The mesh adaptor should return true if the mesh was modified.
// otherwise, it should return false.
// iteration is the iteration number of the mesh adaptation loop
virtual bool Apply(int iteration) = 0;
protected:
// call this after the model was updated
void UpdateModel();
private:
FEElementSet* m_elemSet;
};
// helper function for projecting integration point data to nodes
void FECORE_API projectToNodes(FEMesh& mesh, std::vector<double>& nodeVals, std::function<double (FEMaterialPoint& mp)> f);
void FECORE_API projectToNodes(FEDomain& dom, std::vector<double>& nodeVals, std::function<double(FEMaterialPoint& mp)> f);
| Unknown |
3D | febiosoftware/FEBio | FECore/FELinearSolver.h | .h | 3,274 | 107 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FESolver.h"
//-----------------------------------------------------------------------------
// forward declarations
class FEGlobalVector;
class FEGlobalMatrix;
class FELinearSystem;
class LinearSolver;
//-----------------------------------------------------------------------------
//! Abstract Base class for finite element solution algorithms (i.e. "FE solvers") that require the solution
//! of a linear system of equations.
class FECORE_API FELinearSolver : public FESolver
{
public:
//! constructor
FELinearSolver(FEModel* pfem);
//! Set the degrees of freedom
void SetDOF(vector<int>& dof);
//! Get the number of equations
int NumberOfEquations() const;
//! Get the linear solver
LinearSolver* GetLinearSolver() override;
public: // from FESolver
//! solve the step
bool SolveStep() override;
//! Initialize and allocate data
bool Init() override;
//! Clean up data
void Clean() override;
//! Serialization
void Serialize(DumpStream& ar) override;
public: // these functions need to be implemented by the derived class
//! Evaluate the right-hand side "force" vector
virtual void ForceVector(FEGlobalVector& R);
//! Evaluate the stiffness matrix
virtual bool StiffnessMatrix(FELinearSystem& K);
//! Update the model state
virtual void Update(vector<double>& u) override;
protected: // some helper functions
//! Reform the stiffness matrix
bool ReformStiffness();
//! Create and evaluate the stiffness matrix
bool CreateStiffness();
//! get the stiffness matrix
FEGlobalMatrix* GetStiffnessMatrix() override;
//! get the RHS
std::vector<double> GetLoadVector() override;
protected:
vector<double> m_R; //!< RHS vector
vector<double> m_u; //!< vector containing prescribed values
private:
LinearSolver* m_pls; //!< The linear equation solver
FEGlobalMatrix* m_pK; //!< The global stiffness matrix
vector<int> m_dof; //!< list of active degrees of freedom
bool m_breform; //!< matrix reformation flag
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMaterialPointProperty.h | .h | 2,735 | 78 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "FEMaterialPoint.h"
#include "fecore_type.h"
//--------------------------------------------------------------------
// This class defines a material point property. Material point properties
// are used to move data in and out of material points.
class FEMaterialPointProperty
{
public:
FEMaterialPointProperty(FEDataType dataType) : m_type(dataType) {}
virtual ~FEMaterialPointProperty() {}
FEDataType dataType() const { return m_type; }
virtual void set(FEMaterialPoint& mp, const double& v) {}
virtual void set(FEMaterialPoint& mp, const vec3d& v) {}
virtual void set(FEMaterialPoint& mp, const mat3d& v) {}
virtual void get(FEMaterialPoint& mp, double& v) {}
virtual void get(FEMaterialPoint& mp, vec3d& v) {}
virtual void get(FEMaterialPoint& mp, mat3d& v) {}
private:
FEDataType m_type;
};
//--------------------------------------------------------------------
// Template class for defining material point property classes.
// Derived classes need to override the data member.
template <class T, class A> class FEMaterialPointProperty_T : public FEMaterialPointProperty
{
public:
FEMaterialPointProperty_T() : FEMaterialPointProperty(fecoreType<A>::type()) {}
void set(FEMaterialPoint& mp, const A& Q)
{
T& pt = *mp.ExtractData<T>();
data(pt) = Q;
}
void get(FEMaterialPoint& mp, A& Q)
{
T& pt = *mp.ExtractData<T>();
Q = data(pt);
}
virtual A& data(T& pt) = 0;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELinearConstraintManager.h | .h | 3,138 | 99 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FELinearConstraint.h"
#include "table.h"
class FEGlobalMatrix;
class matrix;
//-----------------------------------------------------------------------------
// This class helps manage all the linear constraints
class FECORE_API FELinearConstraintManager
{
public:
FELinearConstraintManager(FEModel* fem);
~FELinearConstraintManager();
// Clear all constraints
void Clear();
// copy data
void CopyFrom(const FELinearConstraintManager& lcm);
// serialize linear constraints
void Serialize(DumpStream& ar);
// build the matrix profile
void BuildMatrixProfile(FEGlobalMatrix& G);
// add the linear constraint
void AddLinearConstraint(FELinearConstraint* lc);
// return number of linear constraints
int LinearConstraints() const;
// return linear constraint
const FELinearConstraint& LinearConstraint(int i) const;
// return linear constraint
FELinearConstraint& LinearConstraint(int i);
//! remove a linear constraint
void RemoveLinearConstraint(int i);
public:
// one-time initialization
bool Initialize();
// activation
bool Activate();
// assemble element residual into global residual
void AssembleResidual(vector<double>& R, vector<int>& en, vector<int>& elm, vector<double>& fe);
// assemble element matrix into (reduced) global matrix
void AssembleStiffness(FEGlobalMatrix& K, vector<double>& R, vector<double>& ui, const vector<int>& en, const vector<int>& lmi, const vector<int>& lmj, const matrix& ke);
// called before the first reformation for each time step
void PrepStep();
// update nodal variables
void Update();
protected:
void InitTable();
private:
FEModel* m_fem;
vector<FELinearConstraint*> m_LinC; //!< linear constraints data
table<int> m_LCT; //!< linear constraint table
vector<double> m_up; //!< the inhomogenous component of the linear constraint
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELinearSolver.cpp | .cpp | 11,024 | 406 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELinearSolver.h"
#include "FEModel.h"
#include "LinearSolver.h"
#include "FEGlobalMatrix.h"
#include "log.h"
#include "FENodeReorder.h"
#include "FELinearSystem.h"
#include "FEBoundaryCondition.h"
#include "FEGlobalVector.h"
#include "FEDomain.h"
#include "FENodalLoad.h"
#include "FESurfaceLoad.h"
#include "FEBodyLoad.h"
#include "DumpStream.h"
#include "FELinearConstraintManager.h"
//-----------------------------------------------------------------------------
//! constructor
FELinearSolver::FELinearSolver(FEModel* pfem) : FESolver(pfem)
{
m_pls = 0;
m_pK = 0;
m_neq = 0;
m_breform = true;
}
//-----------------------------------------------------------------------------
void FELinearSolver::Clean()
{
if (m_pls) m_pls->Destroy();
}
//-----------------------------------------------------------------------------
//! This function sets the degrees of freedom that will be used by this solver.
//! This is used in the InitEquations method that initializes the equation numbers
//! and the Update method which maps the solution of the linear system to the nodal
//! data.
void FELinearSolver::SetDOF(vector<int>& dof)
{
m_dof = dof;
}
//-----------------------------------------------------------------------------
int FELinearSolver::NumberOfEquations() const
{
return m_neq;
}
//-----------------------------------------------------------------------------
//! Get the linear solver
LinearSolver* FELinearSolver::GetLinearSolver()
{
return m_pls;
}
//-----------------------------------------------------------------------------
bool FELinearSolver::Init()
{
if (FESolver::Init() == false) return false;
// 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_pls == 0)
{
FEModel* fem = GetFEModel();
FECoreKernel& fecore = FECoreKernel::GetInstance();
m_pls = fecore.CreateDefaultLinearSolver(fem);
if (m_pls == 0)
{
feLogError("Unknown solver type selected\n");
return false;
}
if (m_part.empty() == false)
{
m_pls->SetPartitions(m_part);
}
}
// allocate storage for the sparse matrix that will hold the stiffness matrix data
// we let the solver allocate the correct type of matrix format
Matrix_Type mtype = MatrixType();
SparseMatrix* pS = m_pls->CreateSparseMatrix(mtype);
if ((pS == 0) && (mtype == 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_pls->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. \n");
}
}
if (pS == 0)
{
feLogError("The selected linear solver does not support the requested matrix format.\nPlease select a different linear solver.\n");
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 StiffnessMatrix routine.
m_pK = new FEGlobalMatrix(pS);
if (m_pK == 0)
{
feLogError("Failed allocating stiffness matrix\n\n");
return false;
}
// Set the matrix formation flag
m_breform = true;
// get number of equations
int neq = m_neq;
// allocate data structures
m_R.resize(neq);
m_u.resize(neq);
return true;
}
//-----------------------------------------------------------------------------
//! Solve an analysis step
bool FELinearSolver::SolveStep()
{
// Make sure we have a linear solver and a stiffness matrix
if (m_pls == 0) return false;
if (m_pK == 0) return false;
// reset counters
m_niter = 0;
m_nrhs = 0;
m_nref = 0;
m_ntotref = 0;
FEModel& fem = *GetFEModel();
// Set up the prescribed dof vector
// The stiffness matrix assembler uses this to update the RHS vector
// for prescribed dofs.
zero(m_u);
int nbc = fem.BoundaryConditions();
for (int i=0; i<nbc; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.PrepStep(m_u, false);
}
// build the right-hand side
// (Is done by the derived class)
zero(m_R);
vector<double> F(m_neq);
FEGlobalVector rhs(fem, m_R, F);
{
TRACK_TIME(TimerID::Timer_Residual);
ForceVector(rhs);
}
// increase RHS counter
m_nrhs++;
// build the stiffness matrix
ReformStiffness();
// solve the equations
vector<double> u(m_neq);
{
TRACK_TIME(TimerID::Timer_LinSol_Backsolve);
if (m_pls->BackSolve(u, m_R) == false)
throw LinearSolverFailed();
}
// print norms
double rnorm = sqrt(m_R*m_R);
double unorm = sqrt(u*u);
feLog("\trhs norm : %15le\n", rnorm);
feLog("\tsolution norm : %15le\n", unorm);
// the prescribed values are stored in m_u, so let's add it
u += m_u;
// update solution
Update(u);
// increase iteration count
m_niter++;
return true;
}
//-----------------------------------------------------------------------------
bool FELinearSolver::ReformStiffness()
{
// recalculate the shape of the stiffness matrix if necessary
if (m_breform)
{
TRACK_TIME(TimerID::Timer_Reform);
if (!CreateStiffness()) return false;
// since it's not likely that the matrix form changes
// in a linear analysis, we don't recalculate the form
m_breform = false;
}
// Make sure it is all set to zero
m_pK->Zero();
// calculate the stiffness matrix
// (This is done by the derived class)
{
TRACK_TIME(TimerID::Timer_Stiffness);
FELinearSystem K(GetFEModel(), *m_pK, m_R, m_u, (m_msymm == REAL_SYMMETRIC));
if (!StiffnessMatrix(K)) return false;
// do call back
FEModel& fem = *GetFEModel();
fem.DoCallback(CB_MATRIX_REFORM);
}
// factorize the stiffness matrix
{
TRACK_TIME(TimerID::Timer_LinSol_Factor);
m_pls->Factor();
}
// increase total nr of reformations
m_nref++;
m_ntotref++;
return true;
}
//-----------------------------------------------------------------------------
bool FELinearSolver::CreateStiffness()
{
// clean up the solver
if (m_pK->NonZeroes()) m_pls->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, true) == 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);
}
// Do the preprocessing of the solver
{
if (!m_pls->PreProcess()) throw FatalError();
}
// done!
return true;
}
//-----------------------------------------------------------------------------
FEGlobalMatrix* FELinearSolver::GetStiffnessMatrix()
{
return m_pK;
}
//-----------------------------------------------------------------------------
//! get the RHS
std::vector<double> FELinearSolver::GetLoadVector()
{
return m_R;
}
//-----------------------------------------------------------------------------
void FELinearSolver::Serialize(DumpStream& ar)
{
FESolver::Serialize(ar);
ar & m_breform & m_neq;
if (ar.IsSaving() == false)
{
// We need to rebuild the stiffness matrix at some point.
// Currently this is done during Activation, but we don't
// call FEAnalysis::Activate after restart so for now,
// I'll just do it here.
// TODO: Find a better way.
FELinearSolver::Init();
}
}
//-----------------------------------------------------------------------------
//! Evaluate the right-hand side "force" vector
void FELinearSolver::ForceVector(FEGlobalVector& R)
{
// get the modal and mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
FETimeInfo& tp = fem.GetTime();
// loop over model loads
int nml = fem.ModelLoads();
for (int i = 0; i < nml; ++i)
{
FEModelLoad& ml = *fem.ModelLoad(i);
if (ml.IsActive()) ml.LoadVector(R);
}
}
//-----------------------------------------------------------------------------
//! Evaluate the stiffness matrix
bool FELinearSolver::StiffnessMatrix(FELinearSystem& K)
{
return false;
}
//-----------------------------------------------------------------------------
// This function copies the solution back to the nodal variables
// and class the FEDomain::Update to give domains a chance to update
// their local data.
// TODO: Instead of calling Update on all domains, perhaps I should introduce
// a mechanism for solvers only update the domains that are relevant.
void FELinearSolver::Update(vector<double>& u)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
const FETimeInfo& tp = fem.GetTime();
// update nodal variables
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
for (int j=0; j<m_dof.size(); ++j)
{
int n = node.m_ID[m_dof[j]];
if (n >= 0) node.set(m_dof[j], u[n]);
else if (-n-2 >= 0) node.set(m_dof[j], u[-n-2]);
}
}
// make sure linear constraints are satisfied
FELinearConstraintManager& LCM = fem.GetLinearConstraintManager();
if (LCM.LinearConstraints())
{
LCM.Update();
}
// update the domains
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
dom.Update(tp);
}
fem.IncrementUpdateCounter();
}
| C++ |
3D | febiosoftware/FEBio | FECore/fecore_debug_t.h | .h | 3,965 | 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.*/
#pragma once
#include <list>
#include <vector>
#include <iostream>
#include <typeinfo>
#include <stdlib.h>
#include "matrix.h"
#include "mat3d.h"
#include "vec3d.h"
#include "tens4d.h"
#include "fecore_api.h"
// This file defines template constructions that are used by the FECore debugger.
// Don't use anything in here or include this file directly.
// Instead include fecore_debug.h and use the user functions and macros defined there.
template <typename T> void fecore_print_T(T* pd) { std::cout << (*pd); }
template <> FECORE_API void fecore_print_T<matrix>(matrix* pd);
template <> FECORE_API void fecore_print_T<mat3d>(mat3d* pd);
template <> FECORE_API void fecore_print_T<mat3ds>(mat3ds* pd);
template <> FECORE_API void fecore_print_T<mat3da>(mat3da* pd);
template <> FECORE_API void fecore_print_T<mat3dd>(mat3dd* pd);
template <> FECORE_API void fecore_print_T<vec3d>(vec3d* pd);
template <> FECORE_API void fecore_print_T<tens4ds>(tens4ds* pd);
template <> FECORE_API void fecore_print_T<std::vector<double> >(std::vector<double>* pv);
template <> FECORE_API void fecore_print_T<std::vector<int> >(std::vector<int>* pv);
class FECoreBreakPoint;
class FECORE_API FECoreDebugger
{
public:
class Variable
{
public:
Variable(void* pd, const char* sz) { m_pd = pd; m_szname = sz; }
virtual ~Variable() {}
virtual void print() = 0;
public:
void* m_pd;
const char* m_szname;
};
template <typename T> class Variable_T : public Variable
{
public:
Variable_T(void* pd, const char* sz) : Variable(pd, sz) {}
void print()
{
std::cout << typeid(T).name() << std::endl;
fecore_print_T<T>((T*)m_pd);
}
};
public:
static void Break(FECoreBreakPoint* pbr);
static void Clear();
static void Add(Variable* pvar);
static void Remove(Variable* pvar);
static void Print(const char* szformat, ...);
private:
FECoreDebugger() {}
static std::list<Variable*> m_var;
static FILE* m_fp;
};
class FECoreWatchVariable
{
public:
FECoreWatchVariable(FECoreDebugger::Variable* pvar) : m_pvar(pvar)
{
if (pvar) FECoreDebugger::Add(pvar);
}
~FECoreWatchVariable()
{
if (m_pvar) FECoreDebugger::Remove(m_pvar);
}
protected:
FECoreDebugger::Variable* m_pvar;
};
class FECoreBreakPoint
{
public:
FECoreBreakPoint() { static int n = 1; m_bactive = true; m_nid = n++; }
void Deactivate() { m_bactive = false; }
bool IsActive() { return m_bactive; }
void Break()
{
if (m_bactive) { FECoreDebugger::Break(this); }
}
int GetID() { return m_nid; }
private:
int m_nid;
bool m_bactive;
};
template <typename T> FECoreDebugger::Variable* create_watch_variable(T* pd, const char* sz) { return new FECoreDebugger::Variable_T<T>(pd, sz); }
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfacePairConstraint.h | .h | 3,628 | 93 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEStepComponent.h"
#include "FESurface.h"
//-----------------------------------------------------------------------------
class FEModel;
class FEGlobalMatrix;
//-----------------------------------------------------------------------------
//! This class describes a general purpose interaction between two surfaces.
// TODO: I like to inherit this from FENLConstraint and potentially eliminate
// The distinction between a nonlinear constraint and a contact interface.
// Since a contact interface essentially is a nonlinear constraint, I think
// this may make things a lot easier. I already made the function definitions consistent
// but am hesitant to push this through at this point.
class FECORE_API FESurfacePairConstraint : public FEStepComponent
{
FECORE_SUPER_CLASS(FESURFACEINTERFACE_ID)
FECORE_BASE_CLASS(FESurfacePairConstraint);
public:
//! constructor
FESurfacePairConstraint(FEModel* pfem);
public:
//! return the primary surface
virtual FESurface* GetPrimarySurface() = 0;
//! return the secondary surface
virtual FESurface* GetSecondarySurface () = 0;
//! temporary construct to determine if contact interface uses nodal integration rule (or facet)
virtual bool UseNodalIntegration() = 0;
//! create a copy of this interface
virtual void CopyFrom(FESurfacePairConstraint* pci) {}
public:
// Build the matrix profile
virtual void BuildMatrixProfile(FEGlobalMatrix& M) = 0;
// reset the state data
virtual void Reset() {}
// do the augmentation
virtual bool Augment(int naug, const FETimeInfo& tp) { return true; }
// allocate equations for lagrange multipliers
// (should return the number of equations to be allocated)
virtual int InitEquations(int neq) { return 0; }
// prepare for next time step
virtual void PrepStep() {}
// update based on solution (use for updating Lagrange Multipliers)
// Ui is the total update for the current time step
// ui is the trial incremental update (e.g. from line search)
virtual void Update(const std::vector<double>& Ui, const std::vector<double>& ui) {}
// This is called after each iteration and asks to Update Ui using ui (this is used by Lagrange Multiplier implementations)
virtual void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) {}
using FEModelComponent::Update;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/fecore_enum.h | .h | 11,084 | 383 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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
//-----------------------------------------------------------------------------
// Element Class:
// Defines the general category of element.
enum FE_Element_Class {
FE_ELEM_INVALID_CLASS,
FE_ELEM_SOLID,
FE_ELEM_SHELL,
FE_ELEM_BEAM,
FE_ELEM_SURFACE,
FE_ELEM_TRUSS,
FE_ELEM_DISCRETE,
FE_ELEM_2D,
FE_ELEM_EDGE,
FE_ELEM_WIRE = 100 // temporary. Can change.
};
//-----------------------------------------------------------------------------
// Element shapes:
// This defines the general element shape classes. This classification differs from the
// element types below, in that the latter is defined by a shape and integration rule.
// Do not change the order of these enums! (NOTE: why??)
enum FE_Element_Shape {
// 3D elements
ET_TET4,
ET_TET5,
ET_TET10,
ET_TET15,
ET_TET20,
ET_PENTA6,
ET_PENTA15,
ET_HEX8,
ET_HEX20,
ET_HEX27,
ET_PYRA5,
ET_PYRA13,
// 2.5D elements
ET_QUAD4,
ET_QUAD8,
ET_QUAD9,
ET_TRI3,
ET_TRI6,
ET_TRI7,
ET_TRI10,
// line elements
ET_TRUSS2,
ET_LINE2,
ET_LINE3,
ET_DISCRETE,
FE_ELEM_INVALID_SHAPE = 999
};
//-----------------------------------------------------------------------------
// Element types:
// Note that these numbers are actually indices into the m_Traits array
// of the ElementLibrary class so make sure the numbers correspond
// with the entries into this array
//
enum FE_Element_Type {
// 3D solid elements
FE_HEX8G8,
FE_HEX8RI,
FE_HEX8G1,
FE_TET4G1,
FE_TET4G4,
FE_TET5G4,
FE_PENTA6G6,
FE_TET10G1,
FE_TET10G4,
FE_TET10G8,
FE_TET10GL11,
FE_TET10G4RI1,
FE_TET10G8RI4,
FE_TET15G4,
FE_TET15G8,
FE_TET15G11,
FE_TET15G15,
FE_TET15G15RI4,
FE_TET20G15,
FE_HEX20G8,
FE_HEX20G27,
FE_HEX27G27,
FE_PENTA15G8,
FE_PENTA15G21,
FE_PYRA5G8,
FE_PYRA13G8,
// 2.5D surface elements
FE_QUAD4G4,
FE_QUAD4G16,
FE_QUAD4NI,
FE_TRI3G1,
FE_TRI3G3,
FE_TRI3G7,
FE_TRI3NI,
FE_TRI6G3,
FE_TRI6G4,
FE_TRI6G7,
// FE_TRI6MG7,
FE_TRI6GL7,
FE_TRI6NI,
FE_TRI7G3,
FE_TRI7G4,
FE_TRI7G7,
FE_TRI7GL7,
FE_TRI10G7,
FE_TRI10G12,
FE_QUAD8G9,
FE_QUAD8NI,
FE_QUAD9G9,
FE_QUAD9NI,
// shell elements
FE_SHELL_QUAD4G4,
FE_SHELL_QUAD4G8,
FE_SHELL_QUAD4G12,
FE_SHELL_QUAD8G18,
FE_SHELL_QUAD8G27,
FE_SHELL_TRI3G3,
FE_SHELL_TRI3G6,
FE_SHELL_TRI3G9,
FE_SHELL_TRI6G14,
FE_SHELL_TRI6G21,
// truss elements
FE_TRUSS,
// discrete elements
FE_DISCRETE,
// 2D elements
FE2D_TRI3G1,
FE2D_TRI6G3,
FE2D_QUAD4G4,
FE2D_QUAD8G9,
FE2D_QUAD9G9,
// line elements
FE_LINE2G1,
FE_LINE2NI,
// beam elements
FE_BEAM2G1,
FE_BEAM2G2,
FE_BEAM3G2,
// unspecified
FE_ELEM_INVALID_TYPE = 0xFFFF
};
//-----------------------------------------------------------------------------
// Shell formulations
enum SHELL_FORMULATION {
NEW_SHELL,
OLD_SHELL,
EAS_SHELL,
ANS_SHELL
};
//-----------------------------------------------------------------------------
//! Helper class for creating domain classes.
struct FE_Element_Spec
{
FE_Element_Class eclass;
FE_Element_Shape eshape;
FE_Element_Type etype;
bool m_bthree_field;
int m_shell_formulation;
bool m_shell_norm_nodal;
bool m_but4;
double m_ut4_alpha;
bool m_ut4_bdev;
FE_Element_Spec()
{
eclass = FE_ELEM_INVALID_CLASS;
eshape = FE_ELEM_INVALID_SHAPE;
etype = FE_ELEM_INVALID_TYPE;
m_bthree_field = false;
m_shell_formulation = NEW_SHELL;
m_shell_norm_nodal = true;
m_but4 = false;
m_ut4_alpha = 0.05;
m_ut4_bdev = false;
}
bool operator == (const FE_Element_Spec& s)
{
if ((eclass == s.eclass) &&
(eshape == s.eshape) &&
(etype == s.etype )) return true;
return false;
}
};
//-----------------------------------------------------------------------------
//! This lists the super-class id's that can be used to register new classes
//! with the kernel. It effectively defines the base class that a class
//! is derived from.
enum SUPER_CLASS_ID {
FEINVALID_ID, // an invalid ID
FEOBJECT_ID, // derived from FECoreBase (TODO: work in progress)
FETASK_ID, // derived from FECoreTask
FESOLVER_ID, // derived from FESolver
FEMATERIAL_ID, // derived from FEMaterial
FEMATERIALPROP_ID, // derived from FEMaterialProperty
FEDISCRETEMATERIAL_ID, // derived from FEDiscreteMaterial
FELOAD_ID, // derived from FEModelLoad
FENLCONSTRAINT_ID, // derived from FENLConstraint
FEPLOTDATA_ID, // derived from FEPlotData
FEANALYSIS_ID, // derived from FEAnalysis
FESURFACEINTERFACE_ID, // derived from FESurfaceInterface
FELOGNODEDATA_ID, // derived from FELogNodeData
FELOGFACEDATA_ID, // derived from FELogFaceData
FELOGELEMDATA_ID, // derived from FELogElemData
FELOGOBJECTDATA_ID, // derived from FELogObjectData
FELOGDOMAINDATA_ID, // derived from FELogDomainData
FELOGNLCONSTRAINTDATA_ID, // derived from FELogNLConstraintData
FELOGSURFACEDATA_ID, // derived from FELogSurfaceData
FELOGMODELDATA_ID, // derived from FEModelLogData
FEBC_ID, // derived from FEBoundaryCondition
FEGLOBALDATA_ID, // derived from FEGlobalData
FECALLBACK_ID, // derived from FECallBack
FESOLIDDOMAIN_ID, // derived from FESolidDomain
FESHELLDOMAIN_ID, // derived from FEShellDomain
FEBEAMDOMAIN_ID, // derived from FEBeamDomain
FEDISCRETEDOMAIN_ID, // derived from FEDiscreteDomain
FEDOMAIN2D_ID, // derived from FEDomain2D
FESURFACE_ID, // derived from FESurface
FEEDGE_ID, // derived from FEEdge
FEIC_ID, // derived from FEInitialCondition
FEMESHDATAGENERATOR_ID, // derived from FEMeshDataGenerator
FELOADCONTROLLER_ID, // derived from FELoadContoller
FEMODEL_ID, // derived from FEModel (TODO: work in progress)
FESCALARVALUATOR_ID, // derived from FEScalarValuator
FEVEC3DVALUATOR_ID, // derived from FEVectorValuator
FEMAT3DVALUATOR_ID, // derived from FEMAT3DValuator
FEMAT3DSVALUATOR_ID, // derived from FEMAT3DSValuator
FEFUNCTION1D_ID, // derived from FEFunction1D
FELINEARSOLVER_ID, // derived from LinearSolver
FEMESHADAPTOR_ID, // derived from FEMeshAdaptor
FEMESHADAPTORCRITERION_ID, // derived from FEMeshAdaptorCriterion
FENEWTONSTRATEGY_ID, // derived from FENewtonStrategy
FETIMECONTROLLER_ID, // derived from FETimeStepController
FEEIGENSOLVER_ID, // derived from EigenSolver
FEDATARECORD_ID, // derived from DataRecord
FECLASS_ID, // derived from FECoreClass
};
//-----------------------------------------------------------------------------
// Plot level sets the frequency of writes to the plot file.
enum FE_Plot_Level {
FE_PLOT_NEVER, // don't output anything
FE_PLOT_MAJOR_ITRS, // only output major iterations (i.e. converged time steps)
FE_PLOT_MINOR_ITRS, // output minor iterations (i.e. every Newton iteration)
FE_PLOT_MUST_POINTS, // output only on must-points
FE_PLOT_FINAL, // only output final converged state
FE_PLOT_AUGMENTATIONS, // plot state before augmentations
FE_PLOT_STEP_FINAL, // output the final step of a step
FE_PLOT_USER1 // plot will only happen on CB_USER1 callback
};
//-----------------------------------------------------------------------------
// Plot hint
enum FE_Plot_Hint {
FE_PLOT_NO_HINT = 0,
FE_PLOT_APPEND = 1 // don't close plot file after run
};
//-----------------------------------------------------------------------------
// Output level sets the frequency of data output is written to the log or data files.
enum FE_Output_Level {
FE_OUTPUT_NEVER,
FE_OUTPUT_MAJOR_ITRS,
FE_OUTPUT_MINOR_ITRS,
FE_OUTPUT_MUST_POINTS,
FE_OUTPUT_FINAL
};
//-----------------------------------------------------------------------------
//! Domain classes
//! The domain class defines the general catergory of element types
#define FE_DOMAIN_SOLID 1
#define FE_DOMAIN_SHELL 2
#define FE_DOMAIN_BEAM 3
#define FE_DOMAIN_SURFACE 4
#define FE_DOMAIN_DISCRETE 5
#define FE_DOMAIN_2D 6
#define FE_DOMAIN_EDGE 7
// --- data types ---
enum Var_Type {
PLT_FLOAT, // scalar : single fp
PLT_VEC3F, // 3D vector : 3 fps
PLT_MAT3FS, // symm 2o tensor : 6 fps
PLT_MAT3FD, // diagonal 2o tensor : 3 fps
PLT_TENS4FS, // symm 4o tensor : 21 fps
PLT_MAT3F, // 2o tensor : 9 fps
PLT_ARRAY, // variable array (see dictionary for size)
PLT_ARRAY_VEC3F // array of vec3f (see dictionary for size)
};
// --- storage format ---
// FMT_NODE : one value stored for each node of a region
// FMT_ITEM : one value stored for each item (e.g. element) of a region
// FMT_MULT : one value for each node of each item of a region
// FMT_REGION: one value per region (surface, domain)
enum Storage_Fmt { FMT_NODE, FMT_ITEM, FMT_MULT, FMT_REGION, FMT_MATPOINTS };
//-----------------------------------------------------------------------------
enum FEDataType {
FE_INVALID_TYPE,
FE_DOUBLE,
FE_VEC2D,
FE_VEC3D,
FE_MAT3D,
FE_MAT3DS
};
//-----------------------------------------------------------------------------
enum FEDataMapType {
FE_INVALID_MAP_TYPE,
FE_NODE_DATA_MAP,
FE_DOMAIN_MAP,
FE_SURFACE_MAP,
FE_EDGE_MAP
};
//-----------------------------------------------------------------------------
//! Different matrix types. This is used when requesting a sparse matrix format
//! from a linear solver.
//! \sa LinearSolver::CreateSparseMatrix.
enum Matrix_Type {
REAL_UNSYMMETRIC, // non-symmetric
REAL_SYMMETRIC, // symmetric (not necessarily positive definite)
REAL_SYMM_STRUCTURE // structurally symmetric
};
//! Constraint enforcement method
namespace FECore {
enum CONSTRAINT_ENFORCEMENT {
PENALTY_METHOD,
AUGLAG_METHOD,
LAGMULT_METHOD
};
}
| Unknown |
3D | febiosoftware/FEBio | FECore/targetver.h | .h | 2,029 | 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
// The following macros define the minimum required platform. The minimum required platform
// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run
// your application. The macros work by enabling all features available on platform versions up to and
// including the version specified.
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
#endif
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFixedBC.cpp | .cpp | 3,520 | 132 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFixedBC.h"
#include "FENodeSet.h"
#include "FENode.h"
#include "DumpStream.h"
#include "log.h"
//-----------------------------------------------------------------------------
FEFixedBC::FEFixedBC(FEModel* pfem) : FENodalBC(pfem)
{
}
FEFixedBC::FEFixedBC(FEModel* pfem, int dof, FENodeSet* ps) : FENodalBC(pfem)
{
SetDOFList(dof);
SetNodeSet(ps);
}
//-----------------------------------------------------------------------------
//! initialization
bool FEFixedBC::Init()
{
if (GetNodeSet() == nullptr) return false;
if (GetDofList().Size() == 0)
{
feLogError("No degrees of freedom are constrained in %s", GetName().c_str());
return false;
}
return FENodalBC::Init();
}
//-----------------------------------------------------------------------------
void FEFixedBC::Activate()
{
FENodalBC::Activate();
FENodeSet& nset = *GetNodeSet();
int n = nset.Size();
int dofs = m_dof.Size();
for (int i = 0; i<n; ++i)
{
// make sure we only activate open dof's
FENode& node = *nset.Node(i);
for (int j=0; j<dofs; ++j)
{
int dofj = m_dof[j];
if (node.get_bc(dofj) == DOF_OPEN)
{
node.set_bc(dofj, DOF_FIXED);
node.set(dofj, 0.0);
}
}
}
}
//-----------------------------------------------------------------------------
void FEFixedBC::Deactivate()
{
FENodalBC::Deactivate();
FENodeSet* pns = GetNodeSet();
int N = pns->Size();
size_t dofs = m_dof.Size();
for (size_t i = 0; i<N; ++i)
{
// get the node
FENode& node = *pns->Node(i);
// set the dof to open
for (size_t j = 0; j < dofs; ++j)
{
node.set_bc(m_dof[j], DOF_OPEN);
}
}
}
//-----------------------------------------------------------------------------
void FEFixedBC::CopyFrom(FEBoundaryCondition* bc)
{
FEFixedBC* fbc = dynamic_cast<FEFixedBC*>(bc);
m_dof = fbc->GetDofList();
}
//=============================================================================
BEGIN_FECORE_CLASS(FEFixedDOF, FEFixedBC)
ADD_PARAMETER(m_dofs, "dofs", 0, "$(dof_list)");
END_FECORE_CLASS();
FEFixedDOF::FEFixedDOF(FEModel* fem) : FEFixedBC(fem)
{
}
void FEFixedDOF::SetDOFS(const std::vector<int>& dofs)
{
m_dofs = dofs;
}
bool FEFixedDOF::Init()
{
SetDOFList(m_dofs);
return FEFixedBC::Init();
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEProperty.h | .h | 5,218 | 162 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
#include "fecore_enum.h"
//-----------------------------------------------------------------------------
class FECoreBase;
class DumpStream;
//-----------------------------------------------------------------------------
//! A property of a class reflects a member variable of the class that is a
//! pointer to a FECoreBase derived class.
class FECORE_API FEProperty
{
public:
enum Flags
{
Optional = 0x00,
Required = 0x01, // the property is required (default)
Preferred = 0x02, // the property is not required, but a default should be allocated when possible.
Reference = 0x04, // references another class in the model
Fixed = 0x08, // fixed properties are fixed type class members
TopLevel = 0x10, // This is a "top-level" property.
};
private:
//! Name of the property.
//! Note that the name is not copied so it must point to a static string.
const char* m_szname;
const char* m_szlongname; // long name (optional; used in FEBio Studio)
unsigned int m_flags; // bitwise or of flags defined above
const char* m_szdefaultType; // default type string (used by FEBio Studio to initialize required properties).
protected:
const char* m_className; // name of class that can be assigned to this
public:
// Set\Get the name of the property
FEProperty& SetName(const char* sz);
const char* GetName() const;
// get\set the long name
FEProperty& SetLongName(const char* sz);
const char* GetLongName() const;
// get the class name
const char* GetClassName() const { return m_className; }
// is the property required
bool IsRequired() const { return (m_flags & Required) != 0; }
// is the property preferred
bool IsPreferred() const { return (m_flags & Preferred) != 0; }
// is this a reference property
bool IsReference() const { return (m_flags & Reference) != 0; }
// is this a top-level property
bool IsTopLevel() const { return (m_flags & TopLevel) != 0; }
// set the flags
void SetFlags(unsigned int flags) { m_flags = flags; }
// add a flag
void AddFlag(unsigned int flag) { m_flags |= flag; }
// get the flags
unsigned int Flags() const { return m_flags; }
// get default type (can be null)
const char* GetDefaultType() const;
// set the default type
FEProperty& SetDefaultType(const char* szdefType);
public: // these functions have to be implemented by derived classes
//! helper function for identifying if this is an array property or not
virtual bool IsArray() const = 0;
//! see if the pc parameter is of the correct type for this property
virtual bool IsType(FECoreBase* pc) const = 0;
//! set the property
virtual void SetProperty(FECoreBase* pc) = 0;
//! return the size of the property
virtual int size() const = 0;
//! return a specific property by index
virtual FECoreBase* get(int i) = 0;
//! return a specific property by name
virtual FECoreBase* get(const char* szname) = 0;
//! return a specific property by ID
virtual FECoreBase* getFromID(int nid) = 0;
//! serialize property data
virtual void Serialize(DumpStream& ar) = 0;
//! initializatoin
virtual bool Init() = 0;
//! validation
virtual bool Validate() = 0;
//! Get the parent of this property
FECoreBase* GetParent() { return m_pParent; }
//! Set the parent of this property
virtual void SetParent(FECoreBase* parent) { m_pParent = parent; }
//! Get the class ID
SUPER_CLASS_ID GetSuperClassID() const { return m_superClassID; }
public:
virtual ~FEProperty();
protected:
//! some helper functions for reading, writing properties
void Write(DumpStream& ar, FECoreBase* pc);
FECoreBase* Read(DumpStream& ar);
protected:
// This class should not be created directly
FEProperty(SUPER_CLASS_ID classID);
protected:
FECoreBase* m_pParent; //!< pointer to the parent class (i.e. the class that defines this property)
SUPER_CLASS_ID m_superClassID; //!< The super class ID
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurfaceLoad.h | .h | 2,418 | 71 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEModelLoad.h"
#include "FESurface.h"
#include "FESolver.h"
#include "FETimeInfo.h"
//-----------------------------------------------------------------------------
class FEModel;
class FEGlobalVector;
//-----------------------------------------------------------------------------
//! This is the base class for all loads that are applied to surfaces
class FECORE_API FESurfaceLoad : public FEModelLoad
{
public:
FESurfaceLoad(FEModel* pfem);
virtual ~FESurfaceLoad(void);
//! Set the surface to apply the load to
virtual void SetSurface(FESurface* ps);
bool Init() override;
//! Get the surface
FESurface& GetSurface() { return *m_psurf; }
void Serialize(DumpStream& ar) override;
public:
virtual double ScalarLoad(FESurfaceMaterialPoint& mp) { return 0; }
virtual vec3d VectorLoad(FESurfaceMaterialPoint& mp) { return vec3d(0,0,0); }
// TODO: Can I get rid of this?
// This is needed to update the mesh after some surface loads, which aren't really
// surface loads modify boundary conditions
void ForceMeshUpdate();
protected:
FESurface* m_psurf;
FECORE_BASE_CLASS(FESurfaceLoad)
};
| Unknown |
3D | febiosoftware/FEBio | FECore/DataRecord.cpp | .cpp | 6,668 | 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 "DataRecord.h"
#include "DumpStream.h"
#include "FEModel.h"
#include "FEAnalysis.h"
#include "log.h"
#include <sstream>
//-----------------------------------------------------------------------------
UnknownDataField::UnknownDataField(const char* sz) : std::runtime_error(sz)
{
}
//-----------------------------------------------------------------------------
DataRecord::DataRecord(FEModel* pfem, int ntype) : FECoreBase(pfem), m_type(ntype)
{
m_nid = 0;
m_szname[0] = 0;
m_szdata[0] = 0;
m_szfmt[0] = 0;
strcpy(m_szdelim, " ");
m_bcomm = true;
m_fp = 0;
m_szfile[0] = 0;
}
//-----------------------------------------------------------------------------
bool DataRecord::SetFileName(const char* szfile)
{
if (szfile == nullptr) return false;
strcpy(m_szfile, szfile);
m_fp = fopen(szfile, "wt");
if (m_fp == 0)
{
feLogError("FAILED CREATING DATA FILE %s\n\n", szfile);
return false;
}
return true;
}
//-----------------------------------------------------------------------------
DataRecord::~DataRecord()
{
if (m_fp)
{
fclose(m_fp);
m_fp = 0;
}
}
//-----------------------------------------------------------------------------
void DataRecord::SetName(const char* sz)
{
strcpy(m_szname, sz);
}
//-----------------------------------------------------------------------------
void DataRecord::SetDelim(const char* sz)
{
strcpy(m_szdelim, sz);
}
//-----------------------------------------------------------------------------
void DataRecord::SetFormat(const char* sz)
{
strcpy(m_szfmt, sz);
}
//-----------------------------------------------------------------------------
bool DataRecord::Initialize()
{
if (m_item.empty()) SelectAllItems();
return true;
}
//-----------------------------------------------------------------------------
std::string DataRecord::printToString(int i)
{
std::stringstream ss;
ss.precision(12);
ss << m_item[i] << m_szdelim;
int nd = Size();
for (int j = 0; j<nd; ++j)
{
double val = Evaluate(m_item[i], j);
ss << val;
if (j != nd - 1) ss << m_szdelim;
else ss << "\n";
}
return ss.str();
}
//-----------------------------------------------------------------------------
std::string DataRecord::printToFormatString(int i)
{
int ndata = Size();
char szfmt[MAX_STRING];
strcpy(szfmt, m_szfmt);
std::stringstream ss;
int nitem = m_item[i];
char* sz = szfmt, *ch = 0;
int j = 0;
do
{
ch = strchr(sz, '%');
if (ch)
{
if (ch[1] == 'i')
{
*ch = 0;
ss << sz;
*ch = '%'; sz = ch + 2;
ss << nitem;
}
else if (ch[1] == 'l')
{
*ch = 0;
ss << sz;
*ch = '%'; sz = ch + 2;
ss << (int)i + 1;
}
else if (ch[1] == 'g')
{
*ch = 0;
ss << sz;
*ch = '%'; sz = ch + 2;
if (j<ndata)
{
double val = Evaluate(nitem, j++);
ss << val;
}
}
else if (ch[1] == 't')
{
*ch = 0;
ss << sz;
*ch = '%'; sz = ch + 2;
ss << "\t";
}
else if (ch[1] == 'n')
{
*ch = 0;
ss << "%s";
*ch = '%'; sz = ch + 2;
ss << "\n";
}
else
{
*ch = 0;
ss << sz;
*ch = '%'; sz = ch + 1;
}
}
else { ss << sz; break; }
} while (*sz);
ss << "\n";
return ss.str();
}
//-----------------------------------------------------------------------------
bool DataRecord::Write()
{
FEModel* fem = GetFEModel();
int nstep = fem->GetCurrentStep()->m_ntimesteps;
double ftime = fem->GetCurrentTime();
// make a note in the log file
feLog("\nData Record #%d\n", m_nid);
feLog("===========================================================================\n");
feLog("Step = %d\n", nstep);
feLog("Time = %.9lg\n", ftime);
feLog("Data = %s\n", m_szname);
// write some comments
FILE* fp = m_fp;
if (fp && m_bcomm)
{
// we save the data in a seperate file
feLog("File = %s\n", m_szfile);
// make a note in the data file
fprintf(fp,"*Step = %d\n", nstep);
fprintf(fp,"*Time = %.9lg\n", ftime);
fprintf(fp,"*Data = %s\n", m_szname);
}
// save the data
if (m_szfmt[0]==0)
{
for (size_t i=0; i<m_item.size(); ++i)
{
std::string out = printToString((int)i);
if (fp) fprintf(fp, "%s", out.c_str());
else feLog(out.c_str(),"");
}
}
else
{
// print using the format string
for (size_t i=0; i<m_item.size(); ++i)
{
std::string out = printToFormatString((int)i);
if (fp) fprintf(fp, "%s", out.c_str());
else feLog(out.c_str(),"");
}
}
if (fp) fflush(fp);
return true;
}
//-----------------------------------------------------------------------------
void DataRecord::SetItemList(const std::vector<int>& items)
{
m_item = items;
}
//-----------------------------------------------------------------------------
void DataRecord::SetItemList(FEItemList* items, const std::vector<int>& selection)
{
// derived classes should override this
assert(false);
}
//-----------------------------------------------------------------------------
void DataRecord::Serialize(DumpStream &ar)
{
if (ar.IsShallow()) return;
// serialize data
ar & m_nid;
ar & m_szname;
ar & m_szdelim;
ar & m_szfile;
ar & m_bcomm;
ar & m_item;
ar & m_szdata;
// when we're loading we need to reinitialize the file
if (ar.IsLoading())
{
SetData(m_szdata);
if (m_fp) fclose(m_fp);
m_fp = 0;
if (m_szfile[0] != 0)
{
// reopen data file for appending
m_fp = fopen(m_szfile, "a+");
}
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FETrussDomain.h | .h | 2,089 | 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 "FEBeamDomain.h"
//-----------------------------------------------------------------------------
//! Abstract base class for truss elements
class FECORE_API FETrussDomain : public FEBeamDomain
{
public:
FETrussDomain(FEModel* pm);
public:
bool Create(int nsize, FE_Element_Spec espec) override;
bool Init() override;
int Elements() const override { return (int)m_Elem.size(); }
FETrussElement& Element(int i) { return m_Elem[i]; }
FEElement& ElementRef(int n) override { return m_Elem[n]; }
const FEElement& ElementRef(int n) const override { return m_Elem[n]; }
public:
void ForEachTrussElement(std::function<void(FETrussElement& el)> f);
public:
//! Calculate the truss normal
vec3d GetTrussAxisVector(FETrussElement& el);
protected:
vector<FETrussElement> m_Elem;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDomainList.h | .h | 2,613 | 80 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include <string>
#include "fecore_api.h"
class FEDomain;
class DumpStream;
//-----------------------------------------------------------------------------
// Class that represents a list of domains.
class FECORE_API FEDomainList
{
public:
//! constructor
FEDomainList();
FEDomainList(FEDomainList& domList);
FEDomainList(std::vector<FEDomain*> domList);
//! Clear the domain list
void Clear();
//! Add a domain to the list
void AddDomain(FEDomain* dom);
//! Add a domain list
void AddDomainList(const FEDomainList& domList);
//! See if a domain is a member of this list
bool IsMember(const FEDomain* dom) const;
//! See if the list is empty
bool IsEmpty() const { return m_dom.empty(); }
//! Return number of domains in list
int Domains() const { return (int) m_dom.size(); }
//! Return a domain
FEDomain* GetDomain(int i) { return m_dom[i]; }
const FEDomain* GetDomain(int i) const { return m_dom[i]; }
//! serialization
void Serialize(DumpStream& ar);
size_t size() const { return m_dom.size(); }
FEDomain* operator [] (size_t n) { return m_dom[n]; }
public:
void SetName(const std::string& name) { m_name = name; }
const std::string& GetName() const { return m_name; }
private:
std::string m_name;
std::vector<FEDomain*> m_dom; // the actual list of domains
};
| Unknown |
3D | febiosoftware/FEBio | FECore/SchurComplement.h | .h | 4,430 | 127 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "SparseMatrix.h"
#include "LinearSolver.h"
// This class implements a sparse matrix operator that represents the Schur complement of a matrix M
//
// | A | B |
// M = | --+-- |
// | C | D |
//
// The Schur complement of A, is given by
//
// S\A = C*A^-1*B - D
//
// The only operator this class implements is the matrix-vector multiplication operator (in mult_vector function).
// This function evaluates a product of the form S*x, where v is a vector, as follows:
// 1. evaluate u = B*x
// 2. evaluate v = A^-1*u, by solving A*v = u
// 3. evaluate r = C*v
// 4. if D is given, then subtract r <-- r - D*x
//
// If D = 0, it does not need to be specified, in which case step 4 is not done.
class FECORE_API SchurComplementA : public SparseMatrix
{
public:
SchurComplementA(LinearSolver* A, SparseMatrix* B, SparseMatrix* C, SparseMatrix* D = 0);
// set the print level
void SetPrintLevel(int printLevel);
// negate schur complement
void NegateSchur(bool b);
//! multiply with vector
bool mult_vector(double* x, double* r) override;
private: // we need to override these functions although we don't want to use them
void Zero() override { assert(false); }
void Create(SparseMatrixProfile& MP) override { assert(false); }
void Assemble(const matrix& ke, const std::vector<int>& lm) override { assert(false); }
void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) override { assert(false); }
bool check(int i, int j) override { assert(false); return false; }
void set(int i, int j, double v) override { assert(false); }
void add(int i, int j, double v) override { assert(false); }
double diag(int i) override { assert(false); return 0.0; }
private:
int m_print_level;
bool m_bnegate;
LinearSolver* m_A;
SparseMatrix* m_B;
SparseMatrix* m_C;
SparseMatrix* m_D;
vector<double> m_tmp1, m_tmp2, m_tmp3;
};
// | A | B |
// M = | --+-- |
// | C | D |
//
// The Schur complement of D, is given by
//
// S\D = B*D^-1*C - A
class FECORE_API SchurComplementD : public SparseMatrix
{
public:
SchurComplementD(SparseMatrix* A, SparseMatrix* B, SparseMatrix* C, LinearSolver* D);
// set the print level
void SetPrintLevel(int printLevel);
//! multiply with vector
bool mult_vector(double* x, double* r) override;
private: // we need to override these functions although we don't want to use them
void Zero() override { assert(false); }
void Create(SparseMatrixProfile& MP) override { assert(false); }
void Assemble(const matrix& ke, const std::vector<int>& lm) override { assert(false); }
void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) override { assert(false); }
bool check(int i, int j) override { assert(false); return false; }
void set(int i, int j, double v) override { assert(false); }
void add(int i, int j, double v) override { assert(false); }
double diag(int i) override { assert(false); return 0.0; }
private:
int m_print_level;
LinearSolver* m_D;
SparseMatrix* m_B;
SparseMatrix* m_C;
SparseMatrix* m_A;
vector<double> m_tmp1, m_tmp2, m_tmp3;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEStepComponent.cpp | .cpp | 2,076 | 60 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEStepComponent.h"
FEStepComponent::FEStepComponent(FEModel* fem) : FEModelComponent(fem)
{
// initialize parameters
m_bactive = true;
}
//-----------------------------------------------------------------------------
bool FEStepComponent::IsActive() const
{
return m_bactive;
}
//-----------------------------------------------------------------------------
void FEStepComponent::Activate()
{
m_bactive = true;
}
//-----------------------------------------------------------------------------
void FEStepComponent::Deactivate()
{
m_bactive = false;
}
//-----------------------------------------------------------------------------
void FEStepComponent::Serialize(DumpStream& ar)
{
FEModelComponent::Serialize(ar);
if (ar.IsShallow()) return;
ar& m_bactive;
}
| C++ |
3D | febiosoftware/FEBio | FECore/tens5ds.hpp | .hpp | 1,397 | 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
// NOTE: This file is automatically included from tens5d.h
// Users should not include this file manually!
| Unknown |
3D | febiosoftware/FEBio | FECore/FEFixedBC.h | .h | 2,358 | 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 "FENodalBC.h"
//-----------------------------------------------------------------------------
//! This class represents a fixed degree of freedom
//! This boundary conditions sets the BC attribute of the nodes in the nodeset
//! to DOF_FIXED when activated.
class FECORE_API FEFixedBC : public FENodalBC
{
public:
//! constructors
FEFixedBC(FEModel* pfem);
FEFixedBC(FEModel* pfem, int dof, FENodeSet* ps);
//! initialization
bool Init() override;
//! activation
void Activate() override;
//! deactivation
void Deactivate() override;
void CopyFrom(FEBoundaryCondition* bc) override;
};
//-----------------------------------------------------------------------------
// This class is obsolete, but provides a direct parameterization of the base class.
// This is maintained for backward compatibility with older feb files.
class FECORE_API FEFixedDOF : public FEFixedBC
{
DECLARE_FECORE_CLASS();
public:
FEFixedDOF(FEModel* fem);
void SetDOFS(const std::vector<int>& dofs);
bool Init() override;
protected:
std::vector<int> m_dofs;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/tens4d.h | .h | 22,844 | 631 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "tensor_base.h"
#include "mat3d.h"
#include "tens3d.h"
//-----------------------------------------------------------------------------
class tens4ds;
class tens4dms;
class tens4dmm;
class tens4d;
//-----------------------------------------------------------------------------
//! Class for 4th order tensors with major and minor symmetries (i.e., super-symmetry)
// Due to the major symmetry we can store this tensor as a 6x6 matrix.
// The tensor is stored in column major order:
//
// / 0 1 3 6 10 15 \ / C0000 C0011 C0022 C0001 C0012 C0002 \
// | 2 4 7 11 16 | | C1111 C1122 C1101 C1112 C1102 |
// | 5 8 12 17 | | C2222 C2201 C2212 C2202 |
// A = | 9 13 18 | = | C0101 C0112 C0102 |
// | 14 19 | | C1212 C1202 |
// \ 20 / \ C0202 /
//
// Note that due to the major symmetry we only store the upper triangular matrix of this tensor
//
class tens4ds
{
public:
enum { NNZ = 21 };
// default constructor
tens4ds() {}
explicit tens4ds(const double g);
tens4ds(double m[6][6]);
double& operator () (int i, int j, int k, int l);
double operator () (int i, int j, int k, int l) const;
// TODO: remove this?
double& operator () (int i, int j);
double operator () (int i, int j) const;
// arithmetic operators
tens4ds operator + (const tens4ds& t) const;
tens4ds operator - (const tens4ds& t) const;
tens4ds operator * (double g) const;
tens4ds operator / (double g) const;
// arithmetic assignment operators
tens4ds& operator += (const tens4ds& t);
tens4ds& operator -= (const tens4ds& t);
tens4ds& operator *= (double g);
tens4ds& operator /= (double g);
// unary operators
tens4ds operator - () const;
// double dot product with 2nd order tensor
mat3ds dot(const mat3ds& m) const;
mat3ds dot(const mat3dd& m) const { return dot(mat3ds(m)); }
mat3ds dot(const mat3d& m) const;
tens3dls dot(const vec3d& m) const;
mat3ds dot2(const mat3d& m) const;
// contractions
mat3ds contract() const;
// trace
double tr() const;
// initialize to zero
void zero();
// extract 6x6 matrix
void extract(double d[6][6]);
// calculates the inverse
tens4ds inverse() const;
// evaluate push/pull operation
tens4ds pp(const mat3d& F);
public:
double d[NNZ]; // stored in column major order
};
//! Check positive definiteness of a 4th-order symmetric tensor
bool IsPositiveDefinite(const tens4ds& t);
// outer (dyadic) products for symmetric matrices
tens4ds dyad1s(const mat3dd& a);
tens4ds dyad1s(const mat3ds& a);
tens4ds dyad1s(const mat3dd& a, const mat3dd& b);
tens4ds dyad1s(const mat3ds& a, const mat3dd& b);
tens4ds dyad1s(const mat3ds& a, const mat3ds& b);
inline tens4ds dyad1s(const mat3dd& a, const mat3ds& b) { return dyad1s(b, a); }
tens4ds dyad4s(const mat3dd& a);
tens4ds dyad4s(const mat3ds& a);
tens4ds dyad4s(const mat3ds& a, const mat3ds& b);
tens4ds dyad4s(const mat3ds& a, const mat3dd& b);
tens4ds dyad4s(const vec3d& a, const mat3d& K, const vec3d& b);
tens4ds dyad5s(const mat3ds& a, const mat3ds& b);
tens4ds ddots(const tens4ds& a, const tens4ds& b);
mat3d vdotTdotv(const vec3d& a, const tens4ds& T, const vec3d& b);
inline tens4ds operator * (const double g, const tens4ds& a) { return a*g; }
// The following file contains the actual definition of the class functions
#include "tens4ds.hpp"
//-----------------------------------------------------------------------------
//! Class for 4th order tensors with major symmetry only
// Due to the lack of minor symmetry, we have to store additional components of this tensor as a 9x9 matrix.
// Major symmetry ensures that this storage matrix is symmetric about its main diagonal.
// The tensor is stored in column major order:
//
// / 0 1 3 6 10 15 21 28 36 \
// | 2 4 7 11 16 22 29 37 |
// | 5 8 12 17 23 30 38 |
// A = | 9 13 18 24 31 39 |
// | 14 19 25 32 40 |
// | 20 26 33 41 |
// | 27 34 42 |
// | 35 43 |
// \ 44 /
//
class tens4dms
{
public:
enum { NNZ = 45 };
// Default constructor
tens4dms() {}
tens4dms(const double g);
tens4dms(double m[9][9]);
// access operators
double& operator () (int i, int j, int k, int l);
double operator () (int i, int j, int k, int l) const;
double& operator () (int i, int j);
double operator () (int i, int j) const;
// arithmetic operators
tens4dms operator + (const tens4dms& t) const;
tens4dms operator - (const tens4dms& t) const;
tens4dms operator * (double g) const;
tens4dms operator / (double g) const;
// arithmetic assignment operators
tens4dms& operator += (const tens4dms& t);
tens4dms& operator -= (const tens4dms& t);
tens4dms& operator *= (double g);
tens4dms& operator /= (double g);
// unary operators
tens4dms operator - () const;
// trace
double tr() const;
// initialize to zero
void zero();
// extract 9x9 matrix
void extract(double d[9][9]);
// compute the super-symmetric (major and minor symmetric) component of the tensor
tens4ds supersymm() const;
//// calculates the inverse
//tens4dms inverse() const;
public:
double d[NNZ]; // stored in column major order
};
// outer (dyadic) products for symmetric and non-symmetric matrices
tens4dms dyad1ms(const mat3d& a);
tens4dms dyad1ms(const mat3ds& a, const mat3ds& b);
// The following file contains the actual definition of the class functions
#include "tens4dms.hpp"
//-----------------------------------------------------------------------------
//! Class for 4th order tensors with both minor symmetries
// We store components of this tensor as a 6x6 matrix.
// The tensor is stored in column major order:
//
// 00 11 22 01 12 20 |
// --------------------------------------------+---
// / 0 6 12 18 24 30 \ | 00
// | 1 7 13 19 25 31 | | 11
// | 2 8 14 20 26 32 | | 22
// A = | 3 9 15 21 27 33 | | 01
// | 4 10 16 22 28 34 | | 12
// \ 5 11 17 23 29 35 / | 20
//
template <> class tensor_traits<tens4dmm> {public: enum { NNZ = 36}; };
class tens4dmm : public tensor_base<tens4dmm>
{
public:
// constructors
tens4dmm() {}
explicit tens4dmm(const double g);
tens4dmm(tens4ds t);
tens4dmm(double m[6][6]);
public:
// access operators
double& operator () (int i, int j, int k, int l);
double operator () (int i, int j, int k, int l) const;
private:
double& operator () (int i, int j);
double operator () (int i, int j) const;
public:
// arithmetic operators
tens4dmm operator + (const tens4dmm& t) const;
tens4dmm operator - (const tens4dmm& t) const;
tens4dmm operator + (const tens4ds& t) const;
tens4dmm operator - (const tens4ds& t) const;
tens4dmm operator * (double g) const;
tens4dmm operator / (double g) const;
// arithmetic assignment operators
tens4dmm& operator += (const tens4dmm& t);
tens4dmm& operator -= (const tens4dmm& t);
tens4dmm& operator += (const tens4ds& t);
tens4dmm& operator -= (const tens4ds& t);
tens4dmm& operator *= (double g);
tens4dmm& operator /= (double g);
// unary operators
tens4dmm operator - () const;
// double dot product with 2nd order tensor
mat3ds dot(const mat3ds& m) const;
mat3ds dot(const mat3dd& m) const { return dot(mat3ds(m)); }
// double dot product with 4th order tensor
tens4dmm ddot(const tens4ds& t) const;
tens4dmm ddot(const tens4dmm& t) const;
// single dot product with 2nd order tensor
tens4dmm operator * (const mat3ds& m) const;
tens4dmm operator * (const mat3d& m) const;
// trace
double tr() const;
// initialize to zero
void zero();
// extract 9x9 matrix
void extract(double d[6][6]);
// compute the super-symmetric (major and minor symmetric) component of the tensor
tens4ds supersymm() const;
// compute the major transpose (Sijkl -> Sklij)
tens4dmm transpose() const;
// calculates the inverse
tens4dmm inverse() const;
// evaluate push/pull operation
tens4dmm pp(const mat3d& F);
};
// dyadic products of second-order tensors
tens4dmm dyad1mm(const mat3ds& a, const mat3ds& b);
tens4dmm dyad4mm(const mat3d& a, const mat3d& b);
inline tens4dmm dyad1mm(const mat3dd& as, const mat3ds& b) { mat3ds a(as); return dyad1mm(a,b); }
inline tens4dmm dyad1mm(const mat3ds& a, const mat3dd& bs) { mat3ds b(bs); return dyad1mm(a,b); }
inline tens4dmm dyad1mm(const mat3dd& as, const mat3dd& bs) { mat3ds a(as); mat3ds b(bs); return dyad1mm(a,b); }
inline tens4dmm dyad4mm(const mat3dd& as, const mat3ds& b) { mat3ds a(as); return dyad4mm(a,b); }
inline tens4dmm dyad4mm(const mat3ds& a, const mat3dd& bs) { mat3ds b(bs); return dyad4mm(a,b); }
inline tens4dmm dyad4mm(const mat3dd& as, const mat3dd& bs) { mat3ds a(as); mat3ds b(bs); return dyad4mm(a,b); }
// other common operations
tens4dmm ddot(const tens4dmm& a, const tens4dmm& b);
tens4dmm ddot(const tens4dmm& a, const tens4ds& b);
inline mat3ds ddot(const tens4dmm& a, const mat3ds& m) { return a.dot(m); }
inline mat3ds ddot(const tens4dmm& a, const mat3dd& m) { return a.dot(m); }
inline tens4dmm operator * (const double g, const tens4dmm& a) { return a*g; }
mat3d vdotTdotv(const vec3d& a, const tens4dmm& T, const vec3d& b);
// The following file contains the actual definition of the class functions
#include "tens4dmm.hpp"
//-----------------------------------------------------------------------------
//! Class for 4th order tensors without symmetry
// We store components of this tensor as a 9x9 matrix.
// The tensor is stored in column major order:
//
// 00 11 22 01 12 20 10 21 02 |
// --------------------------------------------+---
// / 0 9 18 27 36 45 54 63 72 \ | 00
// | 1 10 19 28 37 46 55 64 73 | | 11
// | 2 11 20 29 38 47 56 65 74 | | 22
// A = | 3 12 21 30 39 48 57 66 75 | | 01
// | 4 13 22 31 40 49 58 67 76 | | 12
// | 5 14 23 32 41 50 59 68 77 | | 20
// | 6 15 24 33 42 51 60 69 78 | | 10
// | 7 16 25 34 43 52 61 70 79 | | 21
// \ 8 17 26 35 44 53 62 71 80 / | 02
//
template <> class tensor_traits<tens4d> {public: enum { NNZ = 81}; };
class tens4d : public tensor_base<tens4d>
{
public:
// constructors
tens4d() {}
explicit tens4d(const double g);
tens4d(tens4ds t);
tens4d(tens4dmm t);
tens4d(double m[9][9]);
public:
// access operators
double& operator () (int i, int j, int k, int l);
double operator () (int i, int j, int k, int l) const;
private:
double& operator () (int i, int j);
double operator () (int i, int j) const;
public:
// arithmetic operators
tens4d operator + (const tens4d& t) const;
tens4d operator - (const tens4d& t) const;
tens4d operator + (const tens4ds& t) const;
tens4d operator - (const tens4ds& t) const;
tens4d operator * (double g) const;
tens4d operator / (double g) const;
// arithmetic assignment operators
tens4d& operator += (const tens4d& t);
tens4d& operator -= (const tens4d& t);
tens4d& operator += (const tens4ds& t);
tens4d& operator -= (const tens4ds& t);
tens4d& operator *= (double g);
tens4d& operator /= (double g);
// unary operators
tens4d operator - () const;
// double dot product with 2nd order tensor
mat3d dot(const mat3d& m) const;
mat3d dot(const mat3ds& m) const { return dot(mat3d(m)); }
mat3d dot(const mat3dd& m) const { return dot(mat3d(m)); }
// single dot product with 2nd order tensor
tens4d sdot(const mat3d& m) const;
tens4d sdot(const mat3ds& m) const { return sdot(mat3d(m)); };
tens4d sdot(const mat3dd& m) const { return sdot(mat3d(m)); };
// trace
double tr() const;
// initialize to zero
void zero();
// extract 9x9 matrix
void extract(double d[9][9]);
// compute the super-symmetric (major and minor symmetric) component of the tensor
tens4ds supersymm() const;
// compute the major transpose (Sijkl -> Sklij)
tens4d transpose() const;
// compute the left transpose (Sijkl -> Sjikl)
tens4d left_transpose() const;
// compute the right transpose (Sijkl -> Sijlk)
tens4d right_transpose() const;
// calculates the inverse
tens4d inverse() const;
// evaluate push/pull operation
// tens4d pp(const mat3d& F);
};
// dyadic products of second-order tensors
tens4d dyad1(const mat3d& a, const mat3d& b);
tens4d dyad2(const mat3d& a, const mat3d& b);
tens4d dyad3(const mat3d& a, const mat3d& b);
inline tens4d dyad4(const mat3d& a, const mat3d& b) { return (dyad2(a,b) + dyad3(a,b))/2; }
inline tens4d dyad1(const mat3ds& as, const mat3d& b) { mat3d a(as); return dyad1(a,b); }
inline tens4d dyad1(const mat3d& a, const mat3ds& bs) { mat3d b(bs); return dyad1(a,b); }
inline tens4d dyad1(const mat3ds& as, const mat3ds& bs) { mat3d a(as); mat3d b(bs); return dyad1(a,b); }
inline tens4d dyad2(const mat3ds& as, const mat3d& b) { mat3d a(as); return dyad2(a,b); }
inline tens4d dyad2(const mat3d& a, const mat3ds& bs) { mat3d b(bs); return dyad2(a,b); }
inline tens4d dyad2(const mat3ds& as, const mat3ds& bs) { mat3d a(as); mat3d b(bs); return dyad2(a,b); }
inline tens4d dyad3(const mat3ds& as, const mat3d& b) { mat3d a(as); return dyad3(a,b); }
inline tens4d dyad3(const mat3d& a, const mat3ds& bs) { mat3d b(bs); return dyad3(a,b); }
inline tens4d dyad3(const mat3ds& as, const mat3ds& bs) { mat3d a(as); mat3d b(bs); return dyad3(a,b); }
inline tens4d dyad4(const mat3ds& as, const mat3d& b) { mat3d a(as); return dyad4(a,b); }
inline tens4d dyad4(const mat3d& a, const mat3ds& bs) { mat3d b(bs); return dyad4(a,b); }
inline tens4d dyad4(const mat3ds& as, const mat3ds& bs) { mat3d a(as); mat3d b(bs); return dyad4(a,b); }
inline tens4d dyad1(const mat3dd& as, const mat3d& b) { mat3d a(as); return dyad1(a,b); }
inline tens4d dyad1(const mat3d& a, const mat3dd& bs) { mat3d b(bs); return dyad1(a,b); }
inline tens4d dyad1(const mat3dd& as, const mat3dd& bs) { mat3d a(as); mat3d b(bs); return dyad1(a,b); }
inline tens4d dyad2(const mat3dd& as, const mat3d& b) { mat3d a(as); return dyad2(a,b); }
inline tens4d dyad2(const mat3d& a, const mat3dd& bs) { mat3d b(bs); return dyad2(a,b); }
inline tens4d dyad2(const mat3dd& as, const mat3dd& bs) { mat3d a(as); mat3d b(bs); return dyad2(a,b); }
inline tens4d dyad3(const mat3dd& as, const mat3d& b) { mat3d a(as); return dyad3(a,b); }
inline tens4d dyad3(const mat3d& a, const mat3dd& bs) { mat3d b(bs); return dyad3(a,b); }
inline tens4d dyad3(const mat3dd& as, const mat3dd& bs) { mat3d a(as); mat3d b(bs); return dyad3(a,b); }
inline tens4d dyad4(const mat3dd& as, const mat3d& b) { mat3d a(as); return dyad4(a,b); }
inline tens4d dyad4(const mat3d& a, const mat3dd& bs) { mat3d b(bs); return dyad4(a,b); }
inline tens4d dyad4(const mat3dd& as, const mat3dd& bs) { mat3d a(as); mat3d b(bs); return dyad4(a,b); }
inline tens4d dyad1(const mat3dd& ad, const mat3ds& bs) { mat3d a(ad); mat3d b(bs); return dyad1(a,b); }
inline tens4d dyad1(const mat3ds& as, const mat3dd& bd) { mat3d a(as); mat3d b(bd); return dyad1(a,b); }
inline tens4d dyad2(const mat3dd& ad, const mat3ds& bs) { mat3d a(ad); mat3d b(bs); return dyad2(a,b); }
inline tens4d dyad2(const mat3ds& as, const mat3dd& bd) { mat3d a(as); mat3d b(bd); return dyad2(a,b); }
inline tens4d dyad3(const mat3dd& ad, const mat3ds& bs) { mat3d a(ad); mat3d b(bs); return dyad3(a,b); }
inline tens4d dyad3(const mat3ds& as, const mat3dd& bd) { mat3d a(as); mat3d b(bd); return dyad3(a,b); }
inline tens4d dyad4(const mat3dd& ad, const mat3ds& bs) { mat3d a(ad); mat3d b(bs); return dyad4(a,b); }
inline tens4d dyad4(const mat3ds& as, const mat3dd& bd) { mat3d a(as); mat3d b(bd); return dyad4(a,b); }
// other common operations
mat3d vdotTdotv(const vec3d& a, const tens4d& T, const vec3d& b);
tens4d ddot(const tens4d& a, const tens4d& b);
tens4d ddot(const tens4d& a, const tens4ds& b);
inline mat3d ddot(const tens4d& a, const mat3d& m) { return a.dot(m); }
inline mat3d ddot(const tens4d& a, const mat3ds& m) { return a.dot(m); }
inline mat3d ddot(const tens4d& a, const mat3dd& m) { return a.dot(m); }
inline tens4d operator * (const double g, const tens4d& a) { return a*g; }
class tens4fs
{
public:
enum { NNZ = 21 };
// default constructor
tens4fs() {}
tens4fs(const float g)
{
d[0] = g;
d[1] = g; d[2] = g;
d[3] = g; d[4] = g; d[5] = g;
d[6] = g; d[7] = g; d[8] = g; d[9] = g;
d[10] = g; d[11] = g; d[12] = g; d[13] = g; d[14] = g;
d[15] = g; d[16] = g; d[17] = g; d[18] = g; d[19] = g; d[20] = g;
}
tens4fs(float m[6][6])
{
d[0] = m[0][0];
d[1] = m[0][1]; d[2] = m[1][1];
d[3] = m[0][2]; d[4] = m[1][2]; d[5] = m[2][2];
d[6] = m[0][3]; d[7] = m[1][3]; d[8] = m[2][3]; d[9] = m[3][3];
d[10] = m[0][4]; d[11] = m[1][4]; d[12] = m[2][4]; d[13] = m[3][4]; d[14] = m[4][4];
d[15] = m[0][5]; d[16] = m[1][5]; d[17] = m[2][5]; d[18] = m[3][5]; d[19] = m[4][5]; d[20] = m[5][5];
}
tens4fs(float D[21])
{
d[0] = D[0];
d[1] = D[1]; d[2] = D[2];
d[3] = D[3]; d[4] = D[4]; d[5] = D[5];
d[6] = D[6]; d[7] = D[7]; d[8] = D[8]; d[9] = D[9];
d[10] = D[10]; d[11] = D[11]; d[12] = D[12]; d[13] = D[13]; d[14] = D[14];
d[15] = D[15]; d[16] = D[16]; d[17] = D[17]; d[18] = D[18]; d[19] = D[19]; d[20] = D[20];
}
float& operator () (int i, int j, int k, int l)
{
const int m[3][3] = { { 0,3,5 },{ 3,1,4 },{ 5,4,2 } };
tens4fs& T = (*this);
return T(m[i][j], m[k][l]);
}
float operator () (int i, int j, int k, int l) const
{
const int m[3][3] = { { 0,3,5 },{ 3,1,4 },{ 5,4,2 } };
const tens4fs& T = (*this);
return T(m[i][j], m[k][l]);
}
float& operator () (int i, int j)
{
const int m[6] = { 0, 1, 3, 6, 10, 15 };
if (i <= j) return d[m[j] + i]; else return d[m[i] + j];
}
float operator () (int i, int j) const
{
const int m[6] = { 0, 1, 3, 6, 10, 15 };
if (i <= j) return d[m[j] + i]; else return d[m[i] + j];
}
// arithmetic operators
tens4fs operator + (const tens4fs& t) const {
tens4fs s;
for (int i = 0; i < NNZ; i++) s.d[i] = d[i] + t.d[i];
return s;
}
tens4fs operator - (const tens4fs& t) const {
tens4fs s;
for (int i = 0; i < NNZ; i++) s.d[i] = d[i] - t.d[i];
return s;
}
tens4fs operator * (float g) const {
tens4fs s;
for (int i = 0; i < NNZ; i++) s.d[i] = g * d[i];
return s;
}
tens4fs operator / (float g) const {
tens4fs s;
for (int i = 0; i < NNZ; i++) s.d[i] = d[i] / g;
return s;
}
// arithmetic assignment operators
tens4fs& operator += (const tens4fs& t) {
for (int i = 0; i < NNZ; i++) d[i] += t.d[i];
return (*this);
}
tens4fs& operator -= (const tens4fs& t) {
for (int i = 0; i < NNZ; i++) d[i] -= t.d[i];
return (*this);
}
tens4fs& operator *= (float g) {
for (int i = 0; i < NNZ; i++) d[i] *= g;
return (*this);
}
tens4fs& operator /= (float g) {
for (int i = 0; i < NNZ; i++) d[i] /= g;
return (*this);
}
// unary operators
tens4fs operator - () const {
tens4fs s;
for (int i = 0; i < NNZ; i++) s.d[i] = -d[i];
return s;
}
// double dot product with tensor
mat3fs dot(const mat3fs& m) const {
mat3fs a;
a.x = d[0] * m.x + d[1] * m.y + d[3] * m.z + 2 * d[6] * m.xy + 2 * d[10] * m.yz + 2 * d[15] * m.xz;
a.y = d[1] * m.x + d[2] * m.y + d[4] * m.z + 2 * d[7] * m.xy + 2 * d[11] * m.yz + 2 * d[16] * m.xz;
a.z = d[3] * m.x + d[4] * m.y + d[5] * m.z + 2 * d[8] * m.xy + 2 * d[12] * m.yz + 2 * d[17] * m.xz;
a.xy = d[6] * m.x + d[7] * m.y + d[8] * m.z + 2 * d[9] * m.xy + 2 * d[13] * m.yz + 2 * d[18] * m.xz;
a.yz = d[10] * m.x + d[11] * m.y + d[12] * m.z + 2 * d[13] * m.xy + 2 * d[14] * m.yz + 2 * d[19] * m.xz;
a.xz = d[15] * m.x + d[16] * m.y + d[17] * m.z + 2 * d[18] * m.xy + 2 * d[19] * m.yz + 2 * d[20] * m.xz;
return a;
}
// trace
float tr() const {
return (d[0] + d[2] + d[5] + 2 * (d[1] + d[3] + d[4]));
}
// initialize to zero
void zero() {
d[0] = d[1] = d[2] = d[3] = d[4] = d[5] = d[6] = d[7] = d[8] = d[9] =
d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = d[18] = d[19] = d[20] = 0;
}
// extract 6x6 Matrix
void extract(float D[6][6]) {
D[0][0] = d[0]; D[0][1] = d[1]; D[0][2] = d[3]; D[0][3] = d[6]; D[0][4] = d[10]; D[0][5] = d[15];
D[1][0] = d[1]; D[1][1] = d[2]; D[1][2] = d[4]; D[1][3] = d[7]; D[1][4] = d[11]; D[1][5] = d[16];
D[2][0] = d[3]; D[2][1] = d[4]; D[2][2] = d[5]; D[2][3] = d[8]; D[2][4] = d[12]; D[2][5] = d[17];
D[3][0] = d[6]; D[3][1] = d[7]; D[3][2] = d[8]; D[3][3] = d[9]; D[3][4] = d[13]; D[3][5] = d[18];
D[4][0] = d[10]; D[4][1] = d[11]; D[4][2] = d[12]; D[4][3] = d[13]; D[4][4] = d[14]; D[4][5] = d[19];
D[5][0] = d[15]; D[5][1] = d[16]; D[5][2] = d[17]; D[5][3] = d[18]; D[5][4] = d[19]; D[5][5] = d[20];
}
// calculates the inverse
// tens4fs inverse() const;
public:
float d[NNZ]; // stored in column major order
};
// The following file contains the actual definition of the class functions
#include "tens4d.hpp"
| Unknown |
3D | febiosoftware/FEBio | FECore/FESolidElement.h | .h | 4,677 | 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 "FEElement.h"
//-----------------------------------------------------------------------------
//! This class defines a solid element
class FECORE_API FESolidElement : public FEElement
{
public:
//! default constructor
FESolidElement() {}
//! copy constructor
FESolidElement(const FESolidElement& el);
//! assignment operator
FESolidElement& operator = (const FESolidElement& el);
//! set the element traits
void SetTraits(FEElementTraits* pt) override;
double gr(int n) const { return ((FESolidElementTraits*)(m_pT))->gr[n]; } // integration point coordinate r
double gs(int n) const { return ((FESolidElementTraits*)(m_pT))->gs[n]; } // integration point coordinate s
double gt(int n) const { return ((FESolidElementTraits*)(m_pT))->gt[n]; } // integration point coordinate t
double* GaussWeights() const { return &((FESolidElementTraits*)(m_pT))->gw[0]; } // weights of integration points
double* Gr(int n) const { return ((FESolidElementTraits*)(m_pT))->m_Gr[n]; } // shape function derivative to r
double* Gs(int n) const { return ((FESolidElementTraits*)(m_pT))->m_Gs[n]; } // shape function derivative to s
double* Gt(int n) const { return ((FESolidElementTraits*)(m_pT))->m_Gt[n]; } // shape function derivative to t
double* Grr(int n) const { return ((FESolidElementTraits*)(m_pT))->Grr[n]; } // shape function 2nd derivative to rr
double* Gsr(int n) const { return ((FESolidElementTraits*)(m_pT))->Gsr[n]; } // shape function 2nd derivative to sr
double* Gtr(int n) const { return ((FESolidElementTraits*)(m_pT))->Gtr[n]; } // shape function 2nd derivative to tr
double* Grs(int n) const { return ((FESolidElementTraits*)(m_pT))->Grs[n]; } // shape function 2nd derivative to rs
double* Gss(int n) const { return ((FESolidElementTraits*)(m_pT))->Gss[n]; } // shape function 2nd derivative to ss
double* Gts(int n) const { return ((FESolidElementTraits*)(m_pT))->Gts[n]; } // shape function 2nd derivative to ts
double* Grt(int n) const { return ((FESolidElementTraits*)(m_pT))->Grt[n]; } // shape function 2nd derivative to rt
double* Gst(int n) const { return ((FESolidElementTraits*)(m_pT))->Gst[n]; } // shape function 2nd derivative to st
double* Gtt(int n) const { return ((FESolidElementTraits*)(m_pT))->Gtt[n]; } // shape function 2nd derivative to tt
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t) const { ((FESolidElementTraits*)(m_pT))->shape_fnc(H, r, s, t); }
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t) const { ((FESolidElementTraits*)(m_pT))->shape_deriv(Hr, Hs, Ht, r, s, t); }
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t) const { ((FESolidElementTraits*)(m_pT))->shape_deriv2(Hrr, Hss, Htt, Hrs, Hst, Hrt, r, s, t); }
vec3d evaluate(vec3d* v, double r, double s, double t) const;
double evaluate(double* v, double r, double s, double t) const;
double* Gr(int order, int n) const;
double* Gs(int order, int n) const;
double* Gt(int order, int n) const;
void Serialize(DumpStream& ar) override;
public:
std::vector<bool> m_bitfc; //!< flag for interface nodes
std::vector<mat3d> m_J0i; //!< inverse of reference Jacobian
};
| Unknown |
3D | febiosoftware/FEBio | FECore/MReplace.cpp | .cpp | 4,410 | 169 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "MMath.h"
#include "MEvaluate.h"
#include "MathObject.h"
#include <map>
#include <string>
using namespace std;
//-----------------------------------------------------------------------------
MITEM MReplace(const MITEM& e, const MITEM& x)
{
if (is_equation(x))
{
MITEM l = x.Left();
MITEM r = x.Right();
return MReplace(e, l, r);
}
else return e;
}
//-----------------------------------------------------------------------------
MITEM MReplace(const MITEM& e, const MVariable& x, const MITEM& s)
{
MITEM v(x);
return MReplace(e,v,s);
}
//-----------------------------------------------------------------------------
MITEM MReplace(const MITEM& e, const MITEM& x, const MITEM& s)
{
// see if they are equal
if (e == x) return s;
switch (e.Type())
{
case MCONST:
case MFRAC:
case MNAMED:
case MVAR:
return e;
case MNEG:
return MEvaluate(-(MReplace(-e, x, s)));
case MADD:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MEvaluate(l+r);
}
case MSUB:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MEvaluate(l-r);
}
case MMUL:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MEvaluate(l*r);
}
case MDIV:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MEvaluate(l/r);
}
case MPOW:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MEvaluate(l^r);
}
case MEQUATION:
{
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return MITEM(new MEquation(l.copy(), r.copy()));
}
case MF1D:
{
const MFunc1D* pf = mfnc1d(e);
MITEM p = pf->Item()->copy();
return new MFunc1D(pf->funcptr(), pf->Name(), MReplace(p, x, s).copy());
}
case MF2D:
{
const MFunc2D* pf = mfnc2d(e);
MITEM l = MReplace(e.Left (), x, s);
MITEM r = MReplace(e.Right(), x, s);
return new MFunc2D(pf->funcptr(), pf->Name(), l.copy(), r.copy());
}
/* case MSFND:
{
MSFuncND* pf = msfncnd(e);
MITEM v(pf->Item()->copy());
MITEM vnew = MReplace(v, x, s);
string s = pf->Name();
M1DFuncDef* pfd = DEF1D.find(s)->second;
assert(pfd);
return pfd->CreateFunction(vnew.ItemPtr());
}
*/ case MMATRIX:
{
const MMatrix* pm = mmatrix(e);
int nrows = pm->rows();
int ncols = pm->columns();
MMatrix* pmnew = new MMatrix;
pmnew->Create(nrows, ncols);
for (int i=0; i<nrows; ++i)
for (int j=0; j<nrows; ++j)
{
MITEM mij = pm->Item(i,j)->copy();
(*pmnew)[i][j] = MReplace(mij, x, s).copy();
}
return pmnew;
}
}
assert(false);
return e;
}
//-----------------------------------------------------------------------------
// replace multiple expressions with other expressions
MITEM MReplace(const MITEM& e, const MSequence& x, const MSequence& s)
{
if (x.size() != s.size()) return e;
MITEM r = e;
const int N = x.size();
for (int i=0; i<N; ++i)
{
MITEM xi = x[i]->copy();
MITEM si = s[i]->copy();
r = MReplace(r, xi, si);
}
return r;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEBodyConstraint.h | .h | 2,012 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FENLConstraint.h"
#include "FEDomain.h"
#include "FEDomainList.h"
// Base class for nonlinear constraints that are defined using a surface.
class FECORE_API FEBodyConstraint : public FENLConstraint
{
FECORE_BASE_CLASS(FEBodyConstraint)
public:
FEBodyConstraint(FEModel* fem);
bool Init() override;
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/FECoreClass.h | .h | 1,573 | 40 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "fecore_api.h"
// Generic base class for classes that don't fit in the super-class structure
class FECORE_API FECoreClass : public FECoreBase
{
FECORE_SUPER_CLASS(FECLASS_ID)
public:
FECoreClass(FEModel* fem = nullptr);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEModelParam.h | .h | 6,017 | 217 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEScalarValuator.h"
#include "FEVec3dValuator.h"
#include "FEMat3dValuator.h"
#include "FEMat3dsValuator.h"
#include "FEItemList.h"
//---------------------------------------------------------------------------------------
// Base for model parameters.
class FECORE_API FEModelParam
{
public:
FEModelParam();
virtual ~FEModelParam();
// set the domain
void SetItemList(FEItemList* itemList) { m_dom = itemList; }
// get the domain list
FEItemList* GetItemList() { return m_dom; }
// set the scale factor
void SetScaleFactor(double s) { m_scl = s; }
// return the scale factor
double GetScaleFactor() const { return m_scl; }
public: // serialization
virtual void Serialize(DumpStream& ar);
// these are never called, but we need them to compile some templates
static void SaveClass(DumpStream& ar, FEModelParam*& a) { assert(false); }
static FEModelParam* LoadClass(DumpStream& ar, FEModelParam* a) { assert(false); return nullptr; }
protected:
double m_scl; //!< scale factor. Used to store load curve value
FEItemList* m_dom;
};
//---------------------------------------------------------------------------------------
class FECORE_API FEParamDouble : public FEModelParam
{
public:
FEParamDouble();
~FEParamDouble();
FEParamDouble(const FEParamDouble& p);
// set the value
void operator = (double v);
void operator = (const FEParamDouble& p);
// set the valuator
void setValuator(FEScalarValuator* val);
// get the valuator
FEScalarValuator* valuator();
// evaluate the parameter at a material point
double operator () (const FEMaterialPoint& pt) { return m_scl*(*m_val)(pt); }
// is this a const value
bool isConst() const;
// get the const value (return value undefined if param is not const)
double& constValue();
double constValue() const;
void Serialize(DumpStream& ar) override;
bool Init();
private:
FEScalarValuator* m_val;
};
//=======================================================================================
//---------------------------------------------------------------------------------------
class FECORE_API FEParamVec3 : public FEModelParam
{
public:
FEParamVec3();
~FEParamVec3();
FEParamVec3(const FEParamVec3& p);
bool Init();
// set the value
void operator = (const vec3d& v);
void operator = (const FEParamVec3& p);
// set the valuator
void setValuator(FEVec3dValuator* val);
FEVec3dValuator* valuator();
// evaluate the parameter at a material point
vec3d operator () (const FEMaterialPoint& pt) { return (*m_val)(pt)*m_scl; }
// return a unit vector
vec3d unitVector(const FEMaterialPoint& pt) { return (*this)(pt).normalized(); }
// is this a const
bool isConst() const { return m_val->isConst(); }
// (return value undefined if param is not const)
vec3d& constValue() { assert(isConst()); return *m_val->constValue(); };
void Serialize(DumpStream& ar) override;
private:
FEVec3dValuator* m_val;
};
//=======================================================================================
//---------------------------------------------------------------------------------------
class FECORE_API FEParamMat3d : public FEModelParam
{
public:
FEParamMat3d();
~FEParamMat3d();
FEParamMat3d(const FEParamMat3d& p);
// set the value
void operator = (const mat3d& v);
void operator = (const FEParamMat3d& v);
bool Init();
// set the valuator
void setValuator(FEMat3dValuator* val);
// get the valuator
FEMat3dValuator* valuator();
// evaluate the parameter at a material point
mat3d operator () (const FEMaterialPoint& pt) { return (*m_val)(pt)*m_scl; }
// is this a const
bool isConst() const { return m_val->isConst(); }
// (return value undefined if not constant)
mat3d& constValue() { assert(isConst()); return *m_val->constValue(); };
void Serialize(DumpStream& ar) override;
private:
FEMat3dValuator* m_val;
};
//---------------------------------------------------------------------------------------
class FECORE_API FEParamMat3ds : public FEModelParam
{
public:
FEParamMat3ds();
~FEParamMat3ds();
FEParamMat3ds(const FEParamMat3ds& p);
// set the value
void operator = (const mat3ds& v);
void operator = (const FEParamMat3ds& v);
// set the valuator
void setValuator(FEMat3dsValuator* val);
// get the valuator
FEMat3dsValuator* valuator();
// evaluate the parameter at a material point
mat3ds operator () (const FEMaterialPoint& pt) { return (*m_val)(pt)*m_scl; }
// is this a const
bool isConst() const { return m_val->isConst(); }
// (return value undefined if not constant)
mat3ds& constValue() { assert(isConst()); return *m_val->constValue(); };
void Serialize(DumpStream& ar) override;
private:
FEMat3dsValuator* m_val;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEGlobalData.cpp | .cpp | 1,474 | 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.*/
#include "stdafx.h"
#include "FEGlobalData.h"
//-----------------------------------------------------------------------------
FEGlobalData::FEGlobalData(FEModel* fem) : FEModelComponent(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMat3dSphericalAngleMap.cpp | .cpp | 3,235 | 101 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEMat3dSphericalAngleMap.h"
BEGIN_FECORE_CLASS(FEMat3dSphericalAngleMap, FEMat3dValuator)
ADD_PARAMETER(m_theta, "theta");
ADD_PARAMETER(m_phi, "phi");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dSphericalAngleMap::FEMat3dSphericalAngleMap(FEModel* pfem) : FEMat3dValuator(pfem)
{
m_theta = 0.0;
m_phi = 90.0;
}
//-----------------------------------------------------------------------------
bool FEMat3dSphericalAngleMap::Init()
{
return true;
}
//-----------------------------------------------------------------------------
void FEMat3dSphericalAngleMap::SetAngles(double theta, double phi)
{
m_theta = theta;
m_phi = phi;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dSphericalAngleMap::operator () (const FEMaterialPoint& mp)
{
// convert from degress to radians
const double the = m_theta(mp)*PI / 180.;
const double phi = m_phi(mp)*PI / 180.;
// define the first axis (i.e. the fiber vector)
vec3d a;
a.x = cos(the)*sin(phi);
a.y = sin(the)*sin(phi);
a.z = cos(phi);
vec3d b;
b.x = -sin(the);
b.y = cos(the);
b.z = 0;
vec3d c;
c.x = -cos(the)*cos(phi);
c.y = -sin(the)*cos(phi);
c.z = sin(phi);
// setup the rotation matrix
mat3d Q;
Q[0][0] = a.x; Q[0][1] = b.x; Q[0][2] = c.x;
Q[1][0] = a.y; Q[1][1] = b.y; Q[1][2] = c.y;
Q[2][0] = a.z; Q[2][1] = b.z; Q[2][2] = c.z;
return Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dSphericalAngleMap::copy()
{
FEMat3dSphericalAngleMap* map = new FEMat3dSphericalAngleMap(GetFEModel());
map->m_theta = m_theta;
map->m_phi = m_phi;
return map;
}
//-----------------------------------------------------------------------------
void FEMat3dSphericalAngleMap::Serialize(DumpStream &ar)
{
if (ar.IsShallow()) return;
ar & m_theta & m_phi;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEElementSet.h | .h | 3,768 | 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 "fecore_api.h"
#include "FEItemList.h"
#include "FEElement.h"
#include "FEDomainList.h"
#include "FENodeList.h"
#include <vector>
#include <string>
//-----------------------------------------------------------------------------
class FEMesh;
class DumpStream;
//-----------------------------------------------------------------------------
// This class defines a set of elements
class FECORE_API FEElementSet : public FEItemList
{
public:
//! constructor
FEElementSet(FEModel* fem); // TODO: remove!
FEElementSet(FEMesh* fem);
// Create the element set
void Create(const std::vector<int>& elemList);
void Create(FEDomain* dom, const std::vector<int>& elemList);
void CopyFrom(FEElementSet& eset);
// add another element set
void Add(const FEElementSet& set);
// Create the element set from a domain
void Create(FEDomain* dom);
// Create the element set from a domain
void Create(FEDomainList& dom);
// Return number of elements in the set
int Elements() const { return (int)m_Elem.size(); }
int operator [] (int i) const { return m_Elem[i]; }
// return the local index of an element into the element set
// returns -1 if the element is not part of element set
int GetLocalIndex(const FEElement& el) const;
bool Contains(const FEElement& el) const;
// Get the element ID list
const std::vector<int>& GetElementIDList() const { return m_Elem; }
// get the domain list that generated the element set
FEDomainList& GetDomainList() { return m_dom; }
const FEDomainList& GetDomainList() const { return m_dom; }
// Get an element
FEElement& Element(int i);
const FEElement& Element(int i) const;
// create node list from this element set
FENodeList GetNodeList() const;
public:
void Serialize(DumpStream& ar) override;
static void SaveClass(DumpStream& ar, FEElementSet* p);
static FEElementSet* LoadClass(DumpStream& ar, FEElementSet* p);
private:
// Build the lookup table
void BuildLUT();
protected:
std::vector<int> m_Elem; //!< list of elements' global ID
FEDomainList m_dom; //!< domain list that generated the element set
// used for fast lookup in GetLocalIndex
std::vector<int> m_LUT;
int m_minID, m_maxID;
};
inline int FEElementSet::GetLocalIndex(const FEElement& el) const
{
int eid = el.GetID();
if ((eid < m_minID) || (eid > m_maxID)) return -1;
else return m_LUT[el.GetID() - m_minID];
}
inline bool FEElementSet::Contains(const FEElement& el) const
{
return (GetLocalIndex(el) != -1);
}
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMeshPartition.h | .h | 4,839 | 151 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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"
#include "fecore_enum.h"
#include "FESolver.h"
#include "FEGlobalVector.h"
#include "FETimeInfo.h"
#include <functional>
//-----------------------------------------------------------------------------
// forward declaration of classes
class FEModel;
class FENode;
class FEMesh;
class FEDataExport;
class FEGlobalMatrix;
class FEElementSet;
//-----------------------------------------------------------------------------
//! This class describes a mesh partition, that is, a group of elements that represent
//! a part of the mesh.
class FECORE_API FEMeshPartition : public FECoreBase
{
public:
//! constructor
FEMeshPartition(int nclass, FEModel* fem);
//! virtual destructor
virtual ~FEMeshPartition();
//! return domain class
int Class() { return m_nclass; }
//! set the mesh of this domain
void SetMesh(FEMesh* pm) { m_pMesh = pm; }
//! get the mesh of this domain
FEMesh* GetMesh() { return m_pMesh; }
const FEMesh* GetMesh() const { return m_pMesh; }
//! find the element with a specific ID
FEElement* FindElementFromID(int nid);
//! serialization
void Serialize(DumpStream& ar) override;
public:
//! return number of nodes
int Nodes() const { return (int)m_Node.size(); }
//! return a specific node
FENode& Node(int i);
const FENode& Node(int i) const;
//! return the global node index from a local index
int NodeIndex(int i) const { return m_Node[i]; }
public: // interface for derived classes
//! return number of elements
virtual int Elements() const = 0;
//! return a reference to an element \todo this is not the preferred interface but I've added it for now
virtual FEElement& ElementRef(int i) = 0;
virtual const FEElement& ElementRef(int i) const = 0;
public: // optional functions to overload
//! reset the domain
virtual void Reset() {}
//! create a copy of this domain
virtual void CopyFrom(FEMeshPartition* pd);
//! initialize domain
//! one-time initialization, called during model initialization
bool Init() override;
//! This function is called at the start of a solution step.
//! Domain classes can use this to update time dependant quantities
//! \todo replace this by a version of Update that takes a flag that indicates
//! whether the update is final or not
virtual void PreSolveUpdate(const FETimeInfo& timeInfo) {}
//! Update domain data.
//! This is called when the model state needs to be updated (i.e. at the end of each Newton iteration)
virtual void Update(const FETimeInfo& tp) {}
public:
//! Initialize material points in the domain (optional)
virtual void InitMaterialPoints() {}
// Loop over all material points
void ForEachMaterialPoint(std::function<void(FEMaterialPoint& mp)> f);
// Loop over all elements
void ForEachElement(std::function<void(FEElement& el)> f);
public:
// This is an experimental feature.
// The idea is to let the class define what data it wants to export
// The hope is to eliminate the need for special plot and log classes
// and to automate the I/O completely.
void AddDataExport(FEDataExport* pd);
int DataExports() const { return (int)m_Data.size(); }
FEDataExport* GetDataExport(int i) { return m_Data[i]; }
public:
bool IsActive() const { return m_bactive; }
void SetActive(bool b) { m_bactive = b; }
protected:
FEMesh* m_pMesh; //!< the mesh that this domain is a part of
vector<int> m_Node; //!< list of nodes in this domain
protected:
int m_nclass; //!< domain class
bool m_bactive;
private:
vector<FEDataExport*> m_Data; //!< list of data export classes
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEPrescribedBC.h | .h | 3,690 | 114 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FENodalBC.h"
#include "FESurfaceBC.h"
#include "FEDofList.h"
//-----------------------------------------------------------------------------
// Base class for prescribed BCs on a nodeset
class FECORE_API FEPrescribedNodeSet : public FENodalBC
{
public:
FEPrescribedNodeSet(FEModel* fem);
void Activate() override;
// deactivation
void Deactivate() override;
void Update() override;
void Repair() override;
// set the relative flag
void SetRelativeFlag(bool br);
// This function is called when the solver needs to know the
// prescribed dof values. The brel flag indicates wheter the total
// value is needed or the value with respect to the current nodal dof value
void PrepStep(std::vector<double>& ui, bool brel = true) override;
// serialization
void Serialize(DumpStream& ar) override;
//! Derived classes need to override this function.
//! return the value for node i, dof j (i is index into nodeset, j is index into doflist)
virtual void GetNodalValues(int nodelid, std::vector<double>& val) = 0;
protected:
bool m_brelative; //!< relative flag
protected:
std::vector<double> m_rval; //!< values used for relative BC
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// Base class for prescribed BCs on a surface
class FECORE_API FEPrescribedSurface : public FESurfaceBC
{
public:
FEPrescribedSurface(FEModel* fem);
void Activate() override;
// deactivation
void Deactivate() override;
void Update() override;
void Repair() override;
// This function is called when the solver needs to know the
// prescribed dof values. The brel flag indicates wheter the total
// value is needed or the value with respect to the current nodal dof value
void PrepStep(std::vector<double>& ui, bool brel = true) override;
// set the relative flag
void SetRelativeFlag(bool br);
// serialization
void Serialize(DumpStream& ar) override;
//! Derived classes need to override this function.
//! return the value for node i, dof j (i is index into nodeset, j is index into doflist)
virtual void GetNodalValues(int nodelid, std::vector<double>& val) = 0;
protected:
bool m_brelative; //!< relative flag
protected:
FENodeList m_nodeList; //!< list of nodes to apply bc too
std::vector<double> m_rval; //!< values used for relative BC
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMergedConstraint.h | .h | 2,055 | 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 <FECore/FEMesh.h>
#include "fecore_api.h"
#include <vector>
//-----------------------------------------------------------------------------
// Forward declaration of FEModel class
class FEModel;
//-----------------------------------------------------------------------------
// A merged constraint takes two surfaces and merges them by matching each node of one surface
// to the corresponding node on the other surface and then generates a linear constraint
// between the two nodes that essentially matches the degrees of freedom.
class FECORE_API FEMergedConstraint
{
public:
FEMergedConstraint(FEModel& fem);
~FEMergedConstraint();
bool Merge(FEFacetSet* surf1, FEFacetSet* surf2, const std::vector<int>& dofList);
private:
FEModel& m_fem;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataMap.cpp | .cpp | 2,200 | 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.*/
#include "stdafx.h"
#include "FEDataMap.h"
#include "fecore_type.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
FEDataMap::FEDataMap(FEDataMapType mapType, FEDataType dataType) : FEDataArray(mapType, dataType) {}
//-----------------------------------------------------------------------------
FEDataMap::FEDataMap(const FEDataMap& map) : FEDataArray(map) {}
//-----------------------------------------------------------------------------
void FEDataMap::SetName(const std::string& name)
{
m_name = name;
}
//-----------------------------------------------------------------------------
const std::string& FEDataMap::GetName() const { return m_name; }
//-----------------------------------------------------------------------------
void FEDataMap::Serialize(DumpStream& ar)
{
FEDataArray::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_name;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEModelDataRecord.cpp | .cpp | 2,318 | 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.*/
#include "stdafx.h"
#include "FEModelDataRecord.h"
FEModelLogData::FEModelLogData(FEModel* fem) : FELogData(fem) {}
FEModelLogData::~FEModelLogData() {}
FEModelDataRecord::FEModelDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_MODEL) {}
double FEModelDataRecord::Evaluate(int item, int ndata)
{
assert(item == 0);
return m_data[ndata]->value();
}
void FEModelDataRecord::ClearData()
{
for (int i = 0; i < m_data.size(); ++i) delete m_data[i];
m_data.clear();
}
void FEModelDataRecord::SetData(const char* szexpr)
{
char szcopy[MAX_STRING] = { 0 };
strcpy(szcopy, szexpr);
char* sz = szcopy, * ch;
ClearData();
strcpy(m_szdata, szexpr);
do
{
ch = strchr(sz, ';');
if (ch) *ch++ = 0;
FEModelLogData* pdata = fecore_new<FEModelLogData>(sz, GetFEModel());
if (pdata) m_data.push_back(pdata);
else throw UnknownDataField(sz);
sz = ch;
} while (ch);
}
void FEModelDataRecord::SelectAllItems()
{
std::vector<int> items;
items.push_back(0);
SetItemList(items);
}
int FEModelDataRecord::Size() const
{
return 1;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENodeReorder.h | .h | 2,113 | 55 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FELevelStructure.h"
//-----------------------------------------------------------------------------
//! This class implements an algoritm that calculates a permutation of
//! the node numbering in order to obtain a bandwidth reduced stiffness matrix
//! The algorithm comes from "An algorithm for reducing the bandwidth and
//! profile of a sparse matrix", by N.E.Gibbs e.a. It applies the algorithm
//! on the node numberings in stead of the actual sparse matrix since that
//! was easier to implement :). In the future I would like to extend it to
//! work with the actual sparse matrix.
class FECORE_API FENodeReorder
{
public:
//! default constructor
FENodeReorder();
//! destructor
virtual ~FENodeReorder();
//! calculates the permutation vector
void Apply(FEMesh& m, std::vector<int>& P);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FELogElemData.cpp | .cpp | 1,401 | 31 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FELogElemData.h"
FELogElemData::FELogElemData(FEModel* fem) : FELogData(fem) {}
FELogElemData::~FELogElemData() {}
| C++ |
3D | febiosoftware/FEBio | FECore/FEElementTraits.h | .h | 58,437 | 2,247 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "matrix.h"
#include "vec3d.h"
#include "mat3d.h"
#include "fecore_enum.h"
#include <vector>
//-----------------------------------------------------------------------------
// Forward declaration of the FEElement class
class FEElement;
class FESolidElementShape;
class FESurfaceElementShape;
//-----------------------------------------------------------------------------
//! This class is the base class for all element trait's classes
class FECORE_API FEElementTraits
{
public:
//! constructor
FEElementTraits(int ni, int ne, FE_Element_Class c, FE_Element_Shape s, FE_Element_Type t);
//! destructor
virtual ~FEElementTraits(){}
//! return the element class
FE_Element_Class Class() const { return m_spec.eclass; }
//! return the element shape
FE_Element_Shape Shape() const { return m_spec.eshape; }
//! return the element type
FE_Element_Type Type() const { return m_spec.etype; }
// project integration point data to nodes
virtual void project_to_nodes(double* ai, double* ao) const {}
virtual void project_to_nodes(vec3d* ai, vec3d* ao) const;
virtual void project_to_nodes(mat3ds* ai, mat3ds* ao) const;
virtual void project_to_nodes(mat3d* ai, mat3d* ao) const;
virtual int ShapeFunctions(int order) { return m_neln; }
int Faces() const { return m_faces; }
public:
int m_nint; //!< number of integration points
int m_neln; //!< number of element nodes
matrix m_H; //!< shape function values at gausspoints.
//!< The first index refers to the gauss-point,
//!< the second index to the shape function
std::vector<matrix> m_Hp; //!< shape function values at gausspoints.
//!< The first index refers to the gauss-point,
//!< the second index to the shape function
FE_Element_Spec m_spec; //!< element specs
protected:
// number of faces of element
int m_faces;
//! function to allocate storage for integration point data
virtual void init() = 0;
};
//=============================================================================
// S O L I D E L E M E N T
//
// This section defines a set of solid element formulation used in 3D finite
// element models.
//=============================================================================
//=============================================================================
//! This class defines the specific traits for solid elements and serves as
//! a base class for specific solid element formulations
//
class FECORE_API FESolidElementTraits : public FEElementTraits
{
public:
//! constructor
FESolidElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
//! initialize element traits data
void init() override;
//! values of shape functions
void shape_fnc(double* H, double r, double s, double t);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t);
//! values of shape function second derivatives
void shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t);
int ShapeFunctions(int order) override;
public:
// gauss-point coordinates and weights
std::vector<double> gr;
std::vector<double> gs;
std::vector<double> gt;
std::vector<double> gw;
// element shape class
FESolidElementShape* m_shape;
std::vector<FESolidElementShape*> m_shapeP; // shape classes for different order (some orders can by null)
// local derivatives of shape functions at gauss points
matrix m_Gr, m_Gs, m_Gt;
std::vector<matrix> m_Gr_p;
std::vector<matrix> m_Gs_p;
std::vector<matrix> m_Gt_p;
// local second derivatives of shape functions at gauss points
matrix Grr, Gsr, Gtr, Grs, Gss, Gts, Grt, Gst, Gtt;
};
//=============================================================================
class FECORE_API FESRISolidElementTraits
{
public:
FESRISolidElementTraits() : m_pTRI(0) {}
~FESRISolidElementTraits() { if (m_pTRI) delete m_pTRI; }
FESolidElementTraits* m_pTRI;
};
//=============================================================================
//! Base class for 8-node hexahedral elements
class FEHex8_ : public FESolidElementTraits
{
public:
enum { NELN = 8 };
//! initialize element traits data
void init();
public:
FEHex8_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_HEX8, et) {}
};
//=============================================================================
// 8-node hexahedral elements with 8-point gaussian quadrature
//
class FEHex8G8 : public FEHex8_
{
public:
enum { NINT = 8 };
public:
FEHex8G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 8-node hexahedral elements with 6-point reduced integration rule
//
class FEHex8RI : public FEHex8_
{
public:
enum { NINT = 6 };
public:
FEHex8RI();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// 8-node hexahedral element with uniform deformation gradient
class FEHex8G1 : public FEHex8_
{
public:
enum { NINT = 1 };
public:
FEHex8G1();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//! Base class for 4-node linear tetrahedrons
class FETet4_ : public FESolidElementTraits
{
public:
enum { NELN = 4 };
//! initialize element traits data
void init();
public:
FETet4_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_TET4, et) {}
};
//=============================================================================
// single Gauss point integrated tet element
class FETet4G1 : public FETet4_
{
public:
enum { NINT = 1};
public:
FETet4G1();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// 4-node tetrahedral element using a 4-node Gaussian integration rule
class FETet4G4 : public FETet4_
{
public:
enum { NINT = 4 };
public:
FETet4G4();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
//! Base class for 5-node linear tetrahedrons
class FETet5_ : public FESolidElementTraits
{
public:
enum { NELN = 5 };
//! initialize element traits data
void init();
public:
FETet5_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_TET5, et) {}
};
//=============================================================================
// 5-node tetrahedral element using a 4-node Gaussian integration rule
class FETet5G4 : public FETet5_
{
public:
enum { NINT = 4 };
public:
FETet5G4();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FEPenta6
//
//=============================================================================
//=============================================================================
//! Base class for 6-node pentahedral "wedge" elements
class FEPenta6_ : public FESolidElementTraits
{
public:
enum { NELN = 6 };
//! initialize element traits data
void init();
public:
FEPenta6_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_PENTA6, et){}
};
//=============================================================================
// 6-node pentahedral elements with 6-point gaussian quadrature
class FEPenta6G6 : public FEPenta6_
{
public:
enum { NINT = 6 };
public:
FEPenta6G6();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
//
// FEPenta15
//
//=============================================================================
//=============================================================================
//! Base class for 15-node quadratic pentahedral "wedge" elements
class FEPenta15_ : public FESolidElementTraits
{
public:
enum { NELN = 15 };
public:
FEPenta15_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_PENTA15, et){}
};
//=============================================================================
// 15-node pentahedral elements with 8-point gaussian quadrature
class FEPenta15G8 : public FEPenta15_
{
public:
enum { NINT = 8 };
public:
FEPenta15G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 15-node pentahedral elements with 21-point gaussian quadrature
class FEPenta15G21 : public FEPenta15_
{
public:
enum { NINT = 21 };
public:
FEPenta15G21();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
//
// FETet10
//
//=============================================================================
//=============================================================================
//! Base class for 10-node quadratic tetrahedral elements
class FETet10_ : public FESolidElementTraits
{
public:
enum { NELN = 10 };
//! initialize element traits data
void init();
public:
FETet10_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_TET10, et){}
};
//=============================================================================
// 10-node tetrahedral element using a 4-node Gaussian integration rule
class FETet10G1 : public FETet10_
{
public:
enum { NINT = 1 };
public:
FETet10G1();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix Ai;
};
//=============================================================================
// 10-node tetrahedral element using a 4-node Gaussian integration rule
class FETet10G4 : public FETet10_
{
public:
enum { NINT = 4 };
public:
FETet10G4();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix Ai;
};
//=============================================================================
// 10-node tetrahedral element using a 8-node Gaussian integration rule
class FETet10G8 : public FETet10_
{
public:
enum { NINT = 8 };
public:
FETet10G8();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
class FETet10G4RI1 : public FETet10G4, public FESRISolidElementTraits
{
public:
FETet10G4RI1();
};
//=============================================================================
class FETet10G8RI4 : public FETet10G8, public FESRISolidElementTraits
{
public:
FETet10G8RI4();
};
//=============================================================================
// 10-node tetrahedral element using a 11-node Gauss-Lobatto integration rule
class FETet10GL11 : public FETet10_
{
public:
enum { NINT = 11 };
public:
FETet10GL11();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FETet15
//
//=============================================================================
//=============================================================================
//! Base class for 15-node quadratic tetrahedral elements
class FETet15_ : public FESolidElementTraits
{
public:
enum { NELN = 15 };
public:
FETet15_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_TET15, et){}
};
//=============================================================================
// 15-node tetrahedral element using a 8-node Gaussian integration rule
class FETet15G4 : public FETet15_
{
public:
enum { NINT = 4 };
public:
FETet15G4();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
// 15-node tetrahedral element using a 8-node Gaussian integration rule
class FETet15G8 : public FETet15_
{
public:
enum { NINT = 8 };
public:
FETet15G8();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
// 15-node tetrahedral element using a 11-point Gaussian integration rule
class FETet15G11 : public FETet15_
{
public:
enum { NINT = 11 };
public:
FETet15G11();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
// 15-node tetrahedral element using a 15-point Gaussian integration rule
class FETet15G15 : public FETet15_
{
public:
enum { NINT = 15 };
public:
FETet15G15();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
class FETet15G15RI4 : public FETet15G15, public FESRISolidElementTraits
{
public:
FETet15G15RI4();
};
//=============================================================================
//
// FETet20
//
//=============================================================================
//=============================================================================
//! Base class for 20-node cubic tetrahedral elements
class FETet20_ : public FESolidElementTraits
{
public:
enum { NELN = 20 };
public:
FETet20_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_TET20, et){}
};
//=============================================================================
// 20-node tetrahedral element using a 15-point Gaussian integration rule
class FETet20G15 : public FETet20_
{
public:
enum { NINT = 15 };
public:
FETet20G15();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix N;
matrix Ai;
};
//=============================================================================
//
// FEHex20
//
//=============================================================================
//=============================================================================
//! Base class for 20-node quadratic hexahedral element
class FEHex20_ : public FESolidElementTraits
{
public:
enum { NELN = 20 };
public:
FEHex20_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_HEX20, et){}
//! initialize element traits data
void init();
int Nodes(int order);
};
//=============================================================================
// 20-node hexahedral element using a 2x2x2 Gaussian integration rule
class FEHex20G8 : public FEHex20_
{
public:
enum { NINT = 8 };
public:
FEHex20G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix MT;
};
//=============================================================================
// 20-node hexahedral element using a 3x3x3 Gaussian integration rule
class FEHex20G27 : public FEHex20_
{
public:
enum { NINT = 27 };
public:
FEHex20G27();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
//
// FEHex27
//
//=============================================================================
//=============================================================================
//! Base class for 27-node quadratic hexahedral element
class FEHex27_ : public FESolidElementTraits
{
public:
enum { NELN = 27 };
public:
FEHex27_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_HEX27, et){}
//! initialize element traits data
void init();
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 27-node hexahedral element using a 3x3x3 Gaussian integration rule
class FEHex27G27 : public FEHex27_
{
public:
enum { NINT = 27 };
public:
FEHex27G27();
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FEPyra5
//
//=============================================================================
//=============================================================================
//! Base class for 5-node pyramid element
class FEPyra5_ : public FESolidElementTraits
{
public:
enum { NELN = 5 };
public:
FEPyra5_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_PYRA5, et){}
};
//=============================================================================
// 5-node pyramid element using a 2x2x2 Gaussian integration rule
class FEPyra5G8: public FEPyra5_
{
public:
enum { NINT = 8 };
public:
FEPyra5G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Ai;
};
//=============================================================================
//
// FEPyra13
//
//=============================================================================
//=============================================================================
//! Base class for 13-node pyramid element
class FEPyra13_ : public FESolidElementTraits
{
public:
enum { NELN = 13 };
public:
FEPyra13_(int ni, FE_Element_Type et) : FESolidElementTraits(ni, NELN, ET_PYRA13, et){}
};
//=============================================================================
// 13-node pyramid element using a 2x2x2 Gaussian integration rule
class FEPyra13G8: public FEPyra13_
{
public:
enum { NINT = 8 };
public:
FEPyra13G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Ai;
};
//=============================================================================
// S U R F A C E E L E M E N T S
//
// This section defines a set of surface element formulations for use in 3D
// finite element models. For specific, these elements are used to define
// the surface of 3D volume models.
//=============================================================================
//=============================================================================
// This class defines the traits for surface elements and serves as a
// base class for the specific surface element formulations.
class FECORE_API FESurfaceElementTraits : public FEElementTraits
{
public:
FESurfaceElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
// initialization
void init();
// shape functions at (r,s)
void shape_fnc(double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
// shape functions at (r,s)
void shape_fnc(int order, double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(int order, double* Gr, double* Gs, double r, double s);
public:
// gauss-point coordinates and weights
std::vector<double> gr;
std::vector<double> gs;
std::vector<double> gw;
// element shape class
FESurfaceElementShape* m_shape;
std::vector<FESurfaceElementShape*> m_shapeP; // shape classes for different order (some orders can by null)
// local derivatives of shape functions at gauss points
matrix Gr, Gs;
// local derivatives of shape functions at gauss points, for different interpolation order
std::vector<matrix> Gr_p;
std::vector<matrix> Gs_p;
// parametric coordinates of element center
double cr;
double cs;
};
//=============================================================================
//
// FEQuad4
//
//=============================================================================
//=============================================================================
// Base class for 4-node bilinear quadrilaterals
//
class FEQuad4_ : public FESurfaceElementTraits
{
public:
enum { NELN = 4 };
void init() override;
public:
//! constructor
FEQuad4_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_QUAD4, et){}
};
//=============================================================================
// 4-node quadrilateral elements with 4-point gaussian quadrature
class FEQuad4G4 : public FEQuad4_
{
public:
enum { NINT = 4 };
public:
FEQuad4G4();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 16-node quadrilateral elements with 16-point gaussian quadrature
class FEQuad4G16 : public FEQuad4_
{
public:
enum { NINT = 16 };
public:
FEQuad4G16();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Ai; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 4-node quadrilateral elements with nodal quadrature
class FEQuad4NI : public FEQuad4_
{
public:
enum { NINT = 4 };
public:
//! constructor
FEQuad4NI();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FETri3
//
//=============================================================================
//=============================================================================
//! Base class for linear triangles
class FETri3_ : public FESurfaceElementTraits
{
public:
enum { NELN = 3 };
public:
//! constructor
FETri3_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_TRI3, et){}
// initialization
void init() override;
};
//=============================================================================
//! 3-node triangular element with 1-point gaussian quadrature
class FETri3G1 : public FETri3_
{
public:
enum { NINT = 1 };
public:
//! constructor
FETri3G1();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//! 3-node triangular element with 3-point gaussian quadrature
class FETri3G3 : public FETri3_
{
public:
enum { NINT = 3 };
public:
//! constructor
FETri3G3();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
//! 3-node triangular element with 7-point gaussian quadrature
class FETri3G7 : public FETri3_
{
public:
enum { NINT = 7 };
public:
//! constructor
FETri3G7();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Ai;
};
//=============================================================================
// 3-node triangular element with nodal quadrature
class FETri3NI : public FETri3_
{
public:
enum { NINT = 3 };
public:
// constructor
FETri3NI();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FETri6
//
//=============================================================================
//=============================================================================
// Base class for 6-noded quadratic triangles
class FETri6_ : public FESurfaceElementTraits
{
public:
enum { NELN = 6 };
public:
FETri6_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_TRI6, et){}
// initialization
void init() override;
};
//=============================================================================
// 6-node triangular element with 3-point gaussian quadrature
//
class FETri6G3 : public FETri6_
{
public:
enum { NINT = 3 };
public:
// constructor
FETri6G3();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// 6-node triangular element with 4-point gaussian quadrature
//
class FETri6G4 : public FETri6_
{
public:
enum { NINT = 4 };
public:
// constructor
FETri6G4();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// 6-node triangular element with 7-point gaussian quadrature
//
class FETri6G7 : public FETri6_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri6G7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
// 6-node triangular element with 7-point Gauss-Lobatto quadrature
//
class FETri6GL7 : public FETri6_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri6GL7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// 6-node triangular element with 6-point nodal quadrature
//
class FETri6NI : public FETri6_
{
public:
enum { NINT = 6 };
public:
// constructor
FETri6NI();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FETri6m
//
//=============================================================================
//=============================================================================
// Base class for 6-noded quadratic triangles with modified shape functions
/*
class FETri6m_ : public FESurfaceElementTraits
{
public:
enum { NELN = 6 };
public:
FETri6m_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_TRI6, et){}
// shape function at (r,s)
void shape(double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
// 6-node triangular element (with modified shape functions)
// with 7-point gaussian quadrature
//
class FETri6mG7 : public FETri6m_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri6mG7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
*/
//=============================================================================
//
// FETri7
//
//=============================================================================
//=============================================================================
// Base class for 7-noded quadratic triangles
class FETri7_ : public FESurfaceElementTraits
{
public:
enum { NELN = 7 };
public:
FETri7_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_TRI7, et){}
// initialization
void init() override;
};
//=============================================================================
// 7-node triangular element with 3-point gaussian quadrature
//
class FETri7G3 : public FETri7_
{
public:
enum { NINT = 3 };
public:
// constructor
FETri7G3();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix Ai;
};
//=============================================================================
// 7-node triangular element with 4-point gaussian quadrature
//
class FETri7G4 : public FETri7_
{
public:
enum { NINT = 4 };
public:
// constructor
FETri7G4();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix Ai;
};
//=============================================================================
// 7-node triangular element with 7-point gaussian quadrature
//
class FETri7G7 : public FETri7_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri7G7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
// 7-node triangular element with 7-point Gauss-Lobatto quadrature
//
class FETri7GL7 : public FETri7_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri7GL7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix Ai;
};
//=============================================================================
//
// FETri10
//
//=============================================================================
//=============================================================================
// Base class for 10-noded cubic triangles
class FETri10_ : public FESurfaceElementTraits
{
public:
enum { NELN = 10 };
public:
FETri10_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_TRI10, et){}
// initialization
void init() override;
};
//=============================================================================
// 10-node triangular element with 7-point gaussian quadrature
//
class FETri10G7 : public FETri10_
{
public:
enum { NINT = 7 };
public:
// constructor
FETri10G7();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
// 10-node triangular element with 12-point gaussian quadrature
//
class FETri10G12 : public FETri10_
{
public:
enum { NINT = 12 };
public:
// constructor
FETri10G12();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
//
// FEQuad8
//
//=============================================================================
//=============================================================================
//! Base class for 8-node quadratic quadrilaterals
//
class FEQuad8_ : public FESurfaceElementTraits
{
public:
enum { NELN = 8 };
public:
FEQuad8_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_QUAD8, et) {}
// initialization
void init() override;
};
//=============================================================================
//! class implementing 8-node quad quadrilateral with 9 integration points
//
class FEQuad8G9 : public FEQuad8_
{
public:
enum { NINT = 9 };
// constructor
FEQuad8G9();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
//! class implementing 8-node quad quadrilateral with 8 nodal integration points
//
class FEQuad8NI : public FEQuad8_
{
public:
enum { NINT = 8 };
// constructor
FEQuad8NI();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
//
// FEQuad9
//
//=============================================================================
//=============================================================================
//! Base class for 9-node quadratic quadrilaterals
//
class FEQuad9_ : public FESurfaceElementTraits
{
public:
enum { NELN = 9 };
public:
FEQuad9_(int ni, FE_Element_Type et) : FESurfaceElementTraits(ni, NELN, ET_QUAD9, et) {}
// initialization
void init() override;
};
//=============================================================================
//! class implementing 9-node quad quadrilateral with 9 integration points
//
class FEQuad9G9 : public FEQuad9_
{
public:
enum { NINT = 9 };
// constructor
FEQuad9G9();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
//! class implementing 9-node quad quadrilateral with 9 nodal integration points
//
class FEQuad9NI : public FEQuad9_
{
public:
enum { NINT = 9 };
// constructor
FEQuad9NI();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
// S H E L L E L E M E N T S
//
// This section defines several shell formulations for use in 3D finite element
// analysis.
//=============================================================================
//=============================================================================
// This class defines the specific for shell elements and serves as a base class
// for specific shell formulations
//
class FEShellElementTraits : public FEElementTraits
{
public:
FEShellElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
void init();
//! values of shape functions
virtual void shape_fnc(double* H, double r, double s) = 0;
//! values of shape function derivatives
virtual void shape_deriv(double* Hr, double* Hs, double r, double s) = 0;
using FEElementTraits::project_to_nodes;
virtual void project_to_nodes(mat3ds* ai, mat3ds* ao) const;
public:
int m_nvln; //!< number of element nodes including virtual nodes (e.g., in shell elements)
// gauss-point coordinates and weights
std::vector<double> gr;
std::vector<double> gs;
std::vector<double> gt;
std::vector<double> gw;
// local derivatives of shape functions at gauss points
matrix Hr, Hs;
};
//=============================================================================
// 4-node quadrilateral elements
//
class FEShellQuad4_ : public FEShellElementTraits
{
public:
enum { NELN = 4 };
public:
FEShellQuad4_(int ni, FE_Element_Type et) : FEShellElementTraits(ni, NELN, ET_QUAD4, et) {}
public:
//! values of shape functions
void shape_fnc(double* H, double r, double s);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double r, double s);
};
//=============================================================================
// 4-node quadrilateral elements with 4 point (membrane) gaussian quadrature
class FEShellQuad4G4 : public FEShellQuad4_
{
public:
enum { NINT = 4 };
public:
FEShellQuad4G4();
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 4-node quadrilateral elements with 4*2-point gaussian quadrature
//
class FEShellQuad4G8 : public FEShellQuad4_
{
public:
enum { NINT = 8 };
public:
FEShellQuad4G8();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 4-node quadrilateral elements with 4*3-point gaussian quadrature
//
class FEShellQuad4G12 : public FEShellQuad4_
{
public:
enum { NINT = 12 };
public:
FEShellQuad4G12();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 3-node triangular elements
//
class FEShellTri3_ : public FEShellElementTraits
{
public:
enum { NELN = 3 };
public:
FEShellTri3_(int ni, FE_Element_Type et) : FEShellElementTraits(ni, NELN, ET_TRI3, et) {}
public:
//! values of shape functions
void shape_fnc(double* H, double r, double s);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double r, double s);
};
//=============================================================================
// 3-node triangular elements with 1-point (membrane) gaussian quadrature
//
class FEShellTri3G3 : public FEShellTri3_
{
public:
enum { NINT = 3 };
public:
FEShellTri3G3();
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
// 3-node triangular elements with 3*2-point gaussian quadrature
//
class FEShellTri3G6 : public FEShellTri3_
{
public:
enum { NINT = 6 };
public:
FEShellTri3G6();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 3-node triangular elements with 3*3-point gaussian quadrature
//
class FEShellTri3G9 : public FEShellTri3_
{
public:
enum { NINT = 9 };
public:
FEShellTri3G9();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 8-node quadrilateral elements
//
class FEShellQuad8_ : public FEShellElementTraits
{
public:
enum { NELN = 8 };
public:
FEShellQuad8_(int ni, FE_Element_Type et) : FEShellElementTraits(ni, NELN, ET_QUAD8, et) {}
public:
//! values of shape functions
void shape_fnc(double* H, double r, double s);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double r, double s);
};
//=============================================================================
// 8-node quadrilateral elements with 9*2-point gaussian quadrature
//
class FEShellQuad8G18 : public FEShellQuad8_
{
public:
enum { NINT = 18 };
public:
FEShellQuad8G18();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 8-node quadrilateral elements with 9*3-point gaussian quadrature
//
class FEShellQuad8G27 : public FEShellQuad8_
{
public:
enum { NINT = 27 };
public:
FEShellQuad8G27();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 6-node triangular elements
//
class FEShellTri6_ : public FEShellElementTraits
{
public:
enum { NELN = 6 };
public:
FEShellTri6_(int ni, FE_Element_Type et) : FEShellElementTraits(ni, NELN, ET_TRI6, et) {}
public:
//! values of shape functions
void shape_fnc(double* H, double r, double s);
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double r, double s);
};
//=============================================================================
// 6-node triangular elements with 7*2-point gaussian quadrature
//
class FEShellTri6G14 : public FEShellTri6_
{
public:
enum { NINT = 14 };
public:
FEShellTri6G14();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// 6-node triangular elements with 7*3-point gaussian quadrature
//
class FEShellTri6G21 : public FEShellTri6_
{
public:
enum { NINT = 21 };
public:
FEShellTri6G21();
void project_to_nodes(double* ai, double* ao) const override;
protected:
// use these integration points to project to nodes
static int ni[NELN];
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
matrix m_MT;
};
//=============================================================================
// T R U S S E L E M E N T S
//
// This section defines truss elements for 3D analysis
//=============================================================================
//=============================================================================
class FETrussElementTraits : public FEElementTraits
{
public:
enum { NINT = 2 };
enum { NELN = 2 };
public:
FETrussElementTraits();
void init();
//! shape function at (r)
void shape(double* H, double r);
public:
// gauss-point coordinates and weights
std::vector<double> gr;
std::vector<double> gw;
};
//=============================================================================
// D I S C R E T E E L E M E N T S
//
// This section defines discrete elements for 3D analysis
//=============================================================================
//=============================================================================
class FEDiscreteElementTraits : public FEElementTraits
{
public:
enum { NINT = 1 };
enum { NELN = 2 };
public:
FEDiscreteElementTraits() : FEElementTraits(NINT, NELN, FE_ELEM_DISCRETE, ET_DISCRETE, FE_DISCRETE) { init(); }
void init() {}
};
//=============================================================================
// 2 D E L E M E N T S
//
// This section defines a set of solid element formulation used in 3D finite
// element models.
//=============================================================================
//=============================================================================
// This class defines the traits for 2D elements and serves as a
// base class for the specific 2D element formulations.
class FE2DElementTraits : public FEElementTraits
{
public:
FE2DElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
// initialization
void init();
// shape functions at (r,s)
virtual void shape(double* H, double r, double s) = 0;
// shape function derivatives at (r,s)
virtual void shape_deriv(double* Gr, double* Gs, double r, double s) = 0;
// shape function derivatives at (r,s)
virtual void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s) = 0;
public:
// gauss-point coordinates and weights
std::vector<double> gr;
std::vector<double> gs;
std::vector<double> gw;
// local derivatives of shape functions at gauss points
matrix Gr, Gs;
// local second derivatives of shape functions at gauss points
matrix Grr, Gsr, Grs, Gss;
};
//=============================================================================
//
// FE2DTri3
//
//=============================================================================
//=============================================================================
//! Base class for linear triangles
class FE2DTri3_ : public FE2DElementTraits
{
public:
enum { NELN = 3 };
public:
//! constructor
FE2DTri3_(int ni, FE_Element_Type et) : FE2DElementTraits(ni, NELN, ET_TRI3, et){}
//! shape function at (r,s)
void shape(double* H, double r, double s);
//! shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
//! shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
//! 3-node triangular element with 1-point gaussian quadrature
class FE2DTri3G1 : public FE2DTri3_
{
public:
enum { NINT = 1 };
public:
//! constructor
FE2DTri3G1();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FE2DTri6
//
//=============================================================================
//=============================================================================
// Base class for 6-noded quadratic triangles
class FE2DTri6_ : public FE2DElementTraits
{
public:
enum { NELN = 6 };
public:
FE2DTri6_(int ni, FE_Element_Type et) : FE2DElementTraits(ni, NELN, ET_TRI6, et){}
// shape function at (r,s)
void shape(double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
// 6-node triangular element with 3-point gaussian quadrature
//
class FE2DTri6G3 : public FE2DTri6_
{
public:
enum { NINT = 3 };
public:
// constructor
FE2DTri6G3();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FE2DQuad4
//
//=============================================================================
//=============================================================================
// Base class for 4-node bilinear quadrilaterals
//
class FE2DQuad4_ : public FE2DElementTraits
{
public:
enum { NELN = 4 };
public:
//! constructor
FE2DQuad4_(int ni, FE_Element_Type et) : FE2DElementTraits(ni, NELN, ET_QUAD4, et){}
//! shape functions at (r,s)
void shape(double* H, double r, double s);
//! shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
//! shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
// 4-node quadrilateral elements with 4-point gaussian quadrature
class FE2DQuad4G4 : public FE2DQuad4_
{
public:
enum { NINT = 4 };
public:
FE2DQuad4G4();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
protected:
matrix m_Hi; //!< inverse of H; useful for projection integr. point data to nodal data
};
//=============================================================================
//
// FE2DQuad8
//
//=============================================================================
//=============================================================================
//! Base class for 8-node quadratic quadrilaterals
//
class FE2DQuad8_ : public FE2DElementTraits
{
public:
enum { NELN = 8 };
public:
FE2DQuad8_(int ni, FE_Element_Type et) : FE2DElementTraits(ni, NELN, ET_QUAD8, et) {}
// shape function at (r,s)
void shape(double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
//! class implementing 8-node quad quadrilateral with 9 integration points
//
class FE2DQuad8G9 : public FE2DQuad8_
{
public:
enum { NINT = 9 };
// constructor
FE2DQuad8G9();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
//
// FE2DQuad9
//
//=============================================================================
//=============================================================================
//! Base class for 9-node quadratic quadrilaterals
//
class FE2DQuad9_ : public FE2DElementTraits
{
public:
enum { NELN = 9 };
public:
FE2DQuad9_(int ni, FE_Element_Type et) : FE2DElementTraits(ni, NELN, ET_QUAD9, et) {}
// shape function at (r,s)
void shape(double* H, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv(double* Gr, double* Gs, double r, double s);
// shape function derivatives at (r,s)
void shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s);
};
//=============================================================================
//! class implementing 9-node quad quadrilateral with 9 integration points
//
class FE2DQuad9G9 : public FE2DQuad9_
{
public:
enum { NINT = 9 };
// constructor
FE2DQuad9G9();
// project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
private:
matrix m_Ai;
};
//=============================================================================
// L I N E E L E M E N T S
//
// This section defines a set of element formulations used to describe edges.
//=============================================================================
//=============================================================================
class FELineElementTraits : public FEElementTraits
{
public:
FELineElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
// initialization
void init();
// shape functions at r
virtual void shape(double* H, double r) = 0;
// shape function derivatives at (r)
virtual void shape_deriv(double* Gr, double r) = 0;
// shape function second derivatives at (r)
virtual void shape_deriv2(double* Grr, double r) = 0;
public:
std::vector<double> gr; //!< integration point coordinates
std::vector<double> gw; //!< integration point weights
// local derivatives of shape functions at gauss points
matrix Gr;
// local second derivatives of shape functions at gauss points
matrix Grr;
};
//=============================================================================
//
// FELine2_
//
//=============================================================================
//=============================================================================
//! Base class for two-point lines
class FELine2_ : public FELineElementTraits
{
public:
enum { NELN = 2 };
public:
//! constructor
FELine2_(int ni, FE_Element_Type et) : FELineElementTraits(ni, NELN, ET_LINE2, et){}
//! shape function at (r)
void shape(double* H, double r);
//! shape function derivatives at (r)
void shape_deriv(double* Gr, double r);
//! shape function derivatives at (r)
void shape_deriv2(double* Grr, double r);
};
//=============================================================================
class FELine2G1 : public FELine2_
{
public:
enum { NINT = 1 };
public:
//! constructor
FELine2G1();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
class FELine2NI : public FELine2_
{
public:
enum { NINT = 2 };
public:
//! constructor
FELine2NI();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
// B E A M E L E M E N T S
//
// This section defines a set of element formulations used to describe beams.
//=============================================================================
//=============================================================================
class FEBeamElementTraits : public FEElementTraits
{
public:
FEBeamElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et);
// initialization
void init();
// shape functions at r
virtual void shape(double* H, double r) = 0;
// shape function derivatives at (r)
virtual void shape_deriv(double* Gr, double r) = 0;
// shape function second derivatives at (r)
virtual void shape_deriv2(double* Grr, double r) = 0;
public:
std::vector<double> gr; //!< integration point coordinates
std::vector<double> gw; //!< integration point weights
// local derivatives of shape functions at gauss points
matrix Gr;
// local second derivatives of shape functions at gauss points
matrix Grr;
};
//=============================================================================
//
// FEBeam2_
//
//=============================================================================
//=============================================================================
//! Base class for two-point beam
class FEBeam2_ : public FEBeamElementTraits
{
public:
enum { NELN = 2 };
public:
//! constructor
FEBeam2_(int ni, FE_Element_Type et) : FEBeamElementTraits(ni, NELN, ET_LINE2, et) {}
//! shape function at (r)
void shape(double* H, double r);
//! shape function derivatives at (r)
void shape_deriv(double* Gr, double r);
//! shape function derivatives at (r)
void shape_deriv2(double* Grr, double r);
};
//=============================================================================
class FEBeam2G1 : public FEBeam2_
{
public:
enum { NINT = 1 };
public:
//! constructor
FEBeam2G1();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
class FEBeam2G2 : public FEBeam2_
{
public:
enum { NINT = 2 };
public:
//! constructor
FEBeam2G2();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
//=============================================================================
//
// FEBeam3_
//
//=============================================================================
//=============================================================================
//! Base class for three-point beam
class FEBeam3_ : public FEBeamElementTraits
{
public:
enum { NELN = 3 };
public:
//! constructor
FEBeam3_(int ni, FE_Element_Type et) : FEBeamElementTraits(ni, NELN, ET_LINE3, et) {}
//! shape function at (r)
void shape(double* H, double r);
//! shape function derivatives at (r)
void shape_deriv(double* Gr, double r);
//! shape function derivatives at (r)
void shape_deriv2(double* Grr, double r);
};
//=============================================================================
class FEBeam3G2 : public FEBeam3_
{
public:
enum { NINT = 2 };
public:
//! constructor
FEBeam3G2();
//! project integration point data to nodes
void project_to_nodes(double* ai, double* ao) const override;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDataValue.h | .h | 1,589 | 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 "FELogData.h"
#include "FEItemList.h"
#include <memory>
class FECORE_API FEDataValue
{
public:
FEDataValue();
bool IsValid() const;
void SetLogData(FELogData* logData);
bool GetValues(const FEItemList* itemList, std::vector<double>& val);
private:
FELogData* m_logData = nullptr;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FESurface.h | .h | 12,751 | 342 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "mat2d.h"
#include "vec2d.h"
#include "matrix.h"
#include "FEMeshPartition.h"
#include "FENodeSet.h"
#include "FEDofList.h"
#include "FESurfaceElement.h"
#include "FENode.h"
//-----------------------------------------------------------------------------
class FEMesh;
class FENodeSet;
class FEFacetSet;
class FELinearSystem;
//-----------------------------------------------------------------------------
class FECORE_API FESurfaceMaterialPoint : public FEMaterialPoint
{
public:
vec3d dxr, dxs; // tangent vectors at material point
vec3d m_rp;
// return the surface element
FESurfaceElement* SurfaceElement() { return (FESurfaceElement*)m_elem; }
void Update(const FETimeInfo& tp) override
{
m_rp = m_rt;
}
void Serialize(DumpStream& ar) override
{
FEMaterialPoint::Serialize(ar);
ar & dxr & dxs;
}
};
// helper class for describing shape functions at dofs in integration routines
struct FECORE_API FESurfaceDofShape
{
int index; // local dof index
double shape; // shape functions
double shape_deriv_r; // shape function r-derivative
double shape_deriv_s; // shape function s-derivative
};
//-----------------------------------------------------------------------------
// This typedef defines a surface integrand.
// It evaluates the function at surface material point mp, and returns the value
// it the val vector. The size of the vector is determined by the field variable
// that is being integrated and is already set when the integrand is called.
// This is used in the FESurface::LoadVector function.
typedef std::function<void(FESurfaceMaterialPoint& mp, const FESurfaceDofShape& node_a, std::vector<double>& val)> FESurfaceVectorIntegrand;
typedef std::function<void(FESurfaceMaterialPoint& mp, const FESurfaceDofShape& node_a, const FESurfaceDofShape& node_b, matrix& val)> FESurfaceMatrixIntegrand;
//-----------------------------------------------------------------------------
//! Surface mesh
//! This class implements the basic functionality for an FE surface.
//! More specialized surfaces are derived from this class
class FECORE_API FESurface : public FEMeshPartition
{
FECORE_SUPER_CLASS(FESURFACE_ID)
FECORE_BASE_CLASS(FESurface)
public:
//! default constructor
FESurface(FEModel* fem);
//! destructor
virtual ~FESurface();
//! initialize surface data structure
bool Init() override;
virtual void InitSurface();
//! creates surface
void Create(int nsize, int elemType = -1);
//! Build a surface from a facet set
void Create(const FEFacetSet& set);
//! serialization
void Serialize(DumpStream& ar) override;
//! unpack an LM vector from a dof list
void UnpackLM(const FESurfaceElement& el, const FEDofList& dofList, vector<int>& lm);
//! Extract a node set from this surface
FENodeList GetNodeList();
//! Get a list of bools that indicate whether the corresponding node is on the boundary
// TODO: Move to MeshPartition
void GetBoundaryFlags(std::vector<bool>& boundary) const;
//! Set alpha parameter for intermediate time
void SetAlpha(const double alpha) { m_alpha = alpha; }
public:
//! return number of surface elements
int Elements() const override { return (int)m_el.size(); }
//! return an element of the surface
FESurfaceElement& Element(int i) { return m_el[i]; }
//! return an element of the surface
const FESurfaceElement& Element(int i) const { return m_el[i]; }
//! returns reference to element
FEElement& ElementRef(int n) override { return m_el[n]; }
const FEElement& ElementRef(int n) const override { return m_el[n]; }
//! find the solid or shell element of a surface element
FESurfaceElement::ELEMENT_REF FindElement(FESurfaceElement& el);
//! for interface surfaces, find the index of both solid elements
//! on either side of the interface
void FindElements(FESurfaceElement& el);
//! loop over all elements
void ForEachSurfaceElement(std::function<void(FESurfaceElement& el)> f);
public:
// Create material point data for this surface
virtual FEMaterialPoint* CreateMaterialPoint();
// update surface data
void Update(const FETimeInfo& tp) override;
public:
//! Project a node onto a surface element
vec3d ProjectToSurface(FESurfaceElement& el, vec3d x, double& r, double& s);
//! check to see if a point is on element
bool IsInsideElement(FESurfaceElement& el, double r, double s, double tol = 0);
//! See if a ray intersects an element
bool Intersect(FESurfaceElement& el, vec3d r, vec3d n, double rs[2], double& g, double eps, bool checkNormal = true);
//! Invert the surface
void Invert();
//! Get the spatial position given natural coordinates
vec3d Position(FESurfaceElement& el, double r, double s);
//! Get the spatial position of an integration point
vec3d Position(FESurfaceElement& el, int n);
//! Get the nodal coordinates of an element
void NodalCoordinates(FESurfaceElement& el, vec3d* re);
//! Get the nodal coordinates of an element at previoust time
void PreviousNodalCoordinates(FESurfaceElement& el, vec3d* re);
//! Determine if a face on this surface is pointing away or into a specified element
double FacePointing(FESurfaceElement& se, FEElement& el);
//! Project a FEParamDouble to nodes of the surface
void ProjectToNodes(FEParamDouble& pd, std::vector<double>& d);
public:
//! calculate the reference surface area of a surface element
double FaceArea(FESurfaceElement& el);
//! calculate the current surface area of a surface element
double CurrentFaceArea(FESurfaceElement& el);
//! return the max element size
double MaxElementSize();
//! calculate the metric tensor in the current configuration
mat2d Metric(FESurfaceElement& el, double r, double s);
//! calculate the metric tensor at an integration point
mat2d Metric(const FESurfaceElement& el, int n) const;
//! calculate the metric tensor at an integration point at previous time
mat2d MetricP(FESurfaceElement& el, int n);
//! calculate the metric tensor in the reference configuration
mat2d Metric0(FESurfaceElement& el, double r, double s);
//! calculate the surface normal
vec3d SurfaceNormal(FESurfaceElement& el, double r, double s) const;
//! calculate the surface normal at an integration point
vec3d SurfaceNormal(const FESurfaceElement& el, int n) const;
//! calculate the nodal normals
void UpdateNodeNormals();
//! return the nodal normals
vec3d NodeNormal(const int inode) { return m_nn[inode]; }
//! calculate the global position of an integration point
vec3d Local2Global0(FESurfaceElement& el, int n);
//! calculate the global position of a point on the surface
vec3d Local2Global(FESurfaceElement& el, double r, double s);
//! calculate the global position of an integration point
vec3d Local2Global(FESurfaceElement& el, int n);
//! calculate the global position of a point on the surface at previous time
vec3d Local2GlobalP(FESurfaceElement& el, double r, double s);
//! calculate the global position of an integration point at previous time
vec3d Local2GlobalP(FESurfaceElement& el, int n);
//! calculates the covariant base vectors of a surface at an integration point
void CoBaseVectors(const FESurfaceElement& el, int j, vec3d t[2]) const;
//! calculates the covariant base vectors of a surface
void CoBaseVectors(FESurfaceElement& el, double r, double s, vec3d t[2]);
//! calculates the covariant base vectors of a surface at an integration point in the reference configuration
void CoBaseVectors0(const FESurfaceElement& el, int j, vec3d t[2]) const;
//! calculates covariant base vectors of a surface
void CoBaseVectors0(FESurfaceElement& el, double r, double s, vec3d t[2]);
//! calculates the covariant base vectors of a surface at an integration point at previoust time step
void CoBaseVectorsP(FESurfaceElement& el, int j, vec3d t[2]);
//! calculates contravariant base vectors of a surface at an integration point
void ContraBaseVectors(const FESurfaceElement& el, int j, vec3d t[2]) const;
//! calculates the contravariant base vectors of a surface at an integration point at previoust time step
void ContraBaseVectorsP(FESurfaceElement& el, int j, vec3d t[2]);
//! calculates the parametric derivatives of covariant basis of a surface at an integration point
void CoBaseVectorDerivatives(const FESurfaceElement& el, int j, vec3d dg[2][2]) const;
//! calculates the the parametric derivatives of covariant basis of a surface at an integration point at previoust time step
void CoBaseVectorDerivativesP(FESurfaceElement& el, int j, vec3d dg[2][2]);
//! calculates contravariant base vectors of a surface
void ContraBaseVectors(FESurfaceElement& el, double r, double s, vec3d t[2]);
//! calculates contravariant base vectors of a surface
void ContraBaseVectors0(FESurfaceElement& el, double r, double s, vec3d t[2]);
//! Jacobian in reference configuration for integration point n
double jac0(FESurfaceElement& el, int n);
//! Jacobian in reference configuration for integration point n (and returns normal)
double jac0(const FESurfaceElement& el, int n, vec3d& nu);
//! Interface status
void SetInterfaceStatus(const bool bitfc) { m_bitfc = bitfc; }
bool GetInterfaceStatus() { return m_bitfc; }
//! Get the facet set that created this surface
FEFacetSet* GetFacetSet() { return m_surf; }
public:
// Get nodal reference coordinates
void GetReferenceNodalCoordinates(FESurfaceElement& el, vec3d* r0);
// Get current coordinates
void GetNodalCoordinates(FESurfaceElement& el, vec3d* rt);
// Get current coordinates at intermediate configuration
void GetNodalCoordinates(FESurfaceElement& el, double alpha, vec3d* rt);
// Get the shell bottom flag
bool IsShellBottom() const { return m_bshellb; }
// Set the shell bottom flag
void SetShellBottom(bool b) { m_bshellb = b; }
public:
// Evaluate field variables
double Evaluate(FESurfaceMaterialPoint& mp, int dof);
double Evaluate(int nface, int dof);
public:
//! Evaluate a load vector.
virtual void LoadVector(
FEGlobalVector& R, // The global vector into which the loads are assembled
const FEDofList& dofList, // The degree of freedom list
bool breference, // integrate over reference (true) or current (false) configuration
FESurfaceVectorIntegrand f); // the function that evaluates the integrand
//! Evaluate the stiffness matrix of a load
virtual void LoadStiffness(
FELinearSystem& LS, // The linear system does the assembling
const FEDofList& dofList_a, // The degree of freedom list of node a
const FEDofList& dofList_b, // The degree of freedom list of node b
FESurfaceMatrixIntegrand f // the matrix function to evaluate
);
public:
void CreateMaterialPointData();
protected:
FEFacetSet* m_surf; //!< the facet set from which this surface is built
vector<FESurfaceElement> m_el; //!< surface elements
vector<vec3d> m_nn; //!< node normals
bool m_bitfc; //!< interface status
double m_alpha; //!< intermediate time fraction
bool m_bshellb; //!< true if this surface is the bottom of a shell domain
};
// Calculates the volume inside a (closed) surface.
FECORE_API double CalculateSurfaceVolume(FESurface& s);
| Unknown |
3D | febiosoftware/FEBio | FECore/MIntegral.cpp | .cpp | 4,448 | 152 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "MMath.h"
#include "MEvaluate.h"
using namespace std;
//-----------------------------------------------------------------------------
//! Calculate the definite integral of an expression
MITEM MIntegral(const MITEM& i, const MVariable& x, const MITEM& a, const MITEM& b)
{
MITEM e = MEvaluate(i);
MITEM Ie = MIntegral(e, x);
return MReplace(Ie, x, b) - MReplace(Ie, x, a);
}
//-----------------------------------------------------------------------------
//! Calculate the indefinite integral of an expression.
//! Note that the integration constant is not included in the result
MITEM MIntegral(const MITEM& i, const MVariable& x)
{
// simplify the expression
MITEM e = MEvaluate(i);
// see if there is a dependency on x
if (is_dependent(e, x) == false)
{
// if not, multiply by x and return
return e*MITEM(x);
}
// if we get here, there is a dependency on x so we
// need to find an appropriate integration rule
switch (e.Type())
{
case MVAR:
if (e == x)
{
MITEM X(x);
return Fraction(1.0, 2.0)*(X ^ 2.0);
}
break;
case MNEG: return -MIntegral(e.Item(), x);
case MADD: return MIntegral(e.Left(), x) + MIntegral(e.Right(), x);
case MSUB: return MIntegral(e.Left(), x) - MIntegral(e.Right(), x);
case MMUL:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(l, x) == false) return l*MIntegral(r, x);
if (is_dependent(r, x) == false) return r*MIntegral(l, x);
return MIntegral(MExpand(e), x);
}
break;
case MDIV:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_dependent(r, x) == false) return MIntegral(l, x) / r;
}
break;
case MPOW:
{
MITEM l = e.Left();
MITEM r = e.Right();
if (is_var(l) && isConst(r))
{
if (l == x)
{
if (r.value() != -1.0)
{
MITEM np1( r.value() + 1.0);
return (l^np1)/np1;
}
else return Log(Abs(l));
}
else return e*MITEM(x);
}
if (is_int(r) && (is_add(l) || is_sub(l))) return MIntegral(MExpand(e),x);
if (is_number(l) && (is_dependent(r,x)))
{
if ((is_int(l) == false) || (mnumber(l)->value() > 1.0))
{
if (r == x)
{
return e/Log(l);
}
else if (is_mul(r))
{
MITEM rl = r.Left();
MITEM rr = r.Right();
if (is_number(rl) && (rr == x))
{
return e/(rl*Log(l));
}
}
}
}
}
break;
case MF1D:
{
const string& s = mfnc1d(e)->Name();
MITEM p = mfnc1d(e)->Item()->copy();
if (p == x)
{
if (s.compare("cos") == 0) return Sin(p);
if (s.compare("sin") == 0) return -Cos(p);
if (s.compare("tan") == 0) return -Log(Abs(Cos(p)));
if (s.compare("cot") == 0) return Log(Abs(Sin(p)));
if (s.compare("sec") == 0) return Log(Abs(Sec(p) + Tan(p)));
if (s.compare("csc") == 0) return -Log(Abs(Csc(p) + Cot(p)));
if (s.compare("sinh") == 0) return Cosh(p);
if (s.compare("cosh") == 0) return Sinh(p);
if (s.compare("tanh") == 0) return Log(Cosh(p));
if (s.compare("sech") == 0) return Atan(Sinh(p));
if (s.compare("exp") == 0) return Exp(p);
}
}
break;
}
return new MOpIntegral(e.copy(), new MVarRef(&x));
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMesh.cpp | .cpp | 32,955 | 1,310 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMesh.h"
#include "FEException.h"
#include "FEDiscreteDomain.h"
#include "FETrussDomain.h"
#include "FEShellDomain.h"
#include "FESolidDomain.h"
#include "FEDomain2D.h"
#include "DOFS.h"
#include "FEElemElemList.h"
#include "FEElementList.h"
#include "FESurface.h"
#include "FEDataArray.h"
#include "FEDomainMap.h"
#include "FESurfaceMap.h"
#include "FENodeDataMap.h"
#include "DumpStream.h"
#include "FECoreKernel.h"
#include <algorithm>
//-----------------------------------------------------------------------------
FEDataMap* CreateDataMap(int mapType)
{
FEDataMap* map = nullptr;
switch (mapType)
{
case FE_NODE_DATA_MAP: map = new FENodeDataMap; break;
case FE_DOMAIN_MAP : map = new FEDomainMap; break;
case FE_SURFACE_MAP : map = new FESurfaceMap; break;
default:
assert(false);
}
return map;
}
//=============================================================================
// FEMesh
//-----------------------------------------------------------------------------
FEMesh::FEMesh(FEModel* fem) : m_fem(fem)
{
m_ELT = nullptr;
m_NLT = nullptr;
}
//-----------------------------------------------------------------------------
FEMesh::~FEMesh()
{
Clear();
}
//-----------------------------------------------------------------------------
//! return number of nodes
int FEMesh::Nodes() const
{
return (int)m_Node.size();
}
//-----------------------------------------------------------------------------
void FEMesh::Serialize(DumpStream& ar)
{
// clear the mesh if we are loading from an archive
if ((ar.IsShallow() == false) && (ar.IsLoading())) Clear();
// we don't want to store pointers to all the nodes
// mostly for efficiency, so we tell the archive not to store the pointers
ar.LockPointerTable();
{
// store the node list
ar & m_Node;
}
ar.UnlockPointerTable();
// if this is a shallow archive, we're done
if (ar.IsShallow()) return;
// serialize node sets
ar & m_NodeSet;
if (ar.IsSaving())
{
// write segment sets
int ssets = SegmentSets();
ar << ssets;
for (int i=0; i<ssets; ++i)
{
FESegmentSet& sset = SegmentSet(i);
sset.Serialize(ar);
}
// write element sets
ar << m_ElemSet;
// write facet sets
ar << m_FaceSet;
// write surface pairs
int surfPairs = (int)m_SurfPair.size();
ar << surfPairs;
for (int i = 0; i < surfPairs; ++i)
{
FESurfacePair& sp = *m_SurfPair[i];
ar << sp.GetName();
ar << sp.GetPrimarySurface()->GetName();
ar << sp.GetSecondarySurface()->GetName();
}
// write discrete sets
int dsets = DiscreteSets();
ar << dsets;
for (int i=0; i<dsets; ++i)
{
FEDiscreteSet& dset = DiscreteSet(i);
dset.Serialize(ar);
}
// write data maps
int maps = DataMaps();
ar << maps;
for (int i = 0; i < maps; ++i)
{
FEDataMap* map = GetDataMap(i);
ar << map;
}
}
else
{
FEModel* fem = &ar.GetFEModel();
// read segment sets
int ssets = 0;
ar >> ssets;
for (int i=0; i<ssets; ++i)
{
FESegmentSet* sset = new FESegmentSet(fem);
AddSegmentSet(sset);
sset->Serialize(ar);
}
// read element sets
ar >> m_ElemSet;
// read facet sets
ar >> m_FaceSet;
// read surface pairs
int surfPairs = 0;
ar >> surfPairs;
for (int i = 0; i < surfPairs; ++i)
{
FESurfacePair* sp = new FESurfacePair(this);
std::string name;
ar >> name;
sp->SetName(name);
ar >> name;
FEFacetSet* ps = FindFacetSet(name);
sp->SetPrimarySurface(ps);
ar >> name;
ps = FindFacetSet(name);
sp->SetSecondarySurface(ps);
AddSurfacePair(sp);
}
// read discrete sets
int dsets = 0;
ar >> dsets;
for (int i=0; i<dsets; ++i)
{
FEDiscreteSet* dset = new FEDiscreteSet(this);
AddDiscreteSet(dset);
dset->Serialize(ar);
}
// write data maps
ClearDataMaps();
int maps = 0;
ar >> maps;
for (int i = 0; i < maps; ++i)
{
FEDataMap* map = nullptr;
ar >> map;
AddDataMap(map);
}
UpdateBox();
}
}
void FEMesh::SerializeDomains(DumpStream& ar)
{
// stream domain data
ar & m_Domain;
}
//-----------------------------------------------------------------------------
void FEMesh::SaveClass(DumpStream& ar, FEMesh* p)
{
// we should never get here
assert(false);
}
//-----------------------------------------------------------------------------
FEMesh* FEMesh::LoadClass(DumpStream& ar, FEMesh* p)
{
// we should never get here
assert(false);
return nullptr;
}
//-----------------------------------------------------------------------------
// Allocates storage for mesh data.
//
void FEMesh::CreateNodes(int nodes)
{
assert(nodes);
m_Node.resize(nodes);
// set the default node IDs
for (int i=0; i<nodes; ++i) Node(i).SetID(i+1);
m_NEL.Clear();
m_EEL.Clear();
delete m_ELT; m_ELT = nullptr;
delete m_NLT; m_NLT = nullptr;
}
//-----------------------------------------------------------------------------
// Make more room for nodes
void FEMesh::AddNodes(int nodes)
{
assert(nodes);
int N0 = (int) m_Node.size();
// get the ID of the last node
// (It is assumed that nodes are sorted according their ID
// so the last node should have the highest ID)
int n0 = 1;
if (N0 > 0) n0 = m_Node[N0-1].GetID() + 1;
m_Node.resize(N0 + nodes);
for (int i=0; i<nodes; ++i) m_Node[i+N0].SetID(n0+i);
delete m_ELT; m_ELT = nullptr;
delete m_NLT; m_NLT = nullptr;
}
//-----------------------------------------------------------------------------
void FEMesh::SetDOFS(int n)
{
int NN = Nodes();
#pragma omp parallel for
for (int i = 0; i < NN; ++i)
{
m_Node[i].SetDOFS(n);
}
}
//-----------------------------------------------------------------------------
//! Return the total number elements
int FEMesh::Elements() const
{
int N = 0;
for (int i=0; i<(int) m_Domain.size(); ++i)
{
N += m_Domain[i]->Elements();
}
return N;
}
//-----------------------------------------------------------------------------
//! Return the total number of elements of a specific domain type
int FEMesh::Elements(int ndom_type) const
{
int N = 0;
for (int i=0; i<(int) m_Domain.size(); ++i)
{
FEDomain& dom = *m_Domain[i];
if (dom.Class() == ndom_type) N += m_Domain[i]->Elements();
}
return N;
}
//-----------------------------------------------------------------------------
//! return reference to a node
FENode& FEMesh::Node(int i) { return m_Node[i]; }
const FENode& FEMesh::Node(int i) const { return m_Node[i]; }
//-----------------------------------------------------------------------------
// Updates the bounding box of the mesh (using current coordinates)
//
void FEMesh::UpdateBox()
{
if (Nodes() > 0)
{
m_box = FEBoundingBox(Node(0).m_rt);
for (int i=1; i<Nodes(); ++i)
{
m_box.add(Node(i).m_rt);
}
}
else m_box = FEBoundingBox(vec3d(0,0,0));
}
//-----------------------------------------------------------------------------
// Counts the number of shell elements in the mesh
//
int FEMesh::RemoveIsolatedVertices()
{
int i, j, k, N = Nodes(), n;
// create a valence array
vector<int> val; val.assign(N, 0);
// count the nodal valences
for (i=0; i<(int) m_Domain.size(); ++i)
{
FEDomain& d = Domain(i);
for (j=0; j<d.Elements(); ++j)
{
FEElement& el = d.ElementRef(j);
n = el.Nodes();
for (k=0; k<n; ++k) ++val[el.m_node[k]];
}
}
// See if there are any isolated nodes
// Exclude them from the analysis
int ni = 0;
for (i=0; i<N; ++i)
if (val[i] == 0)
{
++ni;
FENode& node = Node(i);
node.SetFlags(FENode::EXCLUDE);
}
return ni;
}
//-----------------------------------------------------------------------------
//! Does one-time initialization of the Mesh material point data.
void FEMesh::InitMaterialPoints()
{
for (int i = 0; i<Domains(); ++i)
{
FEDomain& dom = Domain(i);
dom.InitMaterialPoints();
}
}
//-----------------------------------------------------------------------------
void FEMesh::Clear()
{
m_Node.clear();
for (size_t i=0; i<m_Domain.size (); ++i) delete m_Domain [i];
// TODO: Surfaces and edges are currently managed by the classes that use them so don't delete them
// for (size_t i=0; i<m_Surf.size (); ++i) delete m_Surf[i];
// for (size_t i=0; i<m_Edge.size (); ++i) delete m_Edge[i];
for (size_t i=0; i<m_NodeSet.size (); ++i) delete m_NodeSet [i];
for (size_t i=0; i<m_LineSet.size (); ++i) delete m_LineSet [i];
for (size_t i=0; i<m_ElemSet.size (); ++i) delete m_ElemSet [i];
for (size_t i=0; i<m_DiscSet.size (); ++i) delete m_DiscSet [i];
for (size_t i=0; i<m_FaceSet.size (); ++i) delete m_FaceSet [i];
for (size_t i=0; i<m_SurfPair.size(); ++i) delete m_SurfPair[i];
for (size_t i=0; i<m_DomList.size (); ++i) delete m_DomList [i];
m_Domain.clear();
m_Surf.clear();
m_NodeSet.clear();
m_LineSet.clear();
m_ElemSet.clear();
m_DiscSet.clear();
m_FaceSet.clear();
m_SurfPair.clear();
m_DomList.clear();
m_NEL.Clear();
m_EEL.Clear();
if (m_ELT) delete m_ELT; m_ELT = nullptr;
if (m_NLT) delete m_NLT; m_NLT = nullptr;
}
//-----------------------------------------------------------------------------
//! Reset the mesh data. Return nodes to their intial position, reset their
//! attributes and zero all element stresses.
void FEMesh::Reset()
{
// reset nodal data
for (int i=0; i<Nodes(); ++i)
{
FENode& node = Node(i);
node.m_rp = node.m_rt = node.m_r0;
node.m_vp = vec3d(0,0,0);
node.m_ap = node.m_at = vec3d(0,0,0);
node.m_dp = node.m_dt = node.m_d0;
// reset ID arrays
int ndof = (int)node.dofs();
for (int i=0; i<ndof; ++i)
{
node.set_inactive(i);
node.set_bc(i, DOF_OPEN);
node.set(i, 0.0);
node.set_load(i, 0.0);
}
}
// update the mesh
UpdateBox();
// reset domain data
for (int n=0; n<(int) m_Domain.size(); ++n) m_Domain[n]->Reset();
}
//-----------------------------------------------------------------------------
//! This function calculates the (initial) volume of an element. In some case, the volume
//! may only be approximate.
double FEMesh::ElementVolume(FEElement &el)
{
double V = 0;
switch (el.Class())
{
case FE_ELEM_SOLID:
{
FESolidDomain* dom = dynamic_cast<FESolidDomain*>(el.GetMeshPartition()); assert(dom);
if (dom) V = dom->Volume(static_cast<FESolidElement&>(el));
}
break;
case FE_ELEM_SHELL:
{
FEShellDomain* dom = dynamic_cast<FEShellDomain*>(el.GetMeshPartition()); assert(dom);
if (dom) V = dom->Volume(static_cast<FEShellElement&>(el));
}
break;
}
return V;
}
//-----------------------------------------------------------------------------
//! This function calculates the (initial) volume of an element. In some case, the volume
//! may only be approximate.
double FEMesh::CurrentElementVolume(FEElement& el)
{
double V = 0;
switch (el.Class())
{
case FE_ELEM_SOLID:
{
FESolidDomain* dom = dynamic_cast<FESolidDomain*>(el.GetMeshPartition()); assert(dom);
if (dom) V =dom->CurrentVolume(static_cast<FESolidElement&>(el));
}
break;
case FE_ELEM_SHELL:
{
FEShellDomain* dom = dynamic_cast<FEShellDomain*>(el.GetMeshPartition()); assert(dom);
if (dom) return dom->CurrentVolume(static_cast<FEShellElement&>(el));
}
break;
}
return V;
}
//-----------------------------------------------------------------------------
//! Find a nodeset by name
FENodeSet* FEMesh::FindNodeSet(const std::string& name)
{
for (size_t i=0; i<m_NodeSet.size(); ++i) if (m_NodeSet[i]->GetName() == name) return m_NodeSet[i];
return 0;
}
//-----------------------------------------------------------------------------
//! Find a segment set set by name
FESegmentSet* FEMesh::FindSegmentSet(const std::string& name)
{
for (size_t i=0; i<m_LineSet.size(); ++i) if (m_LineSet[i]->GetName() == name) return m_LineSet[i];
return 0;
}
//-----------------------------------------------------------------------------
//! Find a surface set set by name
FESurface* FEMesh::FindSurface(const std::string& name)
{
for (size_t i=0; i<m_Surf.size(); ++i) if (m_Surf[i]->GetName() == name) return m_Surf[i];
return 0;
}
//-----------------------------------------------------------------------------
//! Find a surface set set by name and returns its index
int FEMesh::FindSurfaceIndex(const std::string& name)
{
for (size_t i = 0; i < m_Surf.size(); ++i) if (m_Surf[i]->GetName() == name) return i;
return -1;
}
FESurface* FEMesh::CreateSurface(FEFacetSet& facetSet)
{
FESurface* surf = fecore_alloc(FESurface, m_fem);
surf->Create(facetSet);
AddSurface(surf);
return surf;
}
//-----------------------------------------------------------------------------
//! Find a discrete element set set by name
FEDiscreteSet* FEMesh::FindDiscreteSet(const std::string& name)
{
for (size_t i=0; i<m_DiscSet.size(); ++i) if (m_DiscSet[i]->GetName() == name) return m_DiscSet[i];
return 0;
}
//-----------------------------------------------------------------------------
//! Find a element set by name
FEElementSet* FEMesh::FindElementSet(const std::string& name)
{
for (size_t i=0; i<m_ElemSet.size(); ++i) if (m_ElemSet[i]->GetName() == name) return m_ElemSet[i];
return 0;
}
//-----------------------------------------------------------------------------
FEFacetSet* FEMesh::FindFacetSet(const std::string& name)
{
for (size_t i = 0; i<(int)m_FaceSet.size(); ++i) if (m_FaceSet[i]->GetName() == name) return m_FaceSet[i];
return 0;
}
FESurfacePair* FEMesh::FindSurfacePair(const std::string& name)
{
for (FESurfacePair* sp : m_SurfPair) if (sp->GetName() == name) return sp;
return nullptr;
}
FEDomainList* FEMesh::FindDomainList(const std::string& name)
{
for (FEDomainList* dom : m_DomList)
if (dom->GetName() == name) return dom;
return nullptr;
}
//-----------------------------------------------------------------------------
int FEMesh::Domains() { return (int)m_Domain.size(); }
//-----------------------------------------------------------------------------
FEDomain& FEMesh::Domain(int n) { return *m_Domain[n]; }
//-----------------------------------------------------------------------------
void FEMesh::AddDomain(FEDomain* pd)
{
int N = (int)m_Domain.size();
pd->SetID(N);
m_Domain.push_back(pd);
if (m_ELT) delete m_ELT; m_ELT = 0;
}
//-----------------------------------------------------------------------------
//! Find a domain
FEDomain* FEMesh::FindDomain(const std::string& name)
{
for (size_t i = 0; i<m_Domain.size(); ++i) if (m_Domain[i]->GetName() == name) return m_Domain[i];
return 0;
}
int FEMesh::FindDomainIndex(const std::string& name)
{
for (size_t i = 0; i < m_Domain.size(); ++i) if (m_Domain[i]->GetName() == name) return i;
return -1;
}
FEDomain* FEMesh::FindDomain(int domId)
{
for (size_t i = 0; i<m_Domain.size(); ++i) if (m_Domain[i]->GetID() == domId) return m_Domain[i];
return 0;
}
//-----------------------------------------------------------------------------
//! return an element
FEElement* FEMesh::Element(int n)
{
if (n < 0) return nullptr;
for (int i = 0; i < Domains(); ++i)
{
FEDomain& dom = Domain(i);
int NEL = dom.Elements();
if (n < NEL) return &dom.ElementRef(n);
else n -= NEL;
}
return nullptr;
}
//-----------------------------------------------------------------------------
//! Find a node from a given ID. return 0 if the node cannot be found.
FENode* FEMesh::FindNodeFromID(int nid)
{
if (m_NLT == nullptr) m_NLT = new FENodeLUT(*this);
return m_NLT->Find(nid);
}
int FEMesh::FindNodeIndexFromID(int nid)
{
if (m_NLT == nullptr) m_NLT = new FENodeLUT(*this);
return m_NLT->FindIndex(nid);
}
//-----------------------------------------------------------------------------
//! Find an element from a given ID. return 0 if the element cannot be found.
FEElement* FEMesh::FindElementFromID(int elemID)
{
if (m_ELT == nullptr) m_ELT = new FEElementLUT(*this);
return m_ELT->Find(elemID);
}
int FEMesh::FindElementIndexFromID(int elemID)
{
if (m_ELT == nullptr) m_ELT = new FEElementLUT(*this);
return m_ELT->FindIndex(elemID);
}
/*
FEElement* FEMesh::FindElementFromID(int nid)
{
FEElement* pe = 0;
for (int i=0; i<Domains(); ++i)
{
FEDomain& d = Domain(i);
pe = d.FindElementFromID(nid);
if (pe) return pe;
}
return pe;
}
*/
//-----------------------------------------------------------------------------
//! See if all elements are of a particular shape
bool FEMesh::IsType(FE_Element_Shape eshape)
{
FEElementList elemList(*this);
for (FEElementList::iterator it = elemList.begin(); it != elemList.end(); ++it)
{
FEElement& el = *it;
if (el.Shape() != eshape) return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Find the element in which point y lies
FESolidElement* FEMesh::FindSolidElement(vec3d y, double r[3])
{
int ND = (int) m_Domain.size();
for (int i=0; i<ND; ++i)
{
if (m_Domain[i]->Class() == FE_DOMAIN_SOLID)
{
FESolidDomain& bd = static_cast<FESolidDomain&>(*m_Domain[i]);
FESolidElement* pe = bd.FindElement(y, r);
if (pe) return pe;
}
}
return 0;
}
FENodeElemList& FEMesh::NodeElementList()
{
if (m_NEL.Size() != m_Node.size()) m_NEL.Create(*this);
return m_NEL;
}
FEElemElemList& FEMesh::ElementElementList()
{
if (!m_EEL.IsValid()) m_EEL.Create(this);
return m_EEL;
}
//-----------------------------------------------------------------------------
void FEMesh::ClearDomains()
{
int N = Domains();
for (int i = 0; i < N; ++i) delete m_Domain[i];
m_Domain.clear();
if (m_ELT) delete m_ELT; m_ELT = 0;
}
//-----------------------------------------------------------------------------
//! Rebuild the LUT
void FEMesh::RebuildLUT()
{
if (m_ELT) delete m_ELT;
m_ELT = new FEElementLUT(*this);
}
//-----------------------------------------------------------------------------
//! Calculate the surface representing the element boundaries
//! boutside : include all exterior facets
//! binside : include all interior facets
FESurface* FEMesh::ElementBoundarySurface(bool boutside, bool binside)
{
if ((boutside == false) && (binside == false)) return 0;
// create the element neighbor list
FEElemElemList EEL;
EEL.Create(this);
// get the number of elements in this mesh
int NE = Elements();
// count the number of facets we have to create
int NF = 0;
FEElementList EL(*this);
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) && boutside) ++NF;
if ((pen != 0) && (el.GetID() < pen->GetID()) && binside ) ++NF;
}
}
// create the surface
FESurface* ps = fecore_alloc(FESurface, GetFEModel());
if (NF == 0) return ps;
ps->Create(NF);
// build the surface elements
int face[FEElement::MAX_NODES];
NF = 0;
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) && boutside)||
((pen != 0) && (el.GetID() < pen->GetID()) && binside ))
{
FESurfaceElement& se = ps->Element(NF++);
int faceNodes = el.GetFace(j, face);
switch (faceNodes)
{
case 4: se.SetType(FE_QUAD4G4); break;
case 8: se.SetType(FE_QUAD8G9); break;
case 9: se.SetType(FE_QUAD9G9); break;
case 3: se.SetType(FE_TRI3G1 ); break;
case 6: se.SetType(FE_TRI6G7 ); break;
case 7: se.SetType(FE_TRI7G7); break;
default:
assert(false);
}
se.m_elem[0].pe = ⪙
if (pen) se.m_elem[1].pe = pen;
int nn = se.Nodes();
for (int k=0; k<nn; ++k)
{
se.m_node[k] = face[k];
}
}
}
}
// initialize the surface.
// This will set the local surface element ID's and also set the m_nelem IDs.
ps->Init();
// all done
return ps;
}
FESurface* FEMesh::ElementBoundarySurface(std::vector<FEDomain*> domains, bool boutside, bool binside)
{
if ((boutside == false) && (binside == false)) return nullptr;
// create the element neighbor list
FEElemElemList EEL;
EEL.Create(this);
// get the number of elements in this mesh
int NE = Elements();
// count the number of facets we have to create
int NF = 0;
for (int i = 0; i < domains.size(); i++)
{
for (int j = 0; j < domains[i]->Elements(); j++)
{
FEElement& el = domains[i]->ElementRef(j);
int nf = el.Faces();
for (int k = 0; k<nf; ++k)
{
FEElement* pen = EEL.Neighbor(el.GetID()-1, k);
if ((pen == nullptr) && boutside) ++NF;
else if (pen && (std::find(domains.begin(), domains.end(), pen->GetMeshPartition()) == domains.end()) && boutside) ++NF;
if ((pen != nullptr) && (el.GetID() < pen->GetID()) && binside && (std::find(domains.begin(), domains.end(), pen->GetMeshPartition()) != domains.end())) ++NF;
}
}
}
// create the surface
FESurface* ps = fecore_alloc(FESurface, GetFEModel());
if (NF == 0) return ps;
ps->Create(NF);
// build the surface elements
int face[FEElement::MAX_NODES];
NF = 0;
for (int i = 0; i < domains.size(); i++)
{
for (int j = 0; j < domains[i]->Elements(); j++)
{
FEElement& el = domains[i]->ElementRef(j);
int nf = el.Faces();
for (int k = 0; k < nf; ++k)
{
FEElement* pen = EEL.Neighbor(el.GetID()-1, k);
if (((pen == nullptr) && boutside) ||
(pen && (std::find(domains.begin(), domains.end(), pen->GetMeshPartition()) == domains.end()) && boutside) ||
((pen != nullptr) && (el.GetID() < pen->GetID()) && binside && (std::find(domains.begin(), domains.end(), pen->GetMeshPartition()) != domains.end())))
{
FESurfaceElement& se = ps->Element(NF++);
int faceNodes = el.GetFace(k, face);
switch (faceNodes)
{
case 4: se.SetType(FE_QUAD4G4); break;
case 8: se.SetType(FE_QUAD8G9); break;
case 9: se.SetType(FE_QUAD9G9); break;
case 3: se.SetType(FE_TRI3G1 ); break;
case 6: se.SetType(FE_TRI6G7 ); break;
case 7: se.SetType(FE_TRI7G7 ); break;
default:
assert(false);
}
se.m_elem[0].pe = ⪙
if (pen) se.m_elem[1].pe = pen;
int nn = se.Nodes();
for (int p = 0; p < nn; ++p)
{
se.m_node[p] = face[p];
}
}
}
}
}
// initialize the surface.
// This will set the local surface element ID's and also set the m_nelem IDs.
ps->Init();
// all done
return ps;
}
FEFacetSet* FEMesh::DomainBoundary(std::vector<FEDomain*> domains, bool boutside, bool binside)
{
FEDomainList tmp(domains);
return DomainBoundary(tmp, boutside, binside);
}
FEFacetSet* FEMesh::DomainBoundary(FEDomainList& domains, bool boutside, bool binside)
{
if ((boutside == false) && (binside == false)) return nullptr;
// get the element neighbor list
FEElemElemList& EEL = ElementElementList();
// get the number of elements in this mesh
int NE = Elements();
// count the number of facets we have to create
int NF = 0;
for (int i = 0; i < domains.size(); i++)
{
for (int j = 0; j < domains[i]->Elements(); j++)
{
FEElement& el = domains[i]->ElementRef(j);
if (el.isActive())
{
int index = FindElementIndexFromID(el.GetID());
int nf = el.Faces();
for (int k = 0; k < nf; ++k)
{
FEElement* pen = EEL.Neighbor(index, k);
if ((pen == nullptr) && boutside) ++NF;
else if (pen && !pen->isActive() && boutside) ++NF;
else if (pen)
{
FEDomain* domk = dynamic_cast<FEDomain*>(pen->GetMeshPartition()); assert(domk);
if (boutside && !domains.IsMember(domk)) ++NF;
else if (binside && domains.IsMember(domk) && (el.GetID() < pen->GetID())) ++NF;
}
}
}
}
}
// create the surface
FEFacetSet* ps = new FEFacetSet(GetFEModel());
if (NF == 0) return ps;
ps->Create(NF);
// build the surface elements
int faceNodes[FEElement::MAX_NODES];
NF = 0;
for (int i = 0; i < domains.size(); i++)
{
for (int j = 0; j < domains[i]->Elements(); j++)
{
FEElement& el = domains[i]->ElementRef(j);
if (el.isActive())
{
int index = FindElementIndexFromID(el.GetID());
int nf = el.Faces();
for (int k = 0; k < nf; ++k)
{
FEElement* pen = EEL.Neighbor(index, k);
bool addFace = false;
if ((pen == nullptr) && boutside) addFace = true;
else if (pen && !pen->isActive() && boutside) addFace = true;
else if (pen)
{
FEDomain* domk = dynamic_cast<FEDomain*>(pen->GetMeshPartition()); assert(domk);
if (boutside && !domains.IsMember(domk)) addFace = true;
else if (binside && domains.IsMember(domk) && (el.GetID() < pen->GetID())) addFace = true;
}
if (addFace)
{
FEFacetSet::FACET& f = ps->Face(NF++);
int fn = el.GetFace(k, faceNodes);
switch (fn)
{
case 4: f.ntype = FEFacetSet::FACET::QUAD4; break;
case 8: f.ntype = FEFacetSet::FACET::QUAD8; break;
case 9: f.ntype = FEFacetSet::FACET::QUAD9; break;
case 3: f.ntype = FEFacetSet::FACET::TRI3; break;
case 6: f.ntype = FEFacetSet::FACET::TRI6; break;
case 7: f.ntype = FEFacetSet::FACET::TRI7; break;
default:
assert(false);
}
for (int p = 0; p < fn; ++p)
{
f.node[p] = faceNodes[p];
}
}
}
}
}
}
// all done
return ps;
}
//-----------------------------------------------------------------------------
//! Retrieve the nodal coordinates of an element in the reference configuration.
void FEMesh::GetInitialNodalCoordinates(const FEElement& el, vec3d* node)
{
const int neln = el.Nodes();
for (int i=0; i<neln; ++i) node[i] = Node(el.m_node[i]).m_r0;
}
//-----------------------------------------------------------------------------
//! Retrieve the nodal coordinates of an element in the current configuration.
void FEMesh::GetNodalCoordinates(const FEElement& el, vec3d* node)
{
const int neln = el.Nodes();
for (int i=0; i<neln; ++i) node[i] = Node(el.m_node[i]).m_rt;
}
//=============================================================================
FENodeLUT::FENodeLUT(FEMesh& mesh)
{
m_mesh = &mesh;
// get the ID ranges
m_minID = -1;
m_maxID = -1;
for (int i = 0; i < mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
int nid = node.GetID();
if ((nid < m_minID) || (m_minID == -1)) m_minID = nid;
if ((nid > m_maxID) || (m_maxID == -1)) m_maxID = nid;
}
// allocate size
int nsize = m_maxID - m_minID + 1;
m_node.resize(nsize, -1);
// fill the table
for (int i = 0; i < mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
int nid = node.GetID();
m_node[nid - m_minID] = i;
}
}
// Find an element from its ID
FENode* FENodeLUT::Find(int nodeID) const
{
if ((nodeID < m_minID) || (nodeID > m_maxID)) return nullptr;
return &m_mesh->Node(m_node[nodeID - m_minID]);
}
int FENodeLUT::FindIndex(int nodeID) const
{
if ((nodeID < m_minID) || (nodeID > m_maxID)) return -1;
return m_node[nodeID - m_minID];
}
//=============================================================================
FEElementLUT::FEElementLUT(FEMesh& mesh)
{
// get the ID ranges
m_minID = -1;
m_maxID = -1;
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);
int eid = el.GetID();
if ((eid < m_minID) || (m_minID == -1)) m_minID = eid;
if ((eid > m_maxID) || (m_maxID == -1)) m_maxID = eid;
}
}
// allocate size
int nsize = m_maxID - m_minID + 1;
m_elem.resize(nsize, (FEElement*) 0);
m_elid.resize(nsize, -1);
// fill the table
int index = 0;
for (int i = 0; i<NDOM; ++i)
{
FEDomain& dom = mesh.Domain(i);
int NE = dom.Elements();
for (int j = 0; j<NE; ++j, ++index)
{
FEElement& el = dom.ElementRef(j);
int eid = el.GetID();
m_elem[eid - m_minID] = ⪙
m_elid[eid - m_minID] = index;
}
}
}
// Find an element from its ID
FEElement* FEElementLUT::Find(int elemID) const
{
if ((elemID < m_minID) || (elemID > m_maxID)) return nullptr;
return m_elem[elemID - m_minID];
}
int FEElementLUT::FindIndex(int elemID) const
{
if ((elemID < m_minID) || (elemID > m_maxID)) return -1;
return m_elid[elemID - m_minID];
}
// update the domains of the mesh
void FEMesh::Update(const FETimeInfo& tp)
{
for (int i = 0; i<Domains(); ++i)
{
FEDomain& dom = Domain(i);
if (dom.IsActive()) dom.Update(tp);
}
}
//-----------------------------------------------------------------------------
void FEMesh::ClearDataMaps()
{
for (int i = 0; i<(int)m_DataMap.size(); ++i) delete m_DataMap[i];
m_DataMap.clear();
}
//-----------------------------------------------------------------------------
void FEMesh::AddDataMap(FEDataMap* map)
{
m_DataMap.push_back(map);
}
//-----------------------------------------------------------------------------
FEDataMap* FEMesh::FindDataMap(const std::string& mapName)
{
for (int i = 0; i<(int)m_DataMap.size(); ++i)
{
if (m_DataMap[i]->GetName() == mapName) return m_DataMap[i];
}
return 0;
}
//-----------------------------------------------------------------------------
int FEMesh::DataMaps() const
{
return (int)m_DataMap.size();
}
//-----------------------------------------------------------------------------
FEDataMap* FEMesh::GetDataMap(int i)
{
return m_DataMap[i];
}
//==============================================================================
FEElementIterator::FEElementIterator(FEMesh* mesh, FEElementSet* elemSet) : m_mesh(mesh), m_eset(elemSet)
{
reset();
}
void FEElementIterator::reset()
{
assert(m_mesh);
m_el = nullptr;
m_dom = -1;
m_index = -1;
if (m_eset)
{
if (m_eset->Elements())
{
m_index = 0;
m_el = &m_eset->Element(0);
}
}
else if (m_mesh && (m_mesh->Domains() > 0))
{
FEDomain& dom = m_mesh->Domain(0);
if (dom.Elements())
{
m_dom = 0;
m_index = 0;
m_el = &dom.ElementRef(0);
}
}
}
void FEElementIterator::operator++()
{
if (m_el == nullptr)
{
assert(false);
return;
}
if (m_eset)
{
m_index++;
if (m_index < m_eset->Elements())
{
m_el = &m_eset->Element(m_index);
}
else
{
m_el = nullptr;
}
}
else if (m_mesh)
{
m_index++;
FEDomain& dom = m_mesh->Domain(m_dom);
if (m_index >= dom.Elements())
{
m_dom++;
if (m_dom < m_mesh->Domains())
{
FEDomain& dom2 = m_mesh->Domain(m_dom);
if (dom2.Elements())
{
m_index = 0;
m_el = &dom2.ElementRef(0);
}
else
{
m_el = nullptr;
}
}
else
{
m_el = nullptr;
}
}
else m_el = &dom.ElementRef(m_index);
}
else
{
assert(false);
m_el = nullptr;
}
}
// create a copy of this mesh
void FEMesh::CopyFrom(FEMesh& mesh)
{
Clear();
int N0 = mesh.Nodes();
CreateNodes(N0);
for (int i = 0; i < N0; ++i)
{
Node(i) = mesh.Node(i);
}
// now allocate domains
ClearDomains();
for (int i = 0; i < mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
const char* sz = dom.GetTypeStr();
// create a new domain
// create a new domain
FEDomain* pd = nullptr;
switch (dom.Class())
{
case FE_DOMAIN_SOLID : pd = fecore_new<FESolidDomain >(sz, nullptr); break;
case FE_DOMAIN_SHELL : pd = fecore_new<FEShellDomain >(sz, nullptr); break;
case FE_DOMAIN_BEAM : pd = fecore_new<FEBeamDomain >(sz, nullptr); break;
case FE_DOMAIN_2D : pd = fecore_new<FEDomain2D >(sz, nullptr); break;
case FE_DOMAIN_DISCRETE: pd = fecore_new<FEDiscreteDomain>(sz, nullptr); break;
}
assert(pd);
pd->SetMesh(this);
// copy domain data
pd->CopyFrom(&dom);
// add it to the mesh
AddDomain(pd);
}
RebuildLUT();
// copy element sets
for (int i = 0; i < mesh.ElementSets(); ++i)
{
FEElementSet& eset = mesh.ElementSet(i);
FEElementSet* pset = new FEElementSet(GetFEModel());
pset->SetMesh(this);
pset->CopyFrom(eset);
AddElementSet(pset);
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/LinearSolver.h | .h | 5,409 | 163 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "SparseMatrix.h"
#include "FECoreBase.h"
#include "fecore_enum.h"
#include <vector>
class FEModel;
//-----------------------------------------------------------------------------
struct FECORE_API LinearSolverStats
{
int backsolves; // number of times backsolve was called
int iterations; // total number of iterations
};
//-----------------------------------------------------------------------------
//! Abstract base class for the linear solver classes. Linear solver classes
//! are derived from this class and must implement the abstract virtual methods.
//! This class assumes that a linear system is solved in two steps. First, the Factor()
//! method factorizes the matrix, and then BackSolve() solves the system for a given
//! right hand side vector using the previously factored matrix.
class FECORE_API LinearSolver : public FECoreBase
{
FECORE_SUPER_CLASS(FELINEARSOLVER_ID)
FECORE_BASE_CLASS(LinearSolver)
public:
//! constructor
LinearSolver(FEModel* fem);
//! destructor
virtual ~LinearSolver();
virtual void SetPrintLevel(int n) {}
public:
//! create a sparse matrix that can be used with this solver (must be overridden)
virtual SparseMatrix* CreateSparseMatrix(Matrix_Type ntype) = 0;
//! Set the sparse matrix
virtual bool SetSparseMatrix(SparseMatrix* pA);
//! Perform any preprocessing
//! This is called after the structure of the stiffness matrix was determined.
//! At this point, we know the size of the matrix and its sparsity pattern.
virtual bool PreProcess();
//! Factor the matrix (must be overridden)
//! Iterative solvers can use this function for creating a pre-conditioner.
virtual bool Factor() = 0;
//! do a backsolve, i.e. solve for a right-hand side vector y (must be overridden)
virtual bool BackSolve(double* x, double* y) = 0;
//! Do any cleanup
virtual void Destroy();
//! helper function for when this solver is used as a preconditioner
virtual bool mult_vector(double* x, double* y);
//! Used by block solvers do determine the block partition
//! The partition is where the global matrix will be divided into blocks
void SetPartitions(const vector<int>& part);
void SetPartitions(int npart0, int npart1);
// nr of partitions
int Partitions() const;
// get the size of a partition
int GetPartitionSize(int part) const;
//! version for std::vector
bool BackSolve(std::vector<double>& x, std::vector<double>& b)
{
return BackSolve(&x[0], &b[0]);
}
//! convenience function for solving linear systems
bool Solve(vector<double>& x, vector<double>& y);
// returns whether this is an iterative solver or not
virtual bool IsIterative() const;
public:
const LinearSolverStats& GetStats() const;
void ResetStats();
// Calculate (or estimate) condition number. Must be implemented by derived class.
// Base class returns 0;
virtual double ConditionNumber();
protected:
// used by derived classes to update stats.
// Should be called after each backsolve. Will increment backsolves by one and add iterations
void UpdateStats(int iterations);
protected:
std::vector<int> m_part; //!< partitions of linear system.
private:
LinearSolverStats m_stats; //!< stats on how often linear solver was called.
};
//-----------------------------------------------------------------------------
// base class for iterative solvers
class FECORE_API IterativeLinearSolver : public LinearSolver
{
public:
// constructor
IterativeLinearSolver(FEModel* fem);
// return whether the iterative solver has a preconditioner or not
virtual bool HasPreconditioner() const = 0;
// set the preconditioner
virtual void SetLeftPreconditioner(LinearSolver* pc);
virtual void SetRightPreconditioner(LinearSolver* pc);
// get the preconditioner
virtual LinearSolver* GetLeftPreconditioner();
virtual LinearSolver* GetRightPreconditioner();
// returns whether this is an iterative solver or not
bool IsIterative() const override;
public:
// helper function for solving a linear system of equations
bool Solve(SparseMatrix& A, std::vector<double>& x, std::vector<double>& b, LinearSolver* pc = 0);
};
| Unknown |
3D | febiosoftware/FEBio | FECore/colsol.cpp | .cpp | 7,486 | 284 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "math.h"
#include "fecore_api.h"
///////////////////////////////////////////////////////////////////////////////
// LINEAR SOLVER : colsol
// This solver solves linear system of matrices using a skyline format storage
// and a column reduction scheme. The symmetric matrix is stored in skyline format,
// where the values array store the matrix elements that are below the skyline
// and pointers is an array of indices that point to the diagonal elements of
// the matrix.
// The matrix is overwritten with the LDLt factorization and the right hand side
// vector R is replaced by the solution.
//
// The implementation is split into two routines. A matrix factorization and a
// back substitution part. colsol_factor performs the LDLt factorization while
// colsol_solve does the backsubstitution. colsol_solve needs to be called after
// colsol_factor. In order to solve for multiple right hand sides call colsol_factor
// once and then call colsol_solve with the different right hand sides.
//
// Details of the algorithm can be found in Bathe, "Finite Element Procedures",
// section 8.2, page 696 and following
//
FECORE_API void colsol_factor(int N, double* values, int* pointers)
{
int i, j, r, mi, mj, mm;
double krj;
int pi, pj;
// -A- factorize the matrix
// repeat over all columns
for (j=1; j<N; ++j)
{
// find the first non-zero row in column j
mj = j+1 - pointers[j+1] + pointers[j];
pj = pointers[j]+j;
// loop over all rows in column j
for (i=mj+1; i<j; ++i)
{
// find the first non-zero row in column i
mi = i+1 - pointers[i+1] + pointers[i];
// determine max of mi and mj
mm = (mi > mj ? mi : mj);
pi = pointers[i]+i;
double& kij = values[pj - i];
// the next line is replaced by the piece of code between arrows
// where the r loop is unrolled to give this algorithm a
// significant boost in speed.
// Although on good compilers this should not do much,
// on compilers that do a poor optimization this trick can
// double the speed of this algorithm.
// for (r=mm; r<i; ++r) kij -= values[pi - r]*values[pj - r];
//-------------->
for (r=mm; r<i-7; r+=8)
{
kij -= values[pi - r ]*values[pj - r ] +
values[pi - r-1]*values[pj - r-1] +
values[pi - r-2]*values[pj - r-2] +
values[pi - r-3]*values[pj - r-3] +
values[pi - r-4]*values[pj - r-4] +
values[pi - r-5]*values[pj - r-5] +
values[pi - r-6]*values[pj - r-6] +
values[pi - r-7]*values[pj - r-7];
}
for (r=0; r<(i-mm)%8; ++r)
kij -= values[pi - (i-1)+r]*values[pj - (i-1)+r];
//-------------->
}
// determine l[i][j]
for (i=mj; i<j; ++i) values[pj - i] /= values[ pointers[i] ];
// calculate d[j][j] value
double& kjj = values[ pointers[j] ];
for (r=mj; r<j; ++r)
{
krj = values[pj - r];
kjj -= krj*krj*values[ pointers[r] ];
}
}
}
///////////////////////////////////////////////////////////////////////////////
FECORE_API void colsol_solve(int N, double* values, int* pointers, double* R)
{
int i, mi, r;
// -B- back substitution
// calculate V = L^(-T)*R vector
for (i=1; i<N; ++i)
{
mi = i+1 - pointers[i+1] + pointers[i];
for (r=mi; r<i; ++r)
R[i] -= values[ pointers[i] + i - r]*R[r];
}
// calculate Vbar = D^(-1)*V
for (i=0; i<N; ++i) R[i] /= values[ pointers[i] ];
// calculate the solution
for (i=N-1; i>0; --i)
{
mi = i+1 - pointers[i+1] + pointers[i];
const double ri = R[i];
const int pi = pointers[i] + i;
// the following line was replaced
// by the code segment between the arrows
// for (r=mi; r<i; ++r) R[r] -= values[ pointers[i] + i - r]*R[i];
//--------->
for (r=mi; r<i-7; r += 8)
{
R[r ] -= values[ pi - r ]*ri;
R[r+1] -= values[ pi - r-1]*ri;
R[r+2] -= values[ pi - r-2]*ri;
R[r+3] -= values[ pi - r-3]*ri;
R[r+4] -= values[ pi - r-4]*ri;
R[r+5] -= values[ pi - r-5]*ri;
R[r+6] -= values[ pi - r-6]*ri;
R[r+7] -= values[ pi - r-7]*ri;
}
for (r=0; r<(i-mi)%8; ++r)
R[(i-1)- r] -= values[ pi - (i-1) + r ]*ri;
//--------->
}
}
///////////////////////////////////////////////////////////////////////////////
// This LU solver is grabbed from Numerical Recipes in C.
// To solve a system of equations first call ludcmp to calculate
// its LU decomposition. Next you can call the lubksb to perform
// a back substitution. The preferred way of using these functions
// therefore is:
//
// double** a;
// double* b;
// int* indx;
// int n;
// ...
// ludcmp(a,n,indx)
// lubksb(a,n,indx, b)
//
// The lubksb can be called as many times as there are rhs vectors for
// this system that you wish to call. For a specific matrix ludcmp only
// has to be called once.
//
void ludcmp(double**a, int n, int* indx)
{
int i, imax, j, k;
double big, dum, sum, temp;
double* vv;
const double TINY = 1.0e-20;
vv = new double[n];
for (i=0; i<n; ++i)
{
big = 0;
for (j=0; j<n; ++j)
if ((temp = fabs(a[i][j])) > big) big = temp;
vv[i] = 1.0 / big;
}
for (j=0; j<n; ++j)
{
for (i=0; i<j; ++i)
{
sum = a[i][j];
for (k=0; k<i; ++k) sum -= a[i][k]*a[k][j];
a[i][j] = sum;
}
big = 0;
imax = j;
for (i=j; i<n; ++i)
{
sum = a[i][j];
for (k=0; k<j; ++k) sum -= a[i][k]*a[k][j];
a[i][j] = sum;
if ((dum=vv[i]*fabs(sum)) >= big)
{
big = dum;
imax = i;
}
}
if (j != imax)
{
for (k=0; k<n; ++k)
{
dum = a[imax][k];
a[imax][k] = a[j][k];
a[j][k] = dum;
}
vv[imax] = vv[j];
}
indx[j] = imax;
if (a[j][j] == 0.0)
{
a[j][j] = TINY;
}
if (j!=n-1)
{
dum = 1.0/(a[j][j]);
for (i=j+1;i<n; ++i) a[i][j] *= dum;
}
}
// clean up
delete [] vv;
}
///////////////////////////////////////////////////////////////////////////////
void lubksb(double**a, int n, int *indx, double b[])
{
int i, ii=0, ip, j;
double sum;
for (i=0; i<n; ++i)
{
ip = indx[i];
sum = b[ip];
b[ip] = b[i];
if (ii != 0)
for (j=ii-1; j<i; ++j) sum -= a[i][j]*b[j];
else if (sum != 0.0) ii=i+1;
b[i] = sum;
}
for (i=n-1; i>=0; --i)
{
sum = b[i];
for (j=i+1;j<n;++j) sum -= a[i][j]*b[j];
b[i] = sum/a[i][i];
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDiscreteMaterial.cpp | .cpp | 1,885 | 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 "FEDiscreteMaterial.h"
//=============================================================================
FEMaterialPointData* FEDiscreteMaterialPoint::Copy()
{
FEDiscreteMaterialPoint* pt = new FEDiscreteMaterialPoint(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
void FEDiscreteMaterialPoint::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_dr0 & m_drp & m_drt & m_dvt;
}
//=============================================================================
FEDiscreteMaterial::FEDiscreteMaterial(FEModel* pfem) : FEMaterial(pfem) {}
| C++ |
3D | febiosoftware/FEBio | FECore/FEElemElemList.h | .h | 2,642 | 79 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "fecore_api.h"
//-----------------------------------------------------------------------------
class FEMesh;
class FESurface;
class FEElement;
//-----------------------------------------------------------------------------
//! This class finds for each element the neighbouring elements
//!
class FECORE_API FEElemElemList
{
public:
//! constructor
FEElemElemList(void);
//! destructor
~FEElemElemList(void);
bool IsValid() const;
void Clear();
//! create the element-element list
bool Create(FEMesh* pmesh);
//! create the element-element list for a surface
bool Create(const FESurface* psurf);
//! Find the j-th neighbor element of element n
FEElement* Neighbor(int n, int j) { return m_pel[ m_ref[n] + j]; }
//! Find the j-th neighbor element of element n
int NeighborIndex(int n, int j) { return m_peli[m_ref[n] + j]; }
//! Return the size of the neighbor vector
int NeighborSize() { return (int)(m_pel.size()/m_ref.size()); }
protected:
//! Initialization
void Init();
protected:
std::vector<int> m_ref; //!< start index into pel and peli array
std::vector<FEElement*> m_pel; //!< list of all neighbouring elements (or 0 if no neighbor)
std::vector<int> m_peli; //!< indices of neighbor elems (or -1 if no neighbor)
FEMesh* m_pmesh; //!< pointer to mesh that created this list
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMaterialPoint.cpp | .cpp | 4,744 | 183 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMaterialPoint.h"
#include "DumpStream.h"
#include <string.h>
FEMaterialPointData::FEMaterialPointData(FEMaterialPointData* ppt)
{
m_pPrev = 0;
m_pNext = ppt;
if (ppt) ppt->m_pPrev = this;
}
FEMaterialPointData::~FEMaterialPointData()
{
if (m_pNext) delete m_pNext;
m_pNext = m_pPrev = 0;
}
void FEMaterialPointData::SetPrev(FEMaterialPointData* pt)
{
m_pPrev = pt;
}
void FEMaterialPointData::SetNext(FEMaterialPointData* pt)
{
m_pNext = pt;
if (pt) pt->m_pPrev = this;
}
void FEMaterialPointData::Append(FEMaterialPointData* pt)
{
if (pt == nullptr) return;
if (m_pNext) m_pNext->Append(pt);
else SetNext(pt);
}
void FEMaterialPointData::Init()
{
if (m_pNext) m_pNext->Init();
}
void FEMaterialPointData::Update(const FETimeInfo& timeInfo)
{
if (m_pNext) m_pNext->Update(timeInfo);
}
void FEMaterialPointData::Serialize(DumpStream& ar)
{
if (m_pNext) m_pNext->Serialize(ar);
}
//=================================================================================================
FEMaterialPoint::FEMaterialPoint(FEMaterialPointData* data)
{
m_data = data;
m_elem = nullptr;
m_index = -1;
m_shape = nullptr;
m_J0 = m_Jt = 1;
}
FEMaterialPoint::~FEMaterialPoint()
{
delete m_data;
}
// NOTE: We need a copy constructor to create vectors of FEMaterialPoint,
// but we should not actually need to copy anything
FEMaterialPoint::FEMaterialPoint(const FEMaterialPoint&)
{
m_elem = nullptr;
m_shape = nullptr;
m_data = nullptr;
m_J0 = m_Jt = 1;
m_index = -1;
}
FEMaterialPoint& FEMaterialPoint::operator = (const FEMaterialPoint&)
{
m_elem = nullptr;
m_shape = nullptr;
m_data = nullptr;
m_J0 = m_Jt = 1;
m_index = -1;
return *this;
}
void FEMaterialPoint::Init()
{
if (m_data) m_data->Init();
}
FEMaterialPoint* FEMaterialPoint::Copy()
{
FEMaterialPoint* mp = new FEMaterialPoint(*this);
if (m_data) mp->m_data = m_data->Copy();
return mp;
}
void FEMaterialPoint::Update(const FETimeInfo& timeInfo)
{
if (m_data) m_data->Update(timeInfo);
}
void FEMaterialPoint::Serialize(DumpStream& ar)
{
if (ar.IsShallow() == false)
{
ar & m_r0 & m_J0 & m_Jt;
}
if (m_data) m_data->Serialize(ar);
}
void FEMaterialPoint::Append(FEMaterialPointData* pt)
{
if (pt == nullptr) return;
assert(m_data);
if (m_data) m_data->Append(pt);
}
//=================================================================================================
//-----------------------------------------------------------------------------
FEMaterialPointArray::FEMaterialPointArray(FEMaterialPointData* ppt) : FEMaterialPointData(ppt)
{
}
//-----------------------------------------------------------------------------
void FEMaterialPointArray::AddMaterialPoint(FEMaterialPoint* pt)
{
m_mp.push_back(pt);
}
//-----------------------------------------------------------------------------
void FEMaterialPointArray::Init()
{
for (int i = 0; i<(int)m_mp.size(); ++i) m_mp[i]->Init();
FEMaterialPointData::Init();
}
//-----------------------------------------------------------------------------
void FEMaterialPointArray::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
for (int i = 0; i<(int)m_mp.size(); ++i) m_mp[i]->Serialize(ar);
}
//-----------------------------------------------------------------------------
void FEMaterialPointArray::Update(const FETimeInfo& timeInfo)
{
FEMaterialPointData::Update(timeInfo);
for (int i = 0; i<(int)m_mp.size(); ++i) m_mp[i]->Update(timeInfo);
}
| C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.