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 | FEBioXML/FEBioMeshDataSection3.cpp | .cpp | 36,188 | 1,268 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioMeshDataSection.h"
#include "FECore/FEModel.h"
#include <FECore/FEDataGenerator.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FEDataMathGenerator.h>
#include <FECore/FEMaterial.h>
#include <FECore/FEModelParam.h>
#include <FECore/FEDomainMap.h>
#include <FECore/FEConstValueVec3.h>
#include <sstream>
//-----------------------------------------------------------------------------
#ifdef WIN32
#define szcmp _stricmp
#else
#define szcmp strcmp
#endif
//-----------------------------------------------------------------------------
// helper function for converting a datatype attribute to FEDataType
FEDataType str2datatype(const char* szdataType)
{
if (szdataType == nullptr) return FEDataType::FE_DOUBLE;
FEDataType dataType = FEDataType::FE_INVALID_TYPE;
if (strcmp(szdataType, "scalar") == 0) dataType = FEDataType::FE_DOUBLE;
else if (strcmp(szdataType, "vec2" ) == 0) dataType = FEDataType::FE_VEC2D;
else if (strcmp(szdataType, "vec3" ) == 0) dataType = FEDataType::FE_VEC3D;
else if (strcmp(szdataType, "mat3" ) == 0) dataType = FEDataType::FE_MAT3D;
else if (strcmp(szdataType, "mat3s" ) == 0) dataType = FEDataType::FE_MAT3DS;
return dataType;
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::Parse(XMLTag& tag)
{
// Make sure there is something in this tag
if (tag.isleaf()) return;
// make sure the MeshDomain section was processed.
FEMesh& mesh = GetFEModel()->GetMesh();
if (mesh.Domains() == 0)
{
throw FEFileException("MeshData must appear after MeshDomain section.");
}
// loop over all mesh data section
++tag;
do
{
if (tag == "NodeData" ) ParseNodalData (tag);
else if (tag == "SurfaceData") ParseSurfaceData(tag);
else if (tag == "ElementData") ParseElementData(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseNodalData(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// find the node set
const char* szset = tag.AttributeValue("node_set");
FENodeSet* nset = GetBuilder()->FindNodeSet(szset);
if (nset == nullptr) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
// get the data type
const char* szdataType = tag.AttributeValue("datatype", true);
FEDataType dataType = str2datatype(szdataType);
if (dataType == FEDataType::FE_INVALID_TYPE) throw XMLReader::InvalidAttributeValue(tag, "datatype", szdataType);
// get the name (required!)
string sname = tag.AttributeValue("name");
FENodeDataMap* map = nullptr;
// see if there is a generator
const char* szgen = tag.AttributeValue("generator", true);
if (szgen)
{
if (strcmp(szgen, "const") == 0)
{
map = new FENodeDataMap(dataType);
++tag;
do {
if (tag == "value")
{
switch (dataType)
{
case FE_DOUBLE: { double v; tag.value(v); map->fillValue(v); } break;
case FE_VEC2D : { vec2d v; tag.value(v); map->fillValue(v); } break;
case FE_VEC3D : { vec3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3D : { mat3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3DS: { mat3ds v; tag.value(v); map->fillValue(v); } break;
default:
throw XMLReader::InvalidAttributeValue(tag, "type");
break;
}
}
else {
delete map;
throw XMLReader::InvalidTag(tag);
}
++tag;
} while (!tag.isend());
}
else
{
FENodeDataGenerator* gen = nullptr;
gen = fecore_new<FENodeDataGenerator>(szgen, &fem);
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
gen->SetNodeSet(nset);
// read the parameters
ReadParameterList(tag, gen);
// initialize the generator
if (gen->Init() == false) throw FEBioImport::DataGeneratorError();
// generate the data
map = dynamic_cast<FENodeDataMap*>(gen->Generate());
if (map == nullptr) throw FEBioImport::DataGeneratorError();
}
}
else
{
// create the data map
map = new FENodeDataMap(dataType);
map->Create(nset);
// read the data
ParseNodeData(tag, *map);
}
// add it to the mesh
if (map)
{
map->SetName(sname);
mesh.AddDataMap(map);
}
}
void FEBioMeshDataSection3::ParseSurfaceData(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// find the surface in the mesh
const char* szset = tag.AttributeValue("surface");
FEFacetSet* surf = mesh.FindFacetSet(szset);
if (surf == nullptr) throw XMLReader::InvalidAttributeValue(tag, "surface", szset);
// get the data type
const char* szdataType = tag.AttributeValue("datatype", true);
if (szdataType == nullptr) szdataType = "scalar";
FEDataType dataType = str2datatype(szdataType);
if (dataType == FEDataType::FE_INVALID_TYPE) throw XMLReader::InvalidAttributeValue(tag, "datatype", szdataType);
// get the name (required!)
string sname = tag.AttributeValue("name");
FESurfaceMap* map = nullptr;
// see if there is a generator
const char* szgen = tag.AttributeValue("generator", true);
if (szgen)
{
// treat const separately
if (strcmp(szgen, "const") == 0)
{
map = new FESurfaceMap(dataType);
map->Create(surf);
++tag;
do
{
if (tag == "value")
{
switch (dataType)
{
case FE_DOUBLE: { double v; tag.value(v); map->fillValue(v); } break;
case FE_VEC2D : { vec3d v; tag.value(v); map->fillValue(v); } break;
case FE_VEC3D : { vec3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3D : { mat3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3DS: { mat3ds v; tag.value(v); map->fillValue(v); } break;
default:
throw XMLReader::InvalidAttributeValue(tag, "type");
break;
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
else
{
FEFaceDataGenerator* gen = fecore_new<FEFaceDataGenerator>(szgen, &fem);
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
// read the parameters
ReadParameterList(tag, gen);
// initialize the generator
if (gen->Init() == false) throw FEBioImport::DataGeneratorError();
// generate the data
map = dynamic_cast<FESurfaceMap*>(gen->Generate());
if (map == nullptr) throw FEBioImport::DataGeneratorError();
}
}
else
{
map = new FESurfaceMap(dataType);
map->Create(surf);
ParseSurfaceData(tag, *map);
}
if (map)
{
map->SetName(sname);
mesh.AddDataMap(map);
}
}
void FEBioMeshDataSection3::ParseElementData(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// find the element set in the mesh
const char* szset = tag.AttributeValue("elem_set");
FEElementSet* elset = mesh.FindElementSet(szset);
if (elset == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szset);
// get the data type
const char* szdataType = tag.AttributeValue("datatype", true);
if (szdataType == nullptr) szdataType = "scalar";
FEDataType dataType = str2datatype(szdataType);
if (dataType == FEDataType::FE_INVALID_TYPE) throw XMLReader::InvalidAttributeValue(tag, "datatype", szdataType);
// see if a generator is defined
const char* szgen = tag.AttributeValue("generator", true);
// get the name or var (required!)
const char* szvar = tag.AttributeValue("var", true);
const char* szname = (szvar == nullptr ? tag.AttributeValue("name") : nullptr);
string sname = (szname ? szname : "");
bool isVar = (szvar != nullptr);
string mapName = (isVar ? szvar : szname);
// process some special variables
if ((szname == nullptr) && (szgen == nullptr))
{
if (strcmp(szvar, "shell thickness") == 0) ParseShellThickness(tag, *elset);
else if (strcmp(szvar, "fiber" ) == 0) ParseMaterialFibers(tag, *elset);
else if (strcmp(szvar, "mat_axis" ) == 0) ParseMaterialAxes(tag, *elset);
else throw XMLReader::InvalidAttributeValue(tag, "var");
return;
}
// default format
Storage_Fmt fmt = (((dataType == FE_MAT3D) || (dataType == FE_MAT3DS)) ? Storage_Fmt::FMT_ITEM : Storage_Fmt::FMT_MULT);
// format overrider?
const char* szfmt = tag.AttributeValue("format", true);
if (szfmt)
{
if (szcmp(szfmt, "MAT_POINTS") == 0) fmt = Storage_Fmt::FMT_MATPOINTS;
else if (szcmp(szfmt, "ITEM") == 0) fmt = Storage_Fmt::FMT_ITEM;
else throw XMLReader::InvalidAttributeValue(tag, "format", szfmt);
}
// see if there is a generator
if (szgen)
{
// make sure the parameter is valid
FEParamDouble* pp = nullptr;
if (isVar)
{
// find the variable
ParamString paramName(szvar);
FEParam* pv = fem.FindParameter(paramName);
if (pv == nullptr) throw XMLReader::InvalidAttributeValue(tag, "var", szvar);
// make sure it's a mapped parameter
if (pv->type() != FE_PARAM_DOUBLE_MAPPED)throw XMLReader::InvalidAttributeValue(tag, "var", szvar);
// if it's an array parameter, get the right index
if (pv->dim() > 1)
{
ParamString l = paramName.last();
int m = l.Index();
assert(m >= 0);
pp = &(pv->value<FEParamDouble>(m));
}
else pp = &(pv->value<FEParamDouble>());
}
FEElemDataGenerator* gen = nullptr; // data will be generated
if (strcmp(szgen, "const") == 0)
{
FEDomainMap* map = new FEDomainMap(dataType, fmt);
map->Create(elset);
++tag;
do
{
if (tag == "value")
{
switch (dataType)
{
case FE_DOUBLE: { double v; tag.value(v); map->fillValue(v); } break;
case FE_VEC2D : { vec2d v; tag.value(v); map->fillValue(v); } break;
case FE_VEC3D : { vec3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3D : { mat3d v; tag.value(v); map->fillValue(v); } break;
case FE_MAT3DS: { mat3ds v; tag.value(v); map->fillValue(v); } break;
default:
throw XMLReader::InvalidAttributeValue(tag, "type");
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
// see if this map already exists
FEDomainMap* oldMap = dynamic_cast<FEDomainMap*>(mesh.FindDataMap(sname));
if (oldMap)
{
oldMap->Merge(*map);
delete map;
}
else
{
map->SetName(sname);
mesh.AddDataMap(map);
}
}
else
{
gen = fecore_new<FEElemDataGenerator>(szgen, &fem);
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
// read the parameters
ReadParameterList(tag, gen);
// Add it to the list (will be applied after the rest of the model was read in)
GetBuilder()->AddMeshDataGenerator(gen, nullptr, pp);
}
}
else
{
FEDomainMap* map = new FEDomainMap(dataType, fmt);
map->Create(elset);
// read the data
ParseElementData(tag, *map);
// see if this map already exists
FEDomainMap* oldMap = dynamic_cast<FEDomainMap*>(mesh.FindDataMap(sname));
if (oldMap)
{
oldMap->Merge(*map);
delete map;
}
else
{
map->SetName(sname);
mesh.AddDataMap(map);
}
}
}
/*
void FEBioMeshDataSection3::ParseModelParameter(XMLTag& tag, FEParamValue param)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the parameter name
const char* szparam = tag.AttributeValue("param");
// see if the data will be generated or tabulated
const char* szgen = tag.AttributeValue("generator", true);
FEParam* pp = param.param();
if (pp->type() == FE_PARAM_MATERIALPOINT)
{
ParseMaterialPointData(tag, param);
return;
}
// make sure it is a mapped param
if ((pp->type() != FE_PARAM_DOUBLE_MAPPED) &&
(pp->type() != FE_PARAM_VEC3D_MAPPED) &&
(pp->type() != FE_PARAM_MAT3D_MAPPED)) throw XMLReader::InvalidAttributeValue(tag, "param", szparam);
FEDataType dataType = FE_DOUBLE;
if (pp->type() == FE_PARAM_VEC3D_MAPPED) dataType = FE_VEC3D;
if (pp->type() == FE_PARAM_MAT3D_MAPPED) dataType = FE_MAT3D;
// get the parent
FECoreBase* pc = dynamic_cast<FECoreBase*>(pp->parent());
if (pc == 0) throw XMLReader::InvalidAttributeValue(tag, "param", szparam);
// data generator
// TODO: Make this a shared pointer so it will be deleted properly
FEDataGenerator* gen = 0;
if (szgen)
{
// data will be generated
if (strcmp(szgen, "const") == 0)
{
if (dataType == FE_DOUBLE) gen = new FEConstDataGenerator<double>(&fem);
else if (dataType == FE_VEC3D ) gen = new FEConstDataGenerator<vec3d>(&fem);
else if (dataType == FE_MAT3D ) gen = new FEConstDataGenerator<mat3d>(&fem);
}
else
{
gen = fecore_new<FEDataGenerator>(szgen, &fem);
}
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
// read the parameters
ReadParameterList(tag, gen);
// initialize the generator
if (gen->Init() == false) throw FEBioImport::DataGeneratorError();
}
if (dynamic_cast<FEMaterial*>(pc))
{
FEMaterial* mat = dynamic_cast<FEMaterial*>(pc->GetAncestor());
if (mat == 0) throw XMLReader::InvalidAttributeValue(tag, "param", szparam);
FEDomainList& DL = mat->GetDomainList();
FEElementSet* set = new FEElementSet(&fem);
set->Create(DL);
mesh.AddElementSet(set);
// create a new domain map
FEDomainMap* map = nullptr;
switch (dataType)
{
case FE_DOUBLE: map = new FEDomainMap(dataType); break;
case FE_VEC3D : map = new FEDomainMap(dataType); break;
case FE_MAT3D : map = new FEDomainMap(dataType, FMT_ITEM); break;
}
map->Create(set);
map->SetName(szparam);
mesh.AddDataArray(szparam, map);
if (gen)
{
if (gen->Generate(*map, *set) == false) throw FEBioImport::DataGeneratorError();
}
else
{
ParseElementData(tag, *map);
}
if (dataType == FE_DOUBLE)
{
FEParamDouble& p = pp->value<FEParamDouble>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FEMappedValue* val = new FEMappedValue(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
else if (dataType == FE_VEC3D)
{
FEParamVec3& p = pp->value<FEParamVec3>();
FEMappedValueVec3* val = new FEMappedValueVec3(&fem);
val->setDataMap(map);
p.setValuator(val);
}
else if (dataType == FE_MAT3D)
{
FEParamMat3d& p = pp->value<FEParamMat3d>();
FEMappedValueMat3d* val = fecore_alloc(FEMappedValueMat3d, &fem);
val->setDataMap(map);
p.setValuator(val);
}
int a = 0;
}
else if (dynamic_cast<FEBodyLoad*>(pc))
{
FEBodyLoad* pbl = dynamic_cast<FEBodyLoad*>(pc);
FEDomainList& DL = pbl->GetDomainList();
FEElementSet* set = new FEElementSet(&fem);
set->Create(DL);
mesh.AddElementSet(set);
// create a new domain map
FEDomainMap* map = new FEDomainMap(dataType);
map->Create(set);
map->SetName(szparam);
mesh.AddDataArray(szparam, map);
if (gen)
{
if (gen->Generate(*map, *set) == false) throw FEBioImport::DataGeneratorError();
}
else
{
ParseElementData(tag, *map);
}
if (dataType == FE_DOUBLE)
{
FEParamDouble& p = pp->value<FEParamDouble>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FEMappedValue* val = new FEMappedValue(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
else if (dataType == FE_VEC3D)
{
FEParamVec3& p = pp->value<FEParamVec3>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FEMappedValueVec3* val = new FEMappedValueVec3(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
}
else if (dynamic_cast<FESurfaceLoad*>(pc))
{
FESurfaceLoad* psl = dynamic_cast<FESurfaceLoad*>(pc);
FESurface* set = &psl->GetSurface();
// create a new domain map
FESurfaceMap* map = new FESurfaceMap(dataType);
map->Create(set);
map->SetName(szparam);
mesh.AddDataArray(szparam, map);
if (gen)
{
if (gen->Generate(*map, *set->GetFacetSet()) == false) throw FEBioImport::DataGeneratorError();
}
else
{
ParseSurfaceData(tag, *map);
}
if (dataType == FE_DOUBLE)
{
FEParamDouble& p = pp->value<FEParamDouble>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FEMappedValue* val = new FEMappedValue(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
else if (dataType == FE_VEC3D)
{
FEParamVec3& p = pp->value<FEParamVec3>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FEMappedValueVec3* val = new FEMappedValueVec3(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
}
else if (dynamic_cast<FEPrescribedDOF*>(pc))
{
FEPrescribedDOF* bc = dynamic_cast<FEPrescribedDOF*>(pc);
// create node set
const FENodeSet& bc_set = *bc->GetNodeSet();
int nsize = bc_set.Size();
FENodeSet* set = new FENodeSet(&fem);
for (int i = 0; i < nsize; ++i) set->Add(bc_set[i]);
FENodeDataMap* map = new FENodeDataMap(FE_DOUBLE);
mesh.AddDataArray(szparam, map);
if (gen)
{
if (gen->Generate(*map, *set) == false) throw FEBioImport::DataGeneratorError();
}
else
{
map->Create(set->Size());
ParseNodeData(tag, *map);
}
if (dataType == FE_DOUBLE)
{
FEParamDouble& p = pp->value<FEParamDouble>();
if (p.isConst() == false) throw FEBioImport::DataGeneratorError();
FENodeMappedValue* val = new FENodeMappedValue(&fem);
val->setDataMap(map, p.constValue());
p.setValuator(val);
}
}
else throw XMLReader::InvalidAttributeValue(tag, "param", szparam);
}
//-----------------------------------------------------------------------------
// Helper function for setting material point member data
template <class T> void setMaterialPointData(FEElement& el, FEMaterialPointProperty& d, const T& v)
{
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
d.set(mp, v);
}
}
void FEBioMeshDataSection3::ParseMaterialPointData(XMLTag& tag, FEParamValue param)
{
if (param.type() != FE_PARAM_MATERIALPOINT) throw XMLReader::InvalidAttributeValue(tag, "param");
FEParam* pp = param.param();
FEMaterialPointProperty& matProp = pp->value<FEMaterialPointProperty>();
FECoreBase* pc = dynamic_cast<FECoreBase*>(pp->parent());
if (pc == 0) throw XMLReader::InvalidAttributeValue(tag, "param");
FEDataType dataType = matProp.dataType();
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the parameter name
const char* szparam = tag.AttributeValue("param");
// see if the data will be generated or tabulated
const char* szgen = tag.AttributeValue("generator", true);
FEMaterial* mat = dynamic_cast<FEMaterial*>(pc->GetAncestor());
if (mat)
{
FEDomainList& DL = mat->GetDomainList();
FEElementSet* set = new FEElementSet(&fem);
set->Create(DL);
if (szgen)
{
FEDataGenerator* gen = 0;
if (strcmp(szgen, "const") == 0)
{
if (dataType == FE_DOUBLE) gen = new FEConstDataGenerator<double>(&fem);
else if (dataType == FE_VEC2D ) gen = new FEConstDataGenerator<vec2d >(&fem);
else if (dataType == FE_VEC3D ) gen = new FEConstDataGenerator<vec3d >(&fem);
else if (dataType == FE_MAT3D ) gen = new FEConstDataGenerator<mat3d >(&fem);
}
else
{
gen = fecore_new<FEDataGenerator>(szgen, &fem);
}
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
// read the parameters
ReadParameterList(tag, gen);
// initialize the generator
if (gen->Init() == false) throw FEBioImport::DataGeneratorError();
for (int i = 0; i < set->Elements(); ++i)
{
FEElement& el = set->Element(i);
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
vec3d rn = mp.m_r0;
switch (dataType)
{
case FE_DOUBLE: { double d; gen->value(rn, d); matProp.set(mp, d); } break;
case FE_VEC2D : { vec2d d; gen->value(rn, d); matProp.set(mp, d); } break;
case FE_VEC3D : { vec3d d; gen->value(rn, d); matProp.set(mp, d); } break;
case FE_MAT3D : { mat3d d; gen->value(rn, d); matProp.set(mp, d); } break;
}
}
}
}
else
{
vector<ELEMENT_DATA> data;
ParseElementData(tag, *set, data, fecore_data_size(matProp.dataType()));
for (int i = 0; i<set->Elements(); ++i)
{
FEElement& el = set->Element(i);
ELEMENT_DATA& di = data[i];
// make sure the correct number of values were read in
if (di.nval != fecore_data_size(matProp.dataType()))
{
throw FEBioImport::MeshDataError();
}
double* v = di.val;
switch (matProp.dataType())
{
case FE_DOUBLE: setMaterialPointData(el, matProp, v[0]); break;
case FE_VEC2D : setMaterialPointData(el, matProp, vec2d(v[0], v[1])); break;
case FE_VEC3D : setMaterialPointData(el, matProp, vec3d(v[0], v[1], v[2])); break;
case FE_MAT3D : setMaterialPointData(el, matProp, mat3d(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8])); break;
default:
assert(false);
}
}
}
delete set;
return;
}
throw XMLReader::InvalidAttributeValue(tag, "param", szparam);
}
*/
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseShellThickness(XMLTag& tag, FEElementSet& set)
{
if (tag.isleaf())
{
FEMesh& mesh = GetFEModel()->GetMesh();
double h[FEElement::MAX_NODES];
int nval = tag.value(h, FEElement::MAX_NODES);
for (int i=0; i<set.Elements(); ++i)
{
FEShellElement* pel = dynamic_cast<FEShellElement*>(&set.Element(i));
if (pel == 0) throw XMLReader::InvalidValue(tag);
if (pel->Nodes() != nval) throw XMLReader::InvalidValue(tag);
for (int j=0; j<nval; ++j) pel->m_h0[j] = h[j];
}
}
else
{
vector<ELEMENT_DATA> data;
ParseElementData(tag, set, data, FEElement::MAX_NODES);
for (int i=0; i<(int)data.size(); ++i)
{
ELEMENT_DATA& di = data[i];
if (di.nval > 0)
{
FEElement& el = set.Element(i);
if (el.Class() != FE_ELEM_SHELL) throw XMLReader::InvalidTag(tag);
FEShellElement& shell = static_cast<FEShellElement&> (el);
int ne = shell.Nodes();
if (ne != di.nval) throw XMLReader::InvalidTag(tag);
for (int j=0; j<ne; ++j) shell.m_h0[j] = di.val[j];
}
}
}
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseMaterialFibers(XMLTag& tag, FEElementSet& set)
{
// find the domain with the same name
string name = set.GetName();
FEMesh* mesh = const_cast<FEMesh*>(set.GetMesh());
FEDomain* dom = mesh->FindDomain(name);
if (dom == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", name.c_str());
// get the material
FEMaterial* mat = dom->GetMaterial();
if (mat == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", name.c_str());
// get the fiber property
FEProperty* fiber = mat->FindProperty("fiber");
if (fiber == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", name.c_str());
if (fiber->GetSuperClassID() != FEVEC3DVALUATOR_ID) throw XMLReader::InvalidAttributeValue(tag, "elem_set", name.c_str());
// create a domain map
FEDomainMap* map = new FEDomainMap(FE_VEC3D, FMT_ITEM);
map->Create(&set);
FEMappedValueVec3* val = fecore_new<FEMappedValueVec3>("map", GetFEModel());
val->setDataMap(map);
fiber->SetProperty(val);
vector<ELEMENT_DATA> data;
ParseElementData(tag, set, data, 3);
for (int i = 0; i < (int)data.size(); ++i)
{
ELEMENT_DATA& di = data[i];
if (di.nval > 0)
{
FEElement& el = set.Element(i);
if (di.nval != 3) throw XMLReader::InvalidTag(tag);
vec3d v(di.val[0], di.val[1], di.val[2]);
v.unit();
map->set<vec3d>(i, v);
}
}
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseMaterialAxes(XMLTag& tag, FEElementSet& set)
{
// find the domain with the same name
string name = set.GetName();
const char* szname = name.c_str();
FEMesh* mesh = const_cast<FEMesh*>(set.GetMesh());
// find the domain
string domName = set.GetName();
FEDomainList& DL = set.GetDomainList();
if (DL.Domains() != 1)
{
throw XMLReader::InvalidAttributeValue(tag, "elem_set", domName.c_str());
}
FEDomain* dom = DL.GetDomain(0);
// get the material
FEMaterial* mat = dom->GetMaterial();
if (mat == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szname);
Storage_Fmt fmt = FMT_ITEM;
const char* szfmt = tag.AttributeValue("format", true);
if (szfmt)
{
if (szcmp(szfmt, "mat_points") == 0) fmt = FMT_MATPOINTS;
}
// get the mat_axis property
FEProperty* pQ = mat->FindProperty("mat_axis", true);
if (pQ == nullptr)
{
// if the material does not have the mat_axis property, we'll assign it directly to the material points
// This only works for ITEM storage
if (fmt != FMT_ITEM) throw XMLReader::InvalidAttributeValue(tag, "format", szfmt);
++tag;
do
{
if ((tag == "e") || (tag == "elem"))
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int lid = atoi(szlid) - 1;
// make sure the number is valid
if ((lid < 0) || (lid >= set.Elements())) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
// get the element
FEElement* el = mesh->FindElementFromID(set[lid]);
if (el == 0) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
// read parameters
double a[3] = { 0 };
double d[3] = { 0 };
++tag;
do
{
if (tag == "a") tag.value(a, 3);
else if (tag == "d") tag.value(d, 3);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
vec3d v1(a[0], a[1], a[2]);
vec3d v2(d[0], d[1], d[2]);
vec3d e1(v1);
vec3d e3 = v1 ^ v2;
vec3d e2 = e3 ^ e1;
// normalize
e1.unit();
e2.unit();
e3.unit();
// set the value
mat3d A(e1, e2, e3);
// convert to quaternion
quatd Q(A);
// assign to all material points
int ni = el->GaussPoints();
for (int n = 0; n < ni; ++n)
{
FEMaterialPoint* mp = el->GetMaterialPoint(n);
mp->m_Q = Q;
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
return;
}
if (pQ->GetSuperClassID() != FEMAT3DVALUATOR_ID) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szname);
// create the map's name: material_name.mat_axis
stringstream ss;
ss << "material" << mat->GetID() << ".mat_axis";
string mapName = ss.str();
// the domain map we're about to create
FEDomainMap* map = nullptr;
// see if the generator is defined
const char* szgen = tag.AttributeValue("generator", true);
if (szgen)
{
// create a domain map
map = new FEDomainMap(FE_MAT3D, fmt);
map->SetName(mapName);
map->Create(&set);
// data will be generated
FEModel* fem = GetFEModel();
if (strcmp(szgen, "const") == 0)
{
map = new FEDomainMap(FE_MAT3D, fmt);
++tag;
do {
if (tag == "value")
{
mat3d v; tag.value(v); map->fillValue(v);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
else
{
FEElemDataGenerator* gen = fecore_new<FEElemDataGenerator>(szgen, fem);
if (gen == 0) throw XMLReader::InvalidAttributeValue(tag, "generator", szgen);
// read the parameters
ReadParameterList(tag, gen);
// initialize the generator
if (gen->Init() == false) throw FEBioImport::DataGeneratorError();
// generate the data
map = dynamic_cast<FEDomainMap*>(gen->Generate());
if (map == nullptr) throw FEBioImport::DataGeneratorError();
}
}
else
{
// This only works for ITEM storage
if (fmt != FMT_ITEM) throw XMLReader::InvalidAttributeValue(tag, "format", szfmt);
// create a domain map
map = new FEDomainMap(FE_MAT3D, FMT_ITEM);
map->SetName(mapName);
map->Create(&set);
++tag;
do
{
if ((tag == "e") || (tag == "elem"))
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int lid = atoi(szlid) - 1;
// make sure the number is valid
if ((lid < 0) || (lid >= set.Elements())) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
// get the element
FEElement* el = mesh->FindElementFromID(set[lid]);
if (el == 0) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
// read parameters
double a[3] = { 0 };
double d[3] = { 0 };
++tag;
do
{
if (tag == "a") tag.value(a, 3);
else if (tag == "d") tag.value(d, 3);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
vec3d v1(a[0], a[1], a[2]);
vec3d v2(d[0], d[1], d[2]);
vec3d e1(v1);
vec3d e3 = v1 ^ v2;
vec3d e2 = e3 ^ e1;
// normalize
e1.unit();
e2.unit();
e3.unit();
// set the value
mat3d Q(e1, e2, e3);
map->setValue(lid, Q);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
assert(map);
// see if this map already exists
FEDomainMap* oldMap = dynamic_cast<FEDomainMap*>(mesh->FindDataMap(mapName));
if (oldMap)
{
// It does, so merge it
oldMap->Merge(*map);
delete map;
}
else
{
// It does not, so add it
FEMappedValueMat3d* val = fecore_alloc(FEMappedValueMat3d, GetFEModel());
val->setDataMap(map);
pQ->SetProperty(val);
mesh->AddDataMap(map);
}
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseNodeData(XMLTag& tag, FENodeDataMap& map)
{
// get the total nr of nodes
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int nodes = map.DataCount();
FEDataType dataType = map.DataType();
int dataSize = map.DataSize();
double data[3]; // make sure this array is large enough to store any data map type (current 3 for FE_VEC3D)
++tag;
do
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int n = atoi(szlid) - 1;
// make sure the number is valid
if ((n < 0) || (n >= nodes)) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
int nread = tag.value(data, dataSize);
if (nread == dataSize)
{
switch (dataType)
{
case FE_DOUBLE: map.setValue(n, data[0]); break;
case FE_VEC2D: map.setValue(n, vec2d(data[0], data[1])); break;
case FE_VEC3D: map.setValue(n, vec3d(data[0], data[1], data[2])); break;
default:
assert(false);
}
}
else throw XMLReader::InvalidValue(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseSurfaceData(XMLTag& tag, FESurfaceMap& map)
{
const FEFacetSet* set = map.GetFacetSet();
if (set == nullptr) throw XMLReader::InvalidTag(tag);
// get the total nr of elements
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int nelems = set->Faces();
FEDataType dataType = map.DataType();
int dataSize = map.DataSize();
int m = map.MaxNodes();
double data[3 * FEElement::MAX_NODES]; // make sure this array is large enough to store any data map type (current 3 for FE_VEC3D)
++tag;
do
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int n = atoi(szlid) - 1;
// make sure the number is valid
if ((n < 0) || (n >= nelems)) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
int nread = tag.value(data, m*dataSize);
if (nread == dataSize)
{
switch (dataType)
{
case FE_DOUBLE: map.setValue(n, data[0]); break;
case FE_VEC2D: map.setValue(n, vec2d(data[0], data[1])); break;
case FE_VEC3D: map.setValue(n, vec3d(data[0], data[1], data[2])); break;
default:
assert(false);
}
}
else if (nread == m*dataSize)
{
double* pd = data;
for (int i = 0; i < m; ++i, pd += dataSize)
{
switch (dataType)
{
case FE_DOUBLE: map.setValue(n, i, pd[0]); break;
case FE_VEC2D: map.setValue(n, i, vec2d(pd[0], pd[1])); break;
case FE_VEC3D: map.setValue(n, i, vec3d(pd[0], pd[1], pd[2])); break;
default:
assert(false);
}
}
}
else throw XMLReader::InvalidValue(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseElementData(XMLTag& tag, FEDomainMap& map)
{
if (tag.isleaf())
{
if (map.DataType() == FE_DOUBLE)
{
double v = 0.0;
tag.value(v);
map.set(v);
}
else throw XMLReader::InvalidValue(tag);
}
const FEElementSet* set = map.GetElementSet();
if (set == nullptr) throw XMLReader::InvalidTag(tag);
// get the total nr of elements
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int nelems = set->Elements();
FEDataType dataType = map.DataType();
int dataSize = map.DataSize();
int m = map.MaxNodes();
double data[3 * FEElement::MAX_NODES]; // make sure this array is large enough to store any data map type (current 3 for FE_VEC3D)
// TODO: For vec3d values, I sometimes need to normalize the vectors (e.g. for fibers). How can I do this?
int ncount = 0;
++tag;
do
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int n = atoi(szlid) - 1;
// make sure the number is valid
if ((n < 0) || (n >= nelems)) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
int nread = tag.value(data, m*dataSize);
if (nread == dataSize)
{
double* v = data;
switch (dataType)
{
case FE_DOUBLE: map.setValue(n, v[0]); break;
case FE_VEC2D : map.setValue(n, vec2d(v[0], v[1])); break;
case FE_VEC3D : map.setValue(n, vec3d(v[0], v[1], v[2])); break;
case FE_MAT3D : map.setValue(n, mat3d(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8])); break;
case FE_MAT3DS: map.setValue(n, mat3ds(v[0], v[1], v[2], v[3], v[4], v[5])); break;
default:
assert(false);
}
}
else if (nread == m*dataSize)
{
double* v = data;
for (int i = 0; i < m; ++i, v += dataSize)
{
switch (dataType)
{
case FE_DOUBLE: map.setValue(n, i, v[0]); break;
case FE_VEC2D: map.setValue(n, i, vec2d(v[0], v[1])); break;
case FE_VEC3D: map.setValue(n, i, vec3d(v[0], v[1], v[2])); break;
default:
assert(false);
}
}
}
else throw XMLReader::InvalidValue(tag);
++tag;
ncount++;
}
while (!tag.isend());
if (ncount != nelems) throw FEBioImport::MeshDataError();
}
//-----------------------------------------------------------------------------
void FEBioMeshDataSection3::ParseElementData(XMLTag& tag, FEElementSet& set, vector<ELEMENT_DATA>& values, int nvalues)
{
// get the total nr of elements
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int nelems = set.Elements();
// resize the array
values.resize(nelems);
for (int i=0; i<nelems; ++i) values[i].nval = 0;
++tag;
do
{
// get the local element number
const char* szlid = tag.AttributeValue("lid");
int n = atoi(szlid)-1;
// make sure the number is valid
if ((n<0) || (n>=nelems)) throw XMLReader::InvalidAttributeValue(tag, "lid", szlid);
ELEMENT_DATA& data = values[n];
data.nval = tag.value(data.val, nvalues);
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioMeshAdaptorSection.h | .h | 1,526 | 42 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
class FEBioMeshAdaptorSection : public FEFileSection
{
public:
FEBioMeshAdaptorSection(FEFileImport* pim) : FEFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseMeshAdaptor(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioIncludeSection.cpp | .cpp | 1,986 | 52 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioIncludeSection.h"
//-----------------------------------------------------------------------------
//! Parse the Include section (new in version 2.0)
//! This section includes the contents of another FEB file.
void FEBioIncludeSection::Parse(XMLTag& tag)
{
// see if we need to pre-pend a path
char szin[512];
strcpy(szin, tag.szvalue());
char* ch = strrchr(szin, '\\');
if (ch==0) ch = strrchr(szin, '/');
if (ch==0)
{
// pre-pend the name with the input path
snprintf(szin, sizeof(szin), "%s%s", GetFileReader()->GetFilePath(), tag.szvalue());
}
// read the file
if (GetFEBioImport()->ReadFile(szin, false) == false)
throw XMLReader::InvalidValue(tag);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioLoadsSection.h | .h | 3,052 | 95 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// Version 1.2
class FEBioLoadsSection1x : public FEFileSection
{
public:
FEBioLoadsSection1x(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseNodalLoad (XMLTag& tag);
void ParseBodyForce (XMLTag& tag);
void ParseBodyLoad (XMLTag& tag);
void ParseSurfaceLoad(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// Version 2.0
class FEBioLoadsSection2 : public FEFileSection
{
public:
FEBioLoadsSection2(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseNodalLoad (XMLTag& tag);
void ParseBodyLoad (XMLTag& tag);
void ParseEdgeLoad (XMLTag& tag);
void ParseSurfaceLoad(XMLTag& tag);
void ParseSurfaceLoadSurface(XMLTag& tag, FESurface* psurf);
};
//-----------------------------------------------------------------------------
// Version 2.5
class FEBioLoadsSection25 : public FEFileSection
{
public:
FEBioLoadsSection25(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseNodalLoad (XMLTag& tag);
void ParseEdgeLoad (XMLTag& tag);
void ParseSurfaceLoad(XMLTag& tag);
void ParseBodyLoad (XMLTag& tag);
protected:
void ParseObsoleteLoad(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// Version 3.0
class FEBioLoadsSection3 : public FEFileSection
{
public:
FEBioLoadsSection3(FEFileImport* pim) : FEFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodalLoad (XMLTag& tag);
void ParseEdgeLoad (XMLTag& tag);
void ParseSurfaceLoad(XMLTag& tag);
void ParseBodyLoad (XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/xmltool.h | .h | 2,699 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FECoreBase.h>
#include <FECore/ClassDescriptor.h>
#include "XMLReader.h"
#include "febioxml_api.h"
//This namespace defines some helper functions that facilitate processing the FEBio xml formatted files.
namespace fexml
{
//---------------------------------------------------------------------------------------
// Reads the value of a parameter.
// if paramName is zero, the tag's name will be used as the parameter name.
bool FEBIOXML_API readParameter(XMLTag& tag, FEParameterList& paramList, const char* paramName = 0);
//---------------------------------------------------------------------------------------
bool FEBIOXML_API readParameter(XMLTag& tag, FECoreBase* pc);
//---------------------------------------------------------------------------------------
// reads the parameters and properties of a FECore class
bool FEBIOXML_API readParameterList(XMLTag& tag, FECoreBase* pc);
// read parameters listed as attributes in the tag
bool FEBIOXML_API readAttributeParams(XMLTag& tag, FECoreBase* pc);
//---------------------------------------------------------------------------------------
// read a list of integers
void FEBIOXML_API readList(XMLTag& tag, vector<int>& l);
//---------------------------------------------------------------------------------------
// create a class descriptor from the current tag
FEBIOXML_API FEClassDescriptor* readParameterList(XMLTag& tag);
}
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioMeshAdaptorSection.cpp | .cpp | 2,307 | 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 "FEBioMeshAdaptorSection.h"
#include <FECore/FEMeshAdaptor.h>
void FEBioMeshAdaptorSection::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "mesh_adaptor")
{
ParseMeshAdaptor(tag);
}
++tag;
}
while (!tag.isend());
}
void FEBioMeshAdaptorSection::ParseMeshAdaptor(XMLTag& tag)
{
const char* sztype = tag.AttributeValue("type");
FEModel* fem = GetFEModel();
FEMeshAdaptor* meshAdaptor = fecore_new<FEMeshAdaptor>(sztype, fem);
if (meshAdaptor == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// get the optional element set
const char* set = tag.AttributeValue("elem_set", true);
if (set)
{
FEMesh& mesh = fem->GetMesh();
FEElementSet* elemSet = mesh.FindElementSet(set);
if (elemSet == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", set);
meshAdaptor->SetElementSet(elemSet);
}
fem->AddMeshAdaptor(meshAdaptor);
GetBuilder()->AddComponent(meshAdaptor);
ReadParameterList(tag, meshAdaptor);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioGeometrySection.h | .h | 5,290 | 149 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FEBioImport.h"
#include "FEBModel.h"
//-----------------------------------------------------------------------------
// Geometry Section (base class)
class FEBioGeometrySection : public FEBioFileSection
{
public:
FEBioGeometrySection(FEBioImport* pim) : FEBioFileSection(pim) {}
protected:
bool ReadElement(XMLTag& tag, FEElement& el, int nid);
};
//-----------------------------------------------------------------------------
class FEBioGeometrySection1x : public FEBioGeometrySection
{
protected:
struct FEDOMAIN
{
FE_Element_Spec elem; // element type
int mat; // material ID
int nel; // number of elements
};
public:
FEBioGeometrySection1x(FEBioImport* pim) : FEBioGeometrySection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodeSection(XMLTag& tag);
void ParseNodeSetSection(XMLTag& tag);
void ParseElementSection(XMLTag& tag);
void ParseElementDataSection(XMLTag& tag);
void ParseElementData(FEElement& el, XMLTag& tag);
};
//-----------------------------------------------------------------------------
class FEBioGeometrySection2 : public FEBioGeometrySection
{
public:
FEBioGeometrySection2(FEBioImport* pim) : FEBioGeometrySection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodeSection(XMLTag& tag);
void ParseEdgeSection(XMLTag& tag);
void ParseSurfaceSection (XMLTag& tag);
void ParseElementSection (XMLTag& tag);
void ParseNodeSetSection (XMLTag& tag);
void ParseElementSetSection(XMLTag& tag);
void ParseElementDataSection(XMLTag& tag);
void ParseElementData(FEElement& el, XMLTag& tag);
};
//-----------------------------------------------------------------------------
class FEBioGeometrySection25 : public FEBioGeometrySection
{
public:
FEBioGeometrySection25(FEBioImport* pim) : FEBioGeometrySection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodeSection (XMLTag& tag);
void ParseDiscreteSetSection(XMLTag& tag);
void ParseSurfacePairSection(XMLTag& tag);
void ParseNodeSetPairSection(XMLTag& tag);
void ParseNodeSetSetSection (XMLTag& tag);
void ParsePartSection (XMLTag& tag);
void ParseInstanceSection (XMLTag& tag);
void ParseSurfaceSection (XMLTag& tag);
void ParseElementSection (XMLTag& tag);
void ParseNodeSetSection (XMLTag& tag);
void ParseEdgeSection (XMLTag& tag);
void ParseElementSetSection (XMLTag& tag);
// New functions for parsing parts
void ParsePart(XMLTag& tag, FEBModel::Part* part);
void ParsePartNodeSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartElementSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartNodeSetSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartSurfaceSection(XMLTag& tag, FEBModel::Part* part);
protected:
FEBModel m_feb;
};
//-----------------------------------------------------------------------------
class FEBioGeometrySection3 : public FEBioGeometrySection
{
public:
FEBioGeometrySection3(FEBioImport* pim) : FEBioGeometrySection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodeSection (XMLTag& tag);
void ParseDiscreteSetSection(XMLTag& tag);
void ParseSurfacePairSection(XMLTag& tag);
void ParseNodeSetPairSection(XMLTag& tag);
void ParseNodeSetSetSection (XMLTag& tag);
void ParsePartSection (XMLTag& tag);
void ParseInstanceSection (XMLTag& tag);
void ParseSurfaceSection (XMLTag& tag);
void ParseElementSection (XMLTag& tag);
void ParseNodeSetSection (XMLTag& tag);
void ParseEdgeSection (XMLTag& tag);
void ParseElementSetSection (XMLTag& tag);
// New functions for parsing parts
void ParsePart(XMLTag& tag, FEBModel::Part* part);
void ParsePartNodeSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartElementSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartNodeSetSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartSurfaceSection(XMLTag& tag, FEBModel::Part* part);
void ParsePartElementSetSection(XMLTag& tag, FEBModel::Part* part);
protected:
FEBModel m_feb;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioRigidSection4.h | .h | 1,616 | 41 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FEBioImport.h"
class FEBioRigidSection4 : public FEFileSection
{
public:
FEBioRigidSection4(FEFileImport* pim) : FEFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseRigidBC(XMLTag& tag);
void ParseRigidIC(XMLTag& tag);
void ParseRigidLoad(XMLTag& tag);
void ParseRigidConnector(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioLoadDataSection3.cpp | .cpp | 3,378 | 115 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioLoadDataSection.h"
#include <FECore/FEModel.h>
#include <FECore/FELoadController.h>
#include <sstream>
//-----------------------------------------------------------------------------
FEBioLoadDataSection3::FEBioLoadDataSection3(FEFileImport* pim) : FEFileSection(pim)
{
m_redefineCurves = false;
}
//-----------------------------------------------------------------------------
//! This function reads the load data section from the xml file
//!
void FEBioLoadDataSection3::Parse(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
++tag;
do
{
if (tag == "load_controller")
{
// load curve ID
int nid;
tag.AttributeValue("id", nid);
// get the type
const char* sztype = tag.AttributeValue("type");
// get the number of load curves
int nlc = fem.LoadControllers();
// create the controller
FELoadController* plc = fecore_new<FELoadController>(sztype, &fem);
if (plc == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type");
// set the ID
plc->SetID(nid - 1);
// see if this refers to a valid curve
if (m_redefineCurves && ((nid > 0) && (nid <= nlc)))
{
fem.ReplaceLoadController(nid - 1, plc);
}
else
{
// check that the ID is one more than the number of load curves defined
// This is to make sure that the ID's are in numerical order and no values are skipped.
if (nid != nlc + 1)
{
delete plc;
throw XMLReader::InvalidAttributeValue(tag, "id");
}
// add the controller
fem.AddLoadController(plc);
}
// read the parameter list
ReadParameterList(tag, plc);
// make sure we have a name
string name = plc->GetName();
if (name.empty())
{
stringstream ss;
ss << "lc" << plc->GetID() + 1;
name = ss.str();
plc->SetName(name);
}
if (m_redefineCurves)
{
// We only get here during restart, in which case the new load controllers
// will not get a chance to be initialized, so we'll do it here.
plc->Init();
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioInitialSection3.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 "FEBioImport.h"
//-----------------------------------------------------------------------------
// Initial Section
class FEBioInitialSection3 : public FEFileSection
{
public:
FEBioInitialSection3(FEFileImport* pim);
void Parse(XMLTag& tag);
void ParseIC(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioControlSection.h | .h | 1,978 | 56 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// Control Section
class FEBioControlSection : public FEBioFileSection
{
public:
FEBioControlSection(FEBioImport* pim) : FEBioFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
bool ParseCommonParams(XMLTag& tag);
void ParseIntegrationRules(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// Control Section for steps
class FEStepControlSection : public FEFileSection
{
public:
FEStepControlSection(FEFileImport* pim) : FEFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
bool ParseCommonParams(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioBoundarySection3.h | .h | 1,723 | 43 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioBoundarySection.h"
//-----------------------------------------------------------------------------
// version 3.0
class FEBioBoundarySection3 : public FEBioBoundarySection
{
public:
FEBioBoundarySection3(FEFileImport* imp) : FEBioBoundarySection(imp) {}
void Parse(XMLTag& tag);
void ParseBC(XMLTag& tag);
void ParseBCRigid(XMLTag& tag); // read rigid contact section
void ParseLinearConstraint(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioConstraintsSection.h | .h | 2,709 | 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 "FEBioImport.h"
class FEFacetSet;
//-----------------------------------------------------------------------------
// Constraints Section
// (Base class. Don't use this directly!)
class FEBioConstraintsSection : public FEFileSection
{
public:
FEBioConstraintsSection(FEFileImport* pim) : FEFileSection(pim){}
protected:
bool ParseSurfaceSection(XMLTag& tag, FESurface& s, int nfmt, bool bnodal);
};
//-----------------------------------------------------------------------------
// Constraints Section (format 1.x)
class FEBioConstraintsSection1x : public FEBioConstraintsSection
{
public:
FEBioConstraintsSection1x(FEFileImport* pim) : FEBioConstraintsSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseRigidConstraint(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// Constraints Section (format 2.0)
class FEBioConstraintsSection2 : public FEBioConstraintsSection
{
public:
FEBioConstraintsSection2(FEFileImport* pim) : FEBioConstraintsSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseRigidConstraint20(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// Constraints Section (format 2.5)
class FEBioConstraintsSection25 : public FEBioConstraintsSection
{
public:
FEBioConstraintsSection25(FEFileImport* pim) : FEBioConstraintsSection(pim){}
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioDiscreteSection.cpp | .cpp | 8,885 | 312 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioDiscreteSection.h"
#include "FECore/FEDiscreteMaterial.h"
#include "FECore/FEDiscreteDomain.h"
#include "FECore/FEModel.h"
#include "FECore/FEModelLoad.h"
#include "FECore/FECoreKernel.h"
//-----------------------------------------------------------------------------
void FEBioDiscreteSection::Parse(XMLTag& tag)
{
// make sure this tag has children
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "spring" ) ParseSpringSection (tag);
else if (tag == "rigid_axial_force") ParseRigidAxialForce(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioDiscreteSection::ParseSpringSection(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// determine the spring type
const char* szt = tag.AttributeValue("type", true);
// in 2.5 the names of the spring materials were changed so
// we have to map the type string to the new names.
if ((szt == 0) || (strcmp(szt, "linear") == 0)) szt = "linear spring";
else if (strcmp(szt, "tension-only linear") == 0) szt = "tension-only linear spring";
else if (strcmp(szt, "nonlinear") == 0) szt = "nonlinear spring";
FEDiscreteMaterial* pm = dynamic_cast<FEDiscreteMaterial*>(fecore_new<FEMaterial>(szt, &fem));
if (pm == 0) throw XMLReader::InvalidAttributeValue(tag, "type", szt);
fem.AddMaterial(pm);
pm->SetID(fem.Materials());
// create a new spring "domain"
FECoreKernel& febio = FECoreKernel::GetInstance();
FE_Element_Spec spec;
spec.eclass = FE_ELEM_DISCRETE;
spec.eshape = ET_DISCRETE;
spec.etype = FE_DISCRETE;
FEDiscreteDomain* pd = dynamic_cast<FEDiscreteDomain*>(febio.CreateDomain(spec, &mesh, pm));
assert(pd);
if (pd == 0) throw FEBioImport::InvalidDomainType();
mesh.AddDomain(pd);
int elems = fem.GetMesh().Elements();
int maxid = elems+1;
// read spring discrete elements
++tag;
do
{
// read the required node tag
if (tag == "node")
{
int n[2];
tag.value(n, 2);
n[0] -= 1;
n[1] -= 1;
pd->AddElement(++maxid, n);
}
else
{
// first read the domain paramters
FEParameterList& pl = pd->GetParameterList();
if (ReadParameter(tag, pl) == 0)
{
// read the actual spring material parameters
FEParameterList& pl = pm->GetParameterList();
if (ReadParameter(tag, pl) == 0)
{
throw XMLReader::InvalidTag(tag);
}
}
}
++tag;
}
while (!tag.isend());
pd->CreateMaterialPointData();
}
//---------------------------------------------------------------------------------
void FEBioDiscreteSection::ParseRigidAxialForce(XMLTag& tag)
{
// create a new rigid constraint
FEModelLoad* paf = fecore_new<FEModelLoad>(tag.Name(), GetFEModel());
// read the parameters
FEParameterList& pl = paf->GetParameterList();
++tag;
do
{
if (ReadParameter(tag, pl) == false) throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// add it to the model
FEModel& fem = *GetFEModel();
fem.AddModelLoad(paf);
}
//-----------------------------------------------------------------------------
void FEBioDiscreteSection25::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
FECoreKernel& febio = FECoreKernel::GetInstance();
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
vector<FEDiscreteMaterial*> dmat;
// figure out the max element ID
// todo: probably should store that when reading elements
int maxid = 0;
for (int i = 0; i < mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
int NE = dom.Elements();
for (int j = 0; j < NE; ++j)
{
int eid = dom.ElementRef(j).GetID();
if (eid > maxid) maxid = eid;
}
}
vector<FEDomain*> discreteDomains;
++tag;
do
{
if (tag == "discrete_material")
{
// determine the discrete material type
const char* szt = tag.AttributeValue("type");
// get the optional name
const char* szname = tag.AttributeValue("name", true);
// create the discrete material
FEDiscreteMaterial* pm = fecore_new<FEDiscreteMaterial>(szt, &fem);
if (pm == 0) throw XMLReader::InvalidAttributeValue(tag, "type", szt);
// set the optional name
if (szname) pm->SetName(szname);
// add it to the model
fem.AddMaterial(pm);
dmat.push_back(pm);
// read the parameter list
ReadParameterList(tag, pm);
// The id in the file is one-based for discrete materials, but we want to have
// a global material ID here.
pm->SetID(fem.Materials());
}
else if (tag == "discrete")
{
// determine the material
int mid;
tag.AttributeValue("dmat", mid);
if ((mid < 1) || (mid > (int) dmat.size())) throw XMLReader::InvalidAttributeValue(tag, "dmat");
// create a new spring "domain"
FE_Element_Spec spec;
spec.eclass = FE_ELEM_DISCRETE;
spec.eshape = ET_TRUSS2;
spec.etype = FE_DISCRETE;
const char* sztype = tag.AttributeValue("type", true);
if (sztype)
{
if (strcmp(sztype, "wire") == 0)
{
spec.eclass = FE_ELEM_WIRE;
}
else if (strcmp(sztype, "spring") == 0)
{
spec.eclass = FE_ELEM_DISCRETE;
}
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
FEDiscreteDomain* pd = dynamic_cast<FEDiscreteDomain*>(febio.CreateDomain(spec, &mesh, dmat[mid - 1]));
mesh.AddDomain(pd);
// get the discrete set
const char* szset = tag.AttributeValue("discrete_set");
FEDiscreteSet* pset = mesh.FindDiscreteSet(szset);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "discrete_set", szset);
// set the name of the domain
pd->SetName(szset);
// build the springs
int N = pset->size();
for (int i=0; i<N; ++i)
{
const FEDiscreteSet::NodePair& np = pset->Element(i);
int n[2] = {np.n0, np.n1};
pd->AddElement(++maxid, n);
}
// get the domain parameters
FEParameterList& pl = pd->GetParameterList();
ReadParameterList(tag, pl);
discreteDomains.push_back(pd);
}
else if (tag == "rigid_axial_force") ParseRigidAxialForce(tag);
else if (tag == "rigid_cable") ParseRigidCable(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// initialize the discrete domains
for (FEDomain* dom : discreteDomains)
{
// create an element set for this domain
FEElementSet* elset = new FEElementSet(&fem);
elset->Create(dom);
elset->SetName(dom->GetName());
mesh.AddElementSet(elset);
// create material point data for this domain
dom->CreateMaterialPointData();
}
}
//---------------------------------------------------------------------------------
void FEBioDiscreteSection25::ParseRigidAxialForce(XMLTag& tag)
{
// create a new rigid constraint
FEModelLoad* paf = fecore_new<FEModelLoad>(tag.Name(), GetFEModel());
// read the parameters
FEParameterList& pl = paf->GetParameterList();
++tag;
do
{
if (ReadParameter(tag, pl) == false) throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
// add it to the model
FEModel& fem = *GetFEModel();
fem.AddModelLoad(paf);
}
//-----------------------------------------------------------------------------
void FEBioDiscreteSection25::ParseRigidCable(XMLTag& tag)
{
// create a new rigid constraint
FEModelLoad* pml = fecore_new<FEModelLoad>(tag.Name(), GetFEModel());
if (pml == nullptr) throw XMLReader::InvalidTag(tag);
// read all parameters and properties
++tag;
do
{
if (ReadParameter(tag, pml) == false) throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
// add it to the model
FEModel& fem = *GetFEModel();
fem.AddModelLoad(pml);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/XMLWriter.h | .h | 5,553 | 193 | /*This file is part of the FEBio Studio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio-Studio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <assert.h>
#include "febioxml_api.h"
class XMLWriter;
class FEBIOXML_API XMLElement
{
public:
class XMLAtt
{
public:
XMLAtt() {}
XMLAtt(const std::string& name, const std::string& val) : m_name(name), m_val(val) {}
XMLAtt(const XMLAtt& att) : m_name(att.m_name), m_val(att.m_val) {}
void operator = (const XMLAtt& att) { m_name = att.m_name; m_val = att.m_val; }
const char* name() const { return m_name.c_str(); }
const char* value() const { return m_val.c_str(); }
public:
std::string m_name;
std::string m_val;
};
public:
XMLElement(const char* szname = 0)
{
clear();
if (szname) m_tag = szname;
}
void clear()
{
m_att.clear();
m_tag.clear();
m_val.clear();
}
void name(const char* sz) { if (sz) m_tag = sz; else m_tag.clear(); }
const char* name() const { return m_tag.c_str(); }
void value(const char* sz) { if (sz) m_val = sz; else m_val.clear(); }
void value(int n);
void value(int* pi, int n);
void value(bool b);
void value(double g);
void value(double* pg, int n);
void value(const std::vector<int>& v);
void value(const std::vector<double>& v);
template <class T> void value(const T& v);
int add_attribute(const char* szn, const char* szv);
int add_attribute(const char* szn, int n);
int add_attribute(const char* szn, bool b);
int add_attribute(const char* szn, double g);
int add_attribute(const char* szn, const std::string& s);
void set_attribute(int nid, const char* szv);
void set_attribute(int nid, int n);
void set_attribute(int nid, bool b);
void set_attribute(int nid, double g);
int attributes() const { return (int) m_att.size(); }
const XMLAtt& attribute(int i) const { return m_att[i]; }
protected:
std::string m_tag; // element name
std::string m_val; // element value
std::vector<XMLAtt> m_att; // attributes
public:
friend class XMLWriter;
};
class FEBIOXML_API XMLWriter
{
enum {MAX_TAGS = 32};
public:
enum XMLFloatFormat {
ScientificFormat,
FixedFormat
};
public:
XMLWriter();
virtual ~XMLWriter();
bool open(const char* szfile);
bool setStringstream(std::ostringstream* stream);
void init();
void close();
void add_branch(XMLElement& el, bool bclear = true);
void add_branch(const char* szname);
void add_empty(XMLElement& el, bool bclear = true);
void add_leaf (XMLElement& el, bool bclear = true);
void add_leaf(const char* szn, const char* szv);
void add_leaf(const char* szn, const std::string& s);
void add_leaf(const char* szn, int n){ char szv[256]; snprintf(szv, sizeof(szv), "%d" , n); write_leaf(szn, szv); }
void add_leaf(const char* szn, bool b){ char szv[256]; snprintf(szv, sizeof(szv), "%d" , b); write_leaf(szn, szv); }
void add_leaf(const char* szn, double g){ char szv[256]; snprintf(szv, sizeof(szv), "%lg", g); write_leaf(szn, szv); }
void add_leaf(const char* szn, float g){ char szv[256]; snprintf(szv, sizeof(szv), "%g" , g); write_leaf(szn, szv); }
void add_leaf(const char* szn, int *pi, int n);
void add_leaf(const char* szn, float* pg, int n);
void add_leaf(const char* szn, double* pg, int n);
void add_leaf(XMLElement& el, const std::vector<int>& A);
template <class T> void add_leaf(const char* szname, const T& v);
void close_branch();
void add_comment(const std::string& s, bool singleLine = false);
public:
static void SetFloatFormat(XMLFloatFormat fmt);
static XMLFloatFormat GetFloatFormat();
void SetEncodeControlChars(bool b) { m_encodeControlChars = b; }
bool EncodeControlChars() const { return m_encodeControlChars; }
protected:
void inc_level();
void dec_level();
void write_leaf(const char* sztag, const char* szval);
protected:
std::ostream* m_stream;
int m_level;
char m_tag[MAX_TAGS][256];
char m_sztab[256];
bool m_encodeControlChars = false;
static XMLFloatFormat m_floatFormat;
};
template <class T> std::string type_to_string(const T& v)
{
return std::string(v);
}
template <class T> void XMLElement::value(const T& v)
{
std::string s = type_to_string<T>(v);
m_val = s;
}
template <class T> void XMLWriter::add_leaf(const char* szname, const T& v)
{
std::string s = type_to_string<T>(v);
add_leaf(szname, s);
}
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioCodeSection.h | .h | 1,649 | 41 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FEBioImport.h"
//-----------------------------------------------------------------------------
// This is an experimental feature.
// This section allows users to define callbacks from the input file.
class FEBioCodeSection : public FEFileSection
{
public:
FEBioCodeSection(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioInitialSection3.cpp | .cpp | 2,511 | 79 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioInitialSection3.h"
#include <FECore/FEInitialCondition.h>
FEBioInitialSection3::FEBioInitialSection3(FEFileImport* pim) : FEFileSection(pim)
{
}
void FEBioInitialSection3::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "ic") ParseIC(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
void FEBioInitialSection3::ParseIC(XMLTag& tag)
{
FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
// read the type attribute
const char* sztype = tag.AttributeValue("type");
// try to allocate the initial condition
FEInitialCondition* pic = fecore_new<FEInitialCondition>(sztype, fem);
if (pic == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// add it to the model
GetBuilder()->AddInitialCondition(pic);
FENodalIC* nic = dynamic_cast<FENodalIC*>(pic);
if (nic)
{
// read required node_set attribute
const char* szset = tag.AttributeValue("node_set");
FENodeSet* nodeSet = GetBuilder()->FindNodeSet(szset);
if (nodeSet == nullptr) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
nic->SetNodeSet(nodeSet);
}
// Read the parameter list
ReadParameterList(tag, pic);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioContactSection.h | .h | 3,206 | 102 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FileImport.h"
#include <FECore/FESurfacePairConstraint.h>
//-----------------------------------------------------------------------------
// Contact section (new in version 2.0)
class FEBioContactSection : public FEFileSection
{
protected:
//! missing primary surface
class MissingPrimarySurface : public FEFileException
{
public:
MissingPrimarySurface();
};
//! missing secondary surface
class MissingSecondarySurface : public FEFileException
{
public:
MissingSecondarySurface();
};
public:
FEBioContactSection(FEFileImport* pim) : FEFileSection(pim){}
protected:
void ParseLinearConstraint (XMLTag& tag);
protected:
bool ParseSurfaceSection (XMLTag& tag, FESurface& s, int nfmt, bool bnodal);
};
//-----------------------------------------------------------------------------
// Version 2.0
class FEBioContactSection2 : public FEBioContactSection
{
public:
FEBioContactSection2(FEFileImport* im) : FEBioContactSection(im){}
void Parse(XMLTag& tag);
protected:
void ParseRigidInterface(XMLTag& tag);
void ParseRigidWall(XMLTag& tag);
void ParseContactInterface(XMLTag& tag, FESurfacePairConstraint* pci);
};
//-----------------------------------------------------------------------------
// Version 2.5
class FEBioContactSection25 : public FEBioContactSection
{
public:
FEBioContactSection25(FEFileImport* im) : FEBioContactSection(im){}
void Parse(XMLTag& tag);
protected:
void ParseRigidWall(XMLTag& tag);
void ParseRigidSliding(XMLTag& tag);
void ParseContactInterface(XMLTag& tag, FESurfacePairConstraint* pci);
};
//-----------------------------------------------------------------------------
// Version 4.0
class FEBioContactSection4 : public FEBioContactSection
{
public:
FEBioContactSection4(FEFileImport* im) : FEBioContactSection(im) {}
void Parse(XMLTag& tag);
protected:
void ParseContactInterface(XMLTag& tag, FESurfacePairConstraint* pci);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioMeshSection4.cpp | .cpp | 12,609 | 441 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioMeshSection4.h"
#include <FECore/FEModel.h>
#include <sstream>
//-----------------------------------------------------------------------------
FEBioMeshSection4::FEBioMeshSection4(FEBioImport* pim) : FEBioFileSection(pim)
{
m_maxNodeId = 0;
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::Parse(XMLTag& tag)
{
FEModelBuilder* builder = GetBuilder();
builder->m_maxid = 0;
m_maxNodeId = 0;
// create a default part
// NOTE: Do not specify a name for the part, otherwise
// all lists will be given the name: partname.listname
FEBModel& feb = builder->GetFEBModel();
assert(feb.Parts() == 0);
FEBModel::Part* part = feb.AddPart("");
// read all sections
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection (tag, part);
else if (tag == "Elements" ) ParseElementSection (tag, part);
else if (tag == "NodeSet" ) ParseNodeSetSection (tag, part);
else if (tag == "Surface" ) ParseSurfaceSection (tag, part);
else if (tag == "Edge" ) ParseEdgeSection (tag, part);
else if (tag == "ElementSet" ) ParseElementSetSection (tag, part);
else if (tag == "PartList" ) ParsePartListSection (tag, part);
else if (tag == "SurfacePair") ParseSurfacePairSection(tag, part);
else if (tag == "DiscreteSet") ParseDiscreteSetSection(tag, part);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioMeshSection4::ParseNodeSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// see if this list defines a set
const char* szname = tag.AttributeValue("name", true);
FEBModel::NodeSet* ps = 0;
if (szname)
{
ps = new FEBModel::NodeSet(szname);
part->AddNodeSet(ps);
}
// allocate node
vector<FEBModel::NODE> node; node.reserve(10000);
vector<int> nodeList; nodeList.reserve(10000);
// read nodal coordinates
++tag;
do {
// nodal coordinates
FEBModel::NODE nd;
value(tag, nd.r);
// get the nodal ID
tag.AttributeValue("id", nd.id);
// make sure node IDs are incrementing
if (nd.id <= m_maxNodeId) throw XMLReader::InvalidAttributeValue(tag, "id");
m_maxNodeId = nd.id;
// add it to the pile
node.push_back(nd);
nodeList.push_back(nd.id);
// go on to the next node
++tag;
} while (!tag.isend());
// add nodes to the part
part->AddNodes(node);
// If a node set is defined add these nodes to the node-set
if (ps) ps->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioMeshSection4::ParseElementSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the (required!) name
const char* szname = tag.AttributeValue("name");
// get the element spec
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// make sure the domain does not exist yet
FEBModel::Domain* dom = part->FindDomain(szname);
if (dom)
{
stringstream ss;
ss << "Duplicate part name found : " << szname;
throw std::runtime_error(ss.str());
}
// create the new domain
dom = new FEBModel::Domain(espec);
if (szname) dom->SetName(szname);
// add domain it to the mesh
part->AddDomain(dom);
// for named domains, we'll also create an element set
FEBModel::ElementSet* pg = 0;
if (szname)
{
pg = new FEBModel::ElementSet(szname);
part->AddElementSet(pg);
}
dom->Reserve(10000);
vector<int> elemList; elemList.reserve(10000);
// keep track of largest ID
// we need to enforce that element IDs are increasing
// (This is currently only done for each domain. Need to modify this
// so it's done on the whole model.)
int maxID = -1;
// read element data
++tag;
do
{
FEBModel::ELEMENT el;
// get the element ID
tag.AttributeValue("id", el.id);
if ((maxID == -1) || (el.id > maxID)) maxID = el.id;
else throw XMLReader::InvalidAttributeValue(tag, "id");
// read the element data
tag.value(el.node, FEElement::MAX_NODES);
dom->AddElement(el);
elemList.push_back(el.id);
// go to next tag
++tag;
} while (!tag.isend());
// set the element list
if (pg) pg->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
//! Reads the Geometry::Groups section of the FEBio input file
void FEBioMeshSection4::ParseNodeSetSection(XMLTag& tag, FEBModel::Part* part)
{
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// make sure it's a leaf
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// see if a nodeset with this name already exists
FEBModel::NodeSet* set = part->FindNodeSet(szname);
if (set) throw FEBioImport::RepeatedNodeSet(szname);
// read the node IDs
vector<int> nodeList;
tag.value(nodeList);
// create the node set
set = new FEBModel::NodeSet(szname);
part->AddNodeSet(set);
// add nodes to the list
set->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParseSurfaceSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this surface was already defined
FEBModel::Surface* ps = part->FindSurface(szname);
if (ps) throw FEBioImport::RepeatedSurface(szname);
// allocate storage for faces
ps = new FEBModel::Surface(szname);
part->AddSurface(ps);
if (tag.isleaf() || tag.isempty()) return;
// count nr of faces
int faces = tag.children();
ps->Create(faces);
// read faces
++tag;
for (int i = 0; i < faces; ++i)
{
FEBModel::FACET& face = ps->GetFacet(i);
// get the ID (although we don't really use this)
tag.AttributeValue("id", face.id);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
tag.value(face.node, N);
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParseElementSetSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this element set was already defined
FEBModel::ElementSet* ps = part->FindElementSet(szname);
if (ps) throw FEBioImport::RepeatedElementSet(szname);
// allocate storage for faces
ps = new FEBModel::ElementSet(szname);
part->AddElementSet(ps);
// read elements
vector<int> elemList;
tag.value(elemList);
if (elemList.empty()) throw XMLReader::InvalidTag(tag);
ps->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParsePartListSection(XMLTag& tag, FEBModel::Part* part)
{
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this part list was already defined
FEBModel::PartList* ps = part->FindPartList(szname);
if (ps) throw FEBioImport::RepeatedPartList(szname);
// create a new part list
ps = new FEBModel::PartList(szname);
part->AddPartList(ps);
// read the part names
vector<string> partList;
tag.value(partList);
if (partList.empty()) throw XMLReader::InvalidTag(tag);
ps->SetPartList(partList);
// we'll also create an element set of this
FEBModel::ElementSet* es = new FEBModel::ElementSet("@part_list:" + string(szname));
part->AddElementSet(es);
vector<int> elemList;
for (string s : partList)
{
FEBModel::ElementSet* a = part->FindElementSet(s);
if (a == nullptr) throw XMLReader::InvalidValue(tag);
const vector<int>& aList = a->ElementList();
elemList.insert(elemList.end(), aList.begin(), aList.end());
}
es->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParseEdgeSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this edge was already defined
FEBModel::EdgeSet* ps = part->FindEdgeSet(szname);
if (ps) throw FEBioImport::RepeatedEdgeSet(szname);
// count nr of edges
int edges = tag.children();
// allocate storage for edges
ps = new FEBModel::EdgeSet(szname);
part->AddEdgeSet(ps);
// read edges
vector<FEBModel::EDGE> edgeSet(edges);
++tag;
for (int i = 0; i < edges; ++i)
{
FEBModel::EDGE& edge = edgeSet[i];
// get the ID (although we don't really use this)
tag.AttributeValue("id", edge.id);
// set the facet type
if (tag == "line2") edge.ntype = 2;
else if (tag == "line3") edge.ntype = 3;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = edge.ntype;
tag.value(edge.node, N);
++tag;
}
ps->SetEdgeList(edgeSet);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParseSurfacePairSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
FEBModel::SurfacePair* surfPair = new FEBModel::SurfacePair;
surfPair->m_name = szname;
part->AddSurfacePair(surfPair);
++tag;
do
{
if (tag == "primary")
{
const char* sz = tag.szvalue();
FEBModel::Surface* surf = part->FindSurface(sz);
if (surf == nullptr) throw XMLReader::InvalidValue(tag);
surfPair->m_primary = surf->Name();
}
else if (tag == "secondary")
{
const char* sz = tag.szvalue();
FEBModel::Surface* surf = part->FindSurface(sz);
if (surf == nullptr) throw XMLReader::InvalidValue(tag);
surfPair->m_secondary = surf->Name();
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioMeshSection4::ParseDiscreteSetSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
FEBModel::DiscreteSet* dset = new FEBModel::DiscreteSet;
dset->SetName(szname);
part->AddDiscreteSet(dset);
int n[2];
++tag;
do
{
if (tag == "delem")
{
tag.value(n, 2);
dset->AddElement(n[0], n[1]);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioMaterialSection.cpp | .cpp | 5,832 | 192 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioMaterialSection.h"
#include "FECore/FEModel.h"
#include "FECore/FEMaterial.h"
#include <FECore/log.h>
#include <sstream>
//-----------------------------------------------------------------------------
//! This function creates a material by checking the type attribute against
//! registered materials. Also, if the tag defines attributes (other than
//! type and name), the material is offered a chance to process the attributes.
FEMaterial* FEBioMaterialSection::CreateMaterial(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// get the material type
const char* sztype = tag.AttributeValue("type", true);
// in some case, a type is not defined (e.g. for solutes)
// in that case, we use the tag name as the type
if (sztype == 0) sztype = tag.Name();
// create a new material of this type
FEMaterial* pmat = GetBuilder()->CreateMaterial(sztype);
if (pmat == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
return pmat;
}
//-----------------------------------------------------------------------------
//! Parse the Materials section.
void FEBioMaterialSection::Parse(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// Make sure no materials are defined
if (fem.Materials() != 0) throw FEBioImport::DuplicateMaterialSection();
// reset material counter
m_nmat = 0;
++tag;
do
{
if (tag == "material")
{
// check that the ID attribute is defined and that it
// equals the number of materials + 1.
int nid = -1;
tag.AttributeValue("id", nid);
int nmat = fem.Materials();
if (nid != nmat+1) throw XMLReader::InvalidAttributeValue(tag, "id");
// make sure that the name is unique
std::string name;
const char* szname = tag.AttributeValue("name", true);
if (szname == nullptr)
{
stringstream ss;
ss << "Material" << nid;
name = ss.str();
feLogWarningEx((&fem), "Material %d has no name.\nIt was given the name %s.", nid, name.c_str());
}
else name = szname;
FEMaterial* mat = fem.FindMaterial(name);
if (mat)
{
throw XMLReader::InvalidAttributeValue(tag, "name");
}
// create a material from this tag
FEMaterial* pmat = CreateMaterial(tag); assert(pmat);
pmat->SetName(name);
// set the material's ID
++m_nmat;
pmat->SetID(m_nmat);
// parse the material parameters
ReadParameterList(tag, pmat);
// add the material
GetBuilder()->AddMaterial(pmat);
}
else throw XMLReader::InvalidTag(tag);
// read next tag
++tag;
}
while (!tag.isend());
}
//===============================================================================
//-----------------------------------------------------------------------------
//! This function creates a material by checking the type attribute against
//! registered materials. Also, if the tag defines attributes (other than
//! type and name), the material is offered a chance to process the attributes.
FEMaterial* FEBioMaterialSection3::CreateMaterial(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// get the material type
const char* sztype = tag.AttributeValue("type", true);
// in some case, a type is not defined (e.g. for solutes)
// in that case, we use the tag name as the type
if (sztype == 0) sztype = tag.Name();
// create a new material of this type
FEMaterial* pmat = GetBuilder()->CreateMaterial(sztype);
if (pmat == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
return pmat;
}
//-----------------------------------------------------------------------------
//! Parse the Materials section.
void FEBioMaterialSection3::Parse(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
++tag;
do
{
if (tag == "material")
{
// check that the ID attribute is defined and that it
// equals the number of materials + 1.
int nid = -1;
tag.AttributeValue("id", nid);
int nmat = fem.Materials();
if (nid != nmat + 1) throw XMLReader::InvalidAttributeValue(tag, "id");
// make sure that the name is unique
const char* szname = tag.AttributeValue("name");
FEMaterial* mat = fem.FindMaterial(szname);
if (mat)
{
throw XMLReader::InvalidAttributeValue(tag, "name");
}
// create a material from this tag
FEMaterial* pmat = CreateMaterial(tag); assert(pmat);
pmat->SetName(szname);
// add the material
fem.AddMaterial(pmat);
// set the material's ID
pmat->SetID(nid);
// parse the material parameters
ReadParameterList(tag, pmat);
}
else throw XMLReader::InvalidTag(tag);
// read next tag
++tag;
} while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioLoadsSection3.cpp | .cpp | 7,025 | 219 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioLoadsSection.h"
#include <FECore/FEBodyLoad.h>
#include <FECore/FEModel.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FENodalLoad.h>
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEEdgeLoad.h>
#include <FECore/FEEdge.h>
//-----------------------------------------------------------------------------
void FEBioLoadsSection3::Parse(XMLTag& tag)
{
// make sure this tag has children
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "nodal_load" ) ParseNodalLoad (tag);
else if (tag == "surface_load") ParseSurfaceLoad(tag);
else if (tag == "edge_load" ) ParseEdgeLoad (tag);
else if (tag == "body_load" ) ParseBodyLoad (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection3::ParseBodyLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
const char* sztype = tag.AttributeValue("type");
FEBodyLoad* pbl = fecore_new<FEBodyLoad>(sztype, &fem);
if (pbl == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// see if a name was defined
const char* szname = tag.AttributeValue("name", true);
if (szname) pbl->SetName(szname);
// see if a specific domain was referenced
const char* szpart = tag.AttributeValue("elem_set", true);
if (szpart)
{
FEMesh& mesh = fem.GetMesh();
FEElementSet* elset = mesh.FindElementSet(szpart);
if (elset == 0) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szpart);
pbl->SetDomainList(elset);
}
ReadParameterList(tag, pbl);
GetBuilder()->AddModelLoad(pbl);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection3::ParseNodalLoad(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the type
const char* sztype = tag.AttributeValue("type");
// create nodal load
FENodalLoad* pfc = fecore_new<FENodalLoad>(sztype, GetFEModel());
if (pfc == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type");
// read (optional) name attribute
const char* szname = tag.AttributeValue("name", true);
if (szname) pfc->SetName(szname);
// get the node set
const char* szset = tag.AttributeValue("node_set");
FENodeSet* nodeSet = GetBuilder()->FindNodeSet(szset);
if (nodeSet == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
// assign the node set
pfc->SetNodeSet(nodeSet);
// add it to the model
GetBuilder()->AddNodalLoad(pfc);
// read parameters
ReadParameterList(tag, pfc);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection3::ParseSurfaceLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create surface load
string typeString = tag.AttributeValue("type");
FESurfaceLoad* psl = fecore_new<FESurfaceLoad>(typeString.c_str(), &fem);
if (psl == 0) throw XMLReader::InvalidTag(tag);
// read (optional) name attribute
const char* szname = tag.AttributeValue("name", true);
if (szname) psl->SetName(szname);
// read required surface attribute
const char* surfaceName = tag.AttributeValue("surface");
FEFacetSet* pface = mesh.FindFacetSet(surfaceName);
if (pface == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", surfaceName);
// create a surface from this facet set
FESurface* psurf = fecore_alloc(FESurface, &fem);
GetBuilder()->BuildSurface(*psurf, *pface);
// assign it
mesh.AddSurface(psurf);
psl->SetSurface(psurf);
// add it to the model
GetBuilder()->AddSurfaceLoad(psl);
// read the parameters
if (!tag.isleaf())
{
++tag;
do
{
if (ReadParameter(tag, psl) == false)
{
// some special handling for fluidnormalvelocity
if ((tag == "value") && (strcmp(typeString.c_str(), "fluid normal velocity") == 0))
{
// The value parameter no longer exists, but for backward compatibility
// we map it to the "velocity" parameter.
// get the surface data attribute
const char* szsurfdata = tag.AttributeValue("surface_data");
// find the surface map
FEDataMap* surfMap = mesh.FindDataMap(szsurfdata);
if (surfMap == nullptr) throw XMLReader::InvalidAttributeValue(tag, "surface_data");
// get the velocity parameter
FEParam* p = psl->GetParameter("velocity");
FEParamDouble& v = p->value<FEParamDouble>();
// we'll map the velocity value to the map's scale factor
double s = 1.0;
if (v.isConst()) s = v.constValue(); else throw XMLReader::InvalidTag(tag);
// create map and assign
FEMappedValue* map = new FEMappedValue(&fem);
map->setDataMap(surfMap);
map->setScaleFactor(s);
v.setValuator(map);
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
}
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection3::ParseEdgeLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create edge load
const char* sztype = tag.AttributeValue("type");
FEEdgeLoad* pel = fecore_new<FEEdgeLoad>(sztype, &fem);
if (pel == 0) throw XMLReader::InvalidTag(tag);
// create a new edge
FEEdge* pedge = new FEEdge(&fem);
mesh.AddEdge(pedge);
pel->SetEdge(pedge);
// get the segment set
const char* szedge = tag.AttributeValue("edge");
FESegmentSet* pset = mesh.FindSegmentSet(szedge);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "edge", szedge);
if (GetBuilder()->BuildEdge(*pedge, *pset) == false) throw XMLReader::InvalidTag(tag);
// add edge load to model
GetBuilder()->AddEdgeLoad(pel);
// read the parameters
ReadParameterList(tag, pel);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioImport.cpp | .cpp | 22,822 | 676 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioImport.h"
#include "FEBioIncludeSection.h"
#include "FEBioModuleSection.h"
#include "FEBioControlSection.h"
#include "FEBioControlSection3.h"
#include "FEBioControlSection4.h"
#include "FEBioGlobalsSection.h"
#include "FEBioMaterialSection.h"
#include "FEBioGeometrySection.h"
#include "FEBioBoundarySection.h"
#include "FEBioBoundarySection3.h"
#include "FEBioLoadsSection.h"
#include "FEBioContactSection.h"
#include "FEBioConstraintsSection.h"
#include "FEBioInitialSection.h"
#include "FEBioInitialSection3.h"
#include "FEBioLoadDataSection.h"
#include "FEBioOutputSection.h"
#include "FEBioStepSection.h"
#include "FEBioStepSection4.h"
#include "FEBioDiscreteSection.h"
#include "FEBioMeshDataSection.h"
#include "FEBioCodeSection.h"
#include "FEBioRigidSection.h"
#include "FEBioRigidSection4.h"
#include "FEBioMeshAdaptorSection.h"
#include "FEBioMeshSection.h"
#include "FEBioMeshSection4.h"
#include "FEBioMeshDomainsSection4.h"
#include "FEBioStepSection3.h"
#include "FECore/FEModel.h"
#include "FECore/FECoreKernel.h"
#include <string.h>
#include "xmltool.h"
FEBioFileSection::FEBioFileSection(FEBioImport* feb) : FEFileSection(feb) {}
FEBioImport* FEBioFileSection::GetFEBioImport() { return static_cast<FEBioImport*>(GetFileReader()); }
//-----------------------------------------------------------------------------
FEBioImport::InvalidVersion::InvalidVersion()
{
SetErrorString("Invalid version");
}
//-----------------------------------------------------------------------------
FEBioImport::InvalidMaterial::InvalidMaterial(int nel)
{
SetErrorString("Element %d has an invalid material type", nel);
}
//-----------------------------------------------------------------------------
FEBioImport::InvalidDomainType::InvalidDomainType()
{
SetErrorString("Invalid domain type");
}
//-----------------------------------------------------------------------------
FEBioImport::InvalidDomainMaterial::InvalidDomainMaterial()
{
SetErrorString("Invalid domain material");
}
//-----------------------------------------------------------------------------
FEBioImport::FailedCreatingDomain::FailedCreatingDomain()
{
SetErrorString("Failed creating domain");
}
//-----------------------------------------------------------------------------
FEBioImport::InvalidElementType::InvalidElementType()
{
SetErrorString("Invalid element type\n");
}
//-----------------------------------------------------------------------------
FEBioImport::FailedLoadingPlugin::FailedLoadingPlugin(const char* szfile)
{
SetErrorString("failed loading plugin %s\n", szfile);
}
//-----------------------------------------------------------------------------
FEBioImport::DuplicateMaterialSection::DuplicateMaterialSection()
{
SetErrorString("Material section has already been defined");
}
//-----------------------------------------------------------------------------
FEBioImport::MissingProperty::MissingProperty(const std::string& matName, const char* szprop)
{
SetErrorString("Component \"%s\" needs to have property \"%s\" defined", matName.c_str(), szprop);
}
//-----------------------------------------------------------------------------
FEBioImport::FailedAllocatingSolver::FailedAllocatingSolver(const char* sztype)
{
SetErrorString("Failed allocating solver \"%s\"", sztype);
}
//-----------------------------------------------------------------------------
FEBioImport::DataGeneratorError::DataGeneratorError()
{
SetErrorString("Error in data generation");
}
//-----------------------------------------------------------------------------
FEBioImport::FailedBuildingPart::FailedBuildingPart(const std::string& partName)
{
SetErrorString("Failed building part %s", partName.c_str());
}
//-----------------------------------------------------------------------------
FEBioImport::MeshDataError::MeshDataError()
{
SetErrorString("An error occurred processing mesh_data section.");
}
FEBioImport::RepeatedNodeSet::RepeatedNodeSet(const std::string& name)
{
SetErrorString("A nodeset with name \"%s\" was already defined.", name.c_str());
}
FEBioImport::RepeatedSurface::RepeatedSurface(const std::string& name)
{
SetErrorString("A surface with name \"%s\" was already defined.", name.c_str());
}
FEBioImport::RepeatedEdgeSet::RepeatedEdgeSet(const std::string& name)
{
SetErrorString("An edge with name \"%s\" was already defined.", name.c_str());
}
FEBioImport::RepeatedElementSet::RepeatedElementSet(const std::string& name)
{
SetErrorString("An element set with name \"%s\" was already defined.", name.c_str());
}
FEBioImport::RepeatedPartList::RepeatedPartList(const std::string& name)
{
SetErrorString("An part list with name \"%s\" was already defined.", name.c_str());
}
//-----------------------------------------------------------------------------
FEBioImport::FEBioImport()
{
}
//-----------------------------------------------------------------------------
FEBioImport::~FEBioImport()
{
}
//-----------------------------------------------------------------------------
// Build the file section map based on the version number
void FEBioImport::BuildFileSectionMap(int nversion)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
if (nversion < 0x0400) fecore.ShowDeprecationWarnings(false);
// define the file structure
m_map["Module" ] = new FEBioModuleSection (this);
m_map["Globals" ] = new FEBioGlobalsSection (this);
m_map["Output" ] = new FEBioOutputSection (this);
// older formats
if (nversion < 0x0200)
{
m_map["Control" ] = new FEBioControlSection (this);
m_map["Material" ] = new FEBioMaterialSection (this);
m_map["Geometry" ] = new FEBioGeometrySection1x (this);
m_map["Boundary" ] = new FEBioBoundarySection1x (this);
m_map["Loads" ] = new FEBioLoadsSection1x (this);
m_map["Constraints"] = new FEBioConstraintsSection1x(this);
m_map["Step" ] = new FEBioStepSection (this);
m_map["Initial" ] = new FEBioInitialSection (this);
m_map["LoadData" ] = new FEBioLoadDataSection (this);
}
// version 2.0
if (nversion == 0x0200)
{
m_map["Control" ] = new FEBioControlSection (this);
m_map["Material" ] = new FEBioMaterialSection (this);
m_map["Geometry" ] = new FEBioGeometrySection2 (this);
m_map["Initial" ] = new FEBioInitialSection (this);
m_map["Boundary" ] = new FEBioBoundarySection2 (this);
m_map["Loads" ] = new FEBioLoadsSection2 (this);
m_map["Include" ] = new FEBioIncludeSection (this);
m_map["Contact" ] = new FEBioContactSection2 (this);
m_map["Discrete" ] = new FEBioDiscreteSection (this);
m_map["Code" ] = new FEBioCodeSection (this); // added in FEBio 2.4 (experimental feature!)
m_map["Constraints"] = new FEBioConstraintsSection2(this);
m_map["Step" ] = new FEBioStepSection2 (this);
m_map["LoadData" ] = new FEBioLoadDataSection (this);
}
// version 2.5
if (nversion == 0x0205)
{
m_map["Control" ] = new FEBioControlSection (this);
m_map["Material" ] = new FEBioMaterialSection (this);
m_map["Geometry" ] = new FEBioGeometrySection25 (this);
m_map["Include" ] = new FEBioIncludeSection (this);
m_map["Initial" ] = new FEBioInitialSection25 (this);
m_map["Boundary" ] = new FEBioBoundarySection25 (this);
m_map["Loads" ] = new FEBioLoadsSection25 (this);
m_map["Contact" ] = new FEBioContactSection25 (this);
m_map["Discrete" ] = new FEBioDiscreteSection25 (this);
m_map["Constraints"] = new FEBioConstraintsSection25(this);
m_map["Code" ] = new FEBioCodeSection (this); // added in FEBio 2.4 (experimental feature!)
m_map["LoadData" ] = new FEBioLoadDataSection (this);
m_map["MeshData" ] = new FEBioMeshDataSection (this);
m_map["Step" ] = new FEBioStepSection25 (this);
m_map["MeshAdaptor"] = new FEBioMeshAdaptorSection (this); // added in FEBio 3.0
}
// version 3.0
if (nversion == 0x0300)
{
// we no longer allow unknown attributes
SetStopOnUnknownAttribute(true);
m_map["Control" ] = new FEBioControlSection3 (this);
m_map["Material" ] = new FEBioMaterialSection3 (this);
m_map["Geometry" ] = new FEBioGeometrySection3 (this);
m_map["Mesh" ] = new FEBioMeshSection (this);
m_map["MeshDomains"] = new FEBioMeshDomainsSection (this);
m_map["Include" ] = new FEBioIncludeSection (this);
m_map["Initial" ] = new FEBioInitialSection3 (this);
m_map["Boundary" ] = new FEBioBoundarySection3 (this);
m_map["Loads" ] = new FEBioLoadsSection3 (this);
m_map["Contact" ] = new FEBioContactSection25 (this);
m_map["Discrete" ] = new FEBioDiscreteSection25 (this);
m_map["Constraints"] = new FEBioConstraintsSection25(this);
m_map["Code" ] = new FEBioCodeSection (this); // added in FEBio 2.4 (experimental feature!)
m_map["MeshData" ] = new FEBioMeshDataSection3 (this);
m_map["LoadData" ] = new FEBioLoadDataSection3 (this);
m_map["Rigid" ] = new FEBioRigidSection (this); // added in FEBio 3.0
m_map["Step" ] = new FEBioStepSection3 (this);
m_map["MeshAdaptor"] = new FEBioMeshAdaptorSection (this); // added in FEBio 3.0
}
// version 4.0
if (nversion == 0x0400)
{
// we no longer allow unknown attributes
SetStopOnUnknownAttribute(true);
m_map["Control" ] = new FEBioControlSection4 (this);
m_map["Material" ] = new FEBioMaterialSection3 (this);
m_map["Mesh" ] = new FEBioMeshSection4 (this);
m_map["MeshDomains"] = new FEBioMeshDomainsSection4 (this);
m_map["Include" ] = new FEBioIncludeSection (this);
m_map["Initial" ] = new FEBioInitialSection3 (this);
m_map["Boundary" ] = new FEBioBoundarySection3 (this);
m_map["Loads" ] = new FEBioLoadsSection3 (this);
m_map["Contact" ] = new FEBioContactSection4 (this);
m_map["Discrete" ] = new FEBioDiscreteSection25 (this);
m_map["Constraints"] = new FEBioConstraintsSection25(this);
m_map["Code" ] = new FEBioCodeSection (this); // added in FEBio 2.4 (experimental feature!)
m_map["MeshData" ] = new FEBioMeshDataSection4 (this); // added in febio4
m_map["LoadData" ] = new FEBioLoadDataSection3 (this);
m_map["Rigid" ] = new FEBioRigidSection4 (this); // added in FEBio 4.0
m_map["Step" ] = new FEBioStepSection4 (this);
m_map["MeshAdaptor"] = new FEBioMeshAdaptorSection (this); // added in FEBio 3.0
}
}
//-----------------------------------------------------------------------------
bool FEBioImport::Load(FEModel& fem, const char* szfile)
{
if (m_builder == nullptr)
{
m_builder = new FEModelBuilder(fem);
}
// intialize some variables
m_szdmp[0] = 0;
m_szlog[0] = 0;
m_szplt[0] = 0;
m_data.clear();
// extract the path
strcpy(m_szpath, szfile);
char* ch = strrchr(m_szpath, '\\');
if (ch==0) ch = strrchr(m_szpath, '/');
if (ch==0) m_szpath[0] = 0; else *(ch+1)=0;
// clean up
fem.GetMesh().ClearDataMaps();
// read the file
if (ReadFile(szfile) == false) return false;
// finish building
try {
bool b = m_builder->Finish();
if (b == false) return errf("FAILED building FEBio model.");
}
catch (std::exception e)
{
const char* szerr = e.what();
if (szerr == nullptr) szerr = "(unknown exception)";
return errf("%s", e.what());
}
catch (...)
{
return errf("unknown exception.");
}
return true;
}
//-----------------------------------------------------------------------------
// This function parses the XML input file. The broot parameter is used to indicate
// if this is the main control file or an included file.
bool FEBioImport::ReadFile(const char* szfile, bool broot)
{
// Open the XML file
XMLReader xml;
if (xml.Open(szfile) == false) return errf("FATAL ERROR: Failed opening input file %s\n\n", szfile);
// Find the root element
XMLTag tag;
try
{
if (xml.FindTag("febio_spec", tag) == false) return errf("FATAL ERROR: febio_spec tag was not found. This is not a valid input file.\n\n");
}
catch (...)
{
return errf("An error occured while finding the febio_spec tag.\nIs this a valid FEBio input file?\n\n");
}
// parse the file
try
{
// get the version number
ParseVersion(tag);
// FEBio4 only supports file version 1.2, 2.0, 2.5, 3.0, and 4.0
int nversion = GetFileVersion();
if ((nversion != 0x0102) &&
(nversion != 0x0200) &&
(nversion != 0x0205) &&
(nversion != 0x0300) &&
(nversion != 0x0400)) throw InvalidVersion();
// build the file section map based on the version number
BuildFileSectionMap(nversion);
// For versions before 2.5 we need to allocate all the degrees of freedom beforehand.
// This is necessary because the Module section doesn't have to defined until a Control section appears.
// That means that model components that depend on DOFs can be defined before the Module tag (e.g. in multi-step analyses) and this leads to problems.
// In 2.5 this is solved by requiring that the Module tag is defined at the top of the file.
if (broot && (nversion < 0x0205))
{
// We need to define a default Module type since before 2.5 this tag is optional for structural mechanics model definitions.
GetBuilder()->SetActiveModule("solid");
// set default variables for older files.
GetBuilder()->SetDefaultVariables();
}
// parse the file
++tag;
// From version 2.5 and up the first tag of the (main control) file has to be the Module tag.
if (broot && (nversion >= 0x0205))
{
if (tag != "Module")
{
return errf("First tag must be the Module section.\n\n");
}
// try to find a section parser
FEFileSectionMap::iterator is = m_map.find(tag.Name());
// make sure we found a section reader
if (is == m_map.end()) throw XMLReader::InvalidTag(tag);
// parse the module tag
is->second->Parse(tag);
// Now that the Module tag is read in, we'll want to create an analysis step.
// Creating an analysis step will allocate a solver class (based on the module)
// and this in turn will allocate the degrees of freedom.
// TODO: This is kind of a round-about way and I really want to find a better solution.
// NOTE: For version 4.0 we do not allocate the solver by default
GetBuilder()->GetStep(nversion >= 0x0400 ? false : true);
// let's get the next tag
++tag;
}
do
{
// try to find a section parser
FEFileSectionMap::iterator is = m_map.find(tag.Name());
// make sure we found a section reader
if (is == m_map.end()) throw XMLReader::InvalidTag(tag);
// see if the file has the "from" attribute (for version 2.0 and up)
if (nversion >= 0x0200)
{
const char* szinc = tag.AttributeValue("from", true);
if (szinc)
{
// make sure this is a leaf
if (tag.isleaf() == false) return errf("FATAL ERROR: included sections may not have child sections.\n\n");
// read this section from an included file.
XMLReader xml2;
if (xml2.Open(szinc) == false) return errf("FATAL ERROR: failed opening input file %s\n\n", szinc);
// find the febio_spec tag
XMLTag tag2;
if (xml2.FindTag("febio_spec", tag2) == false) return errf("FATAL ERROR: febio_spec tag was not found. This is not a valid input file.\n\n");
// find the section we are looking for
char sz[512] = {0};
snprintf(sz, sizeof(sz), "febio_spec/%s", tag.Name());
if (xml2.FindTag(sz, tag2) == false) return errf("FATAL ERROR: Couldn't find %s section in file %s.\n\n", tag.Name(), szinc);
// parse the section
is->second->Parse(tag2);
}
else is->second->Parse(tag);
}
else
{
// parse the section
is->second->Parse(tag);
}
// go to the next tag
++tag;
}
while (!tag.isend());
}
// --- XML Reader Exceptions ---
catch (XMLReader::Error& e)
{
return errf("%s", e.what());
}
// --- FEBioImport Exceptions ---
catch (FEFileException& e)
{
return errf("%s (line %d)\n", e.GetErrorString(), xml.GetCurrentLine());
}
// --- Exception from DataStore ---
catch (UnknownDataField& e)
{
return errf("\"%s\" is not a valid field variable name (line %d)\n", e.what(), xml.GetCurrentLine()-1);
}
// std::exception
catch (std::exception e)
{
const char* szerr = e.what();
if (szerr == nullptr) szerr = "(unknown exception)";
return errf("%s", szerr);
}
// --- Unknown exceptions ---
catch (...)
{
return errf("unrecoverable error (line %d)\n", xml.GetCurrentLine());
return false;
}
// close the XML file
xml.Close();
// we're done!
return true;
}
//-----------------------------------------------------------------------------
//! This function parses the febio_spec tag for the version number
void FEBioImport::ParseVersion(XMLTag &tag)
{
const char* szv = tag.AttributeValue("version");
assert(szv);
int n1, n2;
int nr = sscanf(szv, "%d.%d", &n1, &n2);
if (nr != 2) throw InvalidVersion();
if ((n1 < 1) || (n1 > 0xFF)) throw InvalidVersion();
if ((n2 < 0) || (n2 > 0xFF)) throw InvalidVersion();
int nversion = (n1 << 8) + n2;
SetFileVerion(nversion);
}
//-----------------------------------------------------------------------------
void FEBioImport::SetDumpfileName(const char* sz) { snprintf(m_szdmp, sizeof(m_szdmp), "%s", sz); }
void FEBioImport::SetLogfileName (const char* sz) { snprintf(m_szlog, sizeof(m_szlog), "%s", sz); }
void FEBioImport::SetPlotfileName(const char* sz) { snprintf(m_szplt, sizeof(m_szplt), "%s", sz); }
//-----------------------------------------------------------------------------
void FEBioImport::AddDataRecord(DataRecord* pd)
{
m_data.push_back(pd);
}
//-----------------------------------------------------------------------------
// This tag parses a node set.
FENodeSet* FEBioImport::ParseNodeSet(XMLTag& tag, const char* szatt)
{
FEMesh& mesh = GetFEModel()->GetMesh();
FENodeSet* pns = 0;
// see if the set attribute is defined
const char* szset = tag.AttributeValue(szatt, true);
if (szset)
{
// Make sure this is an empty tag
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// find the node set
pns = mesh.FindNodeSet(szset);
if (pns == 0) throw XMLReader::InvalidAttributeValue(tag, szatt, szset);
}
else
{
// This defines a node set, so we need a name tag
// (For now this name is optional)
const char* szname = tag.AttributeValue("name", true);
if (szname == 0) szname = "_unnamed";
// create a new node set
pns = new FENodeSet(GetFEModel());
pns->SetName(szname);
// add the nodeset to the mesh
mesh.AddNodeSet(pns);
// read the nodes
if (tag.isleaf())
{
// This format is deprecated
vector<int> l;
fexml::readList(tag, l);
for (int i=0; i<l.size(); ++i) pns->Add(GetBuilder()->FindNodeFromID(l[i]));
}
else
{
// read the nodes
++tag;
do
{
if ((tag == "n") || (tag == "node"))
{
int nid = -1;
tag.AttributeValue("id", nid);
nid = GetBuilder()->FindNodeFromID(nid);
pns->Add(nid);
}
else if (tag == "NodeSet")
{
const char* szset = tag.AttributeValue(szatt);
// Make sure this is an empty tag
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// find the node set
FENodeSet* ps = mesh.FindNodeSet(szset);
if (ps == 0) throw XMLReader::InvalidAttributeValue(tag, szatt, szset);
// add the node set
pns->Add(ps->GetNodeList());
}
else if (tag == "node_list")
{
vector<int> nl;
fexml::readList(tag, nl);
for (int i = 0; i<nl.size(); ++i) pns->Add(GetBuilder()->FindNodeFromID(nl[i]));
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
}
return pns;
}
//-----------------------------------------------------------------------------
FESurface* FEBioImport::ParseSurface(XMLTag& tag, const char* szatt)
{
FEMesh& m = GetFEModel()->GetMesh();
// create new surface
FESurface* psurf = fecore_alloc(FESurface, GetFEModel());
// see if the surface is referenced by a set of defined explicitly
const char* szset = tag.AttributeValue(szatt, true);
if (szset)
{
// make sure this tag does not have any children
if (!tag.isleaf()) throw XMLReader::InvalidTag(tag);
// see if we can find the facet set
FEMesh& m = GetFEModel()->GetMesh();
FEFacetSet* ps = m.FindFacetSet(szset);
// create a surface from the facet set
if (ps)
{
if (GetBuilder()->BuildSurface(*psurf, *ps) == false) throw XMLReader::InvalidTag(tag);
}
else throw XMLReader::InvalidAttributeValue(tag, "set", szset);
}
else
{
// count how many pressure cards there are
int npr = tag.children();
psurf->Create(npr);
FEModelBuilder* feb = GetBuilder();
++tag;
int nf[FEElement::MAX_NODES ], N;
for (int i=0; i<npr; ++i)
{
FESurfaceElement& el = psurf->Element(i);
if (tag == "quad4") el.SetType(FE_QUAD4G4);
else if (tag == "tri3" ) el.SetType(feb->m_ntri3);
else if (tag == "tri6" ) el.SetType(feb->m_ntri6);
else if (tag == "tri7" ) el.SetType(feb->m_ntri7);
else if (tag == "tri10") el.SetType(feb->m_ntri10);
else if (tag == "quad8") el.SetType(FE_QUAD8G9);
else if (tag == "quad9") el.SetType(FE_QUAD9G9);
else throw XMLReader::InvalidTag(tag);
N = el.Nodes();
tag.value(nf, N);
for (int j=0; j<N; ++j) el.m_node[j] = nf[j]-1;
++tag;
}
}
return psurf;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioControlSection3.h | .h | 1,545 | 39 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// Control Section
class FEBioControlSection3 : public FEFileSection
{
public:
FEBioControlSection3(FEFileImport* pim);
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBModel.cpp | .cpp | 19,846 | 722 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBModel.h"
#include <FECore/FEModel.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FEMaterial.h>
#include <FECore/FEDomain.h>
#include <FECore/FEShellDomain.h>
#include <FECore/log.h>
using namespace std;
//=============================================================================
FEBModel::NodeSet::NodeSet() {}
FEBModel::NodeSet::NodeSet(const FEBModel::NodeSet& set)
{
m_name = set.m_name;
m_node = set.m_node;
}
FEBModel::NodeSet::NodeSet(const string& name) : m_name(name) {}
void FEBModel::NodeSet::SetName(const string& name) { m_name = name; }
const string& FEBModel::NodeSet::Name() const { return m_name; }
void FEBModel::NodeSet::SetNodeList(const vector<int>& node) { m_node = node; }
const vector<int>& FEBModel::NodeSet::NodeList() const { return m_node; }
//=============================================================================
FEBModel::EdgeSet::EdgeSet() {}
FEBModel::EdgeSet::EdgeSet(const FEBModel::EdgeSet& set)
{
m_name = set.m_name;
m_edge = set.m_edge;
}
FEBModel::EdgeSet::EdgeSet(const string& name) : m_name(name) {}
void FEBModel::EdgeSet::SetName(const string& name) { m_name = name; }
const string& FEBModel::EdgeSet::Name() const { return m_name; }
void FEBModel::EdgeSet::SetEdgeList(const vector<EDGE>& edge) { m_edge = edge; }
const vector<FEBModel::EDGE>& FEBModel::EdgeSet::EdgeList() const { return m_edge; }
//=============================================================================
FEBModel::ElementSet::ElementSet() {}
FEBModel::ElementSet::ElementSet(const FEBModel::ElementSet& set)
{
m_name = set.m_name;
m_elem = set.m_elem;
}
FEBModel::ElementSet::ElementSet(const string& name) : m_name(name) {}
void FEBModel::ElementSet::SetName(const string& name) { m_name = name; }
const string& FEBModel::ElementSet::Name() const { return m_name; }
void FEBModel::ElementSet::SetElementList(const vector<int>& elem) { m_elem = elem; }
const vector<int>& FEBModel::ElementSet::ElementList() const { return m_elem; }
//=============================================================================
FEBModel::PartList::PartList() {}
FEBModel::PartList::PartList(const std::string& name) : m_name(name) {}
void FEBModel::PartList::SetName(const std::string& name) { m_name = name; }
const std::string& FEBModel::PartList::Name() const { return m_name; }
void FEBModel::PartList::SetPartList(const std::vector<std::string>& parts) { m_parts = parts; }
const std::vector<std::string>& FEBModel::PartList::GetPartList() const { return m_parts; }
FEBModel::PartList* FEBModel::Part::FindPartList(const string& name)
{
for (PartList* ps : m_PList) {
if (ps->Name() == name) return ps;
}
return nullptr;
}
//=============================================================================
FEBModel::SurfacePair::SurfacePair() {}
FEBModel::SurfacePair::SurfacePair(const SurfacePair& surfPair)
{
m_name = surfPair.m_name;
m_primary = surfPair.m_primary;
m_secondary = surfPair.m_secondary;
}
const string& FEBModel::SurfacePair::Name() const { return m_name; }
//=============================================================================
FEBModel::Domain::Domain()
{
m_defaultShellThickness = 0.0;
}
FEBModel::Domain::Domain(const FEBModel::Domain& dom)
{
m_spec = dom.m_spec;
m_name = dom.m_name;
m_matName = dom.m_matName;
m_Elem = dom.m_Elem;
m_defaultShellThickness = dom.m_defaultShellThickness;
}
FEBModel::Domain::Domain(const FE_Element_Spec& spec) : m_spec(spec)
{
m_defaultShellThickness = 0.0;
}
const string& FEBModel::Domain::Name() const { return m_name; }
void FEBModel::Domain::SetName(const string& name) { m_name = name; }
void FEBModel::Domain::SetMaterialName(const string& name) { m_matName = name; }
const string& FEBModel::Domain::MaterialName() const { return m_matName; }
void FEBModel::Domain::SetElementList(const vector<ELEMENT>& el) { m_Elem = el; }
const vector<FEBModel::ELEMENT>& FEBModel::Domain::ElementList() const { return m_Elem; }
//=============================================================================
FEBModel::Surface::Surface() { m_partList = nullptr; }
FEBModel::Surface::Surface(const FEBModel::Surface& surf)
{
m_name = surf.m_name;
m_Face = surf.m_Face;
m_partList = surf.m_partList;
}
FEBModel::Surface::Surface(const string& name) : m_name(name), m_partList(nullptr) {}
FEBModel::Surface::Surface(const string& name, PartList* partList) : m_name(name), m_partList(partList) {}
const string& FEBModel::Surface::Name() const { return m_name; }
void FEBModel::Surface::SetName(const string& name) { m_name = name; }
void FEBModel::Surface::SetFacetList(const vector<FEBModel::FACET>& face) { m_Face = face; }
const vector<FEBModel::FACET>& FEBModel::Surface::FacetList() const { return m_Face; }
//=============================================================================
FEBModel::DiscreteSet::DiscreteSet() {}
FEBModel::DiscreteSet::DiscreteSet(const FEBModel::DiscreteSet& set)
{
m_name = set.m_name;
m_elem = set.m_elem;
}
void FEBModel::DiscreteSet::SetName(const string& name) { m_name = name; }
const string& FEBModel::DiscreteSet::Name() const { return m_name; }
void FEBModel::DiscreteSet::AddElement(int n0, int n1) { m_elem.push_back(ELEM{ n0, n1 } ); }
const vector<FEBModel::DiscreteSet::ELEM>& FEBModel::DiscreteSet::ElementList() const { return m_elem; }
//=============================================================================
FEBModel::Part::Part() {}
FEBModel::Part::Part(const std::string& name) : m_name(name) {}
FEBModel::Part::Part(const FEBModel::Part& part)
{
m_name = part.m_name;
m_Node = part.m_Node;
for (size_t i=0; i<part.m_Dom.size() ; ++i) AddDomain (new Domain (*part.m_Dom[i]));
for (size_t i=0; i<part.m_Surf.size(); ++i) AddSurface(new Surface(*part.m_Surf[i]));
for (size_t i=0; i<part.m_NSet.size(); ++i) AddNodeSet(new NodeSet(*part.m_NSet[i]));
for (size_t i=0; i<part.m_ESet.size(); ++i) AddElementSet(new ElementSet(*part.m_ESet[i]));
for (size_t i = 0; i < part.m_SurfPair.size(); ++i) AddSurfacePair(new SurfacePair(*part.m_SurfPair[i]));
for (size_t i = 0; i < part.m_DiscSet.size(); ++i) AddDiscreteSet(new DiscreteSet(*part.m_DiscSet[i]));
}
FEBModel::Part::~Part()
{
for (size_t i=0; i<m_NSet.size(); ++i) delete m_NSet[i];
for (size_t i=0; i<m_Dom.size(); ++i) delete m_Dom[i];
for (size_t i = 0; i<m_Surf.size(); ++i) delete m_Surf[i];
for (size_t i = 0; i < m_SurfPair.size(); ++i) delete m_SurfPair[i];
for (size_t i = 0; i < m_DiscSet.size(); ++i) delete m_DiscSet[i];
}
void FEBModel::Part::SetName(const std::string& name) { m_name = name; }
const string& FEBModel::Part::Name() const { return m_name; }
void FEBModel::Part::AddNodes(const std::vector<NODE>& nodes)
{
size_t N0 = m_Node.size();
size_t N = nodes.size();
if (N > 0)
{
m_Node.resize(N0 + N);
for (int i=0; i<N; ++i)
{
m_Node[N0 + i] = nodes[i];
}
}
}
FEBModel::Domain* FEBModel::Part::FindDomain(const string& name)
{
for (size_t i = 0; i<m_Dom.size(); ++i)
{
Domain* dom = m_Dom[i];
if (dom->Name() == name) return dom;
}
return 0;
}
void FEBModel::Part::AddDomain(FEBModel::Domain* dom) { m_Dom.push_back(dom); }
void FEBModel::Part::AddSurface(FEBModel::Surface* surf) { m_Surf.push_back(surf); }
FEBModel::Surface* FEBModel::Part::FindSurface(const string& name)
{
if (name.compare(0, 11, "@part_list:") == 0)
{
// make sure this part list exists
string partListName = name.substr(11);
PartList* partList = FindPartList(partListName);
if (partList == nullptr) return nullptr;
// see if a surface already exists
Surface* surf = FindSurface(partListName);
if (surf) return surf;
// create the new surface
surf = new Surface(partListName, partList);
AddSurface(surf);
return surf;
}
else
{
for (size_t i = 0; i < m_Surf.size(); ++i)
{
Surface* surf = m_Surf[i];
if (surf->Name() == name) return surf;
}
}
return nullptr;
}
FEBModel::NodeSet* FEBModel::Part::FindNodeSet(const string& name)
{
for (size_t i = 0; i < m_NSet.size(); ++i)
{
NodeSet* nset = m_NSet[i];
if (nset->Name() == name) return nset;
}
return nullptr;
}
FEBModel::EdgeSet* FEBModel::Part::FindEdgeSet(const string& name)
{
for (size_t i = 0; i < m_LSet.size(); ++i)
{
EdgeSet* lset = m_LSet[i];
if (lset->Name() == name) return lset;
}
return nullptr;
}
FEBModel::ElementSet* FEBModel::Part::FindElementSet(const string& name)
{
for (size_t i = 0; i < m_ESet.size(); ++i)
{
ElementSet* eset = m_ESet[i];
if (eset->Name() == name) return eset;
}
return nullptr;
}
//=============================================================================
FEBModel::FEBModel()
{
}
FEBModel::~FEBModel()
{
for (size_t i=0; i<m_Part.size(); ++i) delete m_Part[i];
m_Part.clear();
}
size_t FEBModel::Parts() const
{
return m_Part.size();
}
FEBModel::Part* FEBModel::GetPart(int i)
{
return m_Part[i];
}
FEBModel::Part* FEBModel::AddPart(const std::string& name)
{
Part* part = new Part(name);
m_Part.push_back(part);
return part;
}
void FEBModel::AddPart(FEBModel::Part* part)
{
m_Part.push_back(part);
}
FEBModel::Part* FEBModel::FindPart(const string& name)
{
for (size_t i=0; i<m_Part.size(); ++i)
{
Part* p = m_Part[i];
if (p->Name() == name) return p;
}
return 0;
}
bool FEBModel::BuildPart(FEModel& fem, Part& part, bool buildDomains, const Transform& T)
{
// we'll need the kernel for creating domains
FECoreKernel& febio = FECoreKernel::GetInstance();
FEMesh& mesh = fem.GetMesh();
// build node-index lookup table
int noff = -1, maxID = 0;
int N0 = mesh.Nodes();
int NN = part.Nodes();
for (int i=0; i<NN; ++i)
{
int nid = part.GetNode(i).id;
if ((noff < 0) || (nid < noff)) noff = nid;
if (nid > maxID) maxID = nid;
}
vector<int> NLT(maxID - noff + 1, -1);
for (int i=0; i<NN; ++i)
{
int nid = part.GetNode(i).id - noff;
NLT[nid] = i + N0;
}
// build element-index lookup table
int eoff = -1; maxID = 0;
int E0 = mesh.Elements();
int NDOM = part.Domains();
for (int i=0; i<NDOM; ++i)
{
const Domain& dom = part.GetDomain(i);
int NE = dom.Elements();
for (int j=0; j<NE; ++j)
{
int eid = dom.GetElement(j).id;
if ((eoff < 0) || (eid < eoff)) eoff = eid;
if (eid > maxID) maxID = eid;
}
}
vector<int> ELT(maxID - eoff + 1, -1);
int ecount = E0;
for (int i = 0; i<NDOM; ++i)
{
const Domain& dom = part.GetDomain(i);
int NE = dom.Elements();
for (int j = 0; j<NE; ++j)
{
int eid = dom.GetElement(j).id - eoff;
ELT[eid] = ecount++;
}
}
// create the nodes
int nid = N0;
mesh.AddNodes(NN);
int n = 0;
for (int j = 0; j<NN; ++j)
{
NODE& partNode = part.GetNode(j);
FENode& meshNode = mesh.Node(N0 + n++);
// TODO: This is going to break multi-part models
meshNode.SetID(partNode.id);
meshNode.m_r0 = T.Apply(partNode.r);
meshNode.m_rt = meshNode.m_r0;
}
assert(n == NN);
// get the part name
string partName = part.Name();
if (partName.empty() == false) partName += ".";
// process domains
if (buildDomains)
{
int eid = E0;
for (int i = 0; i < NDOM; ++i)
{
const Domain& partDomain = part.GetDomain(i);
// element count
int elems = partDomain.Elements();
// get the element spect
FE_Element_Spec spec = partDomain.ElementSpec();
// get the material
string matName = partDomain.MaterialName();
FEMaterial* mat = fem.FindMaterial(matName.c_str());
if (mat == 0) return false;
// create the domain
FEDomain* dom = febio.CreateDomain(spec, &mesh, mat);
if (dom == 0) return false;
if (dom->Create(elems, spec) == false)
{
return false;
}
dom->SetMatID(mat->GetID() - 1);
string domName = partName + partDomain.Name();
dom->SetName(domName);
// process element data
for (int j = 0; j < elems; ++j)
{
const ELEMENT& domElement = partDomain.GetElement(j);
FEElement& el = dom->ElementRef(j);
// TODO: This is going to break multi-part models
el.SetID(domElement.id);
int ne = el.Nodes();
for (int n = 0; n < ne; ++n) el.m_node[n] = NLT[domElement.node[n] - noff];
}
if (partDomain.m_defaultShellThickness != 0.0)
{
double h0 = partDomain.m_defaultShellThickness;
FEShellDomain* shellDomain = dynamic_cast<FEShellDomain*>(dom);
if (shellDomain)
{
int ne = shellDomain->Elements();
for (int n = 0; n < ne; ++n)
{
FEShellElement& el = shellDomain->Element(n);
for (int k = 0; k < el.Nodes(); ++k) el.m_h0[k] = h0;
}
}
else
{
FEModel* pfem = &fem;
feLogWarningEx(pfem, "Shell thickness assigned on non-shell part %s", partDomain.Name().c_str());
}
}
// add the domain to the mesh
mesh.AddDomain(dom);
// initialize material point data
dom->CreateMaterialPointData();
}
}
// create node sets
int NSets = part.NodeSets();
for (int i = 0; i<NSets; ++i)
{
NodeSet* set = part.GetNodeSet(i);
// create a new node set
FENodeSet* feset = new FENodeSet(&fem);
// add the name
string name = partName + set->Name();
feset->SetName(name.c_str());
// copy indices
vector<int> nodeList = set->NodeList();
int nn = (int)nodeList.size();
for (int j=0; j<nn; ++j) nodeList[j] = NLT[nodeList[j] - noff];
feset->Add(nodeList);
// add it to the mesh
mesh.AddNodeSet(feset);
}
// create edges
int Edges = part.EdgeSets();
for (int i = 0; i < Edges; ++i)
{
EdgeSet* edgeSet = part.GetEdgeSet(i);
int N = edgeSet->Edges();
// create a new segment set
FESegmentSet* segSet = new FESegmentSet(&fem);
string name = partName + edgeSet->Name();
segSet->SetName(name.c_str());
// copy data
segSet->Create(N);
for (int j = 0; j < N; ++j)
{
EDGE& edge = edgeSet->Edge(j);
FESegmentSet::SEGMENT& seg = segSet->Segment(j);
seg.ntype = edge.ntype;
int nn = edge.ntype; // we assume that the type also identifies the number of nodes
for (int n = 0; n < nn; ++n) seg.node[n] = NLT[edge.node[n] - noff];
}
// add it to the mesh
mesh.AddSegmentSet(segSet);
}
// create surfaces
int Surfs = part.Surfaces();
for (int i=0; i<Surfs; ++i)
{
Surface* surf = part.GetSurface(i);
int faces = surf->Facets();
FEFacetSet* fset = nullptr;
if ((faces == 0) && surf->GetPartList())
{
// build the domain list
FEBModel::PartList* partList = surf->GetPartList();
std::vector<string> partNames = partList->GetPartList();
std::vector<FEDomain*> domList;
for (string s : partNames)
{
FEDomain* dom = mesh.FindDomain(s);
assert(dom);
if (dom == nullptr) return false;
domList.push_back(dom);
}
// we need to extract the surface from a list of parts
fset = mesh.DomainBoundary(domList);
}
else
{
// create a new facet set
fset = new FEFacetSet(&fem);
// copy data
fset->Create(faces);
for (int j = 0; j < faces; ++j)
{
FACET& srcFacet = surf->GetFacet(j);
FEFacetSet::FACET& face = fset->Face(j);
face.ntype = srcFacet.ntype;
int nf = srcFacet.ntype; // we assume that the type also identifies the number of nodes
for (int n = 0; n < nf; ++n) face.node[n] = NLT[srcFacet.node[n] - noff];
}
}
// add it to the mesh
assert(fset);
string name = partName + surf->Name();
fset->SetName(name.c_str());
mesh.AddFacetSet(fset);
}
// create element sets
int ESets = part.ElementSets();
for (int i=0; i<ESets; ++i)
{
ElementSet& eset = *part.GetElementSet(i);
vector<int> elist = eset.ElementList();
int ne = (int) elist.size();
FEElementSet* feset = new FEElementSet(&fem);
string name = partName + eset.Name();
feset->SetName(name);
// If a domain exists with the same name, we assume
// that this element set refers to the that domain (TODO: should actually check this!)
FEDomain* dom = mesh.FindDomain(name);
if (dom) feset->Create(dom);
else
{
// A domain with the same name is not found, but it is possible that this
// set still coincides with a domain, so let's see if we can find it.
// see if all elements belong to the same domain
bool oneDomain = true;
FEElement* el = mesh.FindElementFromID(elist[0]); assert(el);
FEDomain* dom = dynamic_cast<FEDomain*>(el->GetMeshPartition());
for (int i = 1; i < elist.size(); ++i)
{
FEElement* el_i = mesh.FindElementFromID(elist[i]); assert(el);
FEDomain* dom_i = dynamic_cast<FEDomain*>(el_i->GetMeshPartition());
if (dom != dom_i)
{
oneDomain = false;
break;
}
}
// assign indices to element set
if (oneDomain && (dom->Elements() == elist.size()))
feset->Create(dom, elist);
else
{
// Couldn't find a single domain.
// But maybe this set encompasses the entire mesh?
if (elist.size() == mesh.Elements())
{
FEDomainList allDomains;
for (int i = 0; i < mesh.Domains(); ++i) allDomains.AddDomain(&mesh.Domain(i));
feset->Create(allDomains);
}
else
{
feset->Create(elist);
}
}
}
mesh.AddElementSet(feset);
}
// create surface pairs
int SPairs = part.SurfacePairs();
for (int i = 0; i < SPairs; ++i)
{
SurfacePair& spair = *part.GetSurfacePair(i);
string name = partName + spair.Name();
FESurfacePair* fesurfPair = new FESurfacePair(&mesh);
mesh.AddSurfacePair(fesurfPair);
fesurfPair->SetName(name);
FEFacetSet* surf1 = mesh.FindFacetSet(spair.m_primary);
if (surf1 == nullptr) return false;
fesurfPair->SetPrimarySurface(surf1);
FEFacetSet* surf2 = mesh.FindFacetSet(spair.m_secondary);
if (surf2 == nullptr) return false;
fesurfPair->SetSecondarySurface(surf2);
}
// create domain lists
for (int i = 0; i < part.PartLists(); ++i)
{
FEBModel::PartList* partList = part.GetPartList(i);
FEDomainList* domList = new FEDomainList();
domList->SetName(partList->Name());
for (int j = 0; j < partList->Parts(); ++j)
{
FEDomain* dom = mesh.FindDomain(partList->PartName(j)); assert(dom);
if (dom) domList->AddDomain(dom);
}
mesh.AddDomainList(domList);
}
// create discrete element sets
int DSets = part.DiscreteSets();
for (int i = 0; i < DSets; ++i)
{
DiscreteSet& dset = *part.GetDiscreteSet(i);
string name = partName + dset.Name();
FEDiscreteSet* fedset = new FEDiscreteSet(&mesh);
mesh.AddDiscreteSet(fedset);
fedset->SetName(name);
const std::vector<DiscreteSet::ELEM>& elemList = dset.ElementList();
for (int j = 0; j < elemList.size(); ++j)
{
int n0 = NLT[elemList[j].node[0] - noff];
int n1 = NLT[elemList[j].node[1] - noff];
fedset->add(n0, n1);
}
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioControlSection4.cpp | .cpp | 1,871 | 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) 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 "FEBioControlSection4.h"
#include "FECore/FEAnalysis.h"
//-----------------------------------------------------------------------------
FEBioControlSection4::FEBioControlSection4(FEFileImport* pim) : FEFileSection(pim)
{
}
//-----------------------------------------------------------------------------
void FEBioControlSection4::Parse(XMLTag& tag)
{
// get the step (don't allocate solver)
FEAnalysis* pstep = GetBuilder()->GetStep(false);
if (pstep == 0)
{
throw XMLReader::InvalidTag(tag);
}
// read the step parameters
ReadParameterList(tag, pstep);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/XMLReader.cpp | .cpp | 27,456 | 1,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.*/
#include "XMLReader.h"
#include <assert.h>
#include <stdarg.h>
#include <fstream>
#include <sstream>
using namespace std;
//=============================================================================
// XMLAtt
//=============================================================================
//-----------------------------------------------------------------------------
//! The constructor sets the name and value to zero strings
XMLAtt::XMLAtt()
{
m_bvisited = false;
}
//-----------------------------------------------------------------------------
//! Returns true if the attribute's value is the same as the string that is passed.
//! Note that the comparison is case-sensitive
bool XMLAtt::operator == (const char* sz)
{
return (strcmp(m_val.c_str(), sz) == 0);
}
bool XMLAtt::operator != (const char* szval)
{
return (strcmp(szval, m_val.c_str()) != 0);
}
int XMLAtt::value(int* v, int n)
{
const char* sz = m_val.c_str();
int nr = 0;
for (int i = 0; i < n; ++i)
{
const char* sze = strchr(sz, ',');
v[i] = atoi(sz);
nr++;
if (sze) sz = sze + 1;
else break;
}
return nr;
}
int XMLAtt::value(double* pf, int n)
{
const char* sz = m_val.c_str();
int nr = 0;
for (int i = 0; i < n; ++i)
{
const char* sze = strchr(sz, ',');
pf[i] = atof(sz);
nr++;
if (sze) sz = sze + 1;
else break;
}
return nr;
}
//=============================================================================
// XMLTag
//=============================================================================
//-----------------------------------------------------------------------------
XMLTag::XMLTag()
{
m_preader = 0;
m_bend = false;
m_bleaf = true;
m_bempty = false;
}
//-----------------------------------------------------------------------------
//! Clear tag data
void XMLTag::clear()
{
m_sztag.clear();
m_szval.clear();
m_att.clear();
// m_path.clear(); // NOTE: Do not clear the path!
m_bend = false;
m_bleaf = true;
m_bempty = false;
}
//-----------------------------------------------------------------------------
std::string XMLTag::relpath(const char* szroot) const
{
std::string s;
int m = -1;
if (szroot)
{
for (int i = 0; i < m_path.size(); ++i)
{
if (strcmp(szroot, m_path[i].c_str()) == 0)
{
m = i;
break;
}
}
}
if (m != -1)
{
for (int i = m+1; i < m_path.size(); i++)
{
if (i != m+1) s += ".";
s += m_path[i];
}
}
if (s.empty() == false) s += ".";
s += m_sztag;
return s;
}
//-----------------------------------------------------------------------------
//! This function reads in a comma delimited list of doubles. The function reads
//! in a maximum of n values. The actual number of values that are read is returned.
//!
int XMLTag::value(double* pf, int n)
{
const char* sz = m_szval.c_str();
int nr = 0;
for (int i=0; i<n; ++i)
{
const char* sze = strchr(sz, ',');
pf[i] = atof(sz);
nr++;
if (sze) sz = sze+1;
else break;
}
return nr;
}
//-----------------------------------------------------------------------------
//! This function reads in a comma delimited list of floats. The function reads
//! in a maximum of n values. The actual number of values that are read is returned.
//!
int XMLTag::value(float* pf, int n)
{
const char* sz = m_szval.c_str();
int nr = 0;
for (int i=0; i<n; ++i)
{
const char* sze = strchr(sz, ',');
pf[i] = (float) atof(sz);
nr++;
if (sze) sz = sze+1;
else break;
}
return nr;
}
//-----------------------------------------------------------------------------
//! This function reads in a comma delimited list of ints. The function reads
//! in a maximum of n values. The actual number of values that are read is returned.
//!
int XMLTag::value(int* pi, int n)
{
const char* sz = m_szval.c_str();
int nr = 0;
for (int i=0; i<n; ++i)
{
const char* sze = strchr(sz, ',');
pi[i] = atoi(sz);
nr++;
if (sze) sz = sze+1;
else break;
}
return nr;
}
//-----------------------------------------------------------------------------
int XMLTag::value(std::vector<string>& stringList, int n)
{
stringList.clear();
char tmp[256] = { 0 };
const char* sz = m_szval.c_str();
int nr = 0;
for (int i = 0; i<n; ++i)
{
const char* sze = strchr(sz, ',');
if (sze)
{
int l = (int)(sze - sz);
if (l > 0) strncpy(tmp, sz, l);
tmp[l] = 0;
stringList.push_back(tmp);
}
else stringList.push_back(sz);
nr++;
if (sze) sz = sze + 1;
else break;
}
return nr;
}
//-----------------------------------------------------------------------------
void XMLTag::value(std::vector<string>& stringList)
{
stringList.clear();
char tmp[256] = { 0 };
const char* sz = m_szval.c_str();
while (sz && *sz)
{
const char* sze = strchr(sz, ',');
if (sze)
{
int l = (int)(sze - sz);
if (l > 0) strncpy(tmp, sz, l);
tmp[l] = 0;
stringList.push_back(tmp);
}
else stringList.push_back(sz);
if (sze) sz = sze + 1;
else break;
}
}
//-----------------------------------------------------------------------------
void XMLTag::value(bool& val)
{
int n=0;
sscanf(m_szval.c_str(), "%d", &n);
val = (n != 0);
}
//-----------------------------------------------------------------------------
void XMLTag::value(char* szstr)
{
strcpy(szstr, m_szval.c_str());
}
//-----------------------------------------------------------------------------
void XMLTag::value(std::string& val)
{
val = m_szval;
}
//-----------------------------------------------------------------------------
void XMLTag::value(vector<int>& l)
{
int i, n = 0, n0, n1, nn;
char* szval = strdup(m_szval.c_str());
char* ch;
char* sz = szval;
int nread;
do
{
ch = strchr(sz, ',');
if (ch) *ch = 0;
nread = sscanf(sz, "%d:%d:%d", &n0, &n1, &nn);
switch (nread)
{
case 1:
n1 = n0;
nn = 1;
break;
case 2:
nn = 1;
break;
case 3:
break;
default:
n0 = 0;
n1 = -1;
nn = 1;
}
for (i=n0; i<=n1; i += nn) ++n;
if (ch) *ch = ',';
sz = ch+1;
}
while (ch != 0);
if (n != 0)
{
l.resize(n);
sz = szval;
n = 0;
do
{
ch = strchr(sz, ',');
if (ch) *ch = 0;
nread = sscanf(sz, "%d:%d:%d", &n0, &n1, &nn);
switch (nread)
{
case 1:
n1 = n0;
nn = 1;
break;
case 2:
nn = 1;
break;
case 3:
break;
default:
n0 = 0;
n1 = -1;
nn = 1;
}
for (i=n0; i<=n1; i += nn) l[n++] = i;
assert(n <= (int) l.size());
if (ch) *ch = ',';
sz = ch+1;
}
while (ch != 0);
}
free(szval);
}
//-----------------------------------------------------------------------------
void XMLTag::value(vector<double>& l)
{
l.clear();
const char *sz = m_szval.c_str();
while (sz && *sz)
{
// skip space
while (isspace(*sz)) ++sz;
// read the value
if (sz && *sz)
{
double v = atof(sz);
l.push_back(v);
// find next space or comma
while (*sz && (*sz != ' ') && (*sz != ',')) sz++;
if (*sz == ',') sz++;
}
}
}
void XMLTag::value2(std::vector<int>& l)
{
l.clear();
const char* sz = m_szval.c_str();
while (sz && *sz)
{
// skip space
while (isspace(*sz)) ++sz;
// read the value
if (sz && *sz)
{
int v = (int)atoi(sz);
l.push_back(v);
// find next space or comma
while (*sz && (*sz != ' ') && (*sz != ',')) sz++;
if (*sz == ',') sz++;
}
}
}
//-----------------------------------------------------------------------------
//! Return the number of children of a tag
int XMLTag::children()
{
XMLTag tag(*this); ++tag;
int ncount = 0;
while (!tag.isend()) { ncount++; tag.skip(); ++tag; }
return ncount;
}
//-----------------------------------------------------------------------------
//! return the string value of an attribute
const char* XMLTag::AttributeValue(const char* szat, bool bopt)
{
// find the attribute
for (XMLAtt& att : m_att)
{
if (strcmp(att.m_name.c_str(), szat) == 0)
{
att.m_bvisited = true;
return att.m_val.c_str();
}
}
// If the attribute was not optional, we throw a fit
if (!bopt) throw XMLReader::MissingAttribute(*this, szat);
// we didn't find it
return 0;
}
//-----------------------------------------------------------------------------
XMLAtt* XMLTag::AttributePtr(const char* szat)
{
return Attribute(szat, true);
}
//-----------------------------------------------------------------------------
//! return the attribute
XMLAtt* XMLTag::Attribute(const char* szat, bool bopt)
{
// find the attribute
for (XMLAtt& att : m_att)
{
if (strcmp(att.m_name.c_str(), szat) == 0)
{
att.m_bvisited = true;
return &(att);
}
}
// If the attribute was not optional, we throw a fit
if (!bopt) throw XMLReader::MissingAttribute(*this, szat);
// we didn't find it
return nullptr;
}
//-----------------------------------------------------------------------------
//! return the attribute
XMLAtt& XMLTag::Attribute(const char* szat)
{
// find the attribute
for (XMLAtt& att : m_att)
{
if (strcmp(att.m_name.c_str(), szat) == 0)
{
att.m_bvisited = true;
return att;
}
}
// throw a fit
throw XMLReader::MissingAttribute(*this, szat);
}
//-----------------------------------------------------------------------------
bool XMLTag::AttributeValue(const char* szat, double& d, bool bopt)
{
const char* szv = AttributeValue(szat, bopt);
if (szv == 0) return false;
d = atof(szv);
return true;
}
//-----------------------------------------------------------------------------
bool XMLTag::AttributeValue(const char* szat, int& n, bool bopt)
{
const char* szv = AttributeValue(szat, bopt);
if (szv == 0) return false;
n = atoi(szv);
return true;
}
//=============================================================================
// XMLReader - Exceptions
//=============================================================================
// helper function for formatting a string
string format_string(const char* sz, ...)
{
// get a pointer to the argument list
va_list args;
// make the message
char szbuf[512];
va_start(args, sz);
vsnprintf(szbuf, sizeof(szbuf), sz, args);
va_end(args);
return szbuf;
}
//-----------------------------------------------------------------------------
XMLReader::Error::Error(XMLTag& tag, const std::string& err) : \
std::runtime_error(format_string("tag \"%s\" (line %d) : ", tag.Name(), tag.m_nstart_line) + err) {}
//-----------------------------------------------------------------------------
XMLReader::XMLSyntaxError::XMLSyntaxError(int line_number) : \
XMLReader::Error(format_string("syntax error (line %d)", line_number)) {}
//-----------------------------------------------------------------------------
XMLReader::UnmatchedEndTag::UnmatchedEndTag(XMLTag& tag) : \
XMLReader::Error(tag, "unmatched end tag") {}
//-----------------------------------------------------------------------------
XMLReader::InvalidTag::InvalidTag(XMLTag& tag) : \
XMLReader::Error(tag, "unrecognized tag") {}
//-----------------------------------------------------------------------------
XMLReader::InvalidValue::InvalidValue(XMLTag& tag) : \
XMLReader::Error(tag, format_string("invalid value: %s", tag.isleaf() ? tag.szvalue() : "")) {}
//-----------------------------------------------------------------------------
XMLReader::InvalidAttributeValue::InvalidAttributeValue(XMLTag& tag, const char* sza, const char* szv) : \
XMLReader::Error(tag, format_string("invalid value for attribute \"%s\"", sza)) {}
XMLReader::InvalidAttributeValue::InvalidAttributeValue(XMLTag& tag, XMLAtt& att) : \
XMLReader::Error(tag, format_string("invalid value for attribute \"%s\"", att.cvalue())) {}
//-----------------------------------------------------------------------------
XMLReader::InvalidAttribute::InvalidAttribute(XMLTag& tag, const char* sza) :\
XMLReader::Error(tag, format_string("invalid attribute \"%s\"", sza)) {}
//-----------------------------------------------------------------------------
XMLReader::MissingAttribute::MissingAttribute(XMLTag& tag, const char* sza) : \
XMLReader::Error(tag, format_string("missing attribute \"%s\"", sza)) {}
//-----------------------------------------------------------------------------
XMLReader::MissingTag::MissingTag(XMLTag& tag, const char* sza) : \
XMLReader::Error(tag, format_string("missing tag \"%s\"", sza)) {}
//=============================================================================
// XMLReader
//=============================================================================
//-----------------------------------------------------------------------------
XMLReader::XMLReader()
{
m_stream = nullptr;
m_nline = 0;
m_bufIndex = 0;
m_bufSize = 0;
m_eof = false;
m_currentPos = 0;
m_buf = new char[BUF_SIZE];
}
//-----------------------------------------------------------------------------
XMLReader::~XMLReader()
{
Close();
delete[] m_buf;
}
//-----------------------------------------------------------------------------
void XMLReader::Close()
{
if(m_stream)
{
ifstream* fileStream = dynamic_cast<ifstream*>(m_stream);
if(fileStream)
{
fileStream->close();
}
delete m_stream;
m_stream = nullptr;
}
m_nline = 0;
m_bufIndex = 0;
m_bufSize = 0;
m_eof = false;
m_currentPos = 0;
}
//-----------------------------------------------------------------------------
bool XMLReader::Open(const char* szfile, bool checkForXMLTag)
{
// make sure this reader has not been attached to a file yet
if(m_stream) return false;
// open the file
m_stream = new ifstream;
static_cast<ifstream*>(m_stream)->open(szfile, ifstream::in|ifstream::binary);
if(m_stream->fail()) return false;
// read the first line
if (checkForXMLTag)
{
char szline[256] = { 0 };
// fgets(szline, 255, m_fp);
m_stream->get(szline, 255);
// make sure it is correct
if (strncmp(szline, "<?xml", 5) != 0)
{
// This file is not an XML file
return false;
}
}
m_currentPos = 0;
// This file is ready to be processed
return true;
}
bool XMLReader::OpenString(std::string& xml, bool checkForXMLTag)
{
// make sure this we don't already have a stream
if(m_stream) return false;
// create string stream
m_stream = new std::istringstream(xml);
if(m_stream->fail()) return false;
// read the first line
if (checkForXMLTag)
{
char szline[256] = { 0 };
// fgets(szline, 255, m_fp);
m_stream->get(szline, 255);
// make sure it is correct
if (strncmp(szline, "<?xml", 5) != 0)
{
// This file is not an XML file
return false;
}
}
m_currentPos = 0;
// This file is ready to be processed
return true;
}
//-----------------------------------------------------------------------------
class XMLPath
{
struct TAG
{
char* tag;
char* att;
char* atv;
};
public:
XMLPath(const char* xpath)
{
int l = (int)strlen(xpath);
m_path = new char[l+1];
strncpy(m_path, xpath, l);
m_path[l] = 0;
m_index = 0;
parse();
}
~XMLPath()
{
delete [] m_path;
}
void next() { m_index++; }
bool match(XMLTag& tag)
{
// make sure index is valid
if ((m_index < 0) || (m_index >= (int) m_tag.size())) return false;
// get current tag
TAG& t = m_tag[m_index];
// do tag name compare?
if (strcmp(t.tag, tag.Name()) != 0) return false;
// if tag requires attribute, make sure it exist
if (t.att)
{
const char* szatt = tag.AttributeValue(t.att, true);
if (szatt)
{
// if the value is specified, make sure it matches too
if (t.atv)
{
if (strcmp(t.atv, szatt) == 0) return true;
else return false;
}
else return false;
}
else return false;
}
else return true;
}
bool valid() { return ((m_index >= 0) && (m_index < m_tag.size())); }
private:
void parse()
{
char* sz = m_path;
char* ch = strchr(m_path, '/');
do
{
TAG tag;
tag.tag = sz;
tag.att = 0;
tag.atv = 0;
if (ch) *ch = 0;
if (sz)
{
char* cl = strchr(sz, '[');
if (cl)
{
char* cr = strchr(cl+1, ']');
if (cr)
{
*cl++ = 0;
if (cl[0]=='@') cl++;
tag.att = cl;
*cr = 0;
cr = strchr(cl, '=');
if (cr)
{
*cr++ = 0;
tag.atv = cr;
}
}
}
}
sz = (ch ? ch + 1 : 0);
if (ch) ch = strchr(sz, '/');
m_tag.push_back(tag);
}
while (sz);
}
private:
char* m_path;
vector<TAG> m_tag;
int m_index;
};
bool XMLReader::FindTag(const char* xpath, XMLTag& tag)
{
// go to the beginning of the file
m_stream->seekg(0, ios_base::beg);
m_bufIndex = m_bufSize = 0;
m_currentPos = 0;
m_eof = false;
// set the first tag
tag.m_preader = this;
tag.m_ncurrent_line = 1;
tag.m_fpos = currentPos();
XMLPath path(xpath);
// find the correct tag
bool bfound = false;
try
{
// get the next tag
++tag;
do
{
// check for match
if (path.match(tag))
{
path.next();
if (path.valid()) ++tag;
bfound = true;
}
else
{
tag.skip();
++tag;
bfound = false;
}
}
while (path.valid());
}
catch (...)
{
// an error has occured (or the end-of-file was reached)
return false;
}
return bfound;
}
//-----------------------------------------------------------------------------
void XMLReader::NextTag(XMLTag& tag)
{
assert( tag.m_preader == this);
// set current line number
m_nline = tag.m_ncurrent_line;
// set the current file position
if (m_currentPos != tag.m_fpos)
{
m_stream->seekg(tag.m_fpos, ios_base::beg);
m_currentPos = tag.m_fpos;
m_bufSize = m_bufIndex = 0;
m_eof = false;
}
// update the path
if (!tag.isend() && !tag.isempty() && !tag.isleaf())
{
// keep a copy of the name
tag.m_path.push_back(tag.m_sztag);
}
else if (tag.isend())
{
// make sure the name is the same as the root
if (strcmp(tag.m_sztag.c_str(), tag.m_path.back().c_str()) != 0) throw UnmatchedEndTag(tag);
tag.m_path.erase(--tag.m_path.end());
}
// clear tag's content
tag.clear();
// read the start tag
ReadTag(tag);
// read value and end tag if tag is not empty
if (!tag.isempty() && !tag.isend())
{
// read the value
ReadValue(tag);
// read the end tag
ReadEndTag(tag);
}
// store current line number
tag.m_ncurrent_line = m_nline;
// store start file pos for next element
tag.m_fpos = currentPos();
}
//-----------------------------------------------------------------------------
inline bool isvalid(char c)
{
return (isalnum(c) || (c=='_') || (c=='.') || (c=='-') || (c==':'));
}
//-----------------------------------------------------------------------------
void XMLReader::ReadTag(XMLTag& tag)
{
// find the start token
char ch;
while (true)
{
while ((ch=GetChar())!='<')
if (!isspace(ch))
{
throw XMLSyntaxError(m_nline);
}
ch = GetChar();
if (ch == '?')
{
// parse the xml header tag
while ((ch = GetChar()) != '?');
ch = GetChar();
if (ch != '>') throw XMLSyntaxError(m_nline);
}
else break;
}
// record the startline
tag.m_nstart_line = m_nline;
if (ch == '/')
{
tag.m_bend = true;
m_comment.clear();
ch = GetChar();
}
// skip whitespace
while (isspace(ch)) ch = GetChar();
// read the tag name
if (!isvalid(ch)) throw XMLSyntaxError(m_nline);
tag.m_sztag.clear();
tag.m_sztag.push_back(ch);
while (isvalid(ch=GetChar())) tag.m_sztag.push_back(ch);
// read attributes
tag.m_att.clear();
int n = 0;
while (true)
{
// skip whitespace
while (isspace(ch)) ch = GetChar();
if (ch == '/')
{
tag.m_bempty = true;
ch = GetChar();
if (ch != '>') throw XMLSyntaxError(m_nline);
break;
}
else if (ch == '>') break;
// read the attribute's name
XMLAtt att;
std::string& name = att.m_name;
name.clear();
if (!isvalid(ch)) throw XMLSyntaxError(m_nline);
name.push_back(ch);
while (isvalid(ch=GetChar())) name.push_back(ch);
// skip whitespace
while (isspace(ch)) ch=GetChar();
if (ch != '=') throw XMLSyntaxError(m_nline);
// skip whitespace
while (isspace(ch=GetChar()));
// make sure the attribute's value starts with an apostrophe or quotation mark
if ((ch != '"')&&(ch != '\'')) throw XMLSyntaxError(m_nline);
char quot = ch;
// read the value
std::string& val = att.m_val;
while ((ch=GetChar())!=quot) val.push_back(ch);
ch=GetChar();
// mark tag as unvisited
att.m_bvisited = false;
++n;
tag.m_att.push_back(att);
}
}
//-----------------------------------------------------------------------------
void XMLReader::ReadValue(XMLTag& tag)
{
char ch;
if (!tag.isend())
{
tag.m_szval.clear();
tag.m_szval.reserve(256);
while ((ch=GetChar())!='<')
{
tag.m_szval.push_back(ch);
}
}
else while ((ch=GetChar())!='<');
}
//-----------------------------------------------------------------------------
void XMLReader::ReadEndTag(XMLTag& tag)
{
char ch;
const char* sz = tag.m_sztag.c_str();
if (!tag.isend())
{
ch = GetChar();
if (ch == '/')
{
// this is the end tag
// skip whitespace
while (isspace(ch=GetChar()));
int n = 0;
do
{
if (ch != *sz++) throw UnmatchedEndTag(tag);
ch = GetChar();
++n;
}
while (!isspace(ch) && (ch!='>'));
if (n != (int) tag.m_sztag.size()) throw UnmatchedEndTag(tag);
// skip whitespace
while (isspace(ch)) ch=GetChar();
if (ch != '>') throw XMLSyntaxError(m_nline);
// find the start of the next tag
if (tag.m_path.empty() == false)
{
while (isspace(ch=GetChar()));
if (ch != '<') throw XMLSyntaxError(m_nline);
rewind(1);
}
}
else
{
// this element has child elements
// and therefor is not a leaf
tag.m_bleaf = false;
rewind(2);
}
}
else
{
rewind(1);
}
}
//-----------------------------------------------------------------------------
char XMLReader::readNextChar()
{
if (m_bufIndex >= m_bufSize)
{
if (m_eof)
{
throw UnexpectedEOF();
}
m_stream->read(m_buf, BUF_SIZE);
// clear eofbit and failbit if eof is hit. Unless we do this, seekg doesn't work
// we handle eof manually, so we can clear it without issue.
m_stream->clear();
m_bufSize = m_stream->gcount();
m_bufIndex = 0;
m_eof = (m_bufSize != BUF_SIZE);
}
m_currentPos++;
char ch = m_buf[m_bufIndex++];
if (ch == '\n') m_nline++;
return ch;
}
//-----------------------------------------------------------------------------
int64_t XMLReader::currentPos()
{
return m_currentPos;
}
//-----------------------------------------------------------------------------
//! move the file pointer
void XMLReader::rewind(int64_t nstep)
{
// NOTE: What if we rewind past a newline? Won't that mess up the line index?
m_bufIndex -= nstep;
m_currentPos -= nstep;
if (m_bufIndex < 0)
{
m_stream->seekg(m_bufIndex - m_bufSize, ios_base::cur);
m_bufIndex = m_bufSize = 0;
m_eof = false;
}
}
// clean the string by removing whitespace at the front and back
void clean_string(string& s)
{
if (s.empty()) return;
size_t n = s.size();
char* tmp = new char[n + 1];
strncpy(tmp, s.c_str(), n);
tmp[n] = 0;
char* cl = tmp;
while (*cl && isspace(*cl)) cl++;
n = strlen(cl);
if (n > 0)
{
char* cr = &cl[n - 1];
while ((cr > cl) && isspace(*cr)) *cr-- = 0;
}
s = cl;
delete[] tmp;
}
//-----------------------------------------------------------------------------
//! Read the next character in the file (skipping over comments).
char XMLReader::GetChar()
{
char ch = readNextChar();
while (ch == '\r') ch = readNextChar();
if ((ch == '\t') || (ch == '\n')) ch = ' ';
// check for comments
if (ch == '<')
{
char tmp = readNextChar();
if (tmp == '!')
{
m_comment.clear();
// parse the comment
ch = readNextChar(); if (ch != '-') throw XMLSyntaxError(m_nline);
ch = readNextChar(); if (ch != '-') throw XMLSyntaxError(m_nline);
// find the end of the comment
int n = 0;
do
{
ch = readNextChar();
if (ch == '-') n++;
else if ((ch == '>') && (n >= 2)) break;
else
{
if (n > 0) m_comment += '-';
if (n > 1) m_comment += '-';
if (ch != '\r') m_comment += ch; // don't append \r
n = 0;
}
} while (1);
// eat whitespace at the start and end of the comment
clean_string(m_comment);
ch = readNextChar();
}
else rewind(1);
}
// read entity references
if (ch=='&')
{
char szbuf[16]={0};
szbuf[0] = '&';
int i = 1;
do
{
ch = readNextChar();
szbuf[i++]=ch;
}
while ((i<16)&&(ch!=';'));
if (ch!=';') throw XMLSyntaxError(m_nline);
if (strcmp(szbuf, "<" )==0) ch = '<';
else if (strcmp(szbuf, ">" )==0) ch = '>';
else if (strcmp(szbuf, "&" )==0) ch = '&';
else if (strcmp(szbuf, "'")==0) ch = '\'';
else if (strcmp(szbuf, """)==0) ch = '"';
else if ((strcmp(szbuf, "	" ) == 0) || (strcmp(szbuf, "	") == 0)) ch = '\t';
else if ((strcmp(szbuf, " ") == 0) || (strcmp(szbuf, "
") == 0)) ch = '\n';
else if ((strcmp(szbuf, " ") == 0) || (strcmp(szbuf, "
") == 0)) ch = '\r';
else throw XMLSyntaxError(m_nline);
}
return ch;
}
//-----------------------------------------------------------------------------
//! Skip a tag
void XMLReader::SkipTag(XMLTag& tag)
{
// if this tag is a leaf we just return
if (tag.isleaf()) { return; }
// if it is not a leaf we have to loop over all
// the children, skipping each child in turn
++tag;
do
{
SkipTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
char XMLReader::GetNextChar()
{
char ch;
do
{
ch = readNextChar();
if (ch == '\n') ++m_nline;
} while (ch == '\r');
return ch;
}
ifstream* XMLReader::GetFileStream()
{
return dynamic_cast<ifstream*>(m_stream);
}
//! return the current line
int XMLReader::GetCurrentLine() { return m_nline; }
const std::string& XMLReader::GetLastComment()
{
// Get rid of starting and trailing new lines in comments
if (m_comment.empty() == false)
{
if (*m_comment.begin() == '\n')
{
m_comment.erase(m_comment.begin());
}
if (*m_comment.rbegin() == '\n')
{
m_comment.erase(m_comment.end());
}
}
return m_comment;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioGlobalsSection.h | .h | 1,705 | 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 "FileImport.h"
//-----------------------------------------------------------------------------
//! Globals Section
class FEBIOXML_API FEBioGlobalsSection : public FEFileSection
{
public:
FEBioGlobalsSection(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseConstants (XMLTag& tag);
void ParseGlobalData (XMLTag& tag);
void ParseVariables (XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioStepSection3.h | .h | 1,549 | 39 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// Step Section (3.0 format)
class FEBioStepSection3 : public FEFileSection
{
public:
FEBioStepSection3(FEFileImport* pim);
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEModelBuilder.cpp | .cpp | 32,617 | 937 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEModelBuilder.h"
#include <FECore/FEMaterial.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FENodalLoad.h>
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEEdgeLoad.h>
#include <FECore/FEInitialCondition.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FELoadCurve.h>
#include <FECore/FESurfaceMap.h>
#include <FECore/FEDomainMap.h>
#include <FECore/FEEdge.h>
#include <FECore/FEConstValueVec3.h>
#include <FECore/FEDataGenerator.h>
#include <FECore/FEPointFunction.h>
#include <FECore/FESurfacePairConstraint.h>
#include <FECore/FENLConstraint.h>
#include <sstream>
//-----------------------------------------------------------------------------
FEModelBuilder::FEModelBuilder(FEModel& fem) : m_fem(fem)
{
m_pStep = 0; // zero step pointer
m_nsteps = 0; // reset step section counter
// default element type
m_ntet4 = FE_TET4G1;
m_nhex8 = FE_HEX8G8;
m_ntet10 = FE_TET10G8;
m_ntet15 = FE_TET15G15;
m_ntet20 = FE_TET20G15;
m_ntri6 = FE_TRI6G7;
m_ntri3 = FE_TRI3G3;
m_ntri7 = FE_TRI7G7;
m_ntri10 = FE_TRI10G7;
m_nquad4 = FE_QUAD4G4;
m_nquad8 = FE_QUAD8G9;
m_nquad9 = FE_QUAD9G9;
// 3-field formulation flags
m_b3field_hex = true;
m_b3field_tet = false;
m_b3field_shell = false;
m_b3field_quad = true;
m_b3field_tri = false;
// shell formulation
m_default_shell = NEW_SHELL;
m_shell_norm_nodal = true;
// UT4 formulation off by default
m_but4 = false;
m_ut4_alpha = 0.05;
m_ut4_bdev = false;
// UDG hourglass parameter
m_udghex_hg = 1.0;
}
//-----------------------------------------------------------------------------
FEModelBuilder::~FEModelBuilder()
{
}
//-----------------------------------------------------------------------------
void FEModelBuilder::SetActiveModule(const std::string& moduleName)
{
m_fem.SetActiveModule(moduleName);
}
//-----------------------------------------------------------------------------
//! Get the module name
std::string FEModelBuilder::GetModuleName() const
{
return m_fem.GetModuleName();
}
//-----------------------------------------------------------------------------
FEAnalysis* FEModelBuilder::CreateNewStep(bool allocSolver)
{
// default analysis type should match module name
std::string modName = GetModuleName();
FEAnalysis* pstep = fecore_new<FEAnalysis>(modName.c_str(), &m_fem);
// make sure we have a solver defined
FESolver* psolver = pstep->GetFESolver();
if ((psolver == 0) && allocSolver)
{
psolver = BuildSolver(m_fem);
if (psolver == 0) return 0;
pstep->SetFESolver(psolver);
}
return pstep;
}
//-----------------------------------------------------------------------------
// create a material
FEMaterial* FEModelBuilder::CreateMaterial(const char* sztype)
{
FEMaterial* pmat = fecore_new<FEMaterial>(sztype, &m_fem);
return pmat;
}
//-----------------------------------------------------------------------------
FESolver* FEModelBuilder::BuildSolver(FEModel& fem)
{
string moduleName = fem.GetModuleName();
const char* sztype = moduleName.c_str();
if (m_defaultSolver.empty() == false) sztype = m_defaultSolver.c_str();
FESolver* ps = fecore_new<FESolver>(sztype, &fem);
return ps;
}
//-----------------------------------------------------------------------------
void FEModelBuilder::NextStep()
{
// reset the step pointer
if (m_nsteps != 0) m_pStep = nullptr;
// increase the step section counter
++m_nsteps;
}
//-----------------------------------------------------------------------------
//! Get the mesh
FEMesh& FEModelBuilder::GetMesh()
{
return m_fem.GetMesh();
}
//-----------------------------------------------------------------------------
//! get the FE model
FEModel& FEModelBuilder::GetFEModel()
{
return m_fem;
}
//-----------------------------------------------------------------------------
//! Create a domain
FEDomain* FEModelBuilder::CreateDomain(FE_Element_Spec espec, FEMaterial* mat)
{
FECoreKernel& febio = FECoreKernel::GetInstance();
FEDomain* pdom = febio.CreateDomain(espec, &m_fem.GetMesh(), mat);
return pdom;
}
//-----------------------------------------------------------------------------
FEAnalysis* FEModelBuilder::GetStep(bool allocSolver)
{
if (m_pStep == 0)
{
m_pStep = CreateNewStep(allocSolver);
m_fem.AddStep(m_pStep);
if (m_fem.Steps() == 1)
{
m_fem.SetCurrentStep(m_pStep);
m_fem.SetCurrentStepIndex(0);
}
}
return m_pStep;
}
void FEModelBuilder::AddMaterial(FEMaterial* pmat)
{
m_fem.AddMaterial(pmat);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddComponent(FEStepComponent* pmc)
{
if (m_nsteps > 0)
{
GetStep()->AddStepComponent(pmc);
pmc->Deactivate();
}
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddBC(FEBoundaryCondition* pbc)
{
m_fem.AddBoundaryCondition(pbc);
AddComponent(pbc);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddNodalLoad(FENodalLoad* pfc)
{
m_fem.AddModelLoad(pfc);
AddComponent(pfc);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddSurfaceLoad(FESurfaceLoad* psl)
{
m_fem.AddModelLoad(psl);
AddComponent(psl);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddEdgeLoad(FEEdgeLoad* pel)
{
m_fem.AddModelLoad(pel);
AddComponent(pel);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddInitialCondition(FEInitialCondition* pic)
{
m_fem.AddInitialCondition(pic);
AddComponent(pic);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddContactInterface(FESurfacePairConstraint* pci)
{
m_fem.AddSurfacePairConstraint(pci);
AddComponent(pci);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddModelLoad(FEModelLoad* pml)
{
m_fem.AddModelLoad(pml);
AddComponent(pml);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddNonlinearConstraint(FENLConstraint* pnc)
{
m_fem.AddNonlinearConstraint(pnc);
AddComponent(pnc);
}
//-----------------------------------------------------------------------------
void FEModelBuilder::AddRigidComponent(FEStepComponent* pmc) { assert(false); }
//---------------------------------------------------------------------------------
// parse a surface section for contact definitions
//
bool FEModelBuilder::BuildSurface(FESurface& s, FEFacetSet& fs, bool bnodal)
{
FEMesh& m = m_fem.GetMesh();
int NN = m.Nodes();
// count nr of faces
int faces = fs.Faces();
// allocate storage for faces
s.Create(fs);
// read faces
for (int i = 0; i<faces; ++i)
{
FESurfaceElement& el = s.Element(i);
FEFacetSet::FACET& fi = fs.Face(i);
// set the element type/integration rule
if (bnodal)
{
if (fi.ntype == 4) el.SetType(FE_QUAD4NI);
else if (fi.ntype == 3) el.SetType(FE_TRI3NI);
else if (fi.ntype == 6) el.SetType(FE_TRI6NI);
else if (fi.ntype == 8) el.SetType(FE_QUAD8NI);
else if (fi.ntype == 9) el.SetType(FE_QUAD9NI);
else return false;
}
else
{
if (fi.ntype == 3) el.SetType(m_ntri3);
else if (fi.ntype == 4) el.SetType(m_nquad4);
else if (fi.ntype == 6) el.SetType(m_ntri6);
else if (fi.ntype == 7) el.SetType(m_ntri7);
else if (fi.ntype == 10) el.SetType(m_ntri10);
else if (fi.ntype == 8) el.SetType(m_nquad8);
else if (fi.ntype == 9) el.SetType(m_nquad9);
else return false;
}
int N = el.Nodes(); assert(N == fi.ntype);
for (int j = 0; j<N; ++j) el.m_node[j] = fi.node[j];
}
// copy the name
s.SetName(fs.GetName());
// finish building the surface
s.InitSurface();
// allocate material point data
s.CreateMaterialPointData();
return true;
}
//-----------------------------------------------------------------------------
bool FEModelBuilder::BuildEdge(FEEdge& e, FESegmentSet& es)
{
// copy the name
e.SetName(es.GetName());
// create the edge
return e.Create(es);
}
//-----------------------------------------------------------------------------
FEModelBuilder::NodeSetPair* FEModelBuilder::FindNodeSetPair(const char* szname)
{
for (int i = 0; i<m_nsetPair.size(); ++i)
if (strcmp(m_nsetPair[i].szname, szname) == 0) return &m_nsetPair[i];
return 0;
}
//-----------------------------------------------------------------------------
FEModelBuilder::NodeSetSet* FEModelBuilder::FindNodeSetSet(const char* szname)
{
for (int i = 0; i<m_nsetSet.size(); ++i)
if (strcmp(m_nsetSet[i].szname, szname) == 0) return &m_nsetSet[i];
return 0;
}
//-----------------------------------------------------------------------------
void FEModelBuilder::BuildNodeList()
{
// find the min, max ID
// (We assume that they are given by the first and last node)
FEMesh& mesh = m_fem.GetMesh();
int NN = mesh.Nodes();
int nmin = mesh.Node(0).GetID();
int nmax = mesh.Node(NN - 1).GetID();
assert(nmax >= nmin);
// get the range
int nn = nmax - nmin + 1;
// allocate list
m_node_off = nmin;
m_node_list.assign(nn, -1);
// build the list
for (int i = 0; i<NN; ++i)
{
int nid = mesh.Node(i).GetID();
m_node_list[nid - m_node_off] = i;
}
}
//-----------------------------------------------------------------------------
int FEModelBuilder::FindNodeFromID(int nid)
{
int N = (int)m_node_list.size();
if (N > 0)
{
int n = nid - m_node_off;
if ((n >= 0) && (n<N)) return m_node_list[n];
}
return -1;
}
//-----------------------------------------------------------------------------
void FEModelBuilder::GlobalToLocalID(int* l, int n, vector<int>& m)
{
assert((int)m.size() == n);
for (int i = 0; i<n; ++i)
{
m[i] = FindNodeFromID(l[i]);
}
}
//-----------------------------------------------------------------------------
// Call this to initialize default variables when reading older files.
void FEModelBuilder::SetDefaultVariables()
{
// Reset degrees of
FEModel& fem = m_fem;
DOFS& dofs = fem.GetDOFS();
dofs.Reset();
// Add the default variables and degrees of freedom
int varD = dofs.AddVariable("displacement", VAR_VEC3);
dofs.SetDOFName(varD, 0, "x");
dofs.SetDOFName(varD, 1, "y");
dofs.SetDOFName(varD, 2, "z");
int varQ = dofs.AddVariable("rotation", VAR_VEC3);
dofs.SetDOFName(varQ, 0, "u");
dofs.SetDOFName(varQ, 1, "v");
dofs.SetDOFName(varQ, 2, "w");
int varSD = dofs.AddVariable("shell displacement", VAR_VEC3);
dofs.SetDOFName(varSD, 0, "sx");
dofs.SetDOFName(varSD, 1, "sy");
dofs.SetDOFName(varSD, 2, "sz");
int varP = dofs.AddVariable("fluid pressure");
dofs.SetDOFName(varP, 0, "p");
int varSP = dofs.AddVariable("shell fluid pressure");
dofs.SetDOFName(varSP, 0, "q");
int varQR = dofs.AddVariable("rigid rotation", VAR_VEC3);
dofs.SetDOFName(varQR, 0, "Ru");
dofs.SetDOFName(varQR, 1, "Rv");
dofs.SetDOFName(varQR, 2, "Rw");
int varV = dofs.AddVariable("velocity", VAR_VEC3);
dofs.SetDOFName(varV, 0, "vx");
dofs.SetDOFName(varV, 1, "vy");
dofs.SetDOFName(varV, 2, "vz");
int varW = dofs.AddVariable("relative fluid velocity", VAR_VEC3);
dofs.SetDOFName(varW, 0, "wx");
dofs.SetDOFName(varW, 1, "wy");
dofs.SetDOFName(varW, 2, "wz");
int varAW = dofs.AddVariable("relative fluid acceleration", VAR_VEC3);
dofs.SetDOFName(varAW, 0, "awx");
dofs.SetDOFName(varAW, 1, "awy");
dofs.SetDOFName(varAW, 2, "awz");
int varVF = dofs.AddVariable("fluid velocity", VAR_VEC3);
dofs.SetDOFName(varVF, 0, "vfx");
dofs.SetDOFName(varVF, 1, "vfy");
dofs.SetDOFName(varVF, 2, "vfz");
int varAF = dofs.AddVariable("fluid acceleration", VAR_VEC3);
dofs.SetDOFName(varAF, 0, "afx");
dofs.SetDOFName(varAF, 1, "afy");
dofs.SetDOFName(varAF, 2, "afz");
int varEF = dofs.AddVariable("fluid dilatation");
dofs.SetDOFName(varEF, 0, "ef");
int varAEF = dofs.AddVariable("fluid dilatation tderiv");
dofs.SetDOFName(varAEF, 0, "aef");
int varQV = dofs.AddVariable("shell velocity", VAR_VEC3);
dofs.SetDOFName(varQV, 0, "svx");
dofs.SetDOFName(varQV, 1, "svy");
dofs.SetDOFName(varQV, 2, "svz");
int varQA = dofs.AddVariable("shell acceleration", VAR_VEC3);
dofs.SetDOFName(varQA, 0, "sax");
dofs.SetDOFName(varQA, 1, "say");
dofs.SetDOFName(varQA, 2, "saz");
int varT = dofs.AddVariable("temperature");
dofs.SetDOFName(varT, 0, "T");
// must be last variable definition!!
int varC = dofs.AddVariable("concentration", VAR_ARRAY); // we start with zero concentrations
// must be last variable definition!!
int varSC = dofs.AddVariable("shell concentration", VAR_ARRAY); // we start with zero concentrations
int varAC = dofs.AddVariable("concentration tderiv", VAR_ARRAY); // we start with zero concentrations
// must be last variable definition!!
}
//-----------------------------------------------------------------------------
//! Get the element type from a XML tag
FE_Element_Spec FEModelBuilder::ElementSpec(const char* sztype)
{
FEMesh& mesh = m_fem.GetMesh();
// determine the element shape
FE_Element_Shape eshape = FE_ELEM_INVALID_SHAPE;
// for shells, don't overwrite m_pim->m_ntri3/6 or m_nquad4/8, since they are needed for surface definitions
FE_Element_Type stype = FE_ELEM_INVALID_TYPE;
if (strcmp(sztype, "hex8" ) == 0) eshape = ET_HEX8;
else if (strcmp(sztype, "hex20" ) == 0) eshape = ET_HEX20;
else if (strcmp(sztype, "hex27" ) == 0) eshape = ET_HEX27;
else if (strcmp(sztype, "penta6" ) == 0) eshape = ET_PENTA6;
else if (strcmp(sztype, "penta15") == 0) eshape = ET_PENTA15;
else if (strcmp(sztype, "pyra5" ) == 0) eshape = ET_PYRA5;
else if (strcmp(sztype, "pyra13" ) == 0) eshape = ET_PYRA13;
else if (strcmp(sztype, "tet4" ) == 0) eshape = ET_TET4;
else if (strcmp(sztype, "tet5" ) == 0) eshape = ET_TET5;
else if (strcmp(sztype, "tet10" ) == 0) eshape = ET_TET10;
else if (strcmp(sztype, "tet15" ) == 0) eshape = ET_TET15;
else if (strcmp(sztype, "tet20" ) == 0) eshape = ET_TET20;
else if (strcmp(sztype, "quad4" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G8; } // default shell type for quad4
else if (strcmp(sztype, "quad8" ) == 0) { eshape = ET_QUAD8; stype = FE_SHELL_QUAD8G18; } // default shell type for quad8
else if (strcmp(sztype, "quad9" ) == 0) eshape = ET_QUAD9;
else if (strcmp(sztype, "tri3" ) == 0) { eshape = ET_TRI3; stype = FE_SHELL_TRI3G6; } // default shell type for tri3
else if (strcmp(sztype, "tri3s" ) == 0) { eshape = ET_TRI3; stype = FE_SHELL_TRI3G3; } // should only be used for rigid shells
else if (strcmp(sztype, "tri6" ) == 0) { eshape = ET_TRI6; stype = FE_SHELL_TRI6G14; } // default shell type for tri6
else if (strcmp(sztype, "q4eas" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G8; m_default_shell = EAS_SHELL; } // default shell type for q4eas
else if (strcmp(sztype, "q4ans" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G8; m_default_shell = ANS_SHELL; } // default shell type for q4ans
else if (strcmp(sztype, "q4s" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G4; m_default_shell = -1; } // should only be used for rigid shells
else if (strcmp(sztype, "truss2" ) == 0) eshape = ET_TRUSS2;
else if (strcmp(sztype, "line2" ) == 0) eshape = ET_TRUSS2;
else if (strcmp(sztype, "line3" ) == 0) eshape = ET_LINE3;
else if (strcmp(sztype, "ut4" ) == 0) { eshape = ET_TET4; m_but4 = true; }
else
{
// new way for defining element type and integration rule at the same time
// this is useful for multi-step analyses where the geometry is read in before the control section.
if (strcmp(sztype, "TET4G4" ) == 0) { eshape = ET_TET4 ; m_ntet4 = FE_TET4G4; }
else if (strcmp(sztype, "TET10G4" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G4; }
else if (strcmp(sztype, "TET10G8" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G8; }
else if (strcmp(sztype, "TET10GL11" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10GL11; }
else if (strcmp(sztype, "TET10G4_S3" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G4; m_ntri6 = FE_TRI6G3; }
else if (strcmp(sztype, "TET10G8_S3" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G8; m_ntri6 = FE_TRI6G3; }
else if (strcmp(sztype, "TET10GL11_S3") == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10GL11; m_ntri6 = FE_TRI6G3; }
else if (strcmp(sztype, "TET10G4_S4" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G4; m_ntri6 = FE_TRI6G4; }
else if (strcmp(sztype, "TET10G8_S4" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G8; m_ntri6 = FE_TRI6G4; }
else if (strcmp(sztype, "TET10GL11_S4") == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10GL11; m_ntri6 = FE_TRI6G4; }
else if (strcmp(sztype, "TET10G4_S7" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G4; m_ntri6 = FE_TRI6G7; }
else if (strcmp(sztype, "TET10G8_S7" ) == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10G8; m_ntri6 = FE_TRI6G7; }
else if (strcmp(sztype, "TET10GL11_S7") == 0) { eshape = ET_TET10; m_ntet10 = FE_TET10GL11; m_ntri6 = FE_TRI6G7; }
else if (strcmp(sztype, "TET15G8" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G8; }
else if (strcmp(sztype, "TET15G11" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G11; }
else if (strcmp(sztype, "TET15G15" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G15; }
else if (strcmp(sztype, "TET15G8_S3" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G8; m_ntri7 = FE_TRI7G3; }
else if (strcmp(sztype, "TET15G11_S3" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G11; m_ntri7 = FE_TRI7G3; }
else if (strcmp(sztype, "TET15G15_S3" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G15; m_ntri7 = FE_TRI7G3; }
else if (strcmp(sztype, "TET15G8_S4" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G8; m_ntri7 = FE_TRI7G4; }
else if (strcmp(sztype, "TET15G11_S4" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G11; m_ntri7 = FE_TRI7G4; }
else if (strcmp(sztype, "TET15G15_S4" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G15; m_ntri7 = FE_TRI7G4; }
else if (strcmp(sztype, "TET15G8_S7" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G8; m_ntri7 = FE_TRI7G7; }
else if (strcmp(sztype, "TET15G11_S7" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G11; m_ntri7 = FE_TRI7G7; }
else if (strcmp(sztype, "TET15G15_S7" ) == 0) { eshape = ET_TET15; m_ntet15 = FE_TET15G15; m_ntri7 = FE_TRI7G7; }
else if (strcmp(sztype, "PENTA15G8" ) == 0) { eshape = ET_PENTA15; stype = FE_PENTA15G8; }
else if (strcmp(sztype, "HEX20G8" ) == 0) { eshape = ET_HEX20; stype = FE_HEX20G8; }
else if (strcmp(sztype, "QUAD4G8" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G8; }
else if (strcmp(sztype, "QUAD4G12" ) == 0) { eshape = ET_QUAD4; stype = FE_SHELL_QUAD4G12; }
else if (strcmp(sztype, "QUAD8G18" ) == 0) { eshape = ET_QUAD8; stype = FE_SHELL_QUAD8G18; }
else if (strcmp(sztype, "QUAD8G27" ) == 0) { eshape = ET_QUAD8; stype = FE_SHELL_QUAD8G27; }
else if (strcmp(sztype, "TRI3G6" ) == 0) { eshape = ET_TRI3; stype = FE_SHELL_TRI3G6; }
else if (strcmp(sztype, "TRI3G9" ) == 0) { eshape = ET_TRI3; stype = FE_SHELL_TRI3G9; }
else if (strcmp(sztype, "TRI6G14" ) == 0) { eshape = ET_TRI6; stype = FE_SHELL_TRI6G14; }
else if (strcmp(sztype, "TRI6G21" ) == 0) { eshape = ET_TRI6; stype = FE_SHELL_TRI6G21; }
else if (strcmp(sztype, "HEX8G1" ) == 0) { eshape = ET_HEX8; m_nhex8 = FE_HEX8G1; }
else if (strcmp(sztype, "HEX8G8" ) == 0) { eshape = ET_HEX8; m_nhex8 = FE_HEX8G8; }
else if (strcmp(sztype, "HEX8G6" ) == 0) { eshape = ET_HEX8; m_nhex8 = FE_HEX8RI; }
else
{
assert(false);
}
}
// this is a hack to choose between 2D elements and shell elements.
// NOTE: This is only used by quad/tri elements.
// TODO: find a better way
int NDIM = 3;
if (GetModuleName() == "fluid") NDIM = 2;
// determine the element type
FE_Element_Type etype = FE_ELEM_INVALID_TYPE;
switch (eshape)
{
case ET_HEX8 : etype = m_nhex8; break;
case ET_PENTA6 : etype = FE_PENTA6G6; break;
case ET_PENTA15: etype = FE_PENTA15G21; break;
case ET_PYRA5 : etype = FE_PYRA5G8; break;
case ET_PYRA13 : etype = FE_PYRA13G8; break;
case ET_TET4 : etype = m_ntet4; break;
case ET_TET5 : etype = FE_TET5G4; break;
case ET_TET10 : etype = m_ntet10; break;
case ET_TET15 : etype = m_ntet15; break;
case ET_TET20 : etype = m_ntet20; break;
case ET_HEX20 : etype = (stype == FE_HEX20G8 ? FE_HEX20G8 : FE_HEX20G27); break;
case ET_HEX27 : etype = FE_HEX27G27; break;
case ET_QUAD4 : etype = (NDIM == 3 ? stype : FE2D_QUAD4G4); break;
case ET_TRI3 : etype = (NDIM == 3 ? stype : FE2D_TRI3G1); break;
case ET_TRI6 : etype = (NDIM == 3 ? stype : FE2D_TRI6G3); break;
case ET_QUAD8 : etype = (NDIM == 3 ? stype : FE2D_QUAD8G9); break;
case ET_QUAD9 : etype = FE2D_QUAD9G9; break;
case ET_TRUSS2 : etype = FE_TRUSS; break;
case ET_LINE3 : etype = FE_BEAM3G2; break;
default:
assert(false);
}
// determine the element class
FE_Element_Class eclass = FEElementLibrary::GetElementClass(etype);
// return the spec
FE_Element_Spec spec;
spec.eclass = eclass;
spec.eshape = eshape;
spec.etype = etype;
// set three-field flag
switch (eshape)
{
case ET_HEX8 : spec.m_bthree_field = m_b3field_hex; break;
case ET_PENTA6 : spec.m_bthree_field = m_b3field_hex; break;
case ET_PYRA5 : spec.m_bthree_field = m_b3field_hex; break;
case ET_TET4 : spec.m_bthree_field = m_b3field_tet; break;
case ET_TET5 : spec.m_bthree_field = m_b3field_tet; break;
case ET_TET10 : spec.m_bthree_field = m_b3field_tet; break;
case ET_TET15 : spec.m_bthree_field = m_b3field_tet; break;
case ET_TET20 : spec.m_bthree_field = m_b3field_tet; break;
case ET_QUAD4 : spec.m_bthree_field = m_b3field_shell || m_b3field_quad; break;
case ET_TRI3 : spec.m_bthree_field = m_b3field_shell || m_b3field_tri; break;
case ET_TRI6 : spec.m_bthree_field = m_b3field_shell; break;
case ET_QUAD8 : spec.m_bthree_field = m_b3field_shell; break;
case ET_QUAD9 : spec.m_bthree_field = m_b3field_shell; break;
}
spec.m_but4 = m_but4;
spec.m_ut4_alpha = m_ut4_alpha;
spec.m_ut4_bdev = m_ut4_bdev;
spec.m_shell_formulation = m_default_shell;
spec.m_shell_norm_nodal = m_shell_norm_nodal;
// Make sure this is a valid element specification
assert(FEElementLibrary::IsValid(spec));
return spec;
}
void FEModelBuilder::AddMappedParameter(FEParam* p, FECoreBase* parent, const char* szmap, int index)
{
MappedParameter mp;
mp.pp = p;
mp.pc = parent;
mp.szname = strdup(szmap);
mp.index = index;
m_mappedParams.push_back(mp);
}
void FEModelBuilder::AddMeshDataGenerator(FEMeshDataGenerator* gen, FEDataMap* pmap, FEParamDouble* pp)
{
m_mapgen.push_back(DataGen{ gen, pmap, pp });
}
void FEModelBuilder::ApplyParameterMaps()
{
FEMesh& mesh = m_fem.GetMesh();
for (int i = 0; i < m_mappedParams.size(); ++i)
{
MappedParameter& mp = m_mappedParams[i];
FEParam& p = *mp.pp;
FEDataMap* data = (FEDataMap*)mesh.FindDataMap(mp.szname);
if (data == nullptr)
{
stringstream ss;
ss << "Can't find map \"" << mp.szname << "\" for parameter \"" << p.name() << "\"";
throw std::runtime_error(ss.str());
}
FEItemList* itemList = data->GetItemList();
// find the map of this parameter
if (p.type() == FE_PARAM_DOUBLE_MAPPED)
{
FEParamDouble& v = p.value<FEParamDouble>(mp.index);
FEMappedValue* map = fecore_alloc(FEMappedValue, &m_fem);
if (data->DataType() != FE_DOUBLE)
{
std::stringstream ss;
ss << "Cannot assign map \"" << data->GetName() << "\" to parameter \"" << p.name() << "\" : bad data type";
string err = ss.str();
throw std::runtime_error(err.c_str());
}
map->setDataMap(data);
v.setValuator(map);
v.SetItemList(itemList);
}
else if (p.type() == FE_PARAM_VEC3D_MAPPED)
{
FEParamVec3& v = p.value<FEParamVec3>();
FEMappedValueVec3* map = fecore_alloc(FEMappedValueVec3, &m_fem);
if (data->DataType() != FE_VEC3D)
{
std::stringstream ss;
ss << "Cannot assign map \"" << data->GetName() << "\" to parameter \"" << p.name() << "\" : bad data type";
string err = ss.str();
throw std::runtime_error(err.c_str());
}
map->setDataMap(data);
v.setValuator(map);
v.SetItemList(itemList);
}
else if (p.type() == FE_PARAM_MAT3D_MAPPED)
{
FEParamMat3d& v = p.value<FEParamMat3d>();
FEMappedValueMat3d* map = fecore_alloc(FEMappedValueMat3d, &m_fem);
if (data->DataType() != FE_MAT3D)
{
std::stringstream ss;
ss << "Cannot assign map \"" << data->GetName() << "\" to parameter \"" << p.name() << "\" : bad data type";
string err = ss.str();
throw std::runtime_error(err.c_str());
}
map->setDataMap(data);
v.setValuator(map);
v.SetItemList(itemList);
}
else if (p.type() == FE_PARAM_MAT3DS_MAPPED)
{
FEParamMat3ds& v = p.value<FEParamMat3ds>();
FEMappedValueMat3ds* map = fecore_alloc(FEMappedValueMat3ds, &m_fem);
if (data->DataType() != FE_MAT3DS)
{
std::stringstream ss;
ss << "Cannot assign map \"" << data->GetName() << "\" to parameter \"" << p.name() << "\" : bad data type";
string err = ss.str();
throw std::runtime_error(err.c_str());
}
map->setDataMap(data);
v.setValuator(map);
v.SetItemList(itemList);
}
else
{
assert(false);
}
}
}
FENodeSet* FEModelBuilder::FindNodeSet(const string& setName)
{
FEMesh& mesh = m_fem.GetMesh();
FENodeSet* nodeSet = nullptr;
if (setName.compare(0, 9, "@surface:") == 0)
{
// see if we can find a surface
string surfName = setName.substr(9);
FEFacetSet* surf = mesh.FindFacetSet(surfName);
if (surf == nullptr) return nullptr;
// we might have been here before. If so, we already create a nodeset
// with the same name as the surface, so look for that first.
nodeSet = mesh.FindNodeSet(surfName);
if (nodeSet) return nodeSet;
// okay, first time here, so let's create a node set from this surface
FENodeList nodeList = surf->GetNodeList();
nodeSet = new FENodeSet(&m_fem);
nodeSet->Add(nodeList);
nodeSet->SetName(surfName);
mesh.AddNodeSet(nodeSet);
}
else if (setName.compare(0, 6, "@edge:") == 0)
{
// see if we can find an edge
string edgeName = setName.substr(6);
FESegmentSet* edge = mesh.FindSegmentSet(edgeName);
if (edge == nullptr) return nullptr;
// we might have been here before. If so, we already create a nodeset
// with the same name as the edge, so look for that first.
nodeSet = mesh.FindNodeSet(edgeName);
if (nodeSet) return nodeSet;
// okay, first time here, so let's create a node set from this surface
FENodeList nodeList = edge->GetNodeList();
nodeSet = new FENodeSet(&m_fem);
nodeSet->Add(nodeList);
nodeSet->SetName(edgeName);
mesh.AddNodeSet(nodeSet);
}
else if (setName.compare(0, 10, "@elem_set:") == 0)
{
// see if we can find an element set
string esetName = setName.substr(10);
FEElementSet* part = mesh.FindElementSet(esetName);
if (part == nullptr) return nullptr;
// we might have been here before. If so, we already create a nodeset
// with the same name as the surface, so look for that first.
nodeSet = mesh.FindNodeSet(esetName);
if (nodeSet) return nodeSet;
// okay, first time here, so let's create a node set from this element set
FENodeList nodeList = part->GetNodeList();
nodeSet = new FENodeSet(&m_fem);
nodeSet->Add(nodeList);
nodeSet->SetName(esetName);
mesh.AddNodeSet(nodeSet);
}
else if (setName.compare(0, 11, "@part_list:") == 0)
{
// see if we can find an element set
FEElementSet* part = mesh.FindElementSet(setName);
if (part == nullptr) return nullptr;
// we might have been here before. If so, we already create a nodeset
// with the same name as the surface, so look for that first.
nodeSet = mesh.FindNodeSet(setName);
if (nodeSet) return nodeSet;
// okay, first time here, so let's create a node set from this element set
FENodeList nodeList = part->GetNodeList();
nodeSet = new FENodeSet(&m_fem);
nodeSet->Add(nodeList);
nodeSet->SetName(setName);
mesh.AddNodeSet(nodeSet);
}
else nodeSet = mesh.FindNodeSet(setName);
return nodeSet;
}
void FEModelBuilder::MapLoadCurveToFunction(FEPointFunction* pf, int lc, double scale)
{
MapLCToFunction m = { lc, scale, pf };
m_lc2fnc.push_back(m);
}
void FEModelBuilder::ApplyLoadcurvesToFunctions()
{
FEModel& fem = m_fem;
for (int i = 0; i < m_lc2fnc.size(); ++i)
{
MapLCToFunction& m = m_lc2fnc[i];
FELoadController* plc = fem.GetLoadController(m.lc); assert(plc);
FELoadCurve* lc = dynamic_cast<FELoadCurve*>(plc);
m.pf->SetInterpolation(lc->GetInterpolation());
m.pf->SetExtendMode(lc->GetExtendMode());
m.pf->SetPoints(lc->GetPoints());
if (m.scale != 1.0) m.pf->Scale(m.scale);
}
}
bool FEModelBuilder::GenerateMeshDataMaps()
{
FEModel& fem = GetFEModel();
FEMesh& mesh = GetMesh();
for (int i = 0; i < m_mapgen.size(); ++i)
{
FEMeshDataGenerator* gen = m_mapgen[i].gen;
// try to initialize the generator
if (gen->Init() == false) return false;
FENodeDataGenerator* ngen = dynamic_cast<FENodeDataGenerator*>(gen);
if (ngen)
{
// see if this map is already defined
string mapName = ngen->GetName();
FENodeDataMap* oldMap = dynamic_cast<FENodeDataMap*>(mesh.FindDataMap(mapName));
if (oldMap) return false;
// generate the node data map
if (ngen->Init() == false) return false;
FEDataMap* map = ngen->Generate();
if (map == nullptr) return false;
map->SetName(mapName);
mesh.AddDataMap(map);
}
FEFaceDataGenerator* fgen = dynamic_cast<FEFaceDataGenerator*>(gen);
if (fgen)
{
// see if this map is already defined
string mapName = fgen->GetName();
FESurfaceMap* oldMap = dynamic_cast<FESurfaceMap*>(mesh.FindDataMap(mapName));
if (oldMap) return false;
// generate data
if (fgen->Init() == false) return false;
FEDataMap* map = fgen->Generate();
if (map == nullptr) return false;
map->SetName(mapName);
mesh.AddDataMap(map);
}
FEElemDataGenerator* egen = dynamic_cast<FEElemDataGenerator*>(gen);
if (egen)
{
if (egen->Init() == false) return false;
// generate the data
FEDomainMap* map = dynamic_cast<FEDomainMap*>(egen->Generate());
if (map == nullptr) return false;
// see if this map is already defined
string mapName = gen->GetName();
FEDomainMap* oldMap = dynamic_cast<FEDomainMap*>(mesh.FindDataMap(mapName));
if (oldMap)
{
// it is, so merge it
oldMap->Merge(*map);
// we can now delete this map
delete map;
}
else
{
// nope, so add it
map->SetName(mapName);
mesh.AddDataMap(map);
// apply the map
FEParamDouble* pp = m_mapgen[i].pp;
if (pp)
{
FEMappedValue* val = fecore_alloc(FEMappedValue, &fem);
val->setDataMap(map);
pp->setValuator(val);
}
}
}
}
return true;
}
// finish the build process
bool FEModelBuilder::Finish()
{
ApplyLoadcurvesToFunctions();
if (GenerateMeshDataMaps() == false) return false;
ApplyParameterMaps();
return true;
}
FEBModel& FEModelBuilder::GetFEBModel()
{
return m_feb;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioLoadDataSection.h | .h | 2,267 | 63 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// LoadData Section
class FEBioLoadDataSection : public FEFileSection
{
public:
FEBioLoadDataSection(FEFileImport* pim);
void Parse(XMLTag& tag);
// Set the redefine curves flag.
// When this flag is set, curves can be redefined by using an existing ID
void SetRedefineCurvesFlag(bool b) { m_redefineCurves = b; }
protected:
bool m_redefineCurves; // flag to allow redefining curves
};
//-----------------------------------------------------------------------------
// LoadData Section
class FEBioLoadDataSection3 : public FEFileSection
{
public:
FEBioLoadDataSection3(FEFileImport* pim);
void Parse(XMLTag& tag);
// Set the redefine curves flag.
// When this flag is set, curves can be redefined by using an existing ID
void SetRedefineCurvesFlag(bool b) { m_redefineCurves = b; }
protected:
bool m_redefineCurves; // flag to allow redefining curves
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioConstraintsSection.cpp | .cpp | 22,529 | 776 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioConstraintsSection.h"
#include "FECore/FEModel.h"
#include "FECore/FECoreKernel.h"
#include <FECore/FESurfaceConstraint.h>
#include <FECore/FEBodyConstraint.h>
#include <FECore/FENodeSetConstraint.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FEMesh.h>
#include <FECore/FESurface.h>
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FEInitialCondition.h>
void FEBioConstraintsSection1x::Parse(XMLTag &tag)
{
// make sure there is something to read
if (tag.isleaf()) return;
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
++tag;
do
{
if (tag == "rigid_body")
{
ParseRigidConstraint(tag);
}
else if (tag == "constraint")
{
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0)
{
// check the name attribute
const char* szname = tag.AttributeValue("name");
if (szname == 0) throw XMLReader::InvalidAttributeValue(tag, "name", "(unknown)");
// make sure this is a leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// see if we can find this constraint
FEModel& fem = *GetFEModel();
int NLC = fem.NonlinearConstraints();
FENLConstraint* plc = 0;
for (int i = 0; i<NLC; ++i)
{
FENLConstraint* pci = fem.NonlinearConstraint(i);
if (pci->GetName() == szname) { plc = pci; }
}
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "name", szname);
// add this boundary condition to the current step
GetBuilder()->AddComponent(plc);
}
else
{
FENLConstraint* plc = fecore_new<FENLConstraint>(sztype, GetFEModel());
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
const char* szname = tag.AttributeValue("name", true);
if (szname) plc->SetName(szname);
++tag;
do
{
if (ReadParameter(tag, plc) == false)
{
if (tag == "surface")
{
FESurfaceConstraint* psc = dynamic_cast<FESurfaceConstraint*>(plc);
if (psc == 0) throw XMLReader::InvalidTag(tag);
const char* sztype = tag.AttributeValue("type", true);
FESurface* psurf = psc->GetSurface();
if (psurf == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
m.AddSurface(psurf);
// see if the set attribute is defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure this tag does not have any children
if (!tag.isleaf()) throw XMLReader::InvalidTag(tag);
// see if we can find the facet set
FEFacetSet* pset = m.FindFacetSet(szset);
// create a surface from the facet set
if (pset)
{
if (GetBuilder()->BuildSurface(*psurf, *pset, true) == false) throw XMLReader::InvalidTag(tag);
}
else throw XMLReader::InvalidAttributeValue(tag, "set", szset);
}
else ParseSurfaceSection(tag, *psurf, 0, true);
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
} while (!tag.isend());
// add this boundary condition to the current step
GetBuilder()->AddNonlinearConstraint(plc);
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
void FEBioConstraintsSection2::Parse(XMLTag &tag)
{
// make sure there is something to read
if (tag.isleaf()) return;
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
++tag;
do
{
if (tag == "rigid_body")
{
ParseRigidConstraint20(tag);
}
else if (tag == "constraint")
{
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0)
{
// check the name attribute
const char* szname = tag.AttributeValue("name");
if (szname == 0) throw XMLReader::InvalidAttributeValue(tag, "name", "(unknown)");
// make sure this is a leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// see if we can find this constraint
FEModel& fem = *GetFEModel();
int NLC = fem.NonlinearConstraints();
FENLConstraint* plc = 0;
for (int i=0; i<NLC; ++i)
{
FENLConstraint* pci = fem.NonlinearConstraint(i);
if (pci->GetName() == szname) { plc = pci; }
}
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "name", szname);
// add this boundary condition to the current step
GetBuilder()->AddComponent(plc);
}
else
{
FENLConstraint* plc = fecore_new<FENLConstraint>(sztype, GetFEModel());
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
const char* szname = tag.AttributeValue("name", true);
if (szname) plc->SetName(szname);
++tag;
do
{
if (ReadParameter(tag, plc) == false)
{
if (tag == "surface")
{
FESurfaceConstraint* psc = dynamic_cast<FESurfaceConstraint*>(plc);
if (psc == 0) throw XMLReader::InvalidTag(tag);
FESurface* psurf = psc->GetSurface();
if (psurf == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
m.AddSurface(psurf);
// see if the set attribute is defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure this tag does not have any children
if (!tag.isleaf()) throw XMLReader::InvalidTag(tag);
// see if we can find the facet set
FEFacetSet* pset = m.FindFacetSet(szset);
// create a surface from the facet set
if (pset)
{
if (GetBuilder()->BuildSurface(*psurf, *pset, true) == false) throw XMLReader::InvalidTag(tag);
}
else throw XMLReader::InvalidAttributeValue(tag, "set", szset);
}
else ParseSurfaceSection(tag, *psurf, 0, true);
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
// add this boundary condition to the current step
GetBuilder()->AddNonlinearConstraint(plc);
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
void FEBioConstraintsSection25::Parse(XMLTag &tag)
{
// make sure there is something to read
if (tag.isleaf()) return;
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
++tag;
do
{
if (tag == "constraint")
{
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0)
{
// check the name attribute
const char* szname = tag.AttributeValue("name");
if (szname == 0) throw XMLReader::InvalidAttributeValue(tag, "name", "(unknown)");
// make sure this is a leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// see if we can find this constraint
FEModel& fem = *GetFEModel();
int NLC = fem.NonlinearConstraints();
FENLConstraint* plc = 0;
for (int i=0; i<NLC; ++i)
{
FENLConstraint* pci = fem.NonlinearConstraint(i);
if (pci->GetName() == szname) { plc = pci; }
}
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "name", szname);
// add this boundary condition to the current step
GetBuilder()->AddComponent(plc);
}
else
{
FENLConstraint* plc = fecore_new<FENLConstraint>(sztype, GetFEModel());
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
const char* szname = tag.AttributeValue("name", true);
if (szname) plc->SetName(szname);
// get the surface
// Note that not all constraints define a surface
FESurfaceConstraint* psc = dynamic_cast<FESurfaceConstraint*>(plc);
if (psc && psc->GetSurface())
{
FESurface* psurf = psc->GetSurface();
mesh.AddSurface(psurf);
const char* szsurf = tag.AttributeValue("surface");
FEFacetSet* pface = mesh.FindFacetSet(szsurf);
if (pface == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", szsurf);
if (GetBuilder()->BuildSurface(*psurf, *pface, psc->UseNodalIntegration()) == false) throw XMLReader::InvalidAttributeValue(tag, "surface", szsurf);
}
// get the element set
FEBodyConstraint* pbc = dynamic_cast<FEBodyConstraint*>(plc);
if (pbc)
{
// see if a specific domain was referenced
const char* szpart = tag.AttributeValue("elem_set", true);
if (szpart)
{
FEMesh& mesh = fem.GetMesh();
FEElementSet* elset = mesh.FindElementSet(szpart);
if (elset == 0) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szpart);
pbc->SetDomainList(elset);
}
}
// get the nodeset for other constraints
// Note that not all constraints define a nodeset
FENodeSetConstraint* pns = dynamic_cast<FENodeSetConstraint*>(plc);
if (pns && pns->GetNodeSet())
{
FENodeSet* pnset = pns->GetNodeSet();
const char* sznset = tag.AttributeValue("node_set");
FENodeSet* pset = mesh.FindNodeSet(sznset);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sznset);
pnset->Add(pset->GetNodeList());
}
// read the parameter list
ReadParameterList(tag, plc);
// add this constraint to the current step
GetBuilder()->AddNonlinearConstraint(plc);
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioConstraintsSection1x::ParseRigidConstraint(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEModelBuilder& feb = *GetBuilder();
const char* szm = tag.AttributeValue("mat");
assert(szm);
// get the material ID
int nmat = atoi(szm);
if ((nmat <= 0) || (nmat > fem.Materials())) throw XMLReader::InvalidAttributeValue(tag, "mat", szm);
++tag;
do
{
if (strncmp(tag.Name(), "trans_", 6) == 0)
{
const char* szt = tag.AttributeValue("type");
int bc = -1;
if (tag.Name()[6] == 'x') bc = 0;
else if (tag.Name()[6] == 'y') bc = 1;
else if (tag.Name()[6] == 'z') bc = 2;
assert(bc >= 0);
if (strcmp(szt, "prescribed") == 0)
{
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
bool brel = false;
const char* szrel = tag.AttributeValue("relative", true);
if (szrel)
{
if (strcmp(szrel, "true" ) == 0) brel = true;
else if (strcmp(szrel, "false") == 0) brel = false;
else throw XMLReader::InvalidAttributeValue(tag, "relative", szrel);
}
double val = 0.0;
value(tag, val);
FEStepComponent* pDC = fecore_new_class<FEBoundaryCondition>("FERigidPrescribedOld", &fem);
feb.AddRigidComponent(pDC);
pDC->SetParameter("rb", nmat);
pDC->SetParameter("dof", bc);
pDC->SetParameter("relative", brel);
pDC->SetParameter("value", val);
// assign a load curve
if (lc >= 0)
{
FEParam* p = pDC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
}
else if (strcmp(szt, "force") == 0)
{
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
double val = 0.0;
value(tag, val);
FEModelLoad* pFC = nullptr;
if (bc < 3)
{
pFC = fecore_new<FEModelLoad>("rigid_force", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc);
pFC->SetParameter("value", val);
}
else
{
pFC = fecore_new<FEModelLoad>("rigid_moment", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc - 3);
pFC->SetParameter("value", val);
}
feb.AddModelLoad(pFC);
if (lc >= 0)
{
FEParam* p = pFC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (strcmp(szt, "fixed") == 0)
{
FEStepComponent* pBC = fecore_new_class<FEBoundaryCondition>("FERigidFixedBCOld", &fem);
feb.AddRigidComponent(pBC);
pBC->SetParameter("rb", nmat);
vector<int> dofs; dofs.push_back(bc);
pBC->SetParameter("dofs", dofs);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", szt);
}
else if (strncmp(tag.Name(), "rot_", 4) == 0)
{
const char* szt = tag.AttributeValue("type");
int bc = -1;
if (tag.Name()[4] == 'x') bc = 3;
else if (tag.Name()[4] == 'y') bc = 4;
else if (tag.Name()[4] == 'z') bc = 5;
assert(bc >= 0);
if (strcmp(szt, "prescribed") == 0)
{
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
double val = 0.0;
value(tag, val);
FEStepComponent* pDC = fecore_new_class<FEBoundaryCondition>("FERigidPrescribedOld", &fem);
feb.AddRigidComponent(pDC);
pDC->SetParameter("rb", nmat);
pDC->SetParameter("dof", bc);
pDC->SetParameter("value", val);
}
else if (strcmp(szt, "force") == 0)
{
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
double val = 0.0;
value(tag, val);
FEModelLoad* pFC = nullptr;
if (bc < 3)
{
pFC = fecore_new<FEModelLoad>("rigid_force", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc);
pFC->SetParameter("value", val);
}
else
{
pFC = fecore_new<FEModelLoad>("rigid_moment", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc - 3);
pFC->SetParameter("value", val);
}
feb.AddModelLoad(pFC);
if (lc >= 0)
{
FEParam* p = pFC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (strcmp(szt, "fixed") == 0)
{
FEStepComponent* pBC = fecore_new_class<FEBoundaryCondition>("FERigidFixedBCOld", &fem);
feb.AddRigidComponent(pBC);
pBC->SetParameter("rb", nmat);
vector<int> dofs; dofs.push_back(bc);
pBC->SetParameter("dofs", dofs);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", szt);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioConstraintsSection2::ParseRigidConstraint20(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEModelBuilder& feb = *GetBuilder();
const char* szm = tag.AttributeValue("mat");
assert(szm);
// get the material ID
int nmat = atoi(szm);
if ((nmat <= 0) || (nmat > fem.Materials())) throw XMLReader::InvalidAttributeValue(tag, "mat", szm);
++tag;
do
{
if (tag == "prescribed")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the loadcurve
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
// get the (optional) type attribute
bool brel = false;
const char* szrel = tag.AttributeValue("type", true);
if (szrel)
{
if (strcmp(szrel, "relative" ) == 0) brel = true;
else if (strcmp(szrel, "absolute" ) == 0) brel = false;
else throw XMLReader::InvalidAttributeValue(tag, "type", szrel);
}
double val = 0.0;
value(tag, val);
FEStepComponent* pDC = fecore_new_class<FEBoundaryCondition>("FERigidPrescribedOld", &fem);
feb.AddRigidComponent(pDC);
pDC->SetParameter("rb", nmat);
pDC->SetParameter("dof", bc);
pDC->SetParameter("relative", brel);
pDC->SetParameter("value", val);
// assign a load curve
if (lc >= 0)
{
FEParam* p = pDC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (tag == "force")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the type
int ntype = 0; // FERigidBodyForce::FORCE_LOAD;
const char* sztype = tag.AttributeValue("type", true);
if (sztype)
{
if (strcmp(sztype, "ramp" ) == 0) ntype = 2; //FERigidBodyForce::FORCE_TARGET;
else if (strcmp(sztype, "follow") == 0) ntype = 1; //FERigidBodyForce::FORCE_FOLLOW;
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
// get the loadcurve
const char* szlc = tag.AttributeValue("lc", true);
int lc = -1;
if (szlc) lc = atoi(szlc) - 1;
// make sure there is a loadcurve for type=0 forces
if ((ntype == 0)&&(lc==-1)) throw XMLReader::MissingAttribute(tag, "lc");
double val = 0.0;
value(tag, val);
// create the rigid body force
FEModelLoad* pFC = nullptr;
if (bc < 3)
{
pFC = fecore_new<FEModelLoad>("rigid_force", &fem);
pFC->SetParameter("load_type", ntype);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc);
pFC->SetParameter("value", val);
}
else
{
pFC = fecore_new<FEModelLoad>("rigid_moment", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc - 3);
pFC->SetParameter("value", val);
}
feb.AddModelLoad(pFC);
if (lc >= 0)
{
FEParam* p = pFC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (tag == "fixed")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
FEStepComponent* pBC = fecore_new_class<FEBoundaryCondition>("FERigidFixedBCOld", &fem);
feb.AddRigidComponent(pBC);
pBC->SetParameter("rb", nmat);
vector<int> dofs; dofs.push_back(bc);
pBC->SetParameter("dofs", dofs);
}
else if (tag == "initial_velocity")
{
// get the initial velocity
vec3d v;
value(tag, v);
// create the initial condition
FEStepComponent* pic = fecore_new_class<FEInitialCondition>("FERigidBodyVelocity", &fem);
pic->SetParameter("rb", nmat);
pic->SetParameter("value", v);
// add this initial condition to the current step
feb.AddRigidComponent(pic);
}
else if (tag == "initial_angular_velocity")
{
// get the initial angular velocity
vec3d w;
value(tag, w);
// create the initial condition
FEStepComponent* pic = fecore_new_class<FEInitialCondition>("FERigidBodyAngularVelocity", &fem);
pic->SetParameter("rb", nmat);
pic->SetParameter("value", w);
// add to model
feb.AddRigidComponent(pic);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//---------------------------------------------------------------------------------
// parse a surface section for contact definitions
//
bool FEBioConstraintsSection::ParseSurfaceSection(XMLTag &tag, FESurface& s, int nfmt, bool bnodal)
{
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
int NN = m.Nodes();
// count nr of faces
int faces = 0, N, nf[9];
XMLTag t(tag); ++t;
while (!t.isend()) { faces++; ++t; }
// allocate storage for faces
s.Create(faces);
FEModelBuilder* feb = GetBuilder();
// read faces
++tag;
for (int i=0; i<faces; ++i)
{
FESurfaceElement& el = s.Element(i);
// set the element type/integration rule
if (bnodal)
{
if (tag == "quad4") el.SetType(FE_QUAD4NI);
else if (tag == "tri3" ) el.SetType(FE_TRI3NI );
else if (tag == "tri6" ) el.SetType(FE_TRI6NI);
else if (tag == "quad8" ) el.SetType(FE_QUAD8NI);
else if (tag == "quad9" ) el.SetType(FE_QUAD9NI);
else throw XMLReader::InvalidTag(tag);
}
else
{
if (tag == "quad4") el.SetType(FE_QUAD4G4);
else if (tag == "tri3" ) el.SetType(feb->m_ntri3);
else if (tag == "tri6" ) el.SetType(feb->m_ntri6);
else if (tag == "tri7" ) el.SetType(feb->m_ntri7);
else if (tag == "tri10") el.SetType(feb->m_ntri10);
else if (tag == "quad8") el.SetType(FE_QUAD8G9);
else if (tag == "quad9") el.SetType(FE_QUAD9G9);
else throw XMLReader::InvalidTag(tag);
}
N = el.Nodes();
if (nfmt == 0)
{
tag.value(nf, N);
for (int j=0; j<N; ++j)
{
int nid = nf[j]-1;
if ((nid<0)||(nid>= NN)) throw XMLReader::InvalidValue(tag);
el.m_node[j] = nid;
}
}
else if (nfmt == 1)
{
tag.value(nf, 2);
FEElement* pe = m.FindElementFromID(nf[0]);
if (pe)
{
int ne[9];
int nn = pe->GetFace(nf[1]-1, ne);
if (nn != N) throw XMLReader::InvalidValue(tag);
for (int j=0; j<N; ++j) el.m_node[j] = ne[j];
el.m_elem[0].pe = pe;
}
else throw XMLReader::InvalidValue(tag);
}
++tag;
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBModel.h | .h | 8,891 | 339 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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/vec3d.h>
#include <vector>
#include <string>
#include <FECore/FEElement.h>
#include <FECore/FETransform.h>
//-----------------------------------------------------------------------------
class FEModel;
//-----------------------------------------------------------------------------
// This is a helper class for parsing the FEBio input file. It manages the geometry
// of the model as composed of parts. After the Geometry section is read in, call the
// BuildMesh function to generate the mesh for the model.
class FEBModel
{
public:
struct NODE
{
int id; // Nodal ID
vec3d r; // Node position
};
struct ELEMENT
{
int id;
int node[FEElement::MAX_NODES];
};
struct FACET
{
int id;
int node[FEElement::MAX_NODES];
int ntype;
};
struct EDGE
{
int id;
int node[FEElement::MAX_NODES];
int ntype;
};
class Domain
{
public:
Domain();
Domain(const Domain& dom);
Domain(const FE_Element_Spec& spec);
void SetName(const std::string& name);
const std::string& Name() const;
void SetMaterialName(const std::string& name);
const std::string& MaterialName() const;
void SetElementList(const std::vector<ELEMENT>& el);
const std::vector<ELEMENT>& ElementList() const;
int Elements() const { return (int) m_Elem.size(); }
FE_Element_Spec ElementSpec() const { return m_spec; }
void SetElementSpec(FE_Element_Spec spec) { m_spec = spec; }
void Create(int nsize) { m_Elem.resize(nsize); }
void Reserve(int nsize) { m_Elem.reserve(nsize); }
const ELEMENT& GetElement(int i) const { return m_Elem[i]; }
ELEMENT& GetElement(int i) { return m_Elem[i]; }
void AddElement(const ELEMENT& el) { m_Elem.push_back(el); }
private:
FE_Element_Spec m_spec;
std::string m_name;
std::string m_matName;
std::vector<ELEMENT> m_Elem;
public:
double m_defaultShellThickness;
};
class PartList;
// a surface can be defined explicitly (using a list of facets)
// or implicitly via a part list (in this case, the facet list will be empty
// and the part list can be found via GetPartList()
class Surface
{
public:
Surface();
Surface(const Surface& surf);
Surface(const std::string& name);
Surface(const std::string& name, PartList* partList);
void SetName(const std::string& name);
const std::string& Name() const;
void SetFacetList(const std::vector<FACET>& el);
const std::vector<FACET>& FacetList() const;
void Create(int n) { m_Face.resize(n); }
int Facets() const { return (int) m_Face.size(); }
FACET& GetFacet(int i) { return m_Face[i]; }
PartList* GetPartList() { return m_partList; }
private:
std::string m_name;
std::vector<FACET> m_Face;
PartList* m_partList;
};
class NodeSet
{
public:
NodeSet();
NodeSet(const NodeSet& set);
NodeSet(const std::string& name);
void SetName(const std::string& name);
const std::string& Name() const;
void SetNodeList(const std::vector<int>& node);
const std::vector<int>& NodeList() const;
private:
std::string m_name;
std::vector<int> m_node;
};
class EdgeSet
{
public:
EdgeSet();
EdgeSet(const EdgeSet& set);
EdgeSet(const std::string& name);
void SetName(const std::string& name);
const std::string& Name() const;
void SetEdgeList(const std::vector<EDGE>& edge);
const std::vector<EDGE>& EdgeList() const;
int Edges() const { return (int)m_edge.size(); }
EDGE& Edge(int i) { return m_edge[i]; }
private:
std::string m_name;
std::vector<EDGE> m_edge;
};
class ElementSet
{
public:
ElementSet();
ElementSet(const ElementSet& set);
ElementSet(const std::string& name);
void SetName(const std::string& name);
const std::string& Name() const;
void SetElementList(const std::vector<int>& elem);
const std::vector<int>& ElementList() const;
private:
std::string m_name;
std::vector<int> m_elem;
};
class PartList
{
public:
PartList();
PartList(const std::string& name);
void SetName(const std::string& name);
const std::string& Name() const;
void SetPartList(const std::vector<std::string>& parts);
const std::vector<std::string>& GetPartList() const;
size_t Parts() const { return m_parts.size(); }
const std::string& PartName(size_t n) const { return m_parts[n]; }
private:
std::string m_name;
std::vector<std::string> m_parts;
};
class SurfacePair
{
public:
SurfacePair();
SurfacePair(const SurfacePair& surfPair);
const std::string& Name() const;
public:
std::string m_name;
std::string m_primary;
std::string m_secondary;
};
class DiscreteSet
{
public:
struct ELEM
{
int node[2];
};
public:
DiscreteSet();
DiscreteSet(const DiscreteSet& set);
void SetName(const std::string& name);
const std::string& Name() const;
void AddElement(int n0, int n1);
const std::vector<ELEM>& ElementList() const;
private:
std::string m_name;
std::vector<ELEM> m_elem;
};
class Part
{
public:
Part();
Part(const std::string& name);
Part(const Part& part);
~Part();
void SetName(const std::string& name);
const std::string& Name() const;
void AddNodes(const std::vector<NODE>& nodes);
int Domains() const { return (int)m_Dom.size(); }
void AddDomain(Domain* dom);
const Domain& GetDomain(int i) const { return *m_Dom[i]; }
Domain* FindDomain(const std::string& name);
int Surfaces() const { return (int) m_Surf.size(); }
void AddSurface(Surface* surf);
Surface* GetSurface(int i) { return m_Surf[i]; }
Surface* FindSurface(const std::string& name);
int NodeSets() const { return (int) m_NSet.size(); }
void AddNodeSet(NodeSet* nset) { m_NSet.push_back(nset); }
NodeSet* GetNodeSet(int i) { return m_NSet[i]; }
NodeSet* FindNodeSet(const std::string& name);
int EdgeSets() const { return (int)m_LSet.size(); }
void AddEdgeSet(EdgeSet* cset) { m_LSet.push_back(cset); }
EdgeSet* GetEdgeSet(int i) { return m_LSet[i]; }
EdgeSet* FindEdgeSet(const std::string& name);
int ElementSets() const { return (int) m_ESet.size(); }
void AddElementSet(ElementSet* eset) { m_ESet.push_back(eset); }
ElementSet* GetElementSet(int i) { return m_ESet[i]; }
ElementSet* FindElementSet(const std::string& name);
int PartLists() const { return (int)m_PList.size(); }
void AddPartList(PartList* plist) { m_PList.push_back(plist); }
PartList* GetPartList(int i) { return m_PList[i]; }
PartList* FindPartList(const std::string& name);
int SurfacePairs() const { return (int)m_SurfPair.size(); }
void AddSurfacePair(SurfacePair* sp) { m_SurfPair.push_back(sp); }
SurfacePair* GetSurfacePair(int i) { return m_SurfPair[i]; }
int DiscreteSets() const { return (int)m_DiscSet.size(); }
void AddDiscreteSet(DiscreteSet* sp) { m_DiscSet.push_back(sp); }
DiscreteSet* GetDiscreteSet(int i) { return m_DiscSet[i]; }
int Nodes() const { return (int) m_Node.size(); }
NODE& GetNode(int i) { return m_Node[i]; }
private:
std::string m_name;
std::vector<NODE> m_Node;
std::vector<Domain*> m_Dom;
std::vector<Surface*> m_Surf;
std::vector<NodeSet*> m_NSet;
std::vector<EdgeSet*> m_LSet;
std::vector<ElementSet*> m_ESet;
std::vector<PartList*> m_PList;
std::vector<SurfacePair*> m_SurfPair;
std::vector<DiscreteSet*> m_DiscSet;
};
public:
FEBModel();
~FEBModel();
size_t Parts() const;
Part* GetPart(int i);
Part* AddPart(const std::string& name);
void AddPart(Part* part);
Part* FindPart(const std::string& name);
bool BuildPart(FEModel& fem, Part& part, bool buildDomains = true, const Transform& T = Transform());
private:
std::vector<Part*> m_Part;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioGeometrySection.cpp | .cpp | 49,487 | 1,900 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioGeometrySection.h"
#include "FECore/FESolidDomain.h"
#include "FECore/FEModel.h"
#include "FECore/FEMaterial.h"
#include "FECore/FECoreKernel.h"
#include <FECore/FENodeNodeList.h>
//-----------------------------------------------------------------------------
bool FEBioGeometrySection::ReadElement(XMLTag &tag, FEElement& el, int nid)
{
el.SetID(nid);
int n[FEElement::MAX_NODES];
int m = tag.value(n, el.Nodes());
if (m != el.Nodes()) return false;
GetBuilder()->GlobalToLocalID(n, el.Nodes(), el.m_node);
return true;
}
//=============================================================================
// FEBioGeometrySection1x
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioGeometrySection1x::Parse(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
feb->m_maxid = 0;
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection(tag);
else if (tag == "Elements" ) ParseElementSection(tag);
else if (tag == "ElementData") ParseElementDataSection(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// At this point the mesh is completely read in.
// Now we can allocate the degrees of freedom.
// NOTE: We do this here since the mesh no longer automatically allocates the dofs.
// At some point I want to be able to read the mesh before deciding any physics.
// When that happens I'll have to move this elsewhere.
FEModel& fem = *GetFEModel();
int MAX_DOFS = fem.GetDOFS().GetTotalDOFS();
fem.GetMesh().SetDOFS(MAX_DOFS);
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection1x::ParseNodeSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// get the largest nodal ID
// (It is assumed that nodes are sorted by ID so the last node should have the largest ID)
int max_id = 0;
if (N0 > 0) max_id = mesh.Node(N0 - 1).GetID();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szl = tag.AttributeValue("set", true);
FENodeSet* ps = 0;
if (szl)
{
ps = new FENodeSet(&fem);
ps->SetName(szl);
mesh.AddNodeSet(ps);
}
// resize node's array
mesh.AddNodes(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FENode& node = mesh.Node(N0 + i);
value(tag, node.m_r0);
node.m_rt = node.m_r0;
// get the nodal ID
int nid = -1;
tag.AttributeValue("id", nid);
// Make sure it is valid
if (nid <= max_id) throw XMLReader::InvalidAttributeValue(tag, "id");
// set the ID
node.SetID(nid);
max_id = nid;
// go on to the next node
++tag;
}
// If a node set is defined add these nodes to the node-set
if (ps)
{
for (int i = 0; i<nodes; ++i) ps->Add(N0 + i);
}
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection1x::ParseElementSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// first we need to figure out how many elements
// and how many domains there are
vector<FEDOMAIN> dom;
vector<int> ED; ED.reserve(1000);
XMLTag t(tag); ++t;
int elems = 0, i;
while (!t.isend())
{
// get the material ID
const char* szmat = t.AttributeValue("mat");
int nmat = atoi(szmat) - 1;
if ((nmat < 0) || (nmat >= fem.Materials())) throw FEBioImport::InvalidMaterial(elems + 1);
// get the element type
FE_Element_Spec spec = GetBuilder()->ElementSpec(t.Name());
if (FEElementLibrary::IsValid(spec) == false) throw FEBioImport::InvalidElementType();
// get the element ID
int nid = -1;
t.AttributeValue("id", nid);
// keep track of the largest element ID
if (nid > GetBuilder()->m_maxid) GetBuilder()->m_maxid = nid;
// find a domain for this element
int ndom = -1;
for (i = 0; i<(int)dom.size(); ++i)
{
FEDOMAIN& d = dom[i];
if ((d.mat == nmat) && (d.elem.eshape == spec.eshape))
{
ndom = i;
d.nel++;
break;
}
}
if (ndom == -1)
{
FEDOMAIN d;
d.mat = nmat;
d.elem = spec;
d.nel = 1;
ndom = (int)dom.size();
dom.push_back(d);
}
ED.push_back(ndom);
elems++;
++t;
}
FECoreKernel& febio = FECoreKernel::GetInstance();
// create the domains
for (i = 0; i<(int)dom.size(); ++i)
{
FEDOMAIN& d = dom[i];
// get material class
FEMaterial* pmat = fem.GetMaterial(d.mat);
// create the new domain
FEDomain* pdom = GetBuilder()->CreateDomain(d.elem, pmat);
if (pdom == 0) throw FEBioImport::FailedCreatingDomain();
// add it to the mesh
assert(d.nel);
pdom->Create(d.nel, d.elem);
mesh.AddDomain(pdom);
// we reset the nr of elements since we'll be using
// that variable is a counter in the next loop
d.nel = 0;
}
// read element data
++tag;
int nid = 1;
for (i = 0; i<elems; ++i, ++nid)
{
int nd = ED[i];
int ne = dom[nd].nel++;
// get the domain to which this element belongs
FEDomain& domi = mesh.Domain(nd);
// get the material ID
int nmat = atoi(tag.AttributeValue("mat")) - 1;
domi.SetMatID(nmat);
// get the material class
FEMaterial* pmat = fem.GetMaterial(nmat);
assert(pmat == domi.GetMaterial());
// determine element shape
FE_Element_Spec espec = GetBuilder()->ElementSpec(tag.Name());
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
if (espec.etype != dom[ED[i]].elem.etype) throw XMLReader::InvalidTag(tag);
if (ReadElement(tag, domi.ElementRef(ne), nid) == false) throw XMLReader::InvalidValue(tag);
// go to next tag
++tag;
}
// assign material point data
for (i = 0; i<mesh.Domains(); ++i)
{
FEDomain& d = mesh.Domain(i);
d.CreateMaterialPointData();
}
}
//-----------------------------------------------------------------------------
void set_element_fiber(FEElement& el, const vec3d& v, int ncomp)
{
// normalize fiber
vec3d a = v;
a.unit();
// set up a orthonormal coordinate system
vec3d b(0, 1, 0);
if (fabs(fabs(a*b) - 1) < 1e-7) b = vec3d(0, 0, 1);
vec3d c = a^b;
b = c^a;
// make sure they are unit vectors
b.unit();
c.unit();
for (int i = 0; i<el.GaussPoints(); ++i)
{
FEMaterialPoint* mp = (ncomp == -1) ? el.GetMaterialPoint(i) : el.GetMaterialPoint(i)->GetPointData(ncomp);
/*
FEElasticMaterialPoint& pt = *mp->ExtractData<FEElasticMaterialPoint>();
mat3d& m = pt.m_Q;
m.zero();
m[0][0] = a.x; m[0][1] = b.x; m[0][2] = c.x;
m[1][0] = a.y; m[1][1] = b.y; m[1][2] = c.y;
m[2][0] = a.z; m[2][1] = b.z; m[2][2] = c.z;
*/
}
}
//-----------------------------------------------------------------------------
void set_element_mat_axis(FEElement& el, const vec3d& v1, const vec3d& v2, int ncomp)
{
vec3d a = v1;
vec3d d = v2;
vec3d c = a^d;
vec3d b = c^a;
// normalize
a.unit();
b.unit();
c.unit();
// assign to element
for (int i = 0; i<el.GaussPoints(); ++i)
{
FEMaterialPoint* mp = (ncomp == -1) ? el.GetMaterialPoint(i) : el.GetMaterialPoint(i)->GetPointData(ncomp);
// FEElasticMaterialPoint& pt = *mp->ExtractData<FEElasticMaterialPoint>();
// pt.m_Q = mat3d(a, b, c);
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection1x::ParseElementData(FEElement& el, XMLTag& tag)
{
vec3d a, d;
if (tag == "fiber")
{
// read the fiber direction
value(tag, a);
set_element_fiber(el, a, 0);
}
else if (tag == "mat_axis")
{
++tag;
do
{
if (tag == "a") value(tag, a);
else if (tag == "d") value(tag, d);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
set_element_mat_axis(el, a, d, -1);
}
else if (tag == "thickness")
{
if (el.Class() != FE_ELEM_SHELL) throw XMLReader::InvalidTag(tag);
FEShellElement& shell = static_cast<FEShellElement&> (el);
// read shell thickness
tag.value(&shell.m_h0[0], shell.Nodes());
}
else if (tag == "area")
{
if (el.Class() != FE_ELEM_TRUSS) throw XMLReader::InvalidTag(tag);
FETrussElement& truss = static_cast<FETrussElement&>(el);
// read truss area
value(tag, truss.m_a0);
}
else
{
for (int i = 0; i<el.GaussPoints(); ++i)
{
FEMaterialPoint* pt = el.GetMaterialPoint(i);
// TODO: Material point parameters are no longer supported so I need to reimplement this
/* while (pt)
{
FEParameterList& pl = pt->GetParameterList();
if (ReadParameter(tag, pl)) break;
bool tagFound = false;
for (int i = 0; i<pt->Components(); ++i)
{
FEParameterList& pl = pt->GetPointData(i)->GetParameterList();
if (ReadParameter(tag, pl))
{
tagFound = true;
break;
}
}
if (tagFound) break;
pt = pt->Next();
if (pt == 0) throw XMLReader::InvalidTag(tag);
}
*/ }
}
}
//-----------------------------------------------------------------------------
//! Reads the ElementData section from the FEBio input file
void FEBioGeometrySection1x::ParseElementDataSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the total nr of elements
int nelems = mesh.Elements();
//make sure we've read the element section
if (nelems == 0) throw XMLReader::InvalidTag(tag);
// create the pelem array
vector<FEElement*> pelem;
pelem.assign(nelems, static_cast<FEElement*>(0));
for (int nd = 0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
for (int i = 0; i<d.Elements(); ++i)
{
FEElement& el = d.ElementRef(i);
assert(pelem[el.GetID() - 1] == 0);
pelem[el.GetID() - 1] = ⪙
}
}
// read additional element data
++tag;
do
{
// make sure this is an "element" tag
if (tag == "element")
{
// get the element number
const char* szid = tag.AttributeValue("id");
int n = atoi(szid) - 1;
// make sure the number is valid
if ((n<0) || (n >= nelems)) throw XMLReader::InvalidAttributeValue(tag, "id", szid);
// get a pointer to the element
FEElement* pe = pelem[n];
++tag;
do
{
ParseElementData(*pe, tag);
++tag;
} while (!tag.isend());
}
else if (tag == "elset")
{
const char* szname = tag.AttributeValue("set");
// find domain with this name
FEElementSet* pset = mesh.FindElementSet(szname);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szname);
++tag;
do
{
int n = pset->Elements();
for (int i = 0; i<n; ++i)
{
// get a pointer to the element
int nid = (*pset)[i] - 1;
FEElement* pe = pelem[nid];
ParseElementData(*pe, tag);
}
++tag;
} while (!tag.isend());
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection1x::ParseNodeSetSection(XMLTag& tag)
{
// read the node set
FENodeSet* pns = GetFEBioImport()->ParseNodeSet(tag, "set");
if (pns == 0) throw XMLReader::InvalidTag(tag);
}
//=============================================================================
// FEBioGeometrySection2
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioGeometrySection2::Parse(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
feb->m_maxid = 0;
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection (tag);
else if (tag == "Elements" ) ParseElementSection (tag);
else if (tag == "NodeSet" ) ParseNodeSetSection (tag);
else if (tag == "Surface" ) ParseSurfaceSection (tag);
else if (tag == "Edge" ) ParseEdgeSection (tag);
else if (tag == "ElementSet" ) ParseElementSetSection (tag);
else if (tag == "ElementData") ParseElementDataSection(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// At this point the mesh is completely read in.
// Now we can allocate the degrees of freedom.
// NOTE: We do this here since the mesh no longer automatically allocates the dofs.
// At some point I want to be able to read the mesh before deciding any physics.
// When that happens I'll have to move this elsewhere.
FEModel& fem = *GetFEModel();
int MAX_DOFS = fem.GetDOFS().GetTotalDOFS();
fem.GetMesh().SetDOFS(MAX_DOFS);
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection2::ParseNodeSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// get the largest nodal ID
// (It is assumed that nodes are sorted by ID so the last node should have the largest ID)
int max_id = 0;
if (N0 > 0) max_id = mesh.Node(N0 - 1).GetID();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szl = tag.AttributeValue("set", true);
FENodeSet* ps = 0;
if (szl)
{
ps = new FENodeSet(&fem);
ps->SetName(szl);
mesh.AddNodeSet(ps);
}
// resize node's array
mesh.AddNodes(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FENode& node = mesh.Node(N0 + i);
value(tag, node.m_r0);
node.m_rt = node.m_r0;
// get the nodal ID
int nid = -1;
tag.AttributeValue("id", nid);
// Make sure it is valid
if (nid <= max_id) throw XMLReader::InvalidAttributeValue(tag, "id");
// set the ID
node.SetID(nid);
max_id = nid;
// go on to the next node
++tag;
}
// If a node set is defined add these nodes to the node-set
if (ps)
{
for (int i = 0; i<nodes; ++i) ps->Add(N0 + i);
}
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection2::ParseElementSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the material ID
const char* szmat = tag.AttributeValue("mat");
// as of 2.5, we allow materials to be referenced by name, so try this first
FEMaterial* pmat = fem.FindMaterial(szmat);
if (pmat == 0)
{
// if we didn't find the material we assume that the material tag uses an ID
int nmat = atoi(szmat) - 1;
if ((nmat < 0) || (nmat >= fem.Materials())) throw FEBioImport::InvalidDomainMaterial();
// get the domain's material class
pmat = fem.GetMaterial(nmat);
}
// get the name
const char* szname = tag.AttributeValue("elset", true);
if (szname == 0) szname = "_unnamed";
// get the element type
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// create the new domain
FEDomain* pdom = GetBuilder()->CreateDomain(espec, pmat);
if (pdom == 0) throw FEBioImport::FailedCreatingDomain();
FEDomain& dom = *pdom;
dom.SetName(szname);
// count elements
int elems = tag.children();
assert(elems);
// add domain it to the mesh
pdom->Create(elems, espec);
pdom->SetMatID(pmat->GetID() - 1);
mesh.AddDomain(pdom);
// for named domains, we'll also create an element set
FEElementSet* pg = 0;
if (szname)
{
pg = new FEElementSet(&fem);
pg->SetName(szname);
mesh.AddElementSet(pg);
}
// read element data
++tag;
for (int i = 0; i<elems; ++i)
{
if ((tag == "elem") == false) throw XMLReader::InvalidTag(tag);
// get the element ID
int nid;
tag.AttributeValue("id", nid);
// Make sure element IDs increase
// if (nid <= m_pim->m_maxid) throw XMLReader::InvalidAttributeValue(tag, "id");
// keep track of the largest element ID
// (which by assumption is the ID that was just read in)
GetBuilder()->m_maxid = nid;
// read the element data
if (ReadElement(tag, dom.ElementRef(i), nid) == false) throw XMLReader::InvalidValue(tag);
// go to next tag
++tag;
}
// create the element set
if (pg) pg->Create(pdom);
// assign material point data
dom.CreateMaterialPointData();
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection2::ParseElementData(FEElement& el, XMLTag& tag)
{
vec3d a, d;
if (tag == "fiber")
{
// read the fiber direction
value(tag, a);
set_element_fiber(el, a, -1);
}
else if (tag == "mat_axis")
{
++tag;
do
{
if (tag == "a") value(tag, a);
else if (tag == "d") value(tag, d);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
set_element_mat_axis(el, a, d, -1);
}
else if (tag == "thickness")
{
if (el.Class() != FE_ELEM_SHELL) throw XMLReader::InvalidTag(tag);
FEShellElement& shell = static_cast<FEShellElement&> (el);
// read shell thickness
tag.value(&shell.m_h0[0], shell.Nodes());
}
else if (tag == "area")
{
if (el.Class() != FE_ELEM_TRUSS) throw XMLReader::InvalidTag(tag);
FETrussElement& truss = static_cast<FETrussElement&>(el);
// read truss area
value(tag, truss.m_a0);
}
else
{
for (int i = 0; i<el.GaussPoints(); ++i)
{
FEMaterialPoint* pt = el.GetMaterialPoint(i);
// TODO: material point parameters are no longer supported so I need to reimplement this.
/* while (pt)
{
FEParameterList& pl = pt->GetParameterList();
if (ReadParameter(tag, pl)) break;
bool tagFound = false;
if (pt->Components() > 1)
{
for (int i = 0; i<pt->Components(); ++i)
{
FEParameterList& pl = pt->GetPointData(i)->GetParameterList();
if (ReadParameter(tag, pl))
{
tagFound = true;
break;
}
}
}
if (tagFound) break;
pt = pt->Next();
if (pt == 0) throw XMLReader::InvalidTag(tag);
}
*/ }
}
}
//-----------------------------------------------------------------------------
//! Reads the ElementData section from the FEBio input file
void FEBioGeometrySection2::ParseElementDataSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the total nr of elements
int nelems = mesh.Elements();
//make sure we've read the element section
if (nelems == 0) throw XMLReader::InvalidTag(tag);
// create the pelem array
vector<FEElement*> pelem;
pelem.assign(nelems, static_cast<FEElement*>(0));
for (int nd = 0; nd<mesh.Domains(); ++nd)
{
FEDomain& d = mesh.Domain(nd);
for (int i = 0; i<d.Elements(); ++i)
{
FEElement& el = d.ElementRef(i);
assert(pelem[el.GetID() - 1] == 0);
pelem[el.GetID() - 1] = ⪙
}
}
// read additional element data
++tag;
do
{
// make sure this is an "element" tag
if (tag == "element")
{
// get the element number
const char* szid = tag.AttributeValue("id");
int n = atoi(szid) - 1;
// make sure the number is valid
if ((n<0) || (n >= nelems)) throw XMLReader::InvalidAttributeValue(tag, "id", szid);
// get a pointer to the element
FEElement* pe = pelem[n];
++tag;
do
{
ParseElementData(*pe, tag);
++tag;
} while (!tag.isend());
}
else if (tag == "elset")
{
const char* szname = tag.AttributeValue("set");
// find domain with this name
FEElementSet* pset = mesh.FindElementSet(szname);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szname);
++tag;
do
{
int n = pset->Elements();
for (int i = 0; i<n; ++i)
{
// get a pointer to the element
int nid = (*pset)[i] - 1;
FEElement* pe = pelem[nid];
ParseElementData(*pe, tag);
}
++tag;
} while (!tag.isend());
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection2::ParseNodeSetSection(XMLTag& tag)
{
// read the node set
FENodeSet* pns = GetFEBioImport()->ParseNodeSet(tag, "set");
if (pns == 0) throw XMLReader::InvalidTag(tag);
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Edge section.
void FEBioGeometrySection2::ParseEdgeSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of segments
int nsegs = tag.children();
// allocate storage for segments
FESegmentSet* ps = new FESegmentSet(&fem);
ps->Create(nsegs);
ps->SetName(szname);
// add it to the mesh
mesh.AddSegmentSet(ps);
// read segments
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<nsegs; ++i)
{
FESegmentSet::SEGMENT& line = ps->Segment(i);
// set the facet type
if (tag == "line2") line.ntype = 2;
else throw XMLReader::InvalidTag(tag);
// we assume that the segment type also defines the number of nodes
int N = line.ntype;
tag.value(nf, N);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
line.node[j] = nid;
}
++tag;
}
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Surface section.
void FEBioGeometrySection2::ParseSurfaceSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of faces
int faces = tag.children();
// allocate storage for faces
FEFacetSet* ps = new FEFacetSet(&fem);
ps->Create(faces);
ps->SetName(szname);
// add it to the mesh
mesh.AddFacetSet(ps);
// read faces
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<faces; ++i)
{
FEFacetSet::FACET& face = ps->Face(i);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else if (tag == "tri10") face.ntype = 10;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
tag.value(nf, N);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
face.node[j] = nid;
}
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection2::ParseElementSetSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the name attribute
const char* szname = tag.AttributeValue("name");
// create a new element set
FEElementSet* pg = new FEElementSet(&fem);
pg->SetName(szname);
vector<int> l;
++tag;
do
{
if (tag == "elem")
{
int nid = -1;
tag.AttributeValue("id", nid);
l.push_back(nid);
}
else { delete pg; throw XMLReader::InvalidTag(tag); }
++tag;
} while (!tag.isend());
// only add non-empty element sets
if (l.empty() == false)
{
// assign indices to element set
pg->Create(l);
// add the element set to the mesh
mesh.AddElementSet(pg);
}
else delete pg;
}
//=============================================================================
// FEBioGeometrySection25
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::Parse(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
feb->m_maxid = 0;
// read all sections
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection (tag);
else if (tag == "Elements" ) ParseElementSection (tag);
else if (tag == "NodeSet" ) ParseNodeSetSection (tag);
else if (tag == "Surface" ) ParseSurfaceSection (tag);
else if (tag == "Edge" ) ParseEdgeSection (tag);
else if (tag == "ElementSet" ) ParseElementSetSection (tag);
else if (tag == "DiscreteSet") ParseDiscreteSetSection(tag);
else if (tag == "SurfacePair") ParseSurfacePairSection(tag);
else if (tag == "NodeSetPair") ParseNodeSetPairSection(tag);
else if (tag == "NodeSetSet" ) ParseNodeSetSetSection (tag);
else if (tag == "Part" ) ParsePartSection (tag);
else if (tag == "Instance" ) ParseInstanceSection (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// At this point the mesh is completely read in.
// Now we can allocate the degrees of freedom.
// NOTE: We do this here since the mesh no longer automatically allocates the dofs.
// At some point I want to be able to read the mesh before deciding any physics.
// When that happens I'll have to move this elsewhere.
FEModel& fem = *GetFEModel();
int MAX_DOFS = fem.GetDOFS().GetTotalDOFS();
fem.GetMesh().SetDOFS(MAX_DOFS);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParsePartSection(XMLTag& tag)
{
// get the part name
const char* szname = tag.AttributeValue("name");
// Create a new part
FEBModel::Part* part = m_feb.AddPart(szname);
// get the type attribute
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0) sztype = "template";
// check the value
bool binstance = false;
if (strcmp(sztype, "instance") == 0) binstance = true;
else if (strcmp(sztype, "template") == 0) binstance = false;
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// see if the from attribute is defined
const char* szfrom = tag.AttributeValue("from", true);
if (szfrom)
{
// make sure this is an empty leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// redirect input to another file
char xpath[256] = {0};
snprintf(xpath, sizeof(xpath), "febio_spec/Geometry/Part[@name=%s]", szname);
XMLReader xml;
if (xml.Open(szfrom) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom);
XMLTag tag2;
if (xml.FindTag(xpath, tag2) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom);
// read the part
ParsePart(tag2, part);
}
else ParsePart(tag, part);
// instantiate the part
if (binstance)
{
if (m_feb.BuildPart(*GetFEModel(), *part) == false) throw FEBioImport::FailedBuildingPart(part->Name());
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParsePart(XMLTag& tag, FEBModel::Part* part)
{
// read the part's sections
++tag;
do
{
if (tag == "Nodes" ) ParsePartNodeSection (tag, part);
else if (tag == "Elements" ) ParsePartElementSection(tag, part);
else if (tag == "NodeSet" ) ParsePartNodeSetSection(tag, part);
else if (tag == "Surface" ) ParsePartSurfaceSection(tag, part);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseInstanceSection(XMLTag& tag)
{
// get the name and part tags
const char* szname = tag.AttributeValue("name", true);
const char* szpart = tag.AttributeValue("part");
if (szname == 0) szname = szpart;
// find the part
FEBModel::Part* oldPart = m_feb.FindPart(szpart);
if (oldPart == 0) throw XMLReader::InvalidAttributeValue(tag, "part", szpart);
// copy the part
FEBModel::Part* newPart = new FEBModel::Part(*oldPart);
m_feb.AddPart(newPart);
// rename the part
newPart->SetName(szname);
// parse any child tags
Transform transform;
if (tag.isleaf() == false)
{
++tag;
do
{
if (tag == "translate")
{
double r[3];
tag.value(r, 3);
transform.SetPosition(vec3d(r[0], r[1], r[2]));
}
else if (tag == "rotate")
{
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0) sztype = "quaternion";
if (strcmp(sztype, "quaternion") == 0)
{
double v[4];
tag.value(v, 4);
quatd q(v[0], v[1], v[2], v[3]);
transform.SetRotation(q);
}
else if (strcmp(sztype, "vector") == 0)
{
double v[3];
tag.value(v, 3);
transform.SetRotation(vec3d(v[0], v[1], v[2]));
}
else if (strcmp(sztype, "Euler") == 0)
{
double v[3];
tag.value(v, 3);
transform.SetRotation(v[0], v[1], v[2]);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
else if (tag == "scale")
{
double s[3];
tag.value(s, 3);
transform.SetScale(s[0], s[1], s[2]);
}
else if (tag == "Elements")
{
const char* szdom = tag.AttributeValue("name");
const char* szmat = tag.AttributeValue("mat");
FEBModel::Domain* dom = newPart->FindDomain(szdom);
if (dom == 0) throw XMLReader::InvalidAttributeValue(tag, "name", szdom);
// make sure the material is defined
FEModel& fem = *GetFEModel();
FEMaterial* mat = fem.FindMaterial(szmat);
if (mat == 0) throw FEBioImport::InvalidDomainMaterial();
dom->SetMaterialName(szmat);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
// build this part
if (m_feb.BuildPart(*GetFEModel(), *newPart, true, transform) == false) throw FEBioImport::FailedBuildingPart(newPart->Name());
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection25::ParseNodeSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// get the largest nodal ID
// (It is assumed that nodes are sorted by ID so the last node should have the largest ID)
int max_id = 0;
if (N0 > 0) max_id = mesh.Node(N0 - 1).GetID();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szl = tag.AttributeValue("name", true);
FENodeSet* ps = 0;
if (szl)
{
ps = new FENodeSet(&fem);
ps->SetName(szl);
mesh.AddNodeSet(ps);
}
// resize node's array
mesh.AddNodes(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FENode& node = mesh.Node(N0 + i);
value(tag, node.m_r0);
node.m_rt = node.m_r0;
// get the nodal ID
int nid = -1;
tag.AttributeValue("id", nid);
// Make sure it is valid
if (nid <= max_id) throw XMLReader::InvalidAttributeValue(tag, "id");
// set the ID
node.SetID(nid);
max_id = nid;
// go on to the next node
++tag;
}
// If a node set is defined add these nodes to the node-set
if (ps)
{
for (int i = 0; i<nodes; ++i) ps->Add(N0 + i);
}
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection25::ParsePartNodeSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szname = tag.AttributeValue("name", true);
FEBModel::NodeSet* ps = 0;
if (szname)
{
ps = new FEBModel::NodeSet(szname);
part->AddNodeSet(ps);
}
// allocate node
vector<FEBModel::NODE> node(nodes);
vector<int> nodeList(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FEBModel::NODE& nd = node[i];
value(tag, nd.r);
// get the nodal ID
tag.AttributeValue("id", nd.id);
nodeList[i] = nd.id;
// go on to the next node
++tag;
}
// add nodes to the part
part->AddNodes(node);
// If a node set is defined add these nodes to the node-set
if (ps) ps->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection25::ParseElementSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the material ID
const char* szmat = tag.AttributeValue("mat");
// as of 2.5, we allow materials to be referenced by name, so try this first
FEMaterial* pmat = fem.FindMaterial(szmat);
if (pmat == 0)
{
// if we didn't find the material we assume that the material tag uses an ID
int nmat = atoi(szmat) - 1;
if ((nmat < 0) || (nmat >= fem.Materials())) throw FEBioImport::InvalidDomainMaterial();
// get the domain's material class
pmat = fem.GetMaterial(nmat);
}
// get the name
string name;
const char* szname = tag.AttributeValue("name", true);
if (szname) name = szname;
// get the element type
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// create the new domain
FEDomain* pdom = GetBuilder()->CreateDomain(espec, pmat);
if (pdom == 0) throw FEBioImport::FailedCreatingDomain();
FEDomain& dom = *pdom;
dom.SetName(name);
// active flag
const char* szactive = tag.AttributeValue("active", true);
if (szactive)
{
if (strcmp(szactive, "false") == 0) pdom->SetActive(false);
}
// count elements
vector<FEModelBuilder::ELEMENT> elemList; elemList.reserve(512000);
++tag;
do
{
if ((tag == "elem") == false) throw XMLReader::InvalidTag(tag);
// get the element ID
FEModelBuilder::ELEMENT el;
tag.AttributeValue("id", el.nid);
el.nodes = tag.value(el.node, FEElement::MAX_NODES);
elemList.push_back(el);
++tag;
}
while (!tag.isend());
int elems = (int) elemList.size();
assert(elems);
// add domain it to the mesh
pdom->Create(elems, espec);
pdom->SetMatID(pmat->GetID() - 1);
mesh.AddDomain(pdom);
// read element data
for (int i = 0; i<elems; ++i)
{
FEModelBuilder::ELEMENT& elem = elemList[i];
// get the element ID
int nid = elem.nid;
// Make sure element IDs increase
// if (nid <= m_pim->m_maxid) throw XMLReader::InvalidAttributeValue(tag, "id");
// keep track of the largest element ID
// (which by assumption is the ID that was just read in)
GetBuilder()->m_maxid = nid;
// process the element data
FEElement& el = dom.ElementRef(i);
el.SetID(nid);
if (elem.nodes != el.Nodes()) throw XMLReader::InvalidTag(tag);
GetBuilder()->GlobalToLocalID(elem.node, el.Nodes(), el.m_node);
}
// for named domains, we'll also create an element set
if (!name.empty())
{
FEElementSet* pg = new FEElementSet(&fem);
pg->SetName(name);
mesh.AddElementSet(pg);
pg->Create(pdom);
}
// assign material point data
dom.CreateMaterialPointData();
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection25::ParsePartElementSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the material ID
const char* szmat = tag.AttributeValue("mat", true);
// get the (optional) name
const char* szname = tag.AttributeValue("name", true);
// get the element type
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// create the new domain
FEBModel::Domain* dom = new FEBModel::Domain(espec);
if (szname) dom->SetName(szname);
if (szmat) dom->SetMaterialName(szmat);
// count elements
int elems = tag.children();
assert(elems);
// add domain it to the mesh
dom->Create(elems);
part->AddDomain(dom);
// for named domains, we'll also create an element set
FEBModel::ElementSet* pg = 0;
if (szname)
{
FEBModel::ElementSet* pg = new FEBModel::ElementSet(szname);
part->AddElementSet(pg);
}
vector<int> elemList(elems);
// read element data
++tag;
for (int i = 0; i<elems; ++i)
{
if ((tag == "elem") == false) throw XMLReader::InvalidTag(tag);
FEBModel::ELEMENT& el = dom->GetElement(i);
// get the element ID
tag.AttributeValue("id", el.id);
elemList[i] = el.id;
// read the element data
tag.value(el.node, FEElement::MAX_NODES);
// go to next tag
++tag;
}
// set the element list
if (pg) pg->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseNodeSetSection(XMLTag& tag)
{
// read the node set
FENodeSet* pns = GetFEBioImport()->ParseNodeSet(tag, "node_set");
if (pns == 0) throw XMLReader::InvalidTag(tag);
}
//-----------------------------------------------------------------------------
//! Reads the Geometry::Groups section of the FEBio input file
void FEBioGeometrySection25::ParsePartNodeSetSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
// create the node set
FEBModel::NodeSet* set = new FEBModel::NodeSet(szname);
part->AddNodeSet(set);
int nodes = tag.children();
vector<int> nodeList(nodes);
++tag;
for (int i=0; i<nodes; ++i)
{
if (tag == "node")
{
// get the ID
int nid;
tag.AttributeValue("id", nid);
nodeList[i] = nid;
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
// add nodes to the list
set->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseDiscreteSetSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the name
const char* szname = tag.AttributeValue("name");
// create the discrete element set
FEDiscreteSet* ps = new FEDiscreteSet(&mesh);
ps->SetName(szname);
mesh.AddDiscreteSet(ps);
// see if the generate attribute was defined
const char* szgen = tag.AttributeValue("generate", true);
if (szgen == 0)
{
// read the node pairs
++tag;
do
{
if (tag == "delem")
{
int n[2];
tag.value(n, 2);
n[0] -= 1; n[1] -= 1;
ps->add(n[0], n[1]);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
else
{
assert(tag.isempty());
// generate all the springs from the mesh
FENodeNodeList NNL;
NNL.Create(mesh);
// generate the springs
for (int i = 0; i<NNL.Size(); ++i)
{
int nval = NNL.Valence(i);
for (int j = 0; j<nval; ++j)
{
int n0 = i;
int nj = NNL.NodeList(i)[j];
if (n0 < nj)
{
ps->add(n0, nj);
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Edge section.
void FEBioGeometrySection25::ParseEdgeSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of segments
int nsegs = tag.children();
// allocate storage for segments
FESegmentSet* ps = new FESegmentSet(&fem);
ps->Create(nsegs);
ps->SetName(szname);
// add it to the mesh
mesh.AddSegmentSet(ps);
// read segments
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<nsegs; ++i)
{
FESegmentSet::SEGMENT& line = ps->Segment(i);
// set the facet type
if (tag == "line2") line.ntype = 2;
else throw XMLReader::InvalidTag(tag);
// we assume that the segment type also defines the number of nodes
int N = line.ntype;
tag.value(nf, N);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
line.node[j] = nid;
}
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseSurfacePairSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create new surface pair
FESurfacePair* p = new FESurfacePair(&mesh);
// set its name
const char* szname = tag.AttributeValue("name");
p->SetName(szname);
++tag;
do
{
if (tag == "master")
{
const char* sz = tag.AttributeValue("surface");
p->SetSecondarySurface(mesh.FindFacetSet(sz));
if (p->GetSecondarySurface() == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", sz);
}
else if (tag == "slave")
{
const char* sz = tag.AttributeValue("surface");
p->SetPrimarySurface(mesh.FindFacetSet(sz));
if (p->GetPrimarySurface() == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", sz);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// add it to the mesh
mesh.AddSurfacePair(p);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseNodeSetPairSection(XMLTag& tag)
{
FEModelBuilder::NodeSetPair p;
const char* szname = tag.AttributeValue("name");
strcpy(p.szname, szname);
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
++tag;
do
{
if (tag == "master")
{
const char* sz = tag.AttributeValue("node_set");
p.set2 = mesh.FindNodeSet(sz);
if (p.set2 == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
}
else if (tag == "slave")
{
const char* sz = tag.AttributeValue("node_set");
p.set1 = mesh.FindNodeSet(sz);
if (p.set1 == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
GetBuilder()->AddNodeSetPair(p);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseNodeSetSetSection(XMLTag& tag)
{
FEModelBuilder::NodeSetSet p;
const char* szname = tag.AttributeValue("name");
strcpy(p.szname, szname);
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
++tag;
do
{
if (tag == "node_set")
{
const char* sz = tag.AttributeValue("node_set");
FENodeSet* ns = mesh.FindNodeSet(sz);
if (ns == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
p.add(ns);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
GetBuilder()->AddNodeSetSet(p);
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Surface section.
void FEBioGeometrySection25::ParseSurfaceSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// if parts are defined we use the new format
if (m_feb.Parts() > 0)
{
FEFacetSet* ps = new FEFacetSet(&fem);
ps->SetName(szname);
// add it to the mesh
mesh.AddFacetSet(ps);
// read the child surfaces
++tag;
do
{
if (tag == "Surface")
{
const char* szatt = tag.AttributeValue("surface");
FEFacetSet* pf = mesh.FindFacetSet(szatt);
if (pf == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", szatt);
ps->Add(pf);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
else
{
// count nr of faces
int faces = tag.children();
// allocate storage for faces
FEFacetSet* ps = new FEFacetSet(&fem);
ps->Create(faces);
ps->SetName(szname);
// add it to the mesh
mesh.AddFacetSet(ps);
// read faces
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<faces; ++i)
{
FEFacetSet::FACET& face = ps->Face(i);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else if (tag == "tri10") face.ntype = 10;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
int nread = tag.value(nf, N);
if (nread != face.ntype) throw XMLReader::InvalidValue(tag);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
face.node[j] = nid;
}
++tag;
}
}
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Surface section.
void FEBioGeometrySection25::ParsePartSurfaceSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of faces
int faces = tag.children();
// allocate storage for faces
FEBModel::Surface* ps = new FEBModel::Surface(szname);
part->AddSurface(ps);
ps->Create(faces);
// read faces
++tag;
for (int i = 0; i<faces; ++i)
{
FEBModel::FACET& face = ps->GetFacet(i);
// get the ID (although we don't really use this)
tag.AttributeValue("id", face.id);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
tag.value(face.node, N);
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection25::ParseElementSetSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the name attribute
const char* szname = tag.AttributeValue("name");
// create a new element set
FEElementSet* pg = new FEElementSet(&fem);
pg->SetName(szname);
vector<int> l;
++tag;
do
{
if (tag == "elem")
{
int nid = -1;
tag.AttributeValue("id", nid);
l.push_back(nid);
}
else { delete pg; throw XMLReader::InvalidTag(tag); }
++tag;
} while (!tag.isend());
// only add non-empty element sets
if (l.empty() == false)
{
// see if all elements belong to the same domain
bool oneDomain = true;
FEElement* el = mesh.FindElementFromID(l[0]); assert(el);
FEDomain* dom = dynamic_cast<FEDomain*>(el->GetMeshPartition());
for (int i = 1; i < l.size(); ++i)
{
FEElement* el_i = mesh.FindElementFromID(l[i]); assert(el);
FEDomain* dom_i = dynamic_cast<FEDomain*>(el_i->GetMeshPartition());
if (dom != dom_i)
{
oneDomain = false;
break;
}
}
// assign indices to element set
if (oneDomain)
pg->Create(dom, l);
else
pg->Create(l);
// add the element set to the mesh
mesh.AddElementSet(pg);
}
else delete pg;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioCodeSection.cpp | .cpp | 1,875 | 54 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioCodeSection.h"
#include "FECore/FECallBack.h"
#include "FECore/FECoreKernel.h"
void FEBioCodeSection::Parse(XMLTag& tag)
{
++tag;
do
{
if (tag == "callback")
{
const char* szname = tag.AttributeValue("name");
FECallBack* pcb = fecore_new<FECallBack>(szname, GetFEModel());
// TODO: The constructor of FECallBack already registered the callback class, so
// we don't need to do anything else here. Of course, the question is who
// is going to cleanup pcb?
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioRigidSection4.cpp | .cpp | 3,648 | 117 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioRigidSection4.h"
#include <FECore/FEModel.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FENLConstraint.h>
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FEInitialCondition.h>
void FEBioRigidSection4::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "rigid_bc" ) ParseRigidBC(tag);
else if (tag == "rigid_ic" ) ParseRigidIC(tag);
else if (tag == "rigid_load" ) ParseRigidLoad(tag);
else if (tag == "rigid_connector") ParseRigidConnector(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
void FEBioRigidSection4::ParseRigidBC(XMLTag& tag)
{
FEModel* fem = GetFEModel();
FEModelBuilder& feb = *GetBuilder();
// get the name
const char* szname = tag.AttributeValue("name", true);
// get the type
const char* sztype = tag.AttributeValue("type");
FEBoundaryCondition* bc = fecore_new<FEBoundaryCondition>(sztype, fem);
if (szname) bc->SetName(szname);
GetBuilder()->AddRigidComponent(bc);
ReadParameterList(tag, bc);
}
void FEBioRigidSection4::ParseRigidIC(XMLTag& tag)
{
FEModel* fem = GetFEModel();
// get the name
const char* szname = tag.AttributeValue("name", true);
// get the type
const char* sztype = tag.AttributeValue("type");
FEInitialCondition* ic = fecore_new<FEInitialCondition>(sztype, fem);
if (szname) ic->SetName(szname);
GetBuilder()->AddRigidComponent(ic);
ReadParameterList(tag, ic);
}
void FEBioRigidSection4::ParseRigidLoad(XMLTag& tag)
{
// get the name
const char* szname = tag.AttributeValue("name", true);
// get the type
const char* sztype = tag.AttributeValue("type");
FEModelLoad* ml = fecore_new<FEModelLoad>(sztype, GetFEModel());
if (szname) ml->SetName(szname);
GetBuilder()->AddRigidComponent(ml);
ReadParameterList(tag, ml);
}
void FEBioRigidSection4::ParseRigidConnector(XMLTag& tag)
{
const char* sztype = tag.AttributeValue("type");
FENLConstraint* plc = fecore_new<FENLConstraint>(sztype, GetFEModel());
if (plc == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
const char* szname = tag.AttributeValue("name", true);
if (szname) plc->SetName(szname);
// read the parameter list
ReadParameterList(tag, plc);
// add this constraint to the current step
GetBuilder()->AddNonlinearConstraint(plc);
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioBoundarySection.h | .h | 3,675 | 108 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FEBioImport.h"
#include "FECore/FESurfacePairConstraint.h"
#include <map>
//-----------------------------------------------------------------------------
// Boundary Section
class FEBioBoundarySection : public FEFileSection
{
public:
FEBioBoundarySection(FEFileImport* pim) : FEFileSection(pim){}
protected:
void ParseBCFix (XMLTag& tag);
void ParseBCPrescribe (XMLTag& tag);
void ParseContactSection(XMLTag& tag);
void ParseConstraints (XMLTag& tag);
void ParseSpringSection (XMLTag& tag);
protected:
void ParseContactInterface(XMLTag& tag, FESurfacePairConstraint* psi);
bool ParseSurfaceSection (XMLTag& tag, FESurface& s, int nfmt, bool bnodal);
protected:
void ParseRigidJoint (XMLTag& tag);
void ParseLinearConstraint(XMLTag& tag);
void ParseRigidWall (XMLTag& tag);
void ParseRigidContact (XMLTag& tag);
protected:
void BuildNodeSetMap();
void AddFixedBC(FENodeSet* set, int bc);
protected:
std::map<std::string, FENodeSet*> m_NodeSet; // map for faster lookup of node sets
};
//-----------------------------------------------------------------------------
// older formats (1.2)
class FEBioBoundarySection1x : public FEBioBoundarySection
{
public:
FEBioBoundarySection1x(FEFileImport* imp) : FEBioBoundarySection(imp){}
void Parse(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// version 2.0
class FEBioBoundarySection2 : public FEBioBoundarySection
{
public:
FEBioBoundarySection2(FEFileImport* imp) : FEBioBoundarySection(imp){}
void Parse(XMLTag& tag);
protected:
void ParseBCFix (XMLTag& tag);
void ParseBCPrescribe(XMLTag& tag);
};
//-----------------------------------------------------------------------------
// version 2.5
class FEBioBoundarySection25 : public FEBioBoundarySection
{
public:
FEBioBoundarySection25(FEFileImport* imp) : FEBioBoundarySection(imp){}
void Parse(XMLTag& tag);
protected:
void ParseBCFix (XMLTag& tag);
void ParseBCPrescribe(XMLTag& tag);
void ParseBCRigid (XMLTag& tag);
void ParseRigidBody (XMLTag& tag);
void ParseBC (XMLTag& tag);
void ParsePeriodicLinearConstraint (XMLTag& tag); // version 2.5 (temporary construction)
void ParsePeriodicLinearConstraint2O(XMLTag& tag); // version 2.5 (temporary construction)
void ParseMergeConstraint (XMLTag& tag); // version 2.5
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioGeometrySection3.cpp | .cpp | 26,998 | 1,044 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioGeometrySection.h"
#include "FECore/FESolidDomain.h"
#include "FECore/FEModel.h"
#include "FECore/FEMaterial.h"
#include <FECore/FENodeNodeList.h>
//-----------------------------------------------------------------------------
// functions defined in FEBioGeometrySection
void set_element_fiber(FEElement& el, const vec3d& v, int ncomp);
void set_element_mat_axis(FEElement& el, const vec3d& v1, const vec3d& v2, int ncomp);
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::Parse(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
feb->m_maxid = 0;
// read all sections
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection (tag);
else if (tag == "Elements" ) ParseElementSection (tag);
else if (tag == "NodeSet" ) ParseNodeSetSection (tag);
else if (tag == "Surface" ) ParseSurfaceSection (tag);
else if (tag == "Edge" ) ParseEdgeSection (tag);
else if (tag == "ElementSet" ) ParseElementSetSection (tag);
else if (tag == "DiscreteSet") ParseDiscreteSetSection(tag);
else if (tag == "SurfacePair") ParseSurfacePairSection(tag);
else if (tag == "NodeSetPair") ParseNodeSetPairSection(tag);
else if (tag == "NodeSetSet" ) ParseNodeSetSetSection (tag);
else if (tag == "Part" ) ParsePartSection (tag);
else if (tag == "Instance" ) ParseInstanceSection (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// At this point the mesh is completely read in.
// Now we can allocate the degrees of freedom.
// NOTE: We do this here since the mesh no longer automatically allocates the dofs.
// At some point I want to be able to read the mesh before deciding any physics.
// When that happens I'll have to move this elsewhere.
FEModel& fem = *GetFEModel();
int MAX_DOFS = fem.GetDOFS().GetTotalDOFS();
fem.GetMesh().SetDOFS(MAX_DOFS);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParsePartSection(XMLTag& tag)
{
// get the part name
const char* szname = tag.AttributeValue("name");
// Create a new part
FEBModel::Part* part = m_feb.AddPart(szname);
// get the type attribute
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0) sztype = "template";
// check the value
bool binstance = false;
if (strcmp(sztype, "instance") == 0) binstance = true;
else if (strcmp(sztype, "template") == 0) binstance = false;
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// see if the from attribute is defined
const char* szfrom = tag.AttributeValue("from", true);
if (szfrom)
{
// make sure this is an empty leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// redirect input to another file
char xpath[256] = {0};
snprintf(xpath, sizeof(xpath), "febio_spec/Geometry/Part[@name=%s]", szname);
XMLReader xml;
if (xml.Open(szfrom) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom);
XMLTag tag2;
if (xml.FindTag(xpath, tag2) == false) throw XMLReader::InvalidAttributeValue(tag, "from", szfrom);
// read the part
ParsePart(tag2, part);
}
else ParsePart(tag, part);
// instantiate the part
if (binstance)
{
if (m_feb.BuildPart(*GetFEModel(), *part) == false) throw FEBioImport::FailedBuildingPart(part->Name());
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParsePart(XMLTag& tag, FEBModel::Part* part)
{
// read the part's sections
++tag;
do
{
if (tag == "Nodes" ) ParsePartNodeSection (tag, part);
else if (tag == "Elements" ) ParsePartElementSection(tag, part);
else if (tag == "NodeSet" ) ParsePartNodeSetSection(tag, part);
else if (tag == "Surface" ) ParsePartSurfaceSection(tag, part);
else if (tag == "ElementSet" ) ParsePartElementSetSection(tag, part);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseInstanceSection(XMLTag& tag)
{
// get the name and part tags
const char* szname = tag.AttributeValue("name", true);
const char* szpart = tag.AttributeValue("part");
if (szname == 0) szname = szpart;
// find the part
FEBModel::Part* oldPart = m_feb.FindPart(szpart);
if (oldPart == 0) throw XMLReader::InvalidAttributeValue(tag, "part", szpart);
// copy the part
FEBModel::Part* newPart = new FEBModel::Part(*oldPart);
m_feb.AddPart(newPart);
// rename the part
newPart->SetName(szname);
// parse any child tags
Transform transform;
if (tag.isleaf() == false)
{
++tag;
do
{
if (tag == "transform")
{
++tag;
do
{
if (tag == "translate")
{
double r[3];
tag.value(r, 3);
transform.SetPosition(vec3d(r[0], r[1], r[2]));
}
else if (tag == "rotate")
{
const char* sztype = tag.AttributeValue("type", true);
if (sztype == 0) sztype = "quaternion";
if (strcmp(sztype, "quaternion") == 0)
{
double v[4];
tag.value(v, 4);
quatd q(v[0], v[1], v[2], v[3]);
transform.SetRotation(q);
}
else if (strcmp(sztype, "vector") == 0)
{
double v[3];
tag.value(v, 3);
transform.SetRotation(vec3d(v[0], v[1], v[2]));
}
else if (strcmp(sztype, "Euler") == 0)
{
double v[3];
tag.value(v, 3);
transform.SetRotation(v[0], v[1], v[2]);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
else if (tag == "scale")
{
double s[3];
tag.value(s, 3);
transform.SetScale(s[0], s[1], s[2]);
}
++tag;
}
while (!tag.isend());
}
else if (tag == "domain")
{
const char* szdom = tag.AttributeValue("name");
const char* szmat = tag.AttributeValue("mat");
FEBModel::Domain* dom = newPart->FindDomain(szdom);
if (dom == 0) throw XMLReader::InvalidAttributeValue(tag, "name", szdom);
// make sure the material is defined
FEModel& fem = *GetFEModel();
FEMaterial* mat = fem.FindMaterial(szmat);
if (mat == 0) throw FEBioImport::InvalidDomainMaterial();
dom->SetMaterialName(szmat);
// any additional parameters?
if (tag.isleaf() == false)
{
++tag;
do
{
if (tag == "shell_thickness")
{
double h = 0.0;
tag.value(h);
dom->m_defaultShellThickness = h;
}
++tag;
}
while (!tag.isend());
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
// build this part
if (m_feb.BuildPart(*GetFEModel(), *newPart, true, transform) == false) throw FEBioImport::FailedBuildingPart(newPart->Name());
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection3::ParseNodeSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// get the largest nodal ID
// (It is assumed that nodes are sorted by ID so the last node should have the largest ID)
int max_id = 0;
if (N0 > 0) max_id = mesh.Node(N0 - 1).GetID();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szl = tag.AttributeValue("name", true);
FENodeSet* ps = 0;
if (szl)
{
ps = new FENodeSet(&fem);
ps->SetName(szl);
mesh.AddNodeSet(ps);
}
// resize node's array
mesh.AddNodes(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FENode& node = mesh.Node(N0 + i);
value(tag, node.m_r0);
node.m_rt = node.m_r0;
// get the nodal ID
int nid = -1;
tag.AttributeValue("id", nid);
// Make sure it is valid
if (nid <= max_id) throw XMLReader::InvalidAttributeValue(tag, "id");
// set the ID
node.SetID(nid);
max_id = nid;
// go on to the next node
++tag;
}
// If a node set is defined add these nodes to the node-set
if (ps)
{
for (int i = 0; i<nodes; ++i) ps->Add(N0 + i);
}
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioGeometrySection3::ParsePartNodeSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// first we need to figure out how many nodes there are
XMLTag t(tag);
int nodes = tag.children();
// see if this list defines a set
const char* szname = tag.AttributeValue("name", true);
FEBModel::NodeSet* ps = 0;
if (szname)
{
ps = new FEBModel::NodeSet(szname);
part->AddNodeSet(ps);
}
// allocate node
vector<FEBModel::NODE> node(nodes);
vector<int> nodeList(nodes);
// read nodal coordinates
++tag;
for (int i = 0; i<nodes; ++i)
{
FEBModel::NODE& nd = node[i];
value(tag, nd.r);
// get the nodal ID
tag.AttributeValue("id", nd.id);
nodeList[i] = nd.id;
// go on to the next node
++tag;
}
// add nodes to the part
part->AddNodes(node);
// If a node set is defined add these nodes to the node-set
if (ps) ps->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection3::ParseElementSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the material ID
const char* szmat = tag.AttributeValue("mat");
// as of 2.5, we allow materials to be referenced by name, so try this first
FEMaterial* pmat = fem.FindMaterial(szmat);
if (pmat == 0)
{
// if we didn't find the material we assume that the material tag uses an ID
int nmat = atoi(szmat) - 1;
if ((nmat < 0) || (nmat >= fem.Materials())) throw FEBioImport::InvalidDomainMaterial();
// get the domain's material class
pmat = fem.GetMaterial(nmat);
}
// get the name
const char* szname = tag.AttributeValue("name", true);
if (szname == 0) szname = "_unnamed";
// get the element type
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// create the new domain
FEDomain* pdom = GetBuilder()->CreateDomain(espec, pmat);
if (pdom == 0) throw FEBioImport::FailedCreatingDomain();
FEDomain& dom = *pdom;
dom.SetName(szname);
// active flag
const char* szactive = tag.AttributeValue("active", true);
if (szactive)
{
if (strcmp(szactive, "false") == 0) pdom->SetActive(false);
}
// count elements
int elems = tag.children();
assert(elems);
// add domain it to the mesh
pdom->Create(elems, espec);
pdom->SetMatID(pmat->GetID() - 1);
mesh.AddDomain(pdom);
// for named domains, we'll also create an element set
FEElementSet* pg = 0;
if (szname)
{
pg = new FEElementSet(&fem);
pg->SetName(szname);
mesh.AddElementSet(pg);
}
// read element data
++tag;
for (int i = 0; i<elems; ++i)
{
// get the element ID
int nid;
tag.AttributeValue("id", nid);
// Make sure element IDs increase
// if (nid <= m_pim->m_maxid) throw XMLReader::InvalidAttributeValue(tag, "id");
// keep track of the largest element ID
// (which by assumption is the ID that was just read in)
GetBuilder()->m_maxid = nid;
// read the element data
if (ReadElement(tag, dom.ElementRef(i), nid) == false) throw XMLReader::InvalidValue(tag);
// go to next tag
++tag;
}
// create the element set
if (pg) pg->Create(pdom);
// assign material point data
dom.CreateMaterialPointData();
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioGeometrySection3::ParsePartElementSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the material ID
const char* szmat = tag.AttributeValue("mat", true);
// get the (optional) name
const char* szname = tag.AttributeValue("name", true);
// get the element type
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// create the new domain
FEBModel::Domain* dom = new FEBModel::Domain(espec);
if (szname) dom->SetName(szname);
if (szmat) dom->SetMaterialName(szmat);
// count elements
int elems = tag.children();
assert(elems);
// add domain it to the mesh
dom->Create(elems);
part->AddDomain(dom);
// for named domains, we'll also create an element set
FEBModel::ElementSet* pg = 0;
if (szname)
{
pg = new FEBModel::ElementSet(szname);
part->AddElementSet(pg);
}
vector<int> elemList(elems);
// read element data
++tag;
for (int i = 0; i<elems; ++i)
{
FEBModel::ELEMENT& el = dom->GetElement(i);
// get the element ID
tag.AttributeValue("id", el.id);
elemList[i] = el.id;
// read the element data
tag.value(el.node, FEElement::MAX_NODES);
// go to next tag
++tag;
}
// set the element list
if (pg) pg->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseNodeSetSection(XMLTag& tag)
{
FEMesh& mesh = GetFEModel()->GetMesh();
const char* szname = tag.AttributeValue("name");
// create a new node set
FENodeSet* pns = new FENodeSet(GetFEModel());
pns->SetName(szname);
// add the nodeset to the mesh
mesh.AddNodeSet(pns);
++tag;
do
{
if ((tag == "n") || (tag == "node"))
{
int nid = -1;
tag.AttributeValue("id", nid);
nid = GetBuilder()->FindNodeFromID(nid);
pns->Add(nid);
}
else if (tag == "node_set")
{
const char* szset = tag.szvalue();
// find the node set
FENodeSet* ps = mesh.FindNodeSet(szset);
if (ps == 0) throw XMLReader::InvalidValue(tag);
// add the node set
pns->Add(ps->GetNodeList());
}
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
//! Reads the Geometry::Groups section of the FEBio input file
void FEBioGeometrySection3::ParsePartNodeSetSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
// create the node set
FEBModel::NodeSet* set = new FEBModel::NodeSet(szname);
part->AddNodeSet(set);
int nodes = tag.children();
vector<int> nodeList(nodes);
++tag;
for (int i=0; i<nodes; ++i)
{
// get the ID
int nid;
tag.AttributeValue("id", nid);
nodeList[i] = nid;
++tag;
}
// add nodes to the list
set->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseDiscreteSetSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the name
const char* szname = tag.AttributeValue("name");
// create the discrete element set
FEDiscreteSet* ps = new FEDiscreteSet(&mesh);
ps->SetName(szname);
mesh.AddDiscreteSet(ps);
// see if the generate attribute was defined
const char* szgen = tag.AttributeValue("generate", true);
if (szgen == 0)
{
// read the node pairs
++tag;
do
{
if (tag == "delem")
{
int n[2];
tag.value(n, 2);
n[0] -= 1; n[1] -= 1;
ps->add(n[0], n[1]);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
else
{
assert(tag.isempty());
// generate all the springs from the mesh
FENodeNodeList NNL;
NNL.Create(mesh);
// generate the springs
for (int i = 0; i<NNL.Size(); ++i)
{
int nval = NNL.Valence(i);
for (int j = 0; j<nval; ++j)
{
int n0 = i;
int nj = NNL.NodeList(i)[j];
if (n0 < nj)
{
ps->add(n0, nj);
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Edge section.
void FEBioGeometrySection3::ParseEdgeSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of segments
int nsegs = tag.children();
// allocate storage for segments
FESegmentSet* ps = new FESegmentSet(&fem);
ps->Create(nsegs);
ps->SetName(szname);
// add it to the mesh
mesh.AddSegmentSet(ps);
// read segments
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<nsegs; ++i)
{
FESegmentSet::SEGMENT& line = ps->Segment(i);
// set the facet type
if (tag == "line2") line.ntype = 2;
else throw XMLReader::InvalidTag(tag);
// we assume that the segment type also defines the number of nodes
int N = line.ntype;
tag.value(nf, N);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
line.node[j] = nid;
}
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseSurfacePairSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create new surface pair
FESurfacePair* p = new FESurfacePair(&mesh);
// set its name
const char* szname = tag.AttributeValue("name");
p->SetName(szname);
++tag;
do
{
if (tag == "primary")
{
const char* sz = tag.szvalue();
p->SetPrimarySurface(mesh.FindFacetSet(sz));
if (p->GetPrimarySurface() == 0) throw XMLReader::InvalidValue(tag);
}
else if (tag == "secondary")
{
const char* sz = tag.szvalue();
p->SetSecondarySurface(mesh.FindFacetSet(sz));
if (p->GetSecondarySurface() == 0) throw XMLReader::InvalidValue(tag);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// add it to the mesh
mesh.AddSurfacePair(p);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseNodeSetPairSection(XMLTag& tag)
{
FEModelBuilder::NodeSetPair p;
const char* szname = tag.AttributeValue("name");
strcpy(p.szname, szname);
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
++tag;
do
{
if (tag == "primary")
{
const char* sz = tag.AttributeValue("node_set");
p.set1 = mesh.FindNodeSet(sz);
if (p.set1 == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
}
else if (tag == "secondary")
{
const char* sz = tag.AttributeValue("node_set");
p.set2 = mesh.FindNodeSet(sz);
if (p.set2 == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
GetBuilder()->AddNodeSetPair(p);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseNodeSetSetSection(XMLTag& tag)
{
FEModelBuilder::NodeSetSet p;
const char* szname = tag.AttributeValue("name");
strcpy(p.szname, szname);
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
++tag;
do
{
if (tag == "node_set")
{
const char* sz = tag.AttributeValue("node_set");
FENodeSet* ns = mesh.FindNodeSet(sz);
if (ns == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", sz);
p.add(ns);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
GetBuilder()->AddNodeSetSet(p);
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Surface section.
void FEBioGeometrySection3::ParseSurfaceSection(XMLTag& tag)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the number of nodes
// (we use this for checking the node indices of the facets)
int NN = mesh.Nodes();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// if parts are defined we use the new format
if (m_feb.Parts() > 0)
{
FEFacetSet* ps = new FEFacetSet(&fem);
ps->SetName(szname);
// add it to the mesh
mesh.AddFacetSet(ps);
// read the child surfaces
++tag;
do
{
if (tag == "surface")
{
FEFacetSet* pf = mesh.FindFacetSet(tag.szvalue());
if (pf == 0) throw XMLReader::InvalidValue(tag);
ps->Add(pf);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
else
{
// count nr of faces
int faces = tag.children();
// allocate storage for faces
FEFacetSet* ps = new FEFacetSet(&fem);
ps->Create(faces);
ps->SetName(szname);
// add it to the mesh
mesh.AddFacetSet(ps);
// read faces
++tag;
int nf[FEElement::MAX_NODES];
for (int i = 0; i<faces; ++i)
{
FEFacetSet::FACET& face = ps->Face(i);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else if (tag == "tri10") face.ntype = 10;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
int nread = tag.value(nf, N);
if (nread != face.ntype) throw XMLReader::InvalidValue(tag);
for (int j = 0; j<N; ++j)
{
int nid = nf[j] - 1;
if ((nid<0) || (nid >= NN)) throw XMLReader::InvalidValue(tag);
face.node[j] = nid;
}
++tag;
}
}
}
//-----------------------------------------------------------------------------
//! Reads a Geometry\Surface section.
void FEBioGeometrySection3::ParsePartSurfaceSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// count nr of faces
int faces = tag.children();
// allocate storage for faces
FEBModel::Surface* ps = new FEBModel::Surface(szname);
part->AddSurface(ps);
ps->Create(faces);
// read faces
++tag;
for (int i = 0; i<faces; ++i)
{
FEBModel::FACET& face = ps->GetFacet(i);
// get the ID (although we don't really use this)
tag.AttributeValue("id", face.id);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
tag.value(face.node, N);
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParsePartElementSetSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// allocate storage for faces
FEBModel::ElementSet* ps = new FEBModel::ElementSet(szname);
part->AddElementSet(ps);
// read elements
vector<int> elemList;
++tag;
do
{
// get the ID
int id;
tag.AttributeValue("id", id);
elemList.push_back(id);
++tag;
}
while (!tag.isend());
ps->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioGeometrySection3::ParseElementSetSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the name attribute
const char* szname = tag.AttributeValue("name");
// create a new element set
FEElementSet* pg = new FEElementSet(&fem);
pg->SetName(szname);
++tag;
if (tag == "elem_set")
{
do
{
if (tag == "elem_set")
{
const char* sz = tag.szvalue();
FEElementSet* eset = mesh.FindElementSet(sz);
if (eset == 0) throw XMLReader::InvalidValue(tag);
pg->Add(*eset);
}
else { delete pg; throw XMLReader::InvalidTag(tag); }
++tag;
} while (!tag.isend());
}
else
{
vector<int> l;
do
{
int nid = -1;
tag.AttributeValue("id", nid);
l.push_back(nid);
++tag;
}
while (!tag.isend());
// see if all elements belong to the same domain
bool oneDomain = true;
FEElement* el = mesh.FindElementFromID(l[0]); assert(el);
FEDomain* dom = dynamic_cast<FEDomain*>(el->GetMeshPartition());
for (int i = 1; i < l.size(); ++i)
{
FEElement* el_i = mesh.FindElementFromID(l[i]); assert(el);
FEDomain* dom_i = dynamic_cast<FEDomain*>(el_i->GetMeshPartition());
if (dom != dom_i)
{
oneDomain = false;
break;
}
}
// assign indices to element set
if (oneDomain)
pg->Create(dom, l);
else
pg->Create(l);
}
// only add non-empty element sets
if (pg->Elements())
{
// add the element set to the mesh
mesh.AddElementSet(pg);
}
else delete pg;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioMeshSection.cpp | .cpp | 17,626 | 625 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioMeshSection.h"
#include <FECore/FEDomain.h>
#include <FECore/FEModel.h>
#include <FECore/FEMaterial.h>
#include <FECore/FECoreKernel.h>
#include <sstream>
//-----------------------------------------------------------------------------
FEBioMeshSection::FEBioMeshSection(FEBioImport* pim) : FEBioFileSection(pim) {}
//-----------------------------------------------------------------------------
void FEBioMeshSection::Parse(XMLTag& tag)
{
FEModelBuilder* builder = GetBuilder();
builder->m_maxid = 0;
// create a default part
// NOTE: Do not specify a name for the part, otherwise
// all lists will be given the name: partname.listname
FEBModel& feb = builder->GetFEBModel();
assert(feb.Parts() == 0);
FEBModel::Part* part = feb.AddPart("");
// read all sections
++tag;
do
{
if (tag == "Nodes" ) ParseNodeSection (tag, part);
else if (tag == "Elements" ) ParseElementSection (tag, part);
else if (tag == "NodeSet" ) ParseNodeSetSection (tag, part);
else if (tag == "Surface" ) ParseSurfaceSection (tag, part);
// else if (tag == "Edge" ) ParseEdgeSection (tag, part);
else if (tag == "ElementSet" ) ParseElementSetSection (tag, part);
else if (tag == "SurfacePair") ParseSurfacePairSection(tag, part);
else if (tag == "DiscreteSet") ParseDiscreteSetSection(tag, part);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
//! Reads the Nodes section of the FEBio input file
void FEBioMeshSection::ParseNodeSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
int N0 = mesh.Nodes();
// see if this list defines a set
const char* szname = tag.AttributeValue("name", true);
FEBModel::NodeSet* ps = 0;
if (szname)
{
ps = new FEBModel::NodeSet(szname);
part->AddNodeSet(ps);
}
// allocate node
vector<FEBModel::NODE> node; node.reserve(10000);
vector<int> nodeList; nodeList.reserve(10000);
// read nodal coordinates
++tag;
do {
// nodal coordinates
FEBModel::NODE nd;
value(tag, nd.r);
// get the nodal ID
tag.AttributeValue("id", nd.id);
// add it to the pile
node.push_back(nd);
nodeList.push_back(nd.id);
// go on to the next node
++tag;
} while (!tag.isend());
// add nodes to the part
part->AddNodes(node);
// If a node set is defined add these nodes to the node-set
if (ps) ps->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
//! This function reads the Element section from the FEBio input file. It also
//! creates the domain classes which store the element data. A domain is defined
//! by the module (structural, poro, heat, etc), the element type (solid, shell,
//! etc.) and the material.
//!
void FEBioMeshSection::ParseElementSection(XMLTag& tag, FEBModel::Part* part)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the (required!) name
const char* szname = tag.AttributeValue("name");
// get the element spec
const char* sztype = tag.AttributeValue("type");
FE_Element_Spec espec = GetBuilder()->ElementSpec(sztype);
if (FEElementLibrary::IsValid(espec) == false) throw FEBioImport::InvalidElementType();
// make sure the domain does not exist yet
FEBModel::Domain* dom = part->FindDomain(szname);
if (dom)
{
stringstream ss;
ss << "Duplicate part name found : " << szname;
throw std::runtime_error(ss.str());
}
// create the new domain
dom = new FEBModel::Domain(espec);
if (szname) dom->SetName(szname);
// add domain it to the mesh
part->AddDomain(dom);
// for named domains, we'll also create an element set
FEBModel::ElementSet* pg = 0;
if (szname)
{
pg = new FEBModel::ElementSet(szname);
part->AddElementSet(pg);
}
dom->Reserve(10000);
vector<int> elemList; elemList.reserve(10000);
// read element data
++tag;
do
{
FEBModel::ELEMENT el;
// get the element ID
tag.AttributeValue("id", el.id);
// read the element data
tag.value(el.node, FEElement::MAX_NODES);
dom->AddElement(el);
elemList.push_back(el.id);
// go to next tag
++tag;
} while (!tag.isend());
// set the element list
if (pg) pg->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
//! Reads the Geometry::Groups section of the FEBio input file
void FEBioMeshSection::ParseNodeSetSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
// see if a nodeset with this name already exists
FEBModel::NodeSet* set = part->FindNodeSet(szname);
if (set) throw FEBioImport::RepeatedNodeSet(szname);
// create the node set
set = new FEBModel::NodeSet(szname);
part->AddNodeSet(set);
int nodes = tag.children();
vector<int> nodeList(nodes);
++tag;
for (int i = 0; i < nodes; ++i)
{
// get the ID
int nid;
tag.AttributeValue("id", nid);
nodeList[i] = nid;
++tag;
}
// add nodes to the list
set->SetNodeList(nodeList);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection::ParseSurfaceSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this surface was already defined
FEBModel::Surface* ps = part->FindSurface(szname);
if (ps) throw FEBioImport::RepeatedSurface(szname);
// count nr of faces
int faces = tag.children();
// allocate storage for faces
ps = new FEBModel::Surface(szname);
part->AddSurface(ps);
ps->Create(faces);
// read faces
++tag;
for (int i = 0; i < faces; ++i)
{
FEBModel::FACET& face = ps->GetFacet(i);
// get the ID (although we don't really use this)
tag.AttributeValue("id", face.id);
// set the facet type
if (tag == "quad4") face.ntype = 4;
else if (tag == "tri3") face.ntype = 3;
else if (tag == "tri6") face.ntype = 6;
else if (tag == "tri7") face.ntype = 7;
else if (tag == "tri10") face.ntype = 10;
else if (tag == "quad8") face.ntype = 8;
else if (tag == "quad9") face.ntype = 9;
else throw XMLReader::InvalidTag(tag);
// we assume that the facet type also defines the number of nodes
int N = face.ntype;
tag.value(face.node, N);
++tag;
}
}
//-----------------------------------------------------------------------------
void FEBioMeshSection::ParseElementSetSection(XMLTag& tag, FEBModel::Part* part)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the required name attribute
const char* szname = tag.AttributeValue("name");
// see if this element set was already defined
FEBModel::ElementSet* ps = part->FindElementSet(szname);
if (ps) throw FEBioImport::RepeatedElementSet(szname);
// allocate storage for faces
ps = new FEBModel::ElementSet(szname);
part->AddElementSet(ps);
// read elements
vector<int> elemList;
++tag;
do
{
// get the ID
int id;
tag.AttributeValue("id", id);
elemList.push_back(id);
++tag;
} while (!tag.isend());
if (elemList.empty()) throw XMLReader::InvalidTag(tag);
ps->SetElementList(elemList);
}
//-----------------------------------------------------------------------------
void FEBioMeshSection::ParseEdgeSection(XMLTag& tag, FEBModel::Part* part)
{
}
//-----------------------------------------------------------------------------
void FEBioMeshSection::ParseSurfacePairSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
FEBModel::SurfacePair* surfPair = new FEBModel::SurfacePair;
surfPair->m_name = szname;
part->AddSurfacePair(surfPair);
++tag;
do
{
if (tag == "primary")
{
const char* sz = tag.szvalue();
FEBModel::Surface* surf = part->FindSurface(sz);
if (surf == nullptr) throw XMLReader::InvalidValue(tag);
surfPair->m_primary = sz;
}
else if (tag == "secondary")
{
const char* sz = tag.szvalue();
FEBModel::Surface* surf = part->FindSurface(sz);
if (surf == nullptr) throw XMLReader::InvalidValue(tag);
surfPair->m_secondary = sz;
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioMeshSection::ParseDiscreteSetSection(XMLTag& tag, FEBModel::Part* part)
{
const char* szname = tag.AttributeValue("name");
FEBModel::DiscreteSet* dset = new FEBModel::DiscreteSet;
dset->SetName(szname);
part->AddDiscreteSet(dset);
int n[2];
++tag;
do
{
if (tag == "delem")
{
tag.value(n, 2);
dset->AddElement(n[0], n[1]);
}
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
//=============================================================================
FEBioMeshDomainsSection::FEBioMeshDomainsSection(FEBioImport* pim) : FEBioFileSection(pim) {}
void FEBioMeshDomainsSection::Parse(XMLTag& tag)
{
// read all sections
if (tag.isleaf() == false)
{
++tag;
do
{
if (tag == "SolidDomain") ParseSolidDomainSection(tag);
else if (tag == "ShellDomain") ParseShellDomainSection(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
// let's build the part
FEBModel& feb = GetBuilder()->GetFEBModel();
FEBModel::Part* part = feb.GetPart(0); assert(part);
if (feb.BuildPart(*GetFEModel(), *part, false) == false)
{
throw XMLReader::Error("Failed building parts.");
}
// tell the file reader to rebuild the node ID table
GetBuilder()->BuildNodeList();
// At this point the mesh is completely read in.
// allocate material point data
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
for (int i = 0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
dom.CreateMaterialPointData();
}
// Now we can allocate the degrees of freedom.
int MAX_DOFS = fem.GetDOFS().GetTotalDOFS();
fem.GetMesh().SetDOFS(MAX_DOFS);
}
void FEBioMeshDomainsSection::ParseSolidDomainSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
FEBModel& feb = GetBuilder()->GetFEBModel();
FEBModel::Part* part = feb.GetPart(0); assert(part);
if (part == nullptr) throw XMLReader::InvalidTag(tag);
// get the domain name
const char* szname = tag.AttributeValue("name");
FEBModel::Domain* partDomain = part->FindDomain(szname);
if (partDomain == nullptr) throw XMLReader::InvalidAttributeValue(tag, "name", szname);
// get the material name
const char* szmat = tag.AttributeValue("mat");
FEMaterial* mat = fem.FindMaterial(szmat);
if (mat == nullptr) throw XMLReader::InvalidAttributeValue(tag, "mat", szmat);
// set the material name
partDomain->SetMaterialName(szmat);
// see if the element type is specified
const char* szelem = tag.AttributeValue("elem_type", true);
if (szelem)
{
FE_Element_Spec elemSpec = partDomain->ElementSpec();
FE_Element_Spec newSpec = GetBuilder()->ElementSpec(szelem);
// make sure it's valid
if ((FEElementLibrary::IsValid(newSpec) == false) || (elemSpec.eshape != newSpec.eshape))
{
throw XMLReader::InvalidAttributeValue(tag, "elem_type", szelem);
}
partDomain->SetElementSpec(newSpec);
}
// see if the three_field flag is defined
const char* sz3field = tag.AttributeValue("three_field", true);
if (sz3field)
{
if (strcmp(sz3field, "on") == 0)
{
FE_Element_Spec espec = partDomain->ElementSpec();
espec.m_bthree_field = true;
partDomain->SetElementSpec(espec);
}
else if (strcmp(sz3field, "off") == 0)
{
FE_Element_Spec espec = partDomain->ElementSpec();
espec.m_bthree_field = false;
partDomain->SetElementSpec(espec);
}
else throw XMLReader::InvalidAttributeValue(tag, "three_field", sz3field);
}
// --- build the domain ---
// we'll need the kernel for creating domains
FECoreKernel& febio = FECoreKernel::GetInstance();
// element count
int elems = partDomain->Elements();
// get the element spect
FE_Element_Spec spec = partDomain->ElementSpec();
// create the domain
FEDomain* dom = febio.CreateDomain(spec, &mesh, mat);
if (dom == 0) throw XMLReader::InvalidTag(tag);
mesh.AddDomain(dom);
// TODO: Should the domain parameters be read in before
// the domain is created? For UT4 domains, this is necessary
// since the initial ut4 parameters are copied from the element spec.
// but they can be overridden by the parameters.
if (dom->Create(elems, spec) == false)
{
throw XMLReader::InvalidTag(tag);
}
// assign the material
dom->SetMatID(mat->GetID() - 1);
// get the part name
string partName = part->Name();
if (partName.empty() == false) partName += ".";
string domName = partName + partDomain->Name();
dom->SetName(domName);
// process element data
for (int j = 0; j < elems; ++j)
{
const FEBModel::ELEMENT& domElement = partDomain->GetElement(j);
FEElement& el = dom->ElementRef(j);
el.SetID(domElement.id);
// TODO: This assumes one-based indexing of all nodes!
int ne = el.Nodes();
for (int n = 0; n < ne; ++n) el.m_node[n] = domElement.node[n] - 1;
}
// read additional parameters
if (tag.isleaf() == false)
{
ReadParameterList(tag, dom);
}
}
void FEBioMeshDomainsSection::ParseShellDomainSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
FEBModel& feb = GetBuilder()->GetFEBModel();
FEBModel::Part* part = feb.GetPart(0); assert(part);
if (part == nullptr) throw XMLReader::InvalidTag(tag);
// get the domain name
const char* szname = tag.AttributeValue("name");
FEBModel::Domain* partDomain = part->FindDomain(szname);
if (partDomain == nullptr) throw XMLReader::InvalidAttributeValue(tag, "name", szname);
// get the material name
const char* szmat = tag.AttributeValue("mat");
FEMaterial* mat = fem.FindMaterial(szmat);
if (mat == nullptr) throw XMLReader::InvalidAttributeValue(tag, "mat", szmat);
// set the material name
partDomain->SetMaterialName(szmat);
// see if the element type is specified
const char* szelem = tag.AttributeValue("elem_type", true);
if (szelem)
{
FE_Element_Spec elemSpec = partDomain->ElementSpec();
FE_Element_Spec newSpec = GetBuilder()->ElementSpec(szelem);
// make sure it's valid
if ((FEElementLibrary::IsValid(newSpec) == false) || (elemSpec.eshape != newSpec.eshape))
{
throw XMLReader::InvalidAttributeValue(tag, "elem_type", szelem);
}
partDomain->SetElementSpec(newSpec);
}
// see if the three_field flag is defined
const char* sz3field = tag.AttributeValue("three_field", true);
if (sz3field)
{
if (strcmp(sz3field, "on") == 0)
{
FE_Element_Spec espec = partDomain->ElementSpec();
espec.m_bthree_field = true;
partDomain->SetElementSpec(espec);
}
else if (strcmp(sz3field, "off") == 0)
{
FE_Element_Spec espec = partDomain->ElementSpec();
espec.m_bthree_field = false;
partDomain->SetElementSpec(espec);
}
else throw XMLReader::InvalidAttributeValue(tag, "three_field", sz3field);
}
// --- build the domain ---
// we'll need the kernel for creating domains
FECoreKernel& febio = FECoreKernel::GetInstance();
// element count
int elems = partDomain->Elements();
// get the element spect
FE_Element_Spec spec = partDomain->ElementSpec();
// create the domain
FEDomain* dom = febio.CreateDomain(spec, &mesh, mat);
if (dom == 0) throw XMLReader::InvalidTag(tag);
mesh.AddDomain(dom);
if (dom->Create(elems, spec) == false)
{
throw XMLReader::InvalidTag(tag);
}
// assign the material
dom->SetMatID(mat->GetID() - 1);
// get the part name
string partName = part->Name();
if (partName.empty() == false) partName += ".";
string domName = partName + partDomain->Name();
dom->SetName(domName);
// process element data
for (int j = 0; j < elems; ++j)
{
const FEBModel::ELEMENT& domElement = partDomain->GetElement(j);
FEElement& el = dom->ElementRef(j);
el.SetID(domElement.id);
// TODO: This assumes one-based indexing of all nodes!
int ne = el.Nodes();
for (int n = 0; n < ne; ++n) el.m_node[n] = domElement.node[n] - 1;
}
// read additional parameters
if (tag.isleaf() == false)
{
ReadParameterList(tag, dom);
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioControlSection.cpp | .cpp | 14,373 | 435 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioControlSection.h"
#include "FECore/FEAnalysis.h"
#include "FECore/FEModel.h"
#include "FECore/FECoreKernel.h"
#include <FECore/FETimeStepController.h>
#include <FECore/log.h>
#include <FECore/FENewtonSolver.h>
#ifndef WIN32
#define strnicmp strncasecmp
#endif
class FEObsoleteParamHandler25 : public FEObsoleteParamHandler
{
public:
FEObsoleteParamHandler25(XMLTag& tag, FEAnalysis* step, FEModelBuilder* feb) : m_step(step), m_feb(feb), FEObsoleteParamHandler(tag, step)
{
AddParam("max_ups", "solver.qn_method.max_ups", FE_PARAM_INT);
}
bool ProcessTag(XMLTag& tag) override
{
if (tag == "qnmethod")
{
const char* szv = tag.szvalue();
int l = (int)strlen(szv);
if ((strnicmp(szv, "BFGS" , l) == 0) || (strnicmp(szv, "0", l) == 0)) m_qnmethod = QN_BFGS;
else if ((strnicmp(szv, "BROYDEN", l) == 0) || (strnicmp(szv, "1", l) == 0)) m_qnmethod = QN_BROYDEN;
else if ((strnicmp(szv, "JFNK" , l) == 0) || (strnicmp(szv, "2", l) == 0)) m_qnmethod = QN_JFNK;
else return false;
return true;
}
else if (tag == "shell_formulation")
{
int nshell = 0;
tag.value(nshell);
switch (nshell)
{
case 0: m_feb->m_default_shell = OLD_SHELL; break;
case 1: m_feb->m_default_shell = NEW_SHELL; break;
case 2: m_feb->m_default_shell = EAS_SHELL; break;
case 3: m_feb->m_default_shell = ANS_SHELL; break;
default:
return false;
}
return true;
}
else return FEObsoleteParamHandler::ProcessTag(tag);
}
void MapParameters() override
{
FEModel* fem = m_step->GetFEModel();
// first, make sure that the QN method is allocated
if (m_qnmethod != -1)
{
FENewtonSolver& solver = dynamic_cast<FENewtonSolver&>(*m_step->GetFESolver());
FEProperty& qn = *solver.FindProperty("qn_method");
switch (m_qnmethod)
{
case QN_BFGS : solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("BFGS" , fem)); break;
case QN_BROYDEN: solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("Broyden", fem)); break;
case QN_JFNK : solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("JFNK" , fem)); break;
default:
assert(false);
}
}
// now, process the rest
FEObsoleteParamHandler::MapParameters();
}
private:
int m_qnmethod = 0;
FEAnalysis* m_step;
FEModelBuilder* m_feb;
};
//-----------------------------------------------------------------------------
void FEBioControlSection::Parse(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = GetBuilder()->GetStep();
if (pstep == 0)
{
throw XMLReader::InvalidTag(tag);
}
// Get the solver
FESolver* psolver = pstep->GetFESolver();
if (psolver == 0)
{
string m = GetBuilder()->GetModuleName();
throw FEBioImport::FailedAllocatingSolver(m.c_str());
}
FEObsoleteParamHandler25 ctrlParams(tag, pstep, GetBuilder());
++tag;
do
{
// first parse common control parameters
if (ParseCommonParams(tag) == false)
{
// next, check the solver parameters
if (ReadParameter(tag, psolver->GetParameterList()) == false)
{
if (ctrlParams.ProcessTag(tag) == false)
{
throw XMLReader::InvalidTag(tag);
}
}
}
++tag;
}
while (!tag.isend());
ctrlParams.MapParameters();
}
//-----------------------------------------------------------------------------
// Parse control parameters common to all solvers/modules
bool FEBioControlSection::ParseCommonParams(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
FEBioImport* imp = GetFEBioImport();
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = GetBuilder()->GetStep();
FEParameterList& modelParams = fem.GetParameterList();
FEParameterList& stepParams = pstep->GetParameterList();
// The "analysis" parameter is now an actual parameter of FEAnalysis.
// This means the old format, using the type attribute, is not recognized
// and we have to make sure that this parameter gets processed before the step parameters.
if (tag == "analysis")
{
XMLAtt& att = tag.Attribute("type");
if (att == "static" ) pstep->m_nanalysis = 0;
else if (att == "dynamic" ) pstep->m_nanalysis = 1;
else if (att == "steady-state") pstep->m_nanalysis = 0;
else if (att == "transient" ) pstep->m_nanalysis = 1;
else throw XMLReader::InvalidAttributeValue(tag, "type", att.cvalue());
}
else if (ReadParameter(tag, modelParams) == false)
{
if (ReadParameter(tag, stepParams) == false)
{
if (tag == "time_stepper")
{
if (pstep->m_timeController == nullptr) pstep->m_timeController = fecore_alloc(FETimeStepController, &fem);
FETimeStepController& tc = *pstep->m_timeController;
FEParameterList& pl = tc.GetParameterList();
ReadParameterList(tag, pl);
}
else if (tag == "use_three_field_hex") tag.value(feb->m_b3field_hex);
else if (tag == "use_three_field_tet") tag.value(feb->m_b3field_tet);
else if (tag == "use_three_field_shell") tag.value(feb->m_b3field_shell);
else if (tag == "use_three_field_quad") tag.value(feb->m_b3field_quad);
else if (tag == "use_three_field_tri") tag.value(feb->m_b3field_tri);
else if (tag == "shell_formulation")
{
FEMesh& mesh = GetFEModel()->GetMesh();
int nshell = 0;
tag.value(nshell);
switch (nshell)
{
case 0: feb->m_default_shell = OLD_SHELL; break;
case 1: feb->m_default_shell = NEW_SHELL; break;
case 2: feb->m_default_shell = EAS_SHELL; break;
case 3: feb->m_default_shell = ANS_SHELL; break;
default:
throw XMLReader::InvalidValue(tag);
}
}
else if (tag == "shell_normal_nodal") tag.value(feb->m_shell_norm_nodal);
else if (tag == "integration") ParseIntegrationRules(tag);
else if (tag == "print_level")
{
feLogWarningEx((&fem), "The print_level parameter is no longer supported and will be ignored.");
}
else return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
void FEBioControlSection::ParseIntegrationRules(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
FEModel& fem = *GetFEModel();
++tag;
do
{
if (tag == "rule")
{
XMLAtt& elem = tag.Attribute("elem");
const char* szv = tag.szvalue();
if (elem == "hex8")
{
if (tag.isleaf())
{
if (strcmp(szv, "GAUSS8") == 0) feb->m_nhex8 = FE_HEX8G8;
else if (strcmp(szv, "POINT6") == 0) feb->m_nhex8 = FE_HEX8RI;
else if (strcmp(szv, "UDG" ) == 0) feb->m_nhex8 = FE_HEX8G1;
else throw XMLReader::InvalidValue(tag);
}
else
{
const char* szt = tag.AttributeValue("type");
if (strcmp(szt, "GAUSS8") == 0) feb->m_nhex8 = FE_HEX8G8;
else if (strcmp(szt, "POINT6") == 0) feb->m_nhex8 = FE_HEX8RI;
else if (strcmp(szt, "UDG" ) == 0) feb->m_nhex8 = FE_HEX8G1;
else throw XMLReader::InvalidAttributeValue(tag, "type", szt);
++tag;
do
{
if (tag == "hourglass") tag.value(feb->m_udghex_hg);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
}
else if (elem == "tet10")
{
if (strcmp(szv, "GAUSS1" ) == 0) feb->m_ntet10 = FE_TET10G1;
else if (strcmp(szv, "GAUSS4" ) == 0) feb->m_ntet10 = FE_TET10G4;
else if (strcmp(szv, "GAUSS8" ) == 0) feb->m_ntet10 = FE_TET10G8;
else if (strcmp(szv, "LOBATTO11") == 0) feb->m_ntet10 = FE_TET10GL11;
else if (strcmp(szv, "GAUSS4RI1") == 0) feb->m_ntet10 = FE_TET10G4RI1;
else if (strcmp(szv, "GAUSS8RI4") == 0) feb->m_ntet10 = FE_TET10G8RI4;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tet15")
{
if (strcmp(szv, "GAUSS8" ) == 0) feb->m_ntet15 = FE_TET15G8;
else if (strcmp(szv, "GAUSS11" ) == 0) feb->m_ntet15 = FE_TET15G11;
else if (strcmp(szv, "GAUSS15" ) == 0) feb->m_ntet15 = FE_TET15G15;
else if (strcmp(szv, "GAUSS15RI4") == 0) feb->m_ntet10 = FE_TET15G15RI4;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tet20")
{
if (strcmp(szv, "GAUSS15") == 0) feb->m_ntet20 = FE_TET20G15;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tri3")
{
if (strcmp(szv, "GAUSS1") == 0) feb->m_ntri3 = FE_TRI3G1;
else if (strcmp(szv, "GAUSS3") == 0) feb->m_ntri3 = FE_TRI3G3;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tri6")
{
if (strcmp(szv, "GAUSS3" ) == 0) feb->m_ntri6 = FE_TRI6G3;
else if (strcmp(szv, "GAUSS6" ) == 0) feb->m_ntri6 = FE_TRI6NI;
else if (strcmp(szv, "GAUSS4" ) == 0) feb->m_ntri6 = FE_TRI6G4;
else if (strcmp(szv, "GAUSS7" ) == 0) feb->m_ntri6 = FE_TRI6G7;
else if (strcmp(szv, "LOBATTO7" ) == 0) feb->m_ntri6 = FE_TRI6GL7;
// else if (strcmp(szv, "MOD_GAUSS7") == 0) feb->m_ntri6 = FE_TRI6MG7;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tri7")
{
if (strcmp(szv, "GAUSS3" ) == 0) feb->m_ntri7 = FE_TRI7G3;
else if (strcmp(szv, "GAUSS4" ) == 0) feb->m_ntri7 = FE_TRI7G4;
else if (strcmp(szv, "GAUSS7" ) == 0) feb->m_ntri7 = FE_TRI7G7;
else if (strcmp(szv, "LOBATTO7") == 0) feb->m_ntri7 = FE_TRI7GL7;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tri10")
{
if (strcmp(szv, "GAUSS7" ) == 0) feb->m_ntri10 = FE_TRI10G7;
else if (strcmp(szv, "GAUSS12") == 0) feb->m_ntri10 = FE_TRI10G12;
else throw XMLReader::InvalidValue(tag);
}
else if (elem == "tet4")
{
if (tag.isleaf())
{
if (strcmp(szv, "GAUSS4") == 0) feb->m_ntet4 = FE_TET4G4;
else if (strcmp(szv, "GAUSS1") == 0) feb->m_ntet4 = FE_TET4G1;
else if (strcmp(szv, "UT4" ) == 0) feb->m_but4 = true;
else throw XMLReader::InvalidValue(tag);
}
else
{
const char* szt = tag.AttributeValue("type");
if (strcmp(szt, "GAUSS4") == 0) feb->m_ntet4 = FE_TET4G4;
else if (strcmp(szt, "GAUSS1") == 0) feb->m_ntet4 = FE_TET4G1;
else if (strcmp(szt, "UT4" ) == 0) feb->m_but4 = true;
else throw XMLReader::InvalidAttributeValue(tag, "type", szv);
++tag;
do
{
if (tag == "alpha" ) tag.value(feb->m_ut4_alpha);
else if (tag == "iso_stab") tag.value(feb->m_ut4_bdev);
else if (tag == "stab_int")
{
const char* sz = tag.szvalue();
if (strcmp(sz, "GAUSS4") == 0) feb->m_ntet4 = FE_TET4G4;
else if (strcmp(sz, "GAUSS1") == 0) feb->m_ntet4 = FE_TET4G1;
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
}
else throw XMLReader::InvalidAttributeValue(tag, "elem", elem.cvalue());
}
else throw XMLReader::InvalidValue(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEStepControlSection::Parse(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = GetBuilder()->GetStep();
// Get the solver
FESolver* psolver = pstep->GetFESolver();
if (psolver == 0)
{
string m = GetBuilder()->GetModuleName();
throw FEBioImport::FailedAllocatingSolver(m.c_str());
}
FEObsoleteParamHandler25 ctrlParams(tag, pstep, GetBuilder());
++tag;
do
{
// first parse common control parameters
if (ParseCommonParams(tag) == false)
{
// next, check the solver parameters
if (ReadParameter(tag, psolver->GetParameterList()) == false)
{
if (ctrlParams.ProcessTag(tag) == false)
{
throw XMLReader::InvalidTag(tag);
}
}
}
++tag;
} while (!tag.isend());
}
//-----------------------------------------------------------------------------
// Parse control parameters common to all solvers/modules
bool FEStepControlSection::ParseCommonParams(XMLTag& tag)
{
FEModelBuilder* feb = GetBuilder();
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = GetBuilder()->GetStep();
FEParameterList& modelParams = fem.GetParameterList();
FEParameterList& stepParams = pstep->GetParameterList();
// NOTE: The "analysis" parameter is now an actual parameter of the FEAnalysis class.
// This implies that the old format cannot be read anymore, and we have to make
// to make sure that this parameter is processed before any FEAnalysis parameters.
if (tag == "analysis")
{
XMLAtt& att = tag.Attribute("type");
if (att == "static" ) pstep->m_nanalysis = 0;
else if (att == "dynamic" ) pstep->m_nanalysis = 1;
else if (att == "steady-state") pstep->m_nanalysis = 0;
else if (att == "transient" ) pstep->m_nanalysis = 1;
else throw XMLReader::InvalidAttributeValue(tag, "type", att.cvalue());
}
else if (tag == "shell_normal_nodal") tag.value(feb->m_shell_norm_nodal);
else if (ReadParameter(tag, modelParams) == false)
{
if (ReadParameter(tag, stepParams) == false)
{
if (tag == "time_stepper")
{
if (pstep->m_timeController == nullptr) pstep->m_timeController = fecore_alloc(FETimeStepController, &fem);
FETimeStepController& tc = *pstep->m_timeController;
FEParameterList& pl = tc.GetParameterList();
ReadParameterList(tag, pl);
}
else return false;
}
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioRigidSection.h | .h | 1,548 | 42 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
class FEBioRigidSection : public FEFileSection
{
public:
FEBioRigidSection(FEFileImport* pim) : FEFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseRigidBC(XMLTag& tag);
void ParseRigidConnector(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioGlobalsSection.cpp | .cpp | 3,501 | 118 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioGlobalsSection.h"
#include "FECore/FEModel.h"
#include "FECore/FEGlobalData.h"
#include "FECore/FECoreKernel.h"
//-----------------------------------------------------------------------------
//! This function reads the global variables from the xml file
//!
void FEBioGlobalsSection::Parse(XMLTag& tag)
{
++tag;
do
{
if (tag == "Constants" ) ParseConstants(tag);
else if (tag == "Solutes" ) ParseGlobalData(tag);
else if (tag == "SolidBoundMolecules") ParseGlobalData(tag);
else if (tag == "Variables" ) ParseVariables(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGlobalsSection::ParseConstants(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
++tag;
string s;
double v;
do
{
s = string(tag.Name());
tag.value(v);
fem.SetGlobalConstant(s, v);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGlobalsSection::ParseGlobalData(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
// read the global solute data
++tag;
do
{
// create new global data
FEGlobalData* pgd = fecore_new<FEGlobalData>(tag.Name(), &fem);
if (pgd == 0) throw XMLReader::InvalidTag(tag);
fem.AddGlobalData(pgd);
// TODO: We have to call the Init member here because solute data
// allocates the concentration dofs and they have to be allocated before
// materials are read in. I'd like to move this to FEModel::Init but not sure
// yet how.
pgd->Init();
// read solute properties
ReadParameterList(tag, pgd);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioGlobalsSection::ParseVariables(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
fem.GetParameterList();
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "var")
{
const char* szname = tag.AttributeValue("name");
double v = 0; tag.value(v);
fem.AddGlobalVariable(szname, v);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioStepSection4.h | .h | 1,547 | 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) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
//-----------------------------------------------------------------------------
// Step Section (4.0 format)
class FEBioStepSection4 : public FEFileSection
{
public:
FEBioStepSection4(FEFileImport* pim);
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioStepSection4.cpp | .cpp | 2,641 | 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) 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 "FEBioStepSection4.h"
#include "FEBioControlSection4.h"
#include "FEBioInitialSection3.h"
#include "FEBioBoundarySection3.h"
#include "FEBioLoadsSection.h"
#include "FEBioConstraintsSection.h"
#include "FEBioContactSection.h"
#include "FEBioRigidSection4.h"
#include "FEBioMeshAdaptorSection.h"
//-----------------------------------------------------------------------------
FEBioStepSection4::FEBioStepSection4(FEFileImport* pim) : FEFileSection(pim) {}
//-----------------------------------------------------------------------------
void FEBioStepSection4::Parse(XMLTag& tag)
{
// Build the file section map
FEFileImport* imp = GetFileReader();
FEFileSectionMap Map;
Map["Control" ] = new FEBioControlSection4(imp);
Map["Initial" ] = new FEBioInitialSection3(imp);
Map["Boundary" ] = new FEBioBoundarySection3(imp);
Map["Loads" ] = new FEBioLoadsSection3(imp);
Map["Constraints"] = new FEBioConstraintsSection25(imp);
Map["Contact" ] = new FEBioContactSection25(imp);
Map["Rigid" ] = new FEBioRigidSection4(imp);
Map["MeshAdaptor"] = new FEBioMeshAdaptorSection(imp);
++tag;
do
{
if (tag == "step")
{
// create next step
GetBuilder()->NextStep();
// parse the file sections
Map.Parse(tag);
}
else throw XMLReader::MissingTag(tag, "step");
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioMeshDataSection.h | .h | 4,903 | 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 "FEBioImport.h"
//-----------------------------------------------------------------------------
class FEDomainMap;
class FESurfaceMap;
class FENodeDataMap;
//-----------------------------------------------------------------------------
// MeshData Section (introduced in febio_spec 2.5)
class FEBioMeshDataSection : public FEBioFileSection
{
struct ELEMENT_DATA
{
int nval; // number of values read
double val[FEElement::MAX_NODES]; // scalar value
};
public:
FEBioMeshDataSection(FEBioImport* pim) : FEBioFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseShellThickness(XMLTag& tag, FEElementSet& set);
void ParseMaterialFibers(XMLTag& tag, FEElementSet& set);
void ParseElementMaterialAxes(XMLTag& tag, FEElementSet& set);
void ParseMaterialAxesProperty(XMLTag& tag, FEElementSet& set);
void ParseMaterialData (XMLTag& tag, FEElementSet& set, const string& name);
void ParseMaterialFiberProperty(XMLTag& tag, FEElementSet& set);
private:
void ParseNodeData(XMLTag& tag);
void ParseEdgeData(XMLTag& tag);
void ParseSurfaceData(XMLTag& tag);
void ParseElementData(XMLTag& tag);
void ParseElementData(XMLTag& tag, FEElementSet& set, vector<ELEMENT_DATA>& values, int nvalues);
void ParseElementData(XMLTag& tag, FEDomainMap& map);
void ParseDataArray(XMLTag& tag, FEDataArray& map, const char* sztag);
FEElement* ParseElement(XMLTag& tag, FEElementSet& set);
private:
vector<FEElement*> m_pelem;
};
//-----------------------------------------------------------------------------
// MeshData Section for febio_spec 3.0
class FEBioMeshDataSection3 : public FEBioFileSection
{
struct ELEMENT_DATA
{
int nval; // number of values read
double val[FEElement::MAX_NODES]; // scalar value
};
public:
FEBioMeshDataSection3(FEBioImport* pim) : FEBioFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodalData(XMLTag& tag);
void ParseSurfaceData(XMLTag& tag);
void ParseElementData(XMLTag& tag);
protected:
// void ParseModelParameter(XMLTag& tag, FEParamValue param);
// void ParseMaterialPointData(XMLTag& tag, FEParamValue param);
protected:
void ParseShellThickness(XMLTag& tag, FEElementSet& set);
void ParseMaterialFibers(XMLTag& tag, FEElementSet& set);
void ParseMaterialAxes(XMLTag& tag, FEElementSet& set);
void ParseMaterialAxesProperty(XMLTag& tag, FEElementSet& set);
private:
void ParseElementData(XMLTag& tag, FEElementSet& set, vector<ELEMENT_DATA>& values, int nvalues);
void ParseElementData(XMLTag& tag, FEDomainMap& map);
void ParseSurfaceData(XMLTag& tag, FESurfaceMap& map);
void ParseNodeData (XMLTag& tag, FENodeDataMap& map);
};
//-----------------------------------------------------------------------------
// MeshData Section for febio_spec 4.0
class FEBioMeshDataSection4: public FEBioFileSection
{
struct ELEMENT_DATA
{
int nval; // number of values read
double val[FEElement::MAX_NODES]; // scalar value
};
public:
FEBioMeshDataSection4(FEBioImport* pim) : FEBioFileSection(pim) {}
void Parse(XMLTag& tag);
protected:
void ParseNodalData(XMLTag& tag);
void ParseSurfaceData(XMLTag& tag);
void ParseElementData(XMLTag& tag);
private:
void ParseNodeData(XMLTag& tag, FENodeDataMap& map);
void ParseSurfaceData(XMLTag& tag, FESurfaceMap& map);
void ParseElementData(XMLTag& tag, FEElementSet& set, vector<ELEMENT_DATA>& values, int nvalues);
void ParseElementData(XMLTag& tag, FEDomainMap& map);
void ParseShellThickness(XMLTag& tag, FEElementSet& set);
void ParseMaterialAxes(XMLTag& tag, FEElementSet& set);
void ParseMaterialFibers(XMLTag& tag, FEElementSet& set);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioBoundarySection.cpp | .cpp | 44,201 | 1,474 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioBoundarySection.h"
#include <FECore/FEModel.h>
#include <FECore/FEDiscreteMaterial.h>
#include <FECore/FEDiscreteDomain.h>
#include <FECore/FEAugLagLinearConstraint.h>
#include <FECore/FEPrescribedDOF.h>
#include <FECore/FEFixedBC.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FELinearConstraintManager.h>
#include <FECore/FEPeriodicLinearConstraint.h>
#include <FECore/FEMergedConstraint.h>
#include <FECore/FEFacetSet.h>
#include <FECore/log.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FEInitialCondition.h>
//---------------------------------------------------------------------------------
void FEBioBoundarySection::BuildNodeSetMap()
{
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
m_NodeSet.clear();
for (int i = 0; i<m.NodeSets(); ++i)
{
FENodeSet* nsi = m.NodeSet(i);
m_NodeSet[nsi->GetName()] = nsi;
}
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection1x::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "fix" ) ParseBCFix (tag);
else if (tag == "prescribe" ) ParseBCPrescribe (tag);
else if (tag == "contact" ) ParseContactSection(tag);
else if (tag == "linear_constraint") ParseConstraints (tag);
else if (tag == "spring" ) ParseSpringSection (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection2::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "fix" ) ParseBCFix (tag);
else if (tag == "prescribe" ) ParseBCPrescribe(tag);
else if (tag == "linear_constraint") ParseConstraints(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection25::Parse(XMLTag& tag)
{
if (tag.isleaf()) return;
// build the node set map for faster lookup
BuildNodeSetMap();
++tag;
do
{
if (tag == "fix" ) ParseBCFix (tag);
else if (tag == "prescribe" ) ParseBCPrescribe (tag);
else if (tag == "bc" ) ParseBC (tag);
else if (tag == "rigid" ) ParseBCRigid (tag);
else if (tag == "rigid_body" ) ParseRigidBody (tag);
else if (tag == "linear_constraint" ) ParseConstraints (tag);
else if (tag == "periodic_linear_constraint" ) ParsePeriodicLinearConstraint (tag);
else if (tag == "periodic_linear_constraint_2O") ParsePeriodicLinearConstraint2O(tag);
else if (tag == "merge" ) ParseMergeConstraint (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//---------------------------------------------------------------------------------
// parse a surface section for contact definitions
//
bool FEBioBoundarySection::ParseSurfaceSection(XMLTag &tag, FESurface& s, int nfmt, bool bnodal)
{
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
int NN = m.Nodes();
int N, nf[9];
// count nr of faces
int faces = tag.children();
// allocate storage for faces
s.Create(faces);
FEModelBuilder* feb = GetBuilder();
// read faces
++tag;
for (int i=0; i<faces; ++i)
{
FESurfaceElement& el = s.Element(i);
// set the element type/integration rule
if (bnodal)
{
if (tag == "quad4") el.SetType(FE_QUAD4NI);
else if (tag == "tri3" ) el.SetType(FE_TRI3NI );
else if (tag == "tri6" ) el.SetType(FE_TRI6NI );
else if (tag == "quad8" ) el.SetType(FE_QUAD8NI);
else if (tag == "quad9" ) el.SetType(FE_QUAD9NI);
else throw XMLReader::InvalidTag(tag);
}
else
{
if (tag == "quad4") el.SetType(FE_QUAD4G4);
else if (tag == "tri3" ) el.SetType(feb->m_ntri3);
else if (tag == "tri6" ) el.SetType(feb->m_ntri6);
else if (tag == "tri7" ) el.SetType(feb->m_ntri7);
else if (tag == "tri10") el.SetType(feb->m_ntri10);
else if (tag == "quad8") el.SetType(FE_QUAD8G9);
else if (tag == "quad9") el.SetType(FE_QUAD9G9);
else throw XMLReader::InvalidTag(tag);
}
N = el.Nodes();
if (nfmt == 0)
{
tag.value(nf, N);
for (int j=0; j<N; ++j)
{
int nid = nf[j]-1;
if ((nid<0)||(nid>= NN)) throw XMLReader::InvalidValue(tag);
el.m_node[j] = nid;
}
}
else if (nfmt == 1)
{
tag.value(nf, 2);
FEElement* pe = m.FindElementFromID(nf[0]);
if (pe)
{
int ne[9];
int nn = pe->GetFace(nf[1]-1, ne);
if (nn != N) throw XMLReader::InvalidValue(tag);
for (int j=0; j<N; ++j) el.m_node[j] = ne[j];
el.m_elem[0].pe = pe;
}
else throw XMLReader::InvalidValue(tag);
}
++tag;
}
return true;
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection::AddFixedBC(FENodeSet* set, int dof)
{
FEModel* fem = GetFEModel();
FEFixedBC* bc = new FEFixedBC(fem);
bc->SetDOFList(dof);
bc->SetNodeSet(set);
fem->AddBoundaryCondition(bc);
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection::ParseBCFix(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
DOFS& dofs = fem.GetDOFS();
// get the DOF indices
const int dof_X = fem.GetDOFIndex("x");
const int dof_Y = fem.GetDOFIndex("y");
const int dof_Z = fem.GetDOFIndex("z");
const int dof_U = fem.GetDOFIndex("u");
const int dof_V = fem.GetDOFIndex("v");
const int dof_W = fem.GetDOFIndex("w");
const int dof_SX = fem.GetDOFIndex("sx");
const int dof_SY = fem.GetDOFIndex("sy");
const int dof_SZ = fem.GetDOFIndex("sz");
const int dof_WX = fem.GetDOFIndex("wx");
const int dof_WY = fem.GetDOFIndex("wy");
const int dof_WZ = fem.GetDOFIndex("wz");
const int dof_GX = fem.GetDOFIndex("gx");
const int dof_GY = fem.GetDOFIndex("gy");
const int dof_GZ = fem.GetDOFIndex("gz");
// see if a set is defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// read the set
FEMesh& mesh = fem.GetMesh();
FENodeSet* ps = mesh.FindNodeSet(szset);
if (ps == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szset);
// get the bc attribute
const char* sz = tag.AttributeValue("bc");
// Make sure this is a leaf
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// loop over all nodes in the nodeset
int ndof = dofs.GetDOF(sz);
if (ndof >= 0) AddFixedBC(ps, ndof);
else
{
// The supported fixed BC strings don't quite follow the dof naming convention.
// For now, we'll check these BC explicitly, but I want to get rid of this in the future.
if (strcmp(sz, "xy" ) == 0) { AddFixedBC(ps, dof_X ); AddFixedBC(ps, dof_Y); }
else if (strcmp(sz, "yz" ) == 0) { AddFixedBC(ps, dof_Y ); AddFixedBC(ps, dof_Z); }
else if (strcmp(sz, "xz" ) == 0) { AddFixedBC(ps, dof_X ); AddFixedBC(ps, dof_Z); }
else if (strcmp(sz, "xyz" ) == 0) { AddFixedBC(ps, dof_X ); AddFixedBC(ps, dof_Y); AddFixedBC(ps, dof_Z); }
else if (strcmp(sz, "uv" ) == 0) { AddFixedBC(ps, dof_U ); AddFixedBC(ps, dof_V); }
else if (strcmp(sz, "vw" ) == 0) { AddFixedBC(ps, dof_V ); AddFixedBC(ps, dof_W); }
else if (strcmp(sz, "uw" ) == 0) { AddFixedBC(ps, dof_U ); AddFixedBC(ps, dof_W); }
else if (strcmp(sz, "uvw" ) == 0) { AddFixedBC(ps, dof_U ); AddFixedBC(ps, dof_V); AddFixedBC(ps, dof_W); }
else if (strcmp(sz, "sxy" ) == 0) { AddFixedBC(ps, dof_SX); AddFixedBC(ps, dof_SY); }
else if (strcmp(sz, "syz" ) == 0) { AddFixedBC(ps, dof_SY); AddFixedBC(ps, dof_SZ); }
else if (strcmp(sz, "sxz" ) == 0) { AddFixedBC(ps, dof_SX); AddFixedBC(ps, dof_SZ); }
else if (strcmp(sz, "sxyz") == 0) { AddFixedBC(ps, dof_SX); AddFixedBC(ps, dof_SY); AddFixedBC(ps, dof_SZ); }
else if (strcmp(sz, "wxy" ) == 0) { AddFixedBC(ps, dof_WX); AddFixedBC(ps, dof_WY); }
else if (strcmp(sz, "wyz" ) == 0) { AddFixedBC(ps, dof_WY); AddFixedBC(ps, dof_WZ); }
else if (strcmp(sz, "wxz" ) == 0) { AddFixedBC(ps, dof_WX); AddFixedBC(ps, dof_WZ); }
else if (strcmp(sz, "wxyz") == 0) { AddFixedBC(ps, dof_WX); AddFixedBC(ps, dof_WY); AddFixedBC(ps, dof_WZ); }
else if (strcmp(sz, "gxy" ) == 0) { AddFixedBC(ps, dof_GX); AddFixedBC(ps, dof_GY); }
else if (strcmp(sz, "gyz" ) == 0) { AddFixedBC(ps, dof_GY); AddFixedBC(ps, dof_GZ); }
else if (strcmp(sz, "gxz" ) == 0) { AddFixedBC(ps, dof_GX); AddFixedBC(ps, dof_GZ); }
else if (strcmp(sz, "gxyz") == 0) { AddFixedBC(ps, dof_GX); AddFixedBC(ps, dof_GY); AddFixedBC(ps, dof_GZ); }
else throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
}
}
else
{
// The format where the bc can be defined on each line is no longer supported.
throw XMLReader::MissingAttribute(tag, "set");
}
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection2::ParseBCFix(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
DOFS& dofs = fem.GetDOFS();
FEMesh& mesh = fem.GetMesh();
int NN = mesh.Nodes();
// get the required bc attribute
char szbc[32] = { 0 };
strcpy(szbc, tag.AttributeValue("bc"));
// process the bc string
vector<int> bc;
int ndof = dofs.GetDOF(szbc);
if (ndof >= 0) bc.push_back(ndof);
else
{
// get the DOF indices
const int dof_X = fem.GetDOFIndex("x");
const int dof_Y = fem.GetDOFIndex("y");
const int dof_Z = fem.GetDOFIndex("z");
const int dof_U = fem.GetDOFIndex("u");
const int dof_V = fem.GetDOFIndex("v");
const int dof_W = fem.GetDOFIndex("w");
const int dof_SX = fem.GetDOFIndex("sx");
const int dof_SY = fem.GetDOFIndex("sy");
const int dof_SZ = fem.GetDOFIndex("sz");
const int dof_WX = fem.GetDOFIndex("wx");
const int dof_WY = fem.GetDOFIndex("wy");
const int dof_WZ = fem.GetDOFIndex("wz");
const int dof_GX = fem.GetDOFIndex("gx");
const int dof_GY = fem.GetDOFIndex("gy");
const int dof_GZ = fem.GetDOFIndex("gz");
// The supported fixed BC strings don't quite follow the dof naming convention.
// For now, we'll check these BC explicitly, but I want to get rid of this in the future.
if (strcmp(szbc, "x" ) == 0) { bc.push_back(dof_X ); }
else if (strcmp(szbc, "y" ) == 0) { bc.push_back(dof_Y ); }
else if (strcmp(szbc, "z" ) == 0) { bc.push_back(dof_Z ); }
else if (strcmp(szbc, "xy" ) == 0) { bc.push_back(dof_X ); bc.push_back(dof_Y); }
else if (strcmp(szbc, "yz" ) == 0) { bc.push_back(dof_Y ); bc.push_back(dof_Z); }
else if (strcmp(szbc, "xz" ) == 0) { bc.push_back(dof_X ); bc.push_back(dof_Z); }
else if (strcmp(szbc, "xyz" ) == 0) { bc.push_back(dof_X ); bc.push_back(dof_Y); bc.push_back(dof_Z); }
else if (strcmp(szbc, "uv" ) == 0) { bc.push_back(dof_U ); bc.push_back(dof_V); }
else if (strcmp(szbc, "vw" ) == 0) { bc.push_back(dof_V ); bc.push_back(dof_W); }
else if (strcmp(szbc, "uw" ) == 0) { bc.push_back(dof_U ); bc.push_back(dof_W); }
else if (strcmp(szbc, "uvw" ) == 0) { bc.push_back(dof_U ); bc.push_back(dof_V); bc.push_back(dof_W); }
else if (strcmp(szbc, "sxy" ) == 0) { bc.push_back(dof_SX); bc.push_back(dof_SY); }
else if (strcmp(szbc, "syz" ) == 0) { bc.push_back(dof_SY); bc.push_back(dof_SZ); }
else if (strcmp(szbc, "sxz" ) == 0) { bc.push_back(dof_SX); bc.push_back(dof_SZ); }
else if (strcmp(szbc, "sxyz") == 0) { bc.push_back(dof_SX); bc.push_back(dof_SY); bc.push_back(dof_SZ); }
else if (strcmp(szbc, "wxy" ) == 0) { bc.push_back(dof_WX); bc.push_back(dof_WY); }
else if (strcmp(szbc, "wyz" ) == 0) { bc.push_back(dof_WY); bc.push_back(dof_WZ); }
else if (strcmp(szbc, "wxz" ) == 0) { bc.push_back(dof_WX); bc.push_back(dof_WZ); }
else if (strcmp(szbc, "wxyz") == 0) { bc.push_back(dof_WX); bc.push_back(dof_WY); bc.push_back(dof_WZ); }
else if (strcmp(szbc, "gxy" ) == 0) { bc.push_back(dof_GX); bc.push_back(dof_GY); }
else if (strcmp(szbc, "gyz" ) == 0) { bc.push_back(dof_GY); bc.push_back(dof_GZ); }
else if (strcmp(szbc, "gxz" ) == 0) { bc.push_back(dof_GX); bc.push_back(dof_GZ); }
else if (strcmp(szbc, "gxyz") == 0) { bc.push_back(dof_GX); bc.push_back(dof_GY); bc.push_back(dof_GZ); }
else if (strcmp(szbc, "xyzuvw") == 0)
{
bc.push_back(dof_X); bc.push_back(dof_Y); bc.push_back(dof_Z);
bc.push_back(dof_U); bc.push_back(dof_V); bc.push_back(dof_W);
}
else if (strcmp(szbc, "xyzsxyz") == 0)
{
bc.push_back(dof_X); bc.push_back(dof_Y); bc.push_back(dof_Z);
bc.push_back(dof_SX); bc.push_back(dof_SY); bc.push_back(dof_SZ);
}
else
{
// see if this is a comma seperated list
if (dofs.ParseDOFString(szbc, bc) == false)
throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
}
}
if (bc.empty()) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// create the fixed BC's
FEFixedDOF* pbc = dynamic_cast<FEFixedDOF*>(fecore_new<FEBoundaryCondition>("fix", &fem));
pbc->SetDOFS(bc);
// add it to the model
GetBuilder()->AddBC(pbc);
// see if the set attribute is defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure the tag is a leaf
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// process the node set
FENodeSet* pns = mesh.FindNodeSet(szset);
if (pns == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szset);
pbc->SetNodeSet(pns);
}
else
{
FENodeSet* nset = new FENodeSet(&fem);
fem.GetMesh().AddNodeSet(nset);
// Read the fixed nodes
++tag;
do
{
int n = ReadNodeID(tag);
if ((n<0) || (n >= NN)) throw XMLReader::InvalidAttributeValue(tag, "id");
nset->Add(n);
++tag;
}
while (!tag.isend());
pbc->SetNodeSet(nset);
}
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection25::ParseBCFix(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
DOFS& dofs = fem.GetDOFS();
FEMesh& mesh = fem.GetMesh();
// make sure the tag is a leaf
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// get the required bc attribute
char szbc[64] = {0};
strcpy(szbc, tag.AttributeValue("bc"));
// process the bc string
vector<int> bc;
dofs.ParseDOFString(szbc, bc);
// check the list
if (bc.empty()) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
int nbc = (int)bc.size();
for (int i=0; i<nbc; ++i) if (bc[i] == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the nodeset
const char* szset = tag.AttributeValue("node_set");
map<string, FENodeSet*>::iterator nset = m_NodeSet.find(szset);
if (nset == m_NodeSet.end()) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
FENodeSet* nodeSet = (*nset).second;
// create the fixed BC
FEFixedDOF* pbc = dynamic_cast<FEFixedDOF*>(fecore_new<FEBoundaryCondition>("fix", &fem));
pbc->SetDOFS(bc);
pbc->SetNodeSet(nodeSet);
// add it to the model
GetBuilder()->AddBC(pbc);
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection::ParseBCPrescribe(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
// see if this tag defines a set
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// Find the set
FENodeSet* ps = mesh.FindNodeSet(szset);
if (ps == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szset);
// get the bc attribute
const char* sz = tag.AttributeValue("bc");
// find the dof index from its symbol
int bc = dofs.GetDOF(sz);
if (bc == -1)
{
// the temperature degree of freedom was renamed
// for backward compatibility we need to check for it
if (strcmp(sz, "t") == 0) bc = dofs.GetDOF("T");
throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
}
// get the lc attribute
sz = tag.AttributeValue("lc");
int lc = atoi(sz);
// make sure this tag is a leaf
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// get the scale factor
double s = 1;
value(tag, s);
// create the bc
FEPrescribedDOF* pdc = dynamic_cast<FEPrescribedDOF*>(fecore_new<FEBoundaryCondition>("prescribe", &fem));
pdc->SetScale(s).SetDOF(bc);
if (lc >= 0)
{
FEParam* p = pdc->GetParameter("scale");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
// add this boundary condition to the current step
GetBuilder()->AddBC(pdc);
// add nodes in the nodeset
pdc->SetNodeSet(ps);
}
else
{
// count how many prescibed nodes there are
int ndis = tag.children();
// determine whether prescribed BC is relative or absolute
bool br = false;
const char* sztype = tag.AttributeValue("type",true);
if (sztype && strcmp(sztype, "relative") == 0) br = true;
// read the prescribed data
++tag;
for (int i=0; i<ndis; ++i)
{
int n = ReadNodeID(tag);
const char* sz = tag.AttributeValue("bc");
// get the dof index from its symbol
int bc = dofs.GetDOF(sz);
if (bc == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
sz = tag.AttributeValue("lc");
int lc = atoi(sz)-1;
double scale;
tag.value(scale);
FEPrescribedDOF* pdc = dynamic_cast<FEPrescribedDOF*>(fecore_new<FEBoundaryCondition>("prescribe", &fem));
pdc->SetDOF(bc);
pdc->SetScale(scale);
pdc->SetRelativeFlag(br);
FENodeSet* ps = new FENodeSet(&fem);
ps->Add(n);
pdc->SetNodeSet(ps);
if (lc >= 0)
{
FEParam* p = pdc->GetParameter("scale");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
// add this boundary condition to the current step
GetBuilder()->AddBC(pdc);
// next tag
++tag;
}
}
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection2::ParseBCPrescribe(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
int NN = mesh.Nodes();
// count how many prescibed nodes there are
int ndis = tag.children();
// determine whether prescribed BC is relative or absolute
bool br = false;
const char* sztype = tag.AttributeValue("type",true);
if (sztype && strcmp(sztype, "relative") == 0) br = true;
// get the BC
const char* sz = tag.AttributeValue("bc");
int bc = dofs.GetDOF(sz);
if (bc == -1)
{
// the temperature degree of freedom was renamed
// for backward compatibility we need to check for it
if (strcmp(sz, "t") == 0) bc = dofs.GetDOF("T");
else throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
}
// get the load curve number
int lc = -1;
sz = tag.AttributeValue("lc", true);
if (sz) { lc = atoi(sz) - 1; }
// see if the scale attribute is defined
double scale = 1.0;
tag.AttributeValue("scale", scale, true);
// if the value is a leaf, the scale factor is defined as the value
if (tag.isleaf())
{
tag.value(scale);
}
// create a prescribed bc
FEPrescribedDOF* pdc = dynamic_cast<FEPrescribedDOF*>(fecore_new<FEBoundaryCondition>("prescribe", &fem));
pdc->SetDOF(bc);
pdc->SetScale(scale);
pdc->SetRelativeFlag(br);
if (lc >= 0)
{
FEParam* p = pdc->GetParameter("scale");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
// add this boundary condition to the current step
GetBuilder()->AddBC(pdc);
// see if there is a set defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure this is a leaf tag
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// find the node set
FENodeSet* pns = mesh.FindNodeSet(szset);
if (pns == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szset);
// add the nodes
pdc->SetNodeSet(pns);
}
else
{
FENodeSet* nset = new FENodeSet(&fem);
fem.GetMesh().AddNodeSet(nset);
// read the prescribed data
++tag;
for (int i=0; i<ndis; ++i)
{
// get the node ID
int n = ReadNodeID(tag);
value(tag, scale);
// TODO: I need to create a data map for this BC and assign the values
// to that data map
nset->Add(n);
++tag;
}
pdc->SetNodeSet(nset);
}
}
//-----------------------------------------------------------------------------
//! In version 2.5 all prescribed boundary conditions use a node set to define
//! the list of nodes to which the bc is applied.
void FEBioBoundarySection25::ParseBCPrescribe(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
int NN = mesh.Nodes();
// get the BC
const char* sz = tag.AttributeValue("bc");
int bc = dofs.GetDOF(sz);
if (bc == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
// Boundary conditions can be applied to node sets or surfaces
// depending on whether the node_set or surface attribute is defined
FENodeSet* nodeSet = nullptr;
FEFacetSet* facetSet = nullptr;
// get the node set or surface
const char* szset = tag.AttributeValue("node_set");
if (szset) {
map<string, FENodeSet*>::iterator nset = m_NodeSet.find(szset);
if (nset == m_NodeSet.end()) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
nodeSet = (*nset).second;
}
else
{
const char* szset = tag.AttributeValue("surface");
if (szset) {
facetSet = mesh.FindFacetSet(szset);
if (facetSet == nullptr) throw XMLReader::InvalidAttributeValue(tag, "surface", szset);
}
else throw XMLReader::MissingAttribute(tag, "node_set");
}
// create a prescribed bc
FEPrescribedDOF* pdc = dynamic_cast<FEPrescribedDOF*>(fecore_new<FEBoundaryCondition>("prescribe", &fem));
pdc->SetDOF(bc);
// Apply either the node set or the surface
if (nodeSet) pdc->SetNodeSet(nodeSet);
else if (facetSet)
{
FENodeSet* set = new FENodeSet(&fem);
set->Add(facetSet->GetNodeList());
pdc->SetNodeSet(set);
}
// add this boundary condition to the current step
GetBuilder()->AddBC(pdc);
// Read the parameter list
FEParameterList& pl = pdc->GetParameterList();
++tag;
do
{
if (ReadParameter(tag, pl, 0, 0) == false)
{
if (tag == "value")
{
feLogWarningEx((&fem), "The value parameter of the prescribed bc is deprecated.");
// NOTE: This will only work if the scale was set to 1!!
const char* sznodedata = tag.AttributeValue("node_data", true);
if (sznodedata)
{
FEParam* pp = pdc->GetParameter("scale"); assert(pp);
GetBuilder()->AddMappedParameter(pp, pdc, sznodedata);
}
else
{
double v;
tag.value(v);
pdc->SetScale(v);
}
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
} while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection25::ParseBC(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// get the type string
const char* sztype = tag.AttributeValue("type");
// create the boundary condition
FEBoundaryCondition* pdc = fecore_new<FEBoundaryCondition>(sztype, &fem);
if (pdc == 0) throw XMLReader::InvalidTag(tag);
// get the selection
const char* szset = tag.AttributeValue("node_set", true);
if (dynamic_cast<FENodalBC*>(pdc))
{
FENodalBC* pnbc = dynamic_cast<FENodalBC*>(pdc);
FENodeSet* nodeSet = mesh.FindNodeSet(szset);
if (nodeSet == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
// Set the node set
pnbc->SetNodeSet(nodeSet);
// Read the parameter list
FEParameterList& pl = pdc->GetParameterList();
ReadParameterList(tag, pl);
}
else if (dynamic_cast<FESurfaceBC*>(pdc))
{
FESurfaceBC* sbc = dynamic_cast<FESurfaceBC*>(pdc);
// if a node set is not defined, see if a surface is defined
szset = tag.AttributeValue("surface");
FEFacetSet* set = mesh.FindFacetSet(szset);
// Read the parameter list (before setting the surface)
FEParameterList& pl = pdc->GetParameterList();
ReadParameterList(tag, pl);
// add the surface
FESurface* surf = fecore_alloc(FESurface, GetFEModel());
surf->Create(*set);
mesh.AddSurface(surf);
sbc->SetSurface(surf);
}
// add this boundary condition to the current step
GetBuilder()->AddBC(pdc);
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection::ParseSpringSection(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// determine the spring type
const char* szt = tag.AttributeValue("type", true);
if (szt == 0) szt = "linear";
FEDiscreteMaterial* pm = dynamic_cast<FEDiscreteMaterial*>(fecore_new<FEMaterial>(szt, &fem));
if (pm == 0) throw XMLReader::InvalidAttributeValue(tag, "type", szt);
// create a new spring "domain"
FECoreKernel& febio = FECoreKernel::GetInstance();
FE_Element_Spec spec;
spec.eclass = FE_ELEM_TRUSS;
spec.eshape = ET_TRUSS2;
spec.etype = FE_DISCRETE;
FEDiscreteDomain* pd = dynamic_cast<FEDiscreteDomain*>(febio.CreateDomain(spec, &mesh, pm));
mesh.AddDomain(pd);
pd->Create(1, spec);
FEDiscreteElement& de = pd->Element(0);
de.SetID(++GetBuilder()->m_maxid);
// add a new material for each spring
fem.AddMaterial(pm);
pm->SetID(fem.Materials());
pd->SetMatID(fem.Materials()-1);
// read spring discrete elements
++tag;
do
{
// read the required node tag
if (tag == "node")
{
int n[2];
tag.value(n, 2);
de.m_node[0] = n[0]-1;
de.m_node[1] = n[1]-1;
}
else
{
// read the actual spring material parameters
FEParameterList& pl = pm->GetParameterList();
if (ReadParameter(tag, pl) == 0)
{
throw XMLReader::InvalidTag(tag);
}
}
++tag;
}
while (!tag.isend());
pd->CreateMaterialPointData();
}
//-----------------------------------------------------------------------------
//! Parse the linear constraints section of the xml input file
//! This section is a subsection of the Boundary section
void FEBioBoundarySection::ParseConstraints(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
DOFS& dofs = fem.GetDOFS();
// make sure there is a constraint defined
if (tag.isleaf()) return;
FEModelBuilder* feb = GetBuilder();
// read the parent node
int nodeID;
tag.AttributeValue("node", nodeID);
int parentNode = feb->FindNodeFromID(nodeID);
// get the dofs
const char* szbc = tag.AttributeValue("bc");
vector<int> dofList;
dofs.ParseDOFString(szbc, dofList);
int ndofs = (int) dofList.size();
// allocate linear constraints
vector<FELinearConstraint*> LC;
for (int i=0; i<ndofs; ++i)
{
int dof = dofList[i];
if (dof < 0) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
LC[i] = fecore_alloc(FELinearConstraint, &fem);
LC[i]->SetParentDof(dof, parentNode);
}
// read the child nodes
++tag;
do
{
if (tag == "node")
{
// get the node
int childNode = ReadNodeID(tag);
// get the dof
// (if ommitted we take the parent dof)
int childDOF = -1;
const char* szbc = tag.AttributeValue("bc", true);
if (szbc)
{
childDOF = dofs.GetDOF(szbc);
if (childDOF < 0) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
}
// get the coefficient
double val;
tag.value(val);
// add it to the list
for (int i=0; i<ndofs; ++i)
{
int ndof = (childDOF < 0 ? LC[i]->GetParentDof() : childDOF);
LC[i]->AddChildDof(ndof, childNode, val);
}
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// add the linear constraint to the system
for (int i=0; i<ndofs; ++i)
{
fem.GetLinearConstraintManager().AddLinearConstraint(LC[i]);
GetBuilder()->AddComponent(LC[i]);
}
}
void FEBioBoundarySection25::ParseMergeConstraint(XMLTag& tag)
{
// make sure this is an empty tag
if (tag.isempty() == false) throw XMLReader::InvalidValue(tag);
// get the dofs
const char* szbc = tag.AttributeValue("bc");
// get the surface pair name
const char* szsp = tag.AttributeValue("surface_pair");
// get the dof list
FEModel& fem = *GetFEModel();
DOFS& dof = fem.GetDOFS();
vector<int> dofs;
dof.ParseDOFString(szbc, dofs);
if (dofs.empty()) throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the surfaces
FEMesh& mesh = fem.GetMesh();
FESurfacePair* sp = mesh.FindSurfacePair(szsp);
if (sp == 0) throw XMLReader::InvalidAttributeValue(tag, "surface_pair", szsp);
// merge the interfaces
FEMergedConstraint merge(fem);
if (merge.Merge(sp->GetSecondarySurface(), sp->GetPrimarySurface(), dofs) == false)
throw XMLReader::InvalidTag(tag);
}
void FEBioBoundarySection25::ParsePeriodicLinearConstraint(XMLTag& tag)
{
FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
FEPeriodicLinearConstraint plc(fem);
FEModelBuilder* feb = GetBuilder();
++tag;
do
{
if (tag == "constrain")
{
const char* sz = tag.AttributeValue("surface_pair", true);
if (sz)
{
FESurfacePair* spair = mesh.FindSurfacePair(sz);
if (spair == 0) throw XMLReader::InvalidAttributeValue(tag, "surface_pair", sz);
FESurface* surf2 = fecore_alloc(FESurface, fem); feb->BuildSurface(*surf2, *spair->GetSecondarySurface());
FESurface* surf1 = fecore_alloc(FESurface, fem); feb->BuildSurface(*surf1, *spair->GetPrimarySurface());
plc.AddNodeSetPair(surf2->GetNodeList(), surf1->GetNodeList());
}
else throw XMLReader::MissingAttribute(tag, "surface_pair");
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// generate the linear constraints
plc.GenerateConstraints(fem);
// don't forget to activate
}
void FEBioBoundarySection25::ParsePeriodicLinearConstraint2O(XMLTag& tag)
{
assert(false);
throw XMLReader::InvalidTag(tag);
/* FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
FEPeriodicLinearConstraint2O plc;
FEModelBuilder* feb = GetBuilder();
++tag;
do
{
if (tag == "constrain")
{
const char* sz = tag.AttributeValue("surface_pair");
if (sz)
{
FESurfacePair* spair = mesh.FindSurfacePair(sz);
if (spair == 0) throw XMLReader::InvalidAttributeValue(tag, "surface_pair", sz);
FESurface* surf2 = fecore_alloc(FESurface, fem); feb->BuildSurface(*surf2, *spair->GetSecondarySurface());
FESurface* surf1 = fecore_alloc(FESurface, fem); feb->BuildSurface(*surf1, *spair->GetPrimarySurface());
plc.AddNodeSetPair(surf2->GetNodeList(), surf1->GetNodeList());
}
else throw XMLReader::MissingAttribute(tag, "surface_pair");
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// generate the linear constraints
if (plc.GenerateConstraints(fem) == false)
{
throw XMLReader::InvalidTag(tag);
}
*/
}
//-----------------------------------------------------------------------------
void FEBioBoundarySection::ParseContactInterface(XMLTag& tag, FESurfacePairConstraint* pci)
{
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
// get the parameter list
FEParameterList& pl = pci->GetParameterList();
// read the parameters
++tag;
do
{
if (ReadParameter(tag, pl) == false)
{
if (tag == "surface")
{
const char* sztype = tag.AttributeValue("type");
int ntype = 0;
if (strcmp(sztype, "master") == 0) ntype = 1;
else if (strcmp(sztype, "slave") == 0) ntype = 2;
FESurface& s = *(ntype == 1? pci->GetSecondarySurface() : pci->GetPrimarySurface());
m.AddSurface(&s);
int nfmt = 0;
const char* szfmt = tag.AttributeValue("format", true);
if (szfmt)
{
if (strcmp(szfmt, "face nodes") == 0) nfmt = 0;
else if (strcmp(szfmt, "element face") == 0) nfmt = 1;
}
// read the surface section
ParseSurfaceSection(tag, s, nfmt, pci->UseNodalIntegration());
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
//! Parses the contact section of the xml input file
//! The contact section is a subsection of the boundary section
void FEBioBoundarySection::ParseContactSection(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& m = fem.GetMesh();
FEModelBuilder* feb = GetBuilder();
// get the type attribute
const char* szt = tag.AttributeValue("type");
// Not all contact interfaces can be parsed automatically.
// First, check all these special cases.
if (strcmp(szt, "rigid_wall") == 0)
{
// --- R I G I D W A L L I N T E R F A C E ---
FESurfacePairConstraint* ps = fecore_new<FESurfacePairConstraint>(szt, GetFEModel());
if (ps)
{
fem.AddSurfacePairConstraint(ps);
++tag;
do
{
if (ReadParameter(tag, ps) == false)
{
if (tag == "surface")
{
FESurface& s = *ps->GetPrimarySurface();
int nfmt = 0;
const char* szfmt = tag.AttributeValue("format", true);
if (szfmt)
{
if (strcmp(szfmt, "face nodes") == 0) nfmt = 0;
else if (strcmp(szfmt, "element face") == 0) nfmt = 1;
}
// read the surface section
ParseSurfaceSection(tag, s, nfmt, true);
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
}
else throw XMLReader::InvalidAttributeValue(tag, "type", szt);
}
else if (strcmp(szt, "rigid") == 0)
{
// --- R I G I D B O D Y I N T E R F A C E ---
// count how many rigid nodes there are
int nrn= 0;
XMLTag t(tag); ++t;
while (!t.isend()) { nrn++; ++t; }
++tag;
int id, rb, rbp = -1;
FENodalBC* prn = 0;
FENodeSet* ns = 0;
for (int i=0; i<nrn; ++i)
{
id = atoi(tag.AttributeValue("id"))-1;
rb = atoi(tag.AttributeValue("rb"));
if ((prn == 0) || (rb != rbp))
{
prn = fecore_new_class<FENodalBC>("FERigidNodeSet", &fem);
prn->SetParameter("rb", rb);
ns = new FENodeSet(&fem);
prn->SetNodeSet(ns);
// the default shell bc depends on the shell formulation
// hinged shell = 0
// clamped shell = 1
prn->SetParameter("clamp_shells", feb->m_default_shell == OLD_SHELL ? 0 : 1);
feb->AddBC(prn);
rbp = rb;
}
ns->Add(id);
++tag;
}
}
else if (strcmp(szt, "linear constraint") == 0)
{
FEModel& fem = *GetFEModel();
// make sure there is a constraint defined
if (tag.isleaf()) return;
// create a new linear constraint manager
FELinearConstraintSet* pLCS = dynamic_cast<FELinearConstraintSet*>(fecore_new<FENLConstraint>(szt, GetFEModel()));
fem.AddNonlinearConstraint(pLCS);
// read the linear constraints
++tag;
do
{
if (tag == "linear_constraint")
{
FEAugLagLinearConstraint* pLC = fecore_alloc(FEAugLagLinearConstraint, &fem);
++tag;
do
{
int node, bc;
double val;
if (tag == "node")
{
tag.value(val);
const char* szid = tag.AttributeValue("id");
node = atoi(szid);
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
pLC->AddDOF(node, bc, val);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
// add the linear constraint to the system
pLCS->add(pLC);
}
else if (ReadParameter(tag, pLCS) == false)
{
throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
}
else
{
// If we get here, we try to create a contact interface
// using the FEBio kernel.
FESurfacePairConstraint* pci = fecore_new<FESurfacePairConstraint>(szt, GetFEModel());
if (pci)
{
// add it to the model
GetBuilder()->AddContactInterface(pci);
// parse the interface
ParseContactInterface(tag, pci);
}
else
{
// some nonlinear constraints are also defined in the Contact section, so let's try that next.
// TODO: These are mostly rigid constraints. Therefore, I would like to move this elsewhere (maybe in the new Rigid section?)
FENLConstraint* pnlc = fecore_new<FENLConstraint>(szt, GetFEModel());
if (pnlc)
{
ReadParameterList(tag, pnlc);
fem.AddNonlinearConstraint(pnlc);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", szt);
}
}
}
//-----------------------------------------------------------------------------
// Rigid node sets are defined in the Boundary section since version 2.5
// (Used to be defined in the Contact section)
void FEBioBoundarySection25::ParseBCRigid(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
FEModelBuilder* feb = GetBuilder();
int NMAT = fem.Materials();
// get the rigid body material ID
int rb = -1;
tag.AttributeValue("rb", rb);
// make sure we have a valid rigid body reference
if ((rb <= 0)||(rb>NMAT)) throw XMLReader::InvalidAttributeValue(tag, "rb", tag.AttributeValue("rb"));
// get the nodeset
const char* szset = tag.AttributeValue("node_set");
FENodeSet* nodeSet = mesh.FindNodeSet(szset);
if (nodeSet == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
// create new rigid node set
FENodalBC* prn = fecore_new_class<FENodalBC>("FERigidNodeSet", &fem);
// the default shell bc depends on the shell formulation
prn->SetParameter("clamp_shells", feb->m_default_shell == OLD_SHELL ? 0 : 1);
prn->SetParameter("rb", rb);
prn->SetNodeSet(nodeSet);
// add it to the model
feb->AddBC(prn);
// read the parameter list
ReadParameterList(tag, prn);
}
//-----------------------------------------------------------------------------
// The rigid body "constraints" are moved to the Boundary section in 2.5
void FEBioBoundarySection25::ParseRigidBody(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEModelBuilder& feb = *GetBuilder();
const char* szm = tag.AttributeValue("mat");
assert(szm);
// get the material ID
int nmat = atoi(szm);
if ((nmat <= 0) || (nmat > fem.Materials())) throw XMLReader::InvalidAttributeValue(tag, "mat", szm);
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "prescribed")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the loadcurve
const char* szlc = tag.AttributeValue("lc");
int lc = atoi(szlc) - 1;
// get the (optional) type attribute
bool brel = false;
const char* szrel = tag.AttributeValue("type", true);
if (szrel)
{
if (strcmp(szrel, "relative" ) == 0) brel = true;
else if (strcmp(szrel, "absolute" ) == 0) brel = false;
else throw XMLReader::InvalidAttributeValue(tag, "type", szrel);
}
double val = 0.0;
value(tag, val);
// create the rigid displacement constraint
FEStepComponent* pDC = fecore_new_class<FEBoundaryCondition>("FERigidPrescribedOld", &fem);
feb.AddRigidComponent(pDC);
pDC->SetParameter("rb", nmat);
pDC->SetParameter("dof", bc);
pDC->SetParameter("relative", brel);
pDC->SetParameter("value", val);
// assign a load curve
if (lc >= 0)
{
FEParam* p = pDC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (tag == "force")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// get the type
int ntype = 0; // FERigidBodyForce::FORCE_LOAD;
const char* sztype = tag.AttributeValue("type", true);
if (sztype)
{
if (strcmp(sztype, "ramp" ) == 0) ntype = 2; //FERigidBodyForce::FORCE_TARGET;
else if (strcmp(sztype, "follow") == 0) ntype = 1; //FERigidBodyForce::FORCE_FOLLOW;
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
// get the loadcurve
const char* szlc = tag.AttributeValue("lc", true);
int lc = -1;
if (szlc) lc = atoi(szlc) - 1;
// make sure there is a loadcurve for type=0 forces
if ((ntype == 0)&&(lc==-1)) throw XMLReader::MissingAttribute(tag, "lc");
double val = 0.0;
value(tag, val);
// create the rigid body force/moment
FEModelLoad* pFC = nullptr;
if (bc < 3)
{
pFC = fecore_new<FEModelLoad>("rigid_force", &fem);
pFC->SetParameter("load_type", ntype);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc);
pFC->SetParameter("value", val);
}
else
{
pFC = fecore_new<FEModelLoad>("rigid_moment", &fem);
pFC->SetParameter("rb", nmat);
pFC->SetParameter("dof", bc - 3);
pFC->SetParameter("value", val);
}
feb.AddModelLoad(pFC);
if (lc >= 0)
{
FEParam* p = pFC->GetParameter("value");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
GetFEModel()->AttachLoadController(p, lc);
}
}
else if (tag == "fixed")
{
// get the dof
int bc = -1;
const char* szbc = tag.AttributeValue("bc");
if (strcmp(szbc, "x") == 0) bc = 0;
else if (strcmp(szbc, "y") == 0) bc = 1;
else if (strcmp(szbc, "z") == 0) bc = 2;
else if (strcmp(szbc, "Rx") == 0) bc = 3;
else if (strcmp(szbc, "Ry") == 0) bc = 4;
else if (strcmp(szbc, "Rz") == 0) bc = 5;
else throw XMLReader::InvalidAttributeValue(tag, "bc", szbc);
// create the fixed dof
FEBoundaryCondition* pBC = fecore_new_class<FEBoundaryCondition>("FERigidFixedBCOld", &fem);
feb.AddRigidComponent(pBC);
pBC->SetParameter("rb", nmat);
vector<int> dofs; dofs.push_back(bc);
pBC->SetParameter("dofs", dofs);
}
else if (tag == "initial_velocity")
{
// get the initial velocity
vec3d v;
value(tag, v);
// create the initial condition
FEStepComponent* pic = fecore_new_class<FEInitialCondition>("FERigidBodyVelocity", &fem);
pic->SetParameter("rb", nmat);
pic->SetParameter("value", v);
// add to model
feb.AddRigidComponent(pic);
}
else if (tag == "initial_angular_velocity")
{
// get the initial angular velocity
vec3d w;
value(tag, w);
// create the initial condition
FEStepComponent* pic = fecore_new_class<FEInitialCondition>("FERigidBodyAngularVelocity", &fem);
pic->SetParameter("rb", nmat);
pic->SetParameter("value", w);
// add to model
feb.AddRigidComponent(pic);
}
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioControlSection3.cpp | .cpp | 5,247 | 159 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioControlSection3.h"
#include "FECore/FEAnalysis.h"
#include "FECore/FEModel.h"
#include "FECore/FECoreKernel.h"
#include "FECore/FENewtonSolver.h"
#ifndef WIN32
#define strnicmp strncasecmp
#endif
class FEObsoleteStepParamHandler : public FEObsoleteParamHandler
{
public:
FEObsoleteStepParamHandler(XMLTag& tag, FEAnalysis* step, FEModelBuilder* feb) : m_step(step), m_feb(feb), FEObsoleteParamHandler(tag, step)
{
AddParam("solver.max_ups" , "solver.qn_method.max_ups" , FE_PARAM_INT);
AddParam("solver.qn_max_buffer_size", "solver.qn_method.max_buffer_size", FE_PARAM_INT);
AddParam("solver.qn_cycle_buffer" , "solver.qn_method.cycle_buffer" , FE_PARAM_BOOL);
AddParam("solver.cmax" , "solver.qn_method.cmax" , FE_PARAM_DOUBLE);
}
bool ProcessTag(XMLTag& tag) override
{
if (tag == "qnmethod")
{
const char* szv = tag.szvalue();
int l = strlen(szv);
if ((strnicmp(szv, "BFGS" , l) == 0) || (strnicmp(szv, "0", l) == 0)) m_qnmethod = QN_BFGS;
else if ((strnicmp(szv, "BROYDEN", l) == 0) || (strnicmp(szv, "1", l) == 0)) m_qnmethod = QN_BROYDEN;
else if ((strnicmp(szv, "JFNK" , l) == 0) || (strnicmp(szv, "2", l) == 0)) m_qnmethod = QN_JFNK;
else return false;
return true;
}
else if (tag == "analysis")
{
const char* szval = tag.szvalue();
FEParam* p = m_step->GetParameter("analysis");
if (strcmp(szval, "STEADY_STATE") == 0) p->value<int>() = 0;
else if (strcmp(szval, "STEADY-STATE") == 0) p->value<int>() = 0;
else if (strcmp(szval, "STATIC" ) == 0) p->value<int>() = 0;
else if (strcmp(szval, "TRANSIENT" ) == 0) p->value<int>() = 1;
else if (strcmp(szval, "DYNAMIC" ) == 0) p->value<int>() = 1;
else
{
assert(false);
return false;
}
return true;
}
else if (tag == "shell_formulation")
{
int nshell = 0;
tag.value(nshell);
switch (nshell)
{
case 0: m_feb->m_default_shell = OLD_SHELL; break;
case 1: m_feb->m_default_shell = NEW_SHELL; break;
case 2: m_feb->m_default_shell = EAS_SHELL; break;
case 3: m_feb->m_default_shell = ANS_SHELL; break;
default:
return false;
}
return true;
}
else return FEObsoleteParamHandler::ProcessTag(tag);
}
void MapParameters() override
{
FEModel* fem = m_step->GetFEModel();
// first, make sure that the QN method is allocated
if (m_qnmethod != -1)
{
FENewtonSolver& solver = dynamic_cast<FENewtonSolver&>(*m_step->GetFESolver());
FEProperty& qn = *solver.FindProperty("qn_method");
switch (m_qnmethod)
{
case QN_BFGS : solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("BFGS" , fem)); break;
case QN_BROYDEN: solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("Broyden", fem)); break;
case QN_JFNK : solver.SetSolutionStrategy(fecore_new<FENewtonStrategy>("JFNK" , fem)); break;
default:
assert(false);
}
}
// now, process the rest
FEObsoleteParamHandler::MapParameters();
}
private:
int m_qnmethod = -1;
FEAnalysis* m_step;
FEModelBuilder* m_feb;
};
//-----------------------------------------------------------------------------
FEBioControlSection3::FEBioControlSection3(FEFileImport* pim) : FEFileSection(pim)
{
}
//-----------------------------------------------------------------------------
void FEBioControlSection3::Parse(XMLTag& tag)
{
// get the step
FEAnalysis* pstep = GetBuilder()->GetStep();
if (pstep == 0)
{
throw XMLReader::InvalidTag(tag);
}
// Get the solver
FESolver* psolver = pstep->GetFESolver();
if (psolver == 0)
{
string m = GetBuilder()->GetModuleName();
throw FEBioImport::FailedAllocatingSolver(m.c_str());
}
// prepare obsolete parameter mapping.
FEObsoleteStepParamHandler stepParamHandler(tag, pstep, GetBuilder());
// read the step parameters
SetInvalidTagHandler(&stepParamHandler);
ReadParameterList(tag, pstep);
stepParamHandler.MapParameters();
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/FEBioOutputSection.h | .h | 1,673 | 46 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEBioImport.h"
class FEFacetSet;
//-----------------------------------------------------------------------------
// Output Section
class FEBioOutputSection : public FEBioFileSection
{
public:
FEBioOutputSection(FEBioImport* pim) : FEBioFileSection(pim){}
void Parse(XMLTag& tag);
protected:
void ParseLogfile (XMLTag& tag);
void ParsePlotfile (XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioModuleSection.h | .h | 1,575 | 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 "FEBioImport.h"
//-----------------------------------------------------------------------------
// FEBio Module Section
class FEBioModuleSection : public FEBioFileSection
{
public:
FEBioModuleSection(FEBioImport* pim) : FEBioFileSection(pim) {}
void Parse(XMLTag& tag);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/xmltool.cpp | .cpp | 8,516 | 339 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "xmltool.h"
#include <FECore/FECoreKernel.h>
int enumValue(const char* val, const char* szenum);
bool is_number(const char* sz);
//-----------------------------------------------------------------------------
bool parseEnumParam(FEParam* pp, const char* val)
{
// get the enums
const char* ch = pp->enums();
if (ch == nullptr) return false;
// special cases
if (strncmp(ch, "@factory_list", 13) == 0)
{
int classID = atoi(ch + 14);
FECoreKernel& fecore = FECoreKernel::GetInstance();
for (int i = 0, n = 0; i < fecore.FactoryClasses(); ++i)
{
const FECoreFactory* fac = fecore.GetFactoryClass(i);
if (fac->GetSuperClassID() == classID)
{
if (strcmp(fac->GetTypeStr(), val) == 0)
{
pp->value<int>() = n;
return true;
}
n++;
}
}
return false;
}
int n = enumValue(val, ch);
if (n != -1) pp->value<int>() = n;
else
{
// see if the value is an actual number
if (is_number(val))
{
n = atoi(val);
pp->value<int>() = n;
}
}
return (n != -1);
}
//-----------------------------------------------------------------------------
//! This function parses a parameter list
bool fexml::readParameter(XMLTag& tag, FEParameterList& paramList, const char* paramName)
{
// see if we can find this parameter
FEParam* pp = paramList.FindFromName((paramName == 0 ? tag.Name() : paramName));
if (pp == 0) return false;
if (pp->dim() == 1)
{
switch (pp->type())
{
case FE_PARAM_DOUBLE : { double d; tag.value(d); pp->value<double >() = d; } break;
case FE_PARAM_INT :
{
const char* szenum = pp->enums();
if (szenum == 0)
{
int n;
tag.value(n); pp->value<int>() = n;
}
else
{
bool bfound = parseEnumParam(pp, tag.szvalue());
if (bfound == false) throw XMLReader::InvalidValue(tag);
}
}
break;
case FE_PARAM_BOOL : { bool b; tag.value(b); pp->value<bool>() = b; } break;
case FE_PARAM_STD_STRING: { std::string s; tag.value(s); pp->value<std::string>() = s; } break;
default:
assert(false);
return false;
}
}
else
{
switch (pp->type())
{
case FE_PARAM_INT : {
vector<int> d(pp->dim());
tag.value(&d[0], pp->dim());
for (int i=0; i<pp->dim(); ++i)
*(pp->pvalue<int>()+i) = d[i];
}
break;
case FE_PARAM_DOUBLE:
{
vector<double> d(pp->dim());
tag.value(&d[0], pp->dim());
for (int i = 0; i < pp->dim(); ++i)
*(pp->pvalue<double>() + i) = d[i];
}
break;
default:
assert(false);
break;
}
}
return true;
}
//-----------------------------------------------------------------------------
void fexml::readList(XMLTag& tag, vector<int>& l)
{
// make sure the list is empty
l.clear();
// get a pointer to the value
const char* sz = tag.szvalue();
// parse the string
const char* ch;
do
{
int n0, n1, nn;
int nread = sscanf(sz, "%d:%d:%d", &n0, &n1, &nn);
switch (nread)
{
case 1:
n1 = n0;
nn = 1;
break;
case 2:
nn = 1;
break;
}
for (int i = n0; i <= n1; i += nn) l.push_back(i);
ch = strchr(sz, ',');
if (ch) sz = ch + 1;
}
while (ch != 0);
}
bool fexml::readParameterList(XMLTag& tag, FECoreBase* pc)
{
// read attribute parameters
if (!readAttributeParams(tag, pc)) return false;
// make sure this tag has children
if (tag.isleaf()) return true;
// process the parameter lists
++tag;
do
{
if (readParameter(tag, pc) == false) return false;
++tag;
}
while (!tag.isend());
return true;
}
bool fexml::readAttributeParams(XMLTag& tag, FECoreBase* pc)
{
FEParameterList& pl = pc->GetParameterList();
// process all the other attributes
for (XMLAtt& att : tag.m_att)
{
const char* szatt = att.name();
const char* szval = att.cvalue();
if ((att.m_bvisited == false) && szatt && szval)
{
FEParam* param = pl.FindFromName(szatt);
if (param && (param->GetFlags() & FE_PARAM_ATTRIBUTE))
{
switch (param->type())
{
case FE_PARAM_INT:
{
if (param->enums() == nullptr)
param->value<int>() = atoi(szval);
else
{
if (parseEnumParam(param, szval) == false) throw XMLReader::InvalidAttributeValue(tag, szatt, szval);
}
break;
}
case FE_PARAM_DOUBLE: param->value<double>() = atof(szval); break;
case FE_PARAM_STD_STRING: param->value<std::string>() = szval; break;
default:
throw XMLReader::InvalidAttributeValue(tag, szatt, szval);
}
}
else if (strcmp("name", szatt) == 0) pc->SetName(szval);
else if (strcmp("id", szatt) == 0) pc->SetID(atoi(szval));
else if (strcmp("type", szatt) == 0) { /* don't do anything here */ }
else if (strcmp("lc", szatt) == 0) { /* don't do anything. Loadcurves are processed elsewhere. */ }
else
{
assert(false);
return false;
}
}
}
return true;
}
bool fexml::readParameter(XMLTag& tag, FECoreBase* pc)
{
FEParameterList& PL = pc->GetParameterList();
if (readParameter(tag, PL) == false)
{
// see if this is a property
// if we get here, the parameter is not found.
// See if the parameter container has defined a property of this name
int n = pc->FindPropertyIndex(tag.Name());
if (n >= 0)
{
FEProperty* prop = pc->PropertyClass(n);
const char* sztype = tag.AttributeValue("type", true);
if (sztype)
{
// try to allocate the class
FECoreBase* pp = fecore_new<FECoreBase>(prop->GetSuperClassID(), sztype, pc->GetFEModel());
if (pp == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
prop->SetProperty(pp);
// read the property data
readParameterList(tag, pp);
}
else if (prop->Flags() & FEProperty::Fixed)
{
if (prop->IsArray())
{
FECoreBase* pc = prop->get(prop->size());
readParameterList(tag, pc);
}
else
{
FECoreBase* pc = prop->get(0);
readParameterList(tag, pc);
}
}
else
{
throw XMLReader::MissingAttribute(tag, "type");
}
}
else throw XMLReader::InvalidTag(tag);
}
return true;
}
void readClassVariable(XMLTag& tag, FEClassDescriptor::ClassVariable* vars)
{
if (tag.isleaf()) return;
++tag;
do {
if (tag.isleaf())
{
const char* szname = tag.Name();
// see if the type attribute is defined
const char* sztype = tag.AttributeValue("type", true);
if (sztype)
{
FEClassDescriptor::ClassVariable* child = new FEClassDescriptor::ClassVariable(szname, sztype);
vars->AddVariable(child);
}
else
{
const char* szval = tag.szvalue();
FEClassDescriptor::SimpleVariable* var = new FEClassDescriptor::SimpleVariable(szname, szval);
vars->AddVariable(var);
}
}
else
{
const char* szname = tag.Name();
const char* sztype = tag.AttributeValue("type");
FEClassDescriptor::ClassVariable* child = new FEClassDescriptor::ClassVariable(szname, sztype);
vars->AddVariable(child);
readClassVariable(tag, child);
}
++tag;
}
while (!tag.isend());
}
// create a class descriptor from the current tag
FEClassDescriptor* fexml::readParameterList(XMLTag& tag)
{
const char* sztype = tag.AttributeValue("type");
FEClassDescriptor* cd = new FEClassDescriptor(sztype);
FEClassDescriptor::ClassVariable* root = cd->Root();
readClassVariable(tag, root);
return cd;
}
| C++ |
3D | febiosoftware/FEBio | FEBioXML/febioxml_api.h | .h | 1,529 | 44 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#ifdef WIN32
#ifdef FECORE_DLL
#ifdef febioxml_EXPORTS
#define FEBIOXML_API __declspec(dllexport)
#else
#define FEBIOXML_API __declspec(dllimport)
#endif
#else
#define FEBIOXML_API
#endif
#else
#define FEBIOXML_API
#endif
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioImport.h | .h | 5,139 | 208 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FileImport.h"
#include <FEBioXML/XMLReader.h>
#include "FECore/FEAnalysis.h"
#include "FECore/FESolver.h"
#include "FECore/DataStore.h"
#include <FECore/FEMesh.h>
#include <FECore/FESurfaceMap.h>
#include <FECore/tens3d.h>
#include <string>
class FENodeSet;
class FEBioImport;
//-----------------------------------------------------------------------------
//! Base class for FEBio (feb) file sections.
class FEBioFileSection : public FEFileSection
{
public:
FEBioFileSection(FEBioImport* feb);
FEBioImport* GetFEBioImport();
};
//=============================================================================
//! Implements a class to import FEBio input files
//!
class FEBIOXML_API FEBioImport : public FEFileImport
{
public:
// invalid version
class InvalidVersion : public FEFileException
{
public: InvalidVersion();
};
// invalid material defintion
class InvalidMaterial : public FEFileException
{
public: InvalidMaterial(int nel);
};
// invalid domain type
class InvalidDomainType : public FEFileException
{
public: InvalidDomainType();
};
// cannot create domain
class FailedCreatingDomain : public FEFileException
{
public: FailedCreatingDomain();
};
// invalid element type
class InvalidElementType : public FEFileException
{
public: InvalidElementType();
};
// failed loading plugin
class FailedLoadingPlugin : public FEFileException
{
public: FailedLoadingPlugin(const char* sz);
};
// duplicate material section
class DuplicateMaterialSection : public FEFileException
{
public: DuplicateMaterialSection();
};
// invalid domain material
class InvalidDomainMaterial : public FEFileException
{
public: InvalidDomainMaterial();
};
// missing property
class MissingProperty : public FEFileException
{
public: MissingProperty(const std::string& matName, const char* szprop);
};
//! Failed allocating solver
class FailedAllocatingSolver : public FEFileException
{
public: FailedAllocatingSolver(const char* sztype);
};
//! error in data generation
class DataGeneratorError : public FEFileException
{
public:
DataGeneratorError();
};
//! failed building a part
class FailedBuildingPart : public FEFileException
{
public:
FailedBuildingPart(const std::string& partName);
};
// Error while reading mesh data section
class MeshDataError : public FEFileException
{
public:
MeshDataError();
};
// repeated node set
class RepeatedNodeSet : public FEFileException
{
public: RepeatedNodeSet(const std::string& name);
};
// repeated surface
class RepeatedSurface : public FEFileException
{
public: RepeatedSurface(const std::string& name);
};
// repeated edge set
class RepeatedEdgeSet : public FEFileException
{
public: RepeatedEdgeSet(const std::string& name);
};
// repeated element set
class RepeatedElementSet : public FEFileException
{
public: RepeatedElementSet(const std::string& name);
};
// repeated part list
class RepeatedPartList : public FEFileException
{
public: RepeatedPartList(const std::string& name);
};
public:
//! constructor
FEBioImport();
//! destructor
~FEBioImport();
//! open the file
bool Load(FEModel& fem, const char* szfile);
//! read the contents of a file
bool ReadFile(const char* szfile, bool broot = true);
public:
void SetDumpfileName(const char* sz);
void SetLogfileName (const char* sz);
void SetPlotfileName(const char* sz);
void AddDataRecord(DataRecord* pd);
public:
// Helper functions for reading node sets, surfaces, etc.
FENodeSet* ParseNodeSet(XMLTag& tag, const char* szatt = "set");
FESurface* ParseSurface(XMLTag& tag, const char* szatt = "surf");
protected:
void ParseVersion(XMLTag& tag);
void BuildFileSectionMap(int nversion);
public:
char m_szdmp[512];
char m_szlog[512];
char m_szplt[512];
public:
std::vector<DataRecord*> m_data;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioXML/FEBioLoadsSection.cpp | .cpp | 19,702 | 709 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioLoadsSection.h"
#include <FECore/FEBodyLoad.h>
#include <FECore/FEModel.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FENodalLoad.h>
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEEdgeLoad.h>
#include <FECore/FEEdge.h>
#include <FECore/FEPrescribedBC.h>
#include <FECore/log.h>
//=============================================================================
// FEBioLoadsSection1x
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioLoadsSection1x::Parse(XMLTag& tag)
{
// make sure this tag has children
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "force" ) ParseNodalLoad(tag);
else if (tag == "body_force" ) ParseBodyForce(tag);
else if (tag == "heat_source") ParseBodyLoad (tag);
else ParseSurfaceLoad(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
// NOTE: note that this section used to be in the Globals section (version 1.1)
void FEBioLoadsSection1x::ParseBodyForce(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
const char* szt = tag.AttributeValue("type", true);
if (szt == 0) szt = "const";
// create the body force
FEBodyLoad* pf = fecore_new<FEBodyLoad>(szt, &fem);
if (pf == 0) throw XMLReader::InvalidAttributeValue(tag, "type", szt);
// add it to the model
fem.AddModelLoad(pf);
// read the parameter list
ReadParameterList(tag, pf);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection1x::ParseBodyLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEBodyLoad* pbl = fecore_new<FEBodyLoad>(tag.Name(), &fem);
if (pbl == 0) throw XMLReader::InvalidTag(tag);
ReadParameterList(tag, pbl);
fem.AddModelLoad(pbl);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection1x::ParseNodalLoad(XMLTag &tag)
{
// No longer supported
throw XMLReader::InvalidTag(tag);
/*
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
// count how many nodal forces there are
int ncnf = tag.children();
// read the prescribed data
++tag;
for (int i = 0; i<ncnf; ++i)
{
int n = atoi(tag.AttributeValue("id")) - 1, bc;
const char* sz = tag.AttributeValue("bc");
bc = dofs.GetDOF(sz);
if (bc == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
sz = tag.AttributeValue("lc");
int lc = atoi(sz) - 1;
double scale = 0.0;
value(tag, scale);
FENodalLoad* pfc = dynamic_cast<FENodalLoad*>(fecore_new<FEBoundaryCondition>("nodal_load", &fem));
pfc->SetDOF(bc);
pfc->SetLoad(scale);
pfc->AddNode(n);
if (lc >= 0)
{
FEParam* p = pfc->GetParameter("scale");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
// add it to the model
GetBuilder()->AddNodalLoad(pfc);
++tag;
}
*/
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection1x::ParseSurfaceLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// count how many pressure cards there are
int npr = tag.children();
// create a new surface
FESurface* psurf = fecore_alloc(FESurface, &fem);
psurf->Create(npr);
fem.GetMesh().AddSurface(psurf);
// create surface load
FESurfaceLoad* ps = fecore_new<FESurfaceLoad>(tag.Name(), &fem);
if (ps == 0) throw XMLReader::InvalidTag(tag);
FEModelBuilder* feb = GetBuilder();
// read the pressure data
++tag;
int nf[FEElement::MAX_NODES], N;
for (int i = 0; i<npr; ++i)
{
FESurfaceElement& el = psurf->Element(i);
if (tag == "quad4") el.SetType(FE_QUAD4G4);
else if (tag == "tri3") el.SetType(feb->m_ntri3);
else if (tag == "tri6") el.SetType(feb->m_ntri6);
else if (tag == "tri7") el.SetType(feb->m_ntri7);
else if (tag == "tri10") el.SetType(feb->m_ntri10);
else if (tag == "quad8") el.SetType(FE_QUAD8G9);
else if (tag == "quad9") el.SetType(FE_QUAD9G9);
else throw XMLReader::InvalidTag(tag);
N = el.Nodes();
tag.value(nf, N);
for (int j = 0; j<N; ++j) el.m_node[j] = nf[j] - 1;
++tag;
}
ps->SetSurface(psurf);
// add it to the model
GetBuilder()->AddSurfaceLoad(ps);
}
//=============================================================================
// FEBioLoadsSection2
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::Parse(XMLTag& tag)
{
// make sure this tag has children
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "nodal_load" ) ParseNodalLoad(tag);
else if (tag == "surface_load") ParseSurfaceLoad(tag);
else if (tag == "edge_load" ) ParseEdgeLoad(tag);
else if (tag == "body_load" ) ParseBodyLoad(tag);
else throw XMLReader::InvalidTag(tag);
++tag;
} while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::ParseBodyLoad(XMLTag& tag)
{
const char* sztype = tag.AttributeValue("type");
FEModel& fem = *GetFEModel();
FEBodyLoad* pbl = fecore_new<FEBodyLoad>(sztype, &fem);
if (pbl == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
ReadParameterList(tag, pbl);
fem.AddModelLoad(pbl);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::ParseNodalLoad(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
// count how many nodal forces there are
int ncnf = tag.children();
// get the bc
const char* sz = tag.AttributeValue("bc");
int bc = dofs.GetDOF(sz);
if (bc == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
// get the load curve
sz = tag.AttributeValue("lc");
int lc = atoi(sz) - 1;
// see if there is a set defined
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure this is a leaf tag
if (tag.isleaf() == false) throw XMLReader::InvalidValue(tag);
// find the node set
FENodeSet* pns = mesh.FindNodeSet(szset);
if (pns == 0) throw XMLReader::InvalidAttributeValue(tag, "set", szset);
// see if the scale attribute is defined
double scale = 1.0;
tag.AttributeValue("scale", scale, true);
// create new nodal force
FENodalDOFLoad* pfc = fecore_alloc(FENodalDOFLoad, &fem);
pfc->SetDOF(bc);
pfc->SetLoad(scale);
// add it to the model
GetBuilder()->AddNodalLoad(pfc);
}
else
{
// NOTE: no longer supported!
throw XMLReader::InvalidTag(tag);
/*
// read the prescribed data
++tag;
for (int i = 0; i<ncnf; ++i)
{
// get the nodal ID
int n = atoi(tag.AttributeValue("id")) - 1;
// get the load scale factor
double scale = 0.0;
value(tag, scale);
// create new nodal force
FENodalDOFLoad* pfc = fecore_alloc(FENodalDOFLoad, &fem);
pfc->SetDOF(bc);
pfc->SetLoad(scale);
pfc->AddNode(n);
if (lc >= 0)
{
FEParam* p = pfc->GetParameter("scale");
if (p == nullptr) throw XMLReader::InvalidTag(tag);
fem.AttachLoadController(p, lc);
}
// add it to the model
GetBuilder()->AddNodalLoad(pfc);
++tag;
}
*/
}
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::ParseSurfaceLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// create surface load
const char* sztype = tag.AttributeValue("type");
FESurfaceLoad* psl = fecore_new<FESurfaceLoad>(sztype, &fem);
if (psl == 0) throw XMLReader::InvalidTag(tag);
// read name attribute
const char* szname = tag.AttributeValue("name", true);
if (szname) psl->SetName(szname);
// create a new surface
FESurface* psurf = fecore_alloc(FESurface, &fem);
fem.GetMesh().AddSurface(psurf);
// we need to find the surface tag first
ParseSurfaceLoadSurface(tag, psurf);
psl->SetSurface(psurf);
// read the parameters
FEParameterList& pl = psl->GetParameterList();
// read the pressure data
++tag;
do
{
if (ReadParameter(tag, pl) == false)
{
if (tag == "surface")
{
// skip it, we already processed it
tag.m_preader->SkipTag(tag);
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
}
while (!tag.isend());
// add it to the model
GetBuilder()->AddSurfaceLoad(psl);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::ParseSurfaceLoadSurface(XMLTag& tag, FESurface* psurf)
{
FEModelBuilder* feb = GetBuilder();
XMLTag tag2(tag);
++tag2;
do
{
if (tag2 == "surface")
{
// see if the surface is referenced by a set of defined explicitly
const char* szset = tag2.AttributeValue("set", true);
if (szset)
{
// make sure this tag does not have any children
if (!tag2.isleaf()) throw XMLReader::InvalidTag(tag2);
// see if we can find the facet set
FEMesh& m = GetFEModel()->GetMesh();
FEFacetSet* ps = m.FindFacetSet(szset);
// create a surface from the facet set
if (ps)
{
if (feb->BuildSurface(*psurf, *ps) == false) throw XMLReader::InvalidTag(tag2);
}
else throw XMLReader::InvalidAttributeValue(tag2, "set", szset);
}
else
{
// count how many pressure cards there are
int npr = tag2.children();
psurf->Create(npr);
// read surface
++tag2;
int nf[FEElement::MAX_NODES], N;
for (int i = 0; i<npr; ++i)
{
FESurfaceElement& el = psurf->Element(i);
if (tag2 == "quad4") el.SetType(FE_QUAD4G4);
else if (tag2 == "tri3" ) el.SetType(feb->m_ntri3);
else if (tag2 == "tri6" ) el.SetType(feb->m_ntri6);
else if (tag2 == "tri7" ) el.SetType(feb->m_ntri7);
else if (tag2 == "tri10") el.SetType(feb->m_ntri10);
else if (tag2 == "quad8") el.SetType(FE_QUAD8G9);
else if (tag2 == "quad9") el.SetType(FE_QUAD9G9);
else throw XMLReader::InvalidTag(tag2);
N = el.Nodes();
tag2.value(nf, N);
for (int j = 0; j<N; ++j) el.m_node[j] = nf[j] - 1;
++tag2;
}
psurf->CreateMaterialPointData();
}
}
else tag2.skip();
++tag2;
}
while (!tag2.isend());
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection2::ParseEdgeLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
// create edge load
const char* sztype = tag.AttributeValue("type");
FEEdgeLoad* pel = fecore_new<FEEdgeLoad>(sztype, &fem);
if (pel == 0) throw XMLReader::InvalidTag(tag);
// create a new edge
FEEdge* pedge = new FEEdge(&fem);
fem.GetMesh().AddEdge(pedge);
pel->SetEdge(pedge);
// read the parameters
FEParameterList& pl = pel->GetParameterList();
// read the pressure data
++tag;
do
{
if (ReadParameter(tag, pl) == false)
{
if (tag == "edge")
{
// see if the surface is referenced by a set of defined explicitly
const char* szset = tag.AttributeValue("set", true);
if (szset)
{
// make sure this tag does not have any children
if (!tag.isleaf()) throw XMLReader::InvalidTag(tag);
// see if we can find the facet set
FEMesh& m = GetFEModel()->GetMesh();
FESegmentSet* ps = m.FindSegmentSet(szset);
// create an edge from the segment set
if (ps)
{
if (GetBuilder()->BuildEdge(*pedge, *ps) == false) throw XMLReader::InvalidTag(tag);
}
else throw XMLReader::InvalidAttributeValue(tag, "set", szset);
}
else
{
// count how many load cards there are
int npr = tag.children();
pedge->Create(npr);
++tag;
int nf[FEElement::MAX_NODES], N;
for (int i = 0; i<npr; ++i)
{
FELineElement& el = pedge->Element(i);
if (tag == "line2") el.SetType(FE_LINE2G1);
else throw XMLReader::InvalidTag(tag);
N = el.Nodes();
tag.value(nf, N);
for (int j = 0; j<N; ++j) el.m_node[j] = nf[j] - 1;
++tag;
}
}
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
} while (!tag.isend());
// add edge load to model
GetBuilder()->AddEdgeLoad(pel);
}
//=============================================================================
// FEBioLoadsSection25
//=============================================================================
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::Parse(XMLTag& tag)
{
// make sure this tag has children
if (tag.isleaf()) return;
++tag;
do
{
if (tag == "nodal_load" ) ParseNodalLoad (tag);
else if (tag == "surface_load") ParseSurfaceLoad(tag);
else if (tag == "edge_load" ) ParseEdgeLoad (tag);
else if (tag == "body_load" ) ParseBodyLoad (tag);
else throw XMLReader::InvalidTag(tag);
++tag;
}
while (!tag.isend());
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::ParseBodyLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
const char* sztype = tag.AttributeValue("type");
FEBodyLoad* pbl = fecore_new<FEBodyLoad>(sztype, &fem);
if (pbl == 0) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// see if a name was defined
const char* szname = tag.AttributeValue("name", true);
if (szname) pbl->SetName(szname);
// see if a specific domain was referenced
const char* szpart = tag.AttributeValue("elem_set", true);
if (szpart)
{
FEElementSet* elset = mesh.FindElementSet(szpart);
if (elset == 0) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szpart);
pbl->SetDomainList(elset);
}
ReadParameterList(tag, pbl);
fem.AddModelLoad(pbl);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::ParseNodalLoad(XMLTag &tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
DOFS& dofs = fem.GetDOFS();
// get the bc
const char* sz = tag.AttributeValue("bc");
int bc = dofs.GetDOF(sz);
if (bc == -1) throw XMLReader::InvalidAttributeValue(tag, "bc", sz);
// get the node set
const char* szset = tag.AttributeValue("node_set");
FENodeSet* nodeSet = mesh.FindNodeSet(szset);
if (nodeSet == 0) throw XMLReader::InvalidAttributeValue(tag, "node_set", szset);
// create nodal load
FENodalDOFLoad* pfc = fecore_alloc(FENodalDOFLoad, &fem);
pfc->SetDOF(bc);
pfc->SetNodeSet(nodeSet);
// add it to the model
GetBuilder()->AddNodalLoad(pfc);
// read parameters
ReadParameterList(tag, pfc);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::ParseSurfaceLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create surface load
const char* sztype = tag.AttributeValue("type");
FESurfaceLoad* psl = fecore_new<FESurfaceLoad>(sztype, &fem);
if (psl == 0)
{
// there are some obsolete loads that have been moved elsewhere,
// so let's check for those first;
ParseObsoleteLoad(tag);
}
else
{
// read name attribute
const char* szname = tag.AttributeValue("name", true);
if (szname) psl->SetName(szname);
// get the surface
const char* szset = tag.AttributeValue("surface");
FEFacetSet* pface = mesh.FindFacetSet(szset);
if (pface == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", szset);
FESurface* psurf = fecore_alloc(FESurface, &fem);
GetBuilder()->BuildSurface(*psurf, *pface);
mesh.AddSurface(psurf);
psl->SetSurface(psurf);
// read the parameters
if (!tag.isleaf())
{
++tag;
do
{
if (ReadParameter(tag, psl) == false)
{
if ((tag == "value") && (strcmp(psl->GetTypeStr(), "pressure") == 0))
{
feLogWarningEx((&fem), "The value parameter of the pressure load is deprecated.");
FEParam* pp = psl->GetParameter("pressure"); assert(pp);
FEParamDouble& val = pp->value<FEParamDouble>();
// NOTE: This will only work if the pressure was set to 1!!
const char* szsurfdata = tag.AttributeValue("surface_data", true);
if (szsurfdata)
{
GetBuilder()->AddMappedParameter(pp, psl, szsurfdata);
}
else
{
double v;
tag.value(v);
val = v;
}
}
else throw XMLReader::InvalidTag(tag);
}
++tag;
} while (!tag.isend());
}
// add it to the model
GetBuilder()->AddSurfaceLoad(psl);
}
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::ParseEdgeLoad(XMLTag& tag)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// create edge load
const char* sztype = tag.AttributeValue("type");
FEEdgeLoad* pel = fecore_new<FEEdgeLoad>(sztype, &fem);
if (pel == 0) throw XMLReader::InvalidTag(tag);
// create a new edge
FEEdge* pedge = new FEEdge(&fem);
mesh.AddEdge(pedge);
pel->SetEdge(pedge);
// get the segment set
const char* szedge = tag.AttributeValue("edge");
FESegmentSet* pset = mesh.FindSegmentSet(szedge);
if (pset == 0) throw XMLReader::InvalidAttributeValue(tag, "edge", szedge);
if (GetBuilder()->BuildEdge(*pedge, *pset) == false) throw XMLReader::InvalidTag(tag);
// read the parameters
ReadParameterList(tag, pel);
// add edge load to model
GetBuilder()->AddEdgeLoad(pel);
}
//-----------------------------------------------------------------------------
void FEBioLoadsSection25::ParseObsoleteLoad(XMLTag& tag)
{
FEModel* fem = GetFEModel();
FEMesh& mesh = fem->GetMesh();
const char* sztype = tag.AttributeValue("type");
// this "load" was moved to the boundary section
if (strcmp(sztype, "fluid rotational velocity") == 0)
{
FEPrescribedNodeSet* pbc = fecore_new<FEPrescribedNodeSet>(sztype, fem);
if (pbc == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
// get the surface
const char* szset = tag.AttributeValue("surface");
FEFacetSet* pface = mesh.FindFacetSet(szset);
if (pface == 0) throw XMLReader::InvalidAttributeValue(tag, "surface", szset);
// extract the nodeset from the surface
FENodeList nodeList = pface->GetNodeList();
FENodeSet* nodeSet = new FENodeSet(fem);
nodeSet->SetName(pface->GetName());
nodeSet->Add(nodeList);
mesh.AddNodeSet(nodeSet);
// assign the node set
pbc->SetNodeSet(nodeSet);
// Read the parameter list
ReadParameterList(tag, pbc);
// Add the boundary condition
GetBuilder()->AddBC(pbc);
}
else throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEHolmesMow.cpp | .cpp | 4,328 | 133 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEHolmesMow.h"
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FEHolmesMow, FEElasticMaterial)
ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E")->setUnits(UNIT_PRESSURE)->setLongName("Young's modulus");
ADD_PARAMETER(m_v, FE_RANGE_RIGHT_OPEN(-1.0, 0.5), "v")->setLongName("Poisson's ratio");
ADD_PARAMETER(m_b, FE_RANGE_GREATER_OR_EQUAL(0.0), "beta")->setLongName("power exponent");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
bool FEHolmesMow::Validate()
{
if (FEElasticMaterial::Validate() == false) return false;
// Lame coefficients
lam = m_v*m_E/((1+m_v)*(1-2*m_v));
mu = 0.5*m_E/(1+m_v);
Ha = lam + 2*mu;
return true;
}
//-----------------------------------------------------------------------------
mat3ds FEHolmesMow::Stress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
double detF = pt.m_J;
double detFi = 1.0/detF;
// calculate left Cauchy-Green tensor
mat3ds b = pt.LeftCauchyGreen(); //(F*F.transpose()).sym();
mat3ds b2 = b.sqr();
mat3ds identity(1.,1.,1.,0.,0.,0.);
// calculate invariants of B
double I1 = b.tr();
double I2 = (I1*I1 - b2.tr())/2.;
double I3 = b.det();
// Exponential term
double eQ = exp(m_b*((2*mu-lam)*(I1-3) + lam*(I2-3))/Ha)/pow(I3,m_b);
// calculate stress
mat3ds s = 0.5*detFi*eQ*((2*mu+lam*(I1-1))*b - lam*b2 - Ha*identity);
return s;
}
//-----------------------------------------------------------------------------
tens4ds FEHolmesMow::Tangent(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
double detF = pt.m_J;
double detFi = 1.0/detF;
// calculate left Cauchy-Green tensor
mat3ds b = pt.LeftCauchyGreen(); //(F*F.transpose()).sym();
mat3ds b2 = b.sqr();
mat3ds identity(1.,1.,1.,0.,0.,0.);
// calculate invariants of B
double I1 = b.tr();
double I2 = (I1*I1 - b2.tr())*0.5;
double I3 = b.det();
// Exponential term
double eQ = exp(m_b*((2*mu-lam)*(I1-3) + lam*(I2-3))/Ha)/pow(I3,m_b);
// calculate stress
mat3ds s = 0.5*detFi*eQ*((2*mu+lam*(I1-1))*b - lam*b2 - Ha*identity);
// calculate elasticity tensor
tens4ds c = 4.*m_b/Ha*detF/eQ*dyad1s(s)
+ detFi*eQ*(lam*(dyad1s(b) - dyad4s(b)) + Ha*dyad4s(identity));
return c;
}
//-----------------------------------------------------------------------------
double FEHolmesMow::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// calculate left Cauchy-Green tensor
mat3ds b = pt.LeftCauchyGreen(); //(F*F.transpose()).sym();
mat3ds b2 = b.sqr();
// calculate invariants of B
double I1 = b.tr();
double I2 = (I1*I1 - b2.tr())/2.;
double I3 = b.det();
// Exponential term
double eQ = exp(m_b*((2*mu-lam)*(I1-3) + lam*(I2-3))/Ha)/pow(I3,m_b);
// calculate strain energy density
double sed = Ha/(4*m_b)*(eQ - 1);
return sed;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEPressureLoad.cpp | .cpp | 4,151 | 131 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEPressureLoad.h"
#include "FEBioMech.h"
#include <FECore/FEFacetSet.h>
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FEPressureLoad, FESurfaceLoad)
ADD_PARAMETER(m_pressure, "pressure")->setUnits(UNIT_PRESSURE)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE);
ADD_PARAMETER(m_bsymm , "symmetric_stiffness");
ADD_PARAMETER(m_blinear , "linear");
ADD_PARAMETER(m_bshellb , "shell_bottom");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FEPressureLoad::FEPressureLoad(FEModel* pfem) : FESurfaceLoad(pfem)
{
m_pressure = 0.0;
m_bsymm = true;
m_bshellb = false;
m_blinear = false;
}
//-----------------------------------------------------------------------------
bool FEPressureLoad::Init()
{
FESurface& surf = GetSurface();
surf.SetShellBottom(m_bshellb);
// get the degrees of freedom
m_dof.Clear();
if (m_bshellb == false)
{
m_dof.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT));
}
else
{
m_dof.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT));
}
if (m_dof.IsEmpty()) return false;
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
void FEPressureLoad::LoadVector(FEGlobalVector& R)
{
// evaluate the integral
FESurface& surf = GetSurface();
surf.LoadVector(R, m_dof, m_blinear, [&](FESurfaceMaterialPoint& pt, const FESurfaceDofShape& dof_a, std::vector<double>& val) {
// evaluate pressure at this material point
double P = -m_pressure(pt);
if (m_bshellb) P = -P;
double J = (pt.dxr ^ pt.dxs).norm();
// force vector
vec3d N = (pt.dxr ^ pt.dxs); N.unit();
vec3d t = N*P;
double H_u = dof_a.shape;
val[0] = H_u*t.x*J;
val[1] = H_u*t.y*J;
val[2] = H_u*t.z*J;
});
}
//-----------------------------------------------------------------------------
void FEPressureLoad::StiffnessMatrix(FELinearSystem& LS)
{
// Don't calculate stiffness for a linear load
if (m_blinear) return;
// evaluate the integral
FESurface& surf = GetSurface();
surf.LoadStiffness(LS, m_dof, m_dof, [&](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& kab) {
// evaluate pressure at this material point
double P = -m_pressure(mp);
if (m_bshellb) P = -P;
double H_i = dof_a.shape;
double Gr_i = dof_a.shape_deriv_r;
double Gs_i = dof_a.shape_deriv_s;
double H_j = dof_b.shape;
double Gr_j = dof_b.shape_deriv_r;
double Gs_j = dof_b.shape_deriv_s;
vec3d vab(0,0,0);
if (m_bsymm)
vab = (mp.dxr*(H_j * Gs_i - H_i * Gs_j) - mp.dxs*(H_j * Gr_i - H_i * Gr_j)) * 0.5*P;
else
vab = (mp.dxs*Gr_j - mp.dxr*Gs_j)*(P*H_i);
mat3da K(vab);
kab.set(0, 0, K);
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FESlidingElasticInterface.h | .h | 7,037 | 192 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEContactInterface.h"
#include "FEContactSurface.h"
// Elastic sliding contact, reducing the algorithm of biphasic sliding contact
// (FESlidingInterface2) to elastic case. The algorithm derives from Bonet
// & Wood's treatment of surface pressures
//-----------------------------------------------------------------------------
class FESlidingElasticSurface : public FEContactSurface
{
public:
// data for each integration point
class Data : public FEContactMaterialPoint
{
public:
Data();
void Init() override;
void Serialize(DumpStream& ar) override;
public:
vec3d m_dg; //!< vector gap
double m_Lmd; //!< Lagrange multiplier for normal traction
double m_epsn; //!< penalty factor
vec3d m_Lmt; //!< Lagrange multipliers for vector traction
vec3d m_nu; //!< local normal
vec3d m_s1; //!< tangent along slip direction
vec3d m_tr; //!< contact traction
vec2d m_rs; //!< natural coordinates of this integration point
vec2d m_rsp; //!< m_rs at the previous time step
bool m_bstick; //!< stick flag
};
public:
//! constructor
FESlidingElasticSurface(FEModel* pfem);
//! initialization
bool Init() override;
//! initialize sliding surface and store previous values
void InitSlidingSurface();
//! evaluate net contact force
vec3d GetContactForce() override;
//! evaluate net contact area
double GetContactArea() override;
//! create material point data
FEMaterialPoint* CreateMaterialPoint() override;
//! serialization
void Serialize(DumpStream& ar) override;
public:
void GetVectorGap (int nface, vec3d& pg) override;
void GetContactTraction(int nface, vec3d& pt) override;
void GetNodalVectorGap (int nface, vec3d* pg) override;
void GetNodalContactPressure(int nface, double* pg) override;
void GetNodalContactTraction(int nface, vec3d* pt) override;
void GetStickStatus(int nface, double& pg) override;
public:
vec3d m_Ft; //!< total contact force (from equivalent nodal forces)
};
//-----------------------------------------------------------------------------
class FESlidingElasticInterface : public FEContactInterface
{
public:
//! constructor
FESlidingElasticInterface(FEModel* pfem);
//! destructor
~FESlidingElasticInterface();
//! initialization
bool Init() override;
//! interface activation
void Activate() override;
//! calculate the slip direction on the primary surface
vec3d SlipTangent(FESlidingElasticSurface& ss, const int nel, const int nint, FESlidingElasticSurface& ms, double& dh, vec3d& r);
//! calculate contact traction
vec3d ContactTraction(FESlidingElasticSurface& ss, const int nel, const int n, FESlidingElasticSurface& ms, double& pn);
//! calculate contact pressures for file output
void UpdateContactPressures();
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! return the primary and secondary surface
FESurface* GetPrimarySurface() override { return &m_ss; }
FESurface* GetSecondarySurface() override { return &m_ms; }
//! return integration rule class
bool UseNodalIntegration() override { return false; }
//! build the matrix profile for use in the stiffness matrix
void BuildMatrixProfile(FEGlobalMatrix& K) override;
public:
//! calculate contact forces
void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override;
//! calculate contact stiffness
void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override;
//! calculate Lagrangian augmentations
bool Augment(int naug, const FETimeInfo& tp) override;
//! update
void Update() override;
protected:
void ProjectSurface(FESlidingElasticSurface& ss, FESlidingElasticSurface& ms, bool bupseg, bool bmove = false);
//! calculate penalty factor
void UpdateAutoPenalty();
void CalcAutoPenalty(FESlidingElasticSurface& s);
public:
FESlidingElasticSurface m_ss; //!< primary surface
FESlidingElasticSurface m_ms; //!< secondary surface
int m_knmult; //!< higher order stiffness multiplier
bool m_btwo_pass; //!< two-pass flag
double m_atol; //!< augmentation tolerance
double m_gtol; //!< normal gap tolerance
double m_stol; //!< search tolerance
bool m_bsymm; //!< use symmetric stiffness components only
double m_srad; //!< contact search radius
int m_naugmax; //!< maximum nr of augmentations
int m_naugmin; //!< minimum nr of augmentations
int m_nsegup; //!< segment update parameter
bool m_breloc; //!< node relocation on activation
bool m_bsmaug; //!< smooth augmentation
double m_epsn; //!< normal penalty factor
bool m_bautopen; //!< use autopenalty factor
bool m_bupdtpen; //!< update penalty at each time step
bool m_btension; //!< allow tension across interface
double m_mu; //!< friction coefficient
bool m_bfreeze; //!< freeze stick/slip status
bool m_bflips; //!< flip primary surface normal
bool m_bflipm; //!< flip secondary surface normal
bool m_bshellbs; //!< flag for prescribing pressure on shell bottom for primary surface
bool m_bshellbm; //!< flag for prescribing pressure on shell bottom for secondary surface
double m_offset; //!< allow an offset that separates the contact surfaces
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEGenericRigidJoint.cpp | .cpp | 15,000 | 682 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEGenericRigidJoint.h"
#include "FERigidBody.h"
#include <FECore/log.h>
#include <FECore/FEMaterial.h>
#include <FECore/FELinearSystem.h>
#include <FECore/fecore_debug.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEGenericRigidJoint, FERigidConnector);
ADD_PARAMETER(m_laugon , "laugon")->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0LAGMULT\0");
ADD_PARAMETER(m_eps , "penalty");
ADD_PARAMETER(m_tol , "tolerance");
ADD_PARAMETER(m_q0 , "joint" );
ADD_PARAMETER(m_dc[0] , "prescribe_x" , m_bc[0]);
ADD_PARAMETER(m_dc[1] , "prescribe_y" , m_bc[1]);
ADD_PARAMETER(m_dc[2] , "prescribe_z" , m_bc[2]);
ADD_PARAMETER(m_dc[3] , "prescribe_Rx", m_bc[3]);
ADD_PARAMETER(m_dc[4] , "prescribe_Ry", m_bc[4]);
ADD_PARAMETER(m_dc[5] , "prescribe_Rz", m_bc[5]);
ADD_PARAMETER(m_bsymm , "symmetric_stiffness");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEGenericRigidJoint::FEGenericRigidJoint(FEModel* pfem) : FERigidConnector(pfem)
{
static int count = 1;
m_nID = count++;
m_rbA = m_rbB = nullptr;
m_bc[0] = false;
m_bc[1] = false;
m_bc[2] = false;
m_bc[3] = false;
m_bc[4] = false;
m_bc[5] = false;
m_dc[0] = 0.0;
m_dc[1] = 0.0;
m_dc[2] = 0.0;
m_dc[3] = 0.0;
m_dc[4] = 0.0;
m_dc[5] = 0.0;
m_bsymm = false;
m_laugon = FECore::PENALTY_METHOD; // default to penalty method
m_eps = 1.0;
m_tol = 0.0;
vec3d a(1, 0, 0);
vec3d d(0, 1, 0);
vec3d e1 = a.normalized();
vec3d e3 = a ^ d; e3.unit();
vec3d e2 = e3 ^ e1;
m_v0[0] = e1;
m_v0[1] = e2;
m_v0[2] = e3;
for (int i = 0; i < 6; ++i)
{
m_EQ[i] = -1;
m_Lm[i] = 0.0;
m_Lmp[i] = 0.0;
}
}
//-----------------------------------------------------------------------------
bool FEGenericRigidJoint::Init()
{
// base class first
if (FERigidConnector::Init() == false) return false;
// initialize relative joint positions
m_qa0 = m_q0 - m_rbA->m_r0;
m_qb0 = m_q0 - m_rbB->m_r0;
return true;
}
//-----------------------------------------------------------------------------
//! initial position
vec3d FEGenericRigidJoint::InitialPosition() const
{
return m_q0;
}
//-----------------------------------------------------------------------------
//! current position
vec3d FEGenericRigidJoint::Position() const
{
FERigidBody& RBa = *m_rbA;
quatd Qa = RBa.GetRotation();
vec3d qa = Qa * m_qa0;
vec3d ra = RBa.m_rt;
return ra + qa;
}
//-----------------------------------------------------------------------------
// allocate equations
int FEGenericRigidJoint::InitEquations(int neq)
{
if (m_laugon == FECore::LAGMULT_METHOD)
{
int n = neq;
for (int i = 0; i < 6; ++i)
{
if (m_bc[i]) m_EQ[i] = n++; else m_EQ[i] = -1;
}
return n - neq;
}
else return 0;
}
//-----------------------------------------------------------------------------
// Build the matrix profile
void FEGenericRigidJoint::BuildMatrixProfile(FEGlobalMatrix& M)
{
vector<int> lm;
UnpackLM(lm);
// add it to the pile
M.build_add(lm);
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::LoadVector(FEGlobalVector& R, const FETimeInfo& tp)
{
FERigidBody& RBa = *m_rbA;
FERigidBody& RBb = *m_rbB;
quatd Qa = RBa.GetRotation();
vec3d qa = Qa*m_qa0;
quatd Qb = RBb.GetRotation();
vec3d qb = Qb*m_qb0;
vec3d ra = RBa.m_rt;
vec3d rb = RBb.m_rt;
vec3d g = ra + qa - rb - qb;
mat3da ya(-qa); mat3da yaT = -ya;
mat3da yb(-qb); mat3da ybT = -yb;
int ndof = (m_laugon == FECore::LAGMULT_METHOD ? 18 : 12);
// add translational constraints
vector<double> fe(ndof, 0.0);
for (int i = 0; i < 3; ++i)
{
if (m_bc[i])
{
vec3d v = Qa*m_v0[i];
mat3da VT(v);
double c = v*g + m_dc[i];
double L = m_Lm[i];
if (m_laugon != FECore::LAGMULT_METHOD) L += m_eps*c;
vec3d F = v*L;
vec3d Fa = F;
vec3d Fb = -F;
vec3d Ma = yaT*F + VT*(g*L);
vec3d Mb = -ybT*F;
// body A
fe[0] -= Fa.x;
fe[1] -= Fa.y;
fe[2] -= Fa.z;
fe[3] -= Ma.x;
fe[4] -= Ma.y;
fe[5] -= Ma.z;
// body B
fe[6] -= Fb.x;
fe[7] -= Fb.y;
fe[8] -= Fb.z;
fe[9] -= Mb.x;
fe[10] -= Mb.y;
fe[11] -= Mb.z;
// add constraint for Lagrange multiplier
if (m_laugon == FECore::LAGMULT_METHOD)
{
fe[12 + i] -= c;
}
}
}
// add rotational constraints
for (int i = 3; i < 6; ++i)
{
if (m_bc[i])
{
int K = i - 3;
int I = (K + 1) % 3;
int J = (K + 2) % 3;
vec3d va = Qa*m_v0[I];
vec3d vb = Qb*m_v0[J];
double c = va*vb - cos(0.5*PI + m_dc[i]);
double L = m_Lm[i];
if (m_laugon != FECore::LAGMULT_METHOD) L += m_eps*c;
mat3da VaT(va);
mat3da VbT(vb);
vec3d Ma = VaT*vb*L;
vec3d Mb = VbT*va*L;
// body A
fe[ 3] -= Ma.x;
fe[ 4] -= Ma.y;
fe[ 5] -= Ma.z;
// body B
fe[ 9] -= Mb.x;
fe[10] -= Mb.y;
fe[11] -= Mb.z;
// add constraint for Lagrange multiplier
if (m_laugon == FECore::LAGMULT_METHOD)
{
fe[12 + i] -= c;
}
}
}
vector<int> lm;
UnpackLM(lm);
R.Assemble(lm, fe);
RBa.m_Fr -= vec3d(fe[0], fe[1], fe[2]);
RBa.m_Mr -= vec3d(fe[3], fe[4], fe[5]);
RBb.m_Fr -= vec3d(fe[6], fe[7], fe[8]);
RBb.m_Mr -= vec3d(fe[9], fe[10], fe[11]);
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp)
{
if (m_laugon == FECore::LAGMULT_METHOD) StiffnessMatrixLM(LS, tp);
else StiffnessMatrixAL(LS, tp);
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::StiffnessMatrixLM(FELinearSystem& LS, const FETimeInfo& tp)
{
FERigidBody& RBa = *m_rbA;
FERigidBody& RBb = *m_rbB;
quatd Qa = RBa.GetRotation();
vec3d qa = Qa*m_qa0;
quatd Qb = m_rbB->GetRotation();
vec3d qb = Qb*m_qb0;
vec3d ra = RBa.m_rt;
vec3d rb = RBb.m_rt;
vec3d g = ra + qa - rb - qb;
mat3da ya(-qa);
mat3da yaT = -ya;
mat3da yb(-qb);
mat3da ybT = -yb;
mat3da G(-g);
mat3da GT = -G;
FEElementMatrix ke;
ke.resize(18, 18);
ke.zero();
// translational constraints
for (int i = 0; i < 3; ++i)
{
if (m_bc[i])
{
double L = m_Lm[i];
vec3d v = Qa*m_v0[i];
mat3d V = mat3da(-v);
mat3d VT = -V;
ke.add_symm(0, 3, V*L);
ke.add_symm(0, 12 + i, v);
if (m_bsymm) ke.add(3, 3, (yaT*V - GT*V).sym()*L);
else ke.add(3, 3, (yaT*V - GT*V)*L);
ke.add_symm(3, 6, -VT*L);
ke.add_symm(3, 9, -(VT*yb)*L);
ke.add_symm(3, 12 + i, yaT*v + VT*g);
ke.add_symm(6, 12 + i, -v);
if (m_bsymm) ke.add(9, 9 , (VT*yb).sym()*L);
else ke.add(9, 9, (VT*yb)*L);
ke.add_symm(9, 12 + i, -ybT*v);
}
}
// rotational constraints
for (int i = 3; i < 6; ++i)
{
if (m_bc[i])
{
double L = m_Lm[i];
int K = i - 3;
int I = (K + 1) % 3;
int J = (K + 2) % 3;
vec3d va = Qa*m_v0[I];
vec3d vb = Qb*m_v0[J];
mat3da Va(-va), VaT(va);
mat3da Vb(-vb), VbT(vb);
if (m_bsymm) ke.add(3, 3, -(VbT*Va).sym()*L);
else ke.add(3, 3, -(VbT*Va)*L);
ke.add_symm(3, 9, VaT*Vb*L);
ke.add_symm(3, 12 + i, VaT*vb);
if (m_bsymm) ke.add(9, 9, -(VaT*Vb).sym()*L);
else ke.add(9, 9, -(VaT*Vb)*L);
ke.add_symm(9, 12 + i, VbT*va);
}
}
// unpack LM
vector<int> lm;
UnpackLM(lm);
ke.SetIndices(lm);
// assemle into global stiffness matrix
LS.Assemble(ke);
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::StiffnessMatrixAL(FELinearSystem& LS, const FETimeInfo& tp)
{
FERigidBody& RBa = *m_rbA;
FERigidBody& RBb = *m_rbB;
quatd Qa = RBa.GetRotation();
vec3d qa = Qa*m_qa0;
quatd Qb = m_rbB->GetRotation();
vec3d qb = Qb*m_qb0;
vec3d ra = RBa.m_rt;
vec3d rb = RBb.m_rt;
vec3d g = ra + qa - rb - qb;
mat3da ya(-qa);
mat3da yaT = -ya;
mat3da yb(-qb);
mat3da ybT = -yb;
mat3da G(-g);
mat3da GT = -G;
FEElementMatrix ke;
ke.resize(12, 12);
ke.zero();
// translational constraints
for (int i = 0; i < 3; ++i)
{
if (m_bc[i])
{
vec3d w = Qa*m_v0[i];
mat3d W = mat3da(-w);
mat3d WT = -W;
double c = w*g + m_dc[i];
double lam = m_Lm[i] + m_eps*c;
mat3dd I(1.0);
matrix Q(12, 3);
Q.set(0, 0, I);
Q.set(3, 0, yaT);
Q.set(6, 0, -I);
Q.set(9, 0, -ybT);
matrix Qw = Q*w;
matrix V(12, 3); V.zero();
V.set(3, 0, WT);
matrix Vg = V*g;
matrix C = Vg + Qw;
matrix CCT = C*C.transpose();
matrix QVT = Q*V.transpose();
matrix VQT = V*Q.transpose();
ke += CCT*m_eps + (QVT + VQT)*lam;
if (m_bsymm == false)
{
ke.add(3, 3, (GT*W + WT*ya)*(-lam));
ke.add(9, 9, (WT*yb)*(lam));
}
}
}
// rotational constraints
for (int i = 3; i < 6; ++i)
{
if (m_bc[i])
{
int K = i - 3;
int I = (K + 1) % 3;
int J = (K + 2) % 3;
vec3d va = Qa*m_v0[I];
vec3d vb = Qb*m_v0[J];
double c = va*vb - cos(0.5*PI + m_dc[i]);
double lam = m_Lm[i] + m_eps*c;
mat3da Va(-va), VaT(va);
mat3da Vb(-vb), VbT(vb);
mat3dd Id(1.0);
matrix N(12, 3); N.zero();
N.set(3, 0, Id);
N.set(9, 0, -Id);
vec3d vv = VaT*vb;
matrix C = N*vv;
matrix CCT = C*C.transpose();
ke += CCT*m_eps;
if (m_bsymm == false)
{
mat3d VV = VaT*Vb;
matrix WT(3, 12); WT.zero();
WT.add(0, 3, -VV.transpose());
WT.add(0, 9, VV);
matrix JWT = N*WT;
ke += JWT*lam;
}
}
}
// unpack LM
vector<int> lm;
UnpackLM(lm);
ke.SetIndices(lm);
// assemle into global stiffness matrix
LS.Assemble(ke);
}
//-----------------------------------------------------------------------------
bool FEGenericRigidJoint::Augment(int naug, const FETimeInfo& tp)
{
FERigidBody& RBa = *m_rbA;
FERigidBody& RBb = *m_rbB;
quatd Qa = RBa.GetRotation();
quatd Qb = RBb.GetRotation();
vec3d ra = RBa.m_rt;
vec3d rb = RBb.m_rt;
vec3d qa = Qa*m_qa0;
vec3d qb = Qb*m_qb0;
// NOTE: This is NOT the gap that was used in the last residual
// evaluation. Is that a problem?
vec3d pa = ra + qa;
vec3d pb = rb + qb;
vec3d g = (ra - rb) + (qa - qb);
double c[6] = { 0 };
// translational constraints
for (int i = 0; i < 3; ++i)
{
if (m_bc[i])
{
vec3d v = Qa*m_v0[i];
c[i] = v*g + m_dc[i];
}
}
// rotational constraints
for (int i = 3; i < 6; ++i)
{
if (m_bc[i])
{
int K = i - 3;
int I = (K + 1) % 3;
int J = (K + 2) % 3;
vec3d va = Qa*m_v0[I];
vec3d vb = Qb*m_v0[J];
c[i] = va*vb - cos(0.5*PI + m_dc[i]);
}
}
feLog("\n=== rigid connector # %d:\n", m_nID);
bool bconv = true;
double e[6] = { 0 };
double Lm[6] = { 0 };
if (m_laugon == FECore::PENALTY_METHOD)
{
for (int i = 0; i < 6; ++i)
{
Lm[i] = m_eps*c[i];
}
}
else if (m_laugon == FECore::AUGLAG_METHOD)
{
// if (m_tol > 0.0)
{
for (int i = 0; i < 6; ++i)
{
if (m_bc[i])
{
Lm[i] = m_Lm[i] + m_eps*c[i];
double F0 = fabs(m_Lm[i]);
double F1 = fabs(Lm[i]);
double dl = fabs((F1 - F0) / F1);
if (m_tol && (dl > m_tol)) bconv = false;
e[i] = dl;
}
}
// if (bconv == false)
{
for (int i = 0; i < 6; ++i)
m_Lm[i] += m_eps*c[i];
}
}
}
else
{
for (int i = 0; i < 6; ++i) Lm[i] = m_Lm[i];
}
feLog(" Lagrange m. : %13.7lg,%13.7lg,%13.7lg\n", Lm[0], Lm[1], Lm[2]);
feLog(" %13.7lg,%13.7lg,%13.7lg\n", Lm[3], Lm[4], Lm[5]);
feLog(" constraint : %13.7lg,%13.7lg,%13.7lg\n", c[0], c[1], c[2]);
feLog(" %13.7lg,%13.7lg,%13.7lg\n", c[3], c[4], c[5]);
if (m_laugon == FECore::AUGLAG_METHOD)
{
feLog(" error : %13.7lg,%13.7lg,%13.7lg\n", e[0], e[1], e[2]);
feLog(" %13.7lg,%13.7lg,%13.7lg\n", e[3], e[4], e[5]);
}
return bconv;
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::Serialize(DumpStream& ar)
{
FERigidConnector::Serialize(ar);
ar & m_nID;
ar & m_q0 & m_qa0 & m_qb0;
ar & m_Lm & m_Lmp;
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::Update()
{
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::Reset()
{
assert(false);
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::UnpackLM(vector<int>& lm)
{
int ndof = (m_laugon == FECore::LAGMULT_METHOD ? 18 : 12);
// add the dofs of rigid body A
lm.reserve(ndof);
lm.push_back(m_rbA->m_LM[0]);
lm.push_back(m_rbA->m_LM[1]);
lm.push_back(m_rbA->m_LM[2]);
lm.push_back(m_rbA->m_LM[3]);
lm.push_back(m_rbA->m_LM[4]);
lm.push_back(m_rbA->m_LM[5]);
// add the dofs of rigid body B
lm.push_back(m_rbB->m_LM[0]);
lm.push_back(m_rbB->m_LM[1]);
lm.push_back(m_rbB->m_LM[2]);
lm.push_back(m_rbB->m_LM[3]);
lm.push_back(m_rbB->m_LM[4]);
lm.push_back(m_rbB->m_LM[5]);
// add the LM equations
if (m_laugon == FECore::LAGMULT_METHOD)
{
for (int i = 0; i < 6; ++i) lm.push_back(m_EQ[i]);
}
}
//-----------------------------------------------------------------------------
void FEGenericRigidJoint::Update(const std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon == FECore::LAGMULT_METHOD)
{
for (int i = 0; i < 6; ++i)
{
if (m_EQ[i] != -1) m_Lm[i] = m_Lmp[i] + Ui[m_EQ[i]] + ui[m_EQ[i]];
}
}
}
void FEGenericRigidJoint::PrepStep()
{
if (m_laugon == FECore::LAGMULT_METHOD)
{
for (int i = 0; i < 6; ++i)
{
m_Lmp[i] = m_Lm[i];
}
}
}
void FEGenericRigidJoint::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon == FECore::LAGMULT_METHOD)
{
for (int i = 0; i < 6; ++i)
{
if (m_EQ[i] != -1) Ui[m_EQ[i]] += ui[m_EQ[i]];
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FERigidRotationVector.h | .h | 1,726 | 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 "RigidBC.h"
#include "febiomech_api.h"
class FEBIOMECH_API FERigidRotationVector : public FERigidBC
{
public:
FERigidRotationVector(FEModel* fem);
~FERigidRotationVector();
bool Init() override;
void Activate() override;
void Deactivate() override;
void InitTimeStep() override;
void Serialize(DumpStream& ar) override;
private:
double m_vx, m_vy, m_vz;
FERigidPrescribedBC* m_rc[3];
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FENaturalNeoHookean.cpp | .cpp | 5,980 | 181 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENaturalNeoHookean.h"
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FENaturalNeoHookean, FEElasticMaterial)
ADD_PARAMETER(m_E, FE_RANGE_GREATER_OR_EQUAL(0.0), "E")->setUnits(UNIT_PRESSURE)->setLongName("Young's modulus");
ADD_PARAMETER(m_v, FE_RANGE_RIGHT_OPEN(-1, 0.5), "v")->setLongName("Poisson's ratio");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
mat3ds FENaturalNeoHookean::Stress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
double J = pt.m_J;
// get the material parameters
double E = m_E(mp);
double v = m_v(mp);
double k = E/3/(1-2*v);
double mu = E/2/(1+v);
// evaluate spatial Hencky (logarithmic) strain
mat3ds h = pt.LeftHencky();
// evaluate amount of dilatation
double K1 = h.tr();
// evaluate amount of distortion (always positive)
mat3ds hdev = h.dev();
double K2 = hdev.norm();
// Identity
mat3dd I(1);
// Phi
mat3ds Phi;
if (K2 != 0) Phi = hdev/K2;
else Phi.zero();
// calculate stress
mat3ds s = (I*(k*K1) + Phi*(2*mu*K2))/J;
return s;
}
//-----------------------------------------------------------------------------
tens4ds FENaturalNeoHookean::Tangent(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// get the material parameters
double E = m_E(mp);
double v = m_v(mp);
double k = E/3/(1-2*v);
double mu = E/2/(1+v);
// jacobian
double J = pt.m_J;
// get the left Cauchy-Green tensor
mat3ds b = pt.LeftCauchyGreen();
// get the eigenvalues and eigenvectors of b
double lam2[3]; // these are the squares of the eigenvalues of V
vec3d n[3];
EigenValues(b, lam2, n, 1e-12);
// get the eigenvalues of V
double lam[3], lnl[3];
mat3ds a[3];
for (int i=0; i<3; ++i) {
lam[i] = sqrt(lam2[i]);
lnl[i] = log(lam[i]);
a[i] = dyad(n[i]);
}
// evaluate relevant coefficients
double s[3], ss[3], ddW, ds[3];
double c1 = 3*k + 4*mu;
double c2 = 3*k - 2*mu;
double c3 = 3*k + mu;
s[0] = (c1*lnl[0] + c2*(lnl[1] + lnl[2]))/(3*J);
s[1] = (c1*lnl[1] + c2*(lnl[2] + lnl[0]))/(3*J);
s[2] = (c1*lnl[2] + c2*(lnl[0] + lnl[1]))/(3*J);
ss[0] = (c1*(1 - 2*lnl[0]) - 2*c2*(lnl[1] + lnl[2]))/(3*J);
ss[1] = (c1*(1 - 2*lnl[1]) - 2*c2*(lnl[2] + lnl[0]))/(3*J);
ss[2] = (c1*(1 - 2*lnl[2]) - 2*c2*(lnl[0] + lnl[1]))/(3*J);
ddW = c2/(3*J);
if (lam2[1] != lam2[2])
ds[0] = 2*(lam2[2]*s[1] - lam2[1]*s[2])/(lam2[1] - lam2[2]);
else
ds[0] = (6*mu - 4*c3*lnl[1] - 2*c2*lnl[0])/(3*J);
if (lam2[2] != lam2[0])
ds[1] = 2*(lam2[0]*s[2] - lam2[2]*s[0])/(lam2[2] - lam2[0]);
else
ds[1] = (6*mu - 4*c3*lnl[2] - 2*c2*lnl[1])/(3*J);
if (lam2[0] != lam2[1])
ds[2] = 2*(lam2[1]*s[0] - lam2[0]*s[1])/(lam2[0] - lam2[1]);
else
ds[2] = (6*mu - 4*c3*lnl[0] - 2*c2*lnl[2])/(3*J);
tens4ds c = dyad1s(a[0])*ss[0] + dyad1s(a[1])*ss[1] + dyad1s(a[2])*ss[2]
+ (dyad1s(a[1], a[2]) + dyad1s(a[2], a[0]) + dyad1s(a[0], a[1]))*ddW
+ dyad4s(a[1], a[2])*ds[0] + dyad4s(a[2], a[0])*ds[1] + dyad4s(a[0], a[1])*ds[2];
return c;
}
//-----------------------------------------------------------------------------
double FENaturalNeoHookean::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// get the material parameters
double E = m_E(mp);
double v = m_v(mp);
double k = E/3/(1-2*v);
double mu = E/2/(1+v);
// evaluate spatial Hencky (logarithmic) strain
mat3ds h = pt.LeftHencky();
// evaluate amount of dilatation
double K1 = h.tr();
// evaluate amount of distortion (always positive)
mat3ds hdev = h.dev();
double K2 = hdev.norm();
double sed = K1*K1*k/2 + K2*K2*mu;
return sed;
}
//-----------------------------------------------------------------------------
void FENaturalNeoHookean::EigenValues(mat3ds& A, double l[3], vec3d r[3], const double eps)
{
A.eigen(l, r);
// correct for numerical inaccuracy
double d01 = fabs(l[0] - l[1]);
double d12 = fabs(l[1] - l[2]);
double d02 = fabs(l[0] - l[2]);
if (d01 < eps) l[1] = l[0]; //= 0.5*(l[0]+l[1]);
if (d02 < eps) l[2] = l[0]; //= 0.5*(l[0]+l[2]);
if (d12 < eps) l[2] = l[1]; //= 0.5*(l[1]+l[2]);
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEGenericTransIsoHyperelastic.h | .h | 2,670 | 77 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElasticMaterial.h"
#include <FECore/MathObject.h>
//! Transversely isotropic Hyperelastic material, defined by strain energy function.
//! This case assumes the strain energy function to be a function of
//! the invariants: I1, I2, I4, I5, and J. Furthermore, it assumes that the
//! strain energy function is defined by W(C) = W1(I1,I2, I4, I5) + WJ(J), where
//! W1 only depends on I1, I2, I4, and I5, and WJ only depends on J.
class FEGenericTransIsoHyperelastic : public FEElasticMaterial
{
public:
FEGenericTransIsoHyperelastic(FEModel* fem);
bool Init() override;
mat3ds Stress(FEMaterialPoint& mp) override;
tens4ds Tangent(FEMaterialPoint& mp) override;
double StrainEnergyDensity(FEMaterialPoint& mp) override;
private:
std::string m_exp;
FEVec3dValuator* m_fiber;
private:
MSimpleExpression m_W; // strain-energy function
vector<double*> m_param; // user parameters
// strain energy derivatives
MSimpleExpression m_W1;
MSimpleExpression m_W2;
MSimpleExpression m_W4;
MSimpleExpression m_W5;
MSimpleExpression m_WJ;
MSimpleExpression m_W11;
MSimpleExpression m_W12;
MSimpleExpression m_W14;
MSimpleExpression m_W15;
MSimpleExpression m_W22;
MSimpleExpression m_W24;
MSimpleExpression m_W25;
MSimpleExpression m_W44;
MSimpleExpression m_W45;
MSimpleExpression m_W55;
MSimpleExpression m_WJJ;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FENodalForce.cpp | .cpp | 2,430 | 77 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FENodalForce.h"
#include "FEBioMech.h"
#include <FECore/FENodeSet.h>
#include <FECore/FEMaterialPoint.h>
#include <FECore/FENode.h>
BEGIN_FECORE_CLASS(FENodalForce, FENodalLoad)
ADD_PARAMETER(m_f, "value")->setUnits(UNIT_FORCE)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE);
ADD_PARAMETER(m_shellBottom, "shell_bottom");
END_FECORE_CLASS();
FENodalForce::FENodalForce(FEModel* fem) : FENodalLoad(fem)
{
m_f = vec3d(0, 0, 0);
m_shellBottom = false;
}
// set the value
void FENodalForce::SetValue(const vec3d& v)
{
m_f = v;
}
bool FENodalForce::SetDofList(FEDofList& dofList)
{
if (m_shellBottom)
return dofList.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT));
else
return dofList.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT));
}
void FENodalForce::GetNodalValues(int inode, std::vector<double>& val)
{
assert(val.size() == 3);
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;
vec3d f = m_f(mp);
val[0] = f.x;
val[1] = f.y;
val[2] = f.z;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FENonlinearSpring.h | .h | 2,112 | 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 "FEDiscreteElasticMaterial.h"
#include <FECore/FEFunction1D.h>
#include "febiomech_api.h"
//-----------------------------------------------------------------------------
//! This class implements a non-linear spring where users can choose what
//! deformation measure to use in the force curve.
class FEBIOMECH_API FENonlinearSpringMaterial : public FEDiscreteElasticMaterial
{
public:
FENonlinearSpringMaterial(FEModel* pfem);
vec3d Force(FEDiscreteMaterialPoint& mp) override;
mat3d Stiffness(FEDiscreteMaterialPoint& mp) override;
double StrainEnergy(FEDiscreteMaterialPoint& mp) override;
private:
FEFunction1D* m_F; //!< force-displacement function
double m_scale; //!< scale factor for force
int m_measure; //!< deformation measure
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEDamageMaterialPoint.cpp | .cpp | 1,953 | 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.*/
#include "stdafx.h"
#include "FEDamageMaterialPoint.h"
#include <FECore/DumpStream.h>
FEMaterialPointData* FEDamageMaterialPoint::Copy()
{
FEDamageMaterialPoint* pt = new FEDamageMaterialPoint(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
void FEDamageMaterialPoint::Init()
{
FEMaterialPointData::Init();
// intialize data to zero
m_Emax = 0;
m_Etrial = 0;
m_D = 0;
}
void FEDamageMaterialPoint::Update(const FETimeInfo& timeInfo)
{
FEMaterialPointData::Update(timeInfo);
m_Emax = max(m_Emax, m_Etrial);
}
void FEDamageMaterialPoint::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_Etrial & m_Emax & m_D;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FETiedLineConstraint.h | .h | 3,181 | 118 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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/FENLConstraint.h>
#include <FECore/FEEdge.h>
class FETiedLine : public FEEdge
{
public:
struct NodeData
{
FELineElement* me = nullptr;
double r;
vec3d vgap;
vec3d Tc;
vec3d Lm;
};
struct Projection
{
FELineElement* pe = nullptr;
vec3d q;
double r = 0;
};
public:
FETiedLine(FEModel* fem);
FEMaterialPoint* CreateMaterialPoint() override;
void Update();
bool Create(FESegmentSet& eset) override;
bool Init() override;
Projection ClosestProjection(const vec3d& x);
public:
std::vector<NodeData> m_data;
};
//! This class implements a tied-line.
class FETiedLineConstraint : public FENLConstraint
{
public:
//! constructor
FETiedLineConstraint(FEModel* pfem);
//! destructor
virtual ~FETiedLineConstraint(){}
//! Initializes sliding interface
bool Init() override;
//! interface activation
void Activate() override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! build the matrix profile for use in the stiffness matrix
void BuildMatrixProfile(FEGlobalMatrix& K) override;
void ProjectLines(FETiedLine& pl, FETiedLine& sl);
public:
//! calculate contact forces
void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override;
//! calculate contact stiffness
void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override;
//! calculate Lagrangian augmentations
bool Augment(int naug, const FETimeInfo& tp) override;
//! update
void Update() override;
public:
int m_laugon; //!< enforcement method (0=penalty, 1=aug. Lag.)
double m_atol; //!< augmentation tolerance
double m_eps; //!< penalty scale factor
int m_naugmax; //!< maximum nr of augmentations
int m_naugmin; //!< minimum nr of augmentations
double m_Dmax; //!< max distance for contact
private:
FETiedLine pl; // primary line
FETiedLine sl; // secondary line
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEGenericTransIsoHyperelasticUC.h | .h | 2,868 | 77 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEUncoupledMaterial.h"
#include <FECore/MathObject.h>
//! Uncoupled transversely isotropic Hyperelastic material, defined by strain energy function.
//! This case assumes the strain energy function to be a function of
//! the (deviatoric) invariants: I1, I2, I4, I5, and J. Furthermore, it assumes that the
//! strain energy function is defined by W(C) = W1(I1,I2, I4, I5) + WJ(J), where
//! W1 only depends on I1, I2, I4, and I5, and WJ only depends on J.
//! Since FEBio handles WJ automatically, only W1 needs to be implemented
class FEGenericTransIsoHyperelasticUC : public FEUncoupledMaterial
{
public:
FEGenericTransIsoHyperelasticUC(FEModel* fem);
bool Init() override;
mat3ds DevStress(FEMaterialPoint& mp) override;
tens4ds DevTangent(FEMaterialPoint& mp) override;
double DevStrainEnergyDensity(FEMaterialPoint& mp) override;
private:
std::string m_exp; // the string with the strain energy expression
FEVec3dValuator* m_fiber; // fiber direction
bool m_printDerivs; // option to print out derivatives
private:
MSimpleExpression m_W; // strain-energy function
vector<double*> m_param; // user parameters
// strain energy derivatives
MSimpleExpression m_W1;
MSimpleExpression m_W2;
MSimpleExpression m_W4;
MSimpleExpression m_W5;
MSimpleExpression m_W11;
MSimpleExpression m_W12;
MSimpleExpression m_W14;
MSimpleExpression m_W15;
MSimpleExpression m_W22;
MSimpleExpression m_W24;
MSimpleExpression m_W25;
MSimpleExpression m_W44;
MSimpleExpression m_W45;
MSimpleExpression m_W55;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEPrescribedDisplacement.cpp | .cpp | 1,931 | 41 | /*This file 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 "FEPrescribedDisplacement.h"
//=======================================================================================
// NOTE: I'm setting FEBoundaryCondition is the base class since I don't want to pull
// in the parameters of FEPrescribedDOF.
BEGIN_FECORE_CLASS(FEPrescribedDisplacement, FENodalBC)
ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list:displacement)");
ADD_PARAMETER(m_scale, "value")->setUnits(UNIT_LENGTH)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE);
ADD_PARAMETER(m_brelative, "relative");
END_FECORE_CLASS();
FEPrescribedDisplacement::FEPrescribedDisplacement(FEModel* fem) : FEPrescribedDOF(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEPrescribedRotation.cpp | .cpp | 1,921 | 41 | /*This file 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 "FEPrescribedRotation.h"
//=======================================================================================
// NOTE: I'm setting FEBoundaryCondition is the base class since I don't want to pull
// in the parameters of FEPrescribedDOF.
BEGIN_FECORE_CLASS(FEPrescribedRotation, FEBoundaryCondition)
ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list:rotation)");
ADD_PARAMETER(m_scale, "value")->setUnits(UNIT_RADIAN)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE);
ADD_PARAMETER(m_brelative, "relative");
END_FECORE_CLASS();
FEPrescribedRotation::FEPrescribedRotation(FEModel* fem) : FEPrescribedDOF(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEUncoupledReactiveFatigue.cpp | .cpp | 7,737 | 213 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEUncoupledReactiveFatigue.h"
#include "FEDamageCriterion.h"
#include "FEDamageCDF.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
#include <FECore/log.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FEModel.h>
//////////////////////////// FATIGUE MATERIAL /////////////////////////////////
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FEUncoupledReactiveFatigue, FEUncoupledMaterial)
ADD_PARAMETER(m_k0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "k0" );
ADD_PARAMETER(m_beta , FE_RANGE_GREATER_OR_EQUAL(0.0), "beta");
// set material properties
ADD_PROPERTY(m_pBase, "elastic");
ADD_PROPERTY(m_pIdmg, "elastic_damage");
ADD_PROPERTY(m_pFdmg, "fatigue_damage");
ADD_PROPERTY(m_pIcrt, "elastic_criterion");
ADD_PROPERTY(m_pFcrt, "fatigue_criterion");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FEUncoupledReactiveFatigue::FEUncoupledReactiveFatigue(FEModel* pfem) : FEUncoupledMaterial(pfem)
{
m_pBase = 0;
m_pIdmg = 0;
m_pFdmg = 0;
m_pIcrt = 0;
m_pFcrt = 0;
m_k0 = 0;
m_beta = 0;
}
//-----------------------------------------------------------------------------
FEMaterialPointData* FEUncoupledReactiveFatigue::CreateMaterialPointData()
{
return new FEReactiveFatigueMaterialPoint(m_pBase->CreateMaterialPointData());
}
//-----------------------------------------------------------------------------
//! Initialization.
bool FEUncoupledReactiveFatigue::Init()
{
return FEUncoupledMaterial::Init();
}
//-----------------------------------------------------------------------------
//! calculate stress at material point
mat3ds FEUncoupledReactiveFatigue::DevStress(FEMaterialPoint& pt)
{
// evaluate the damage
double d = Damage(pt);
// evaluate the stress
mat3ds s = m_pBase->DevStress(pt);
// return damaged stress
return s*(1-d);
}
//-----------------------------------------------------------------------------
//! calculate tangent stiffness at material point
tens4ds FEUncoupledReactiveFatigue::DevTangent(FEMaterialPoint& pt)
{
// evaluate the damage
double d = Damage(pt);
// evaluate the tangent
tens4ds c = m_pBase->DevTangent(pt);
// return damaged tangent
return c*(1-d);
}
//-----------------------------------------------------------------------------
//! calculate strain energy density at material point
double FEUncoupledReactiveFatigue::DevStrainEnergyDensity(FEMaterialPoint& pt)
{
// evaluate the damage
double d = Damage(pt);
// evaluate the strain energy density
double sed = m_pBase->DevStrainEnergyDensity(pt);
// return damaged sed
return sed*(1-d);
}
//-----------------------------------------------------------------------------
//! calculate damage at material point
double FEUncoupledReactiveFatigue::Damage(FEMaterialPoint& pt)
{
// get the reactive fatigue material point data
FEReactiveFatigueMaterialPoint& pd = *pt.ExtractData<FEReactiveFatigueMaterialPoint>();
return pd.m_D;
}
//-----------------------------------------------------------------------------
// update fatigue material point at each iteration
void FEUncoupledReactiveFatigue::UpdateSpecializedMaterialPoints(FEMaterialPoint& pt, const FETimeInfo& tp)
{
double dt = tp.timeIncrement;
double k0 = m_k0(pt);
double beta = m_beta(pt);
// get the fatigue material point data
FEReactiveFatigueMaterialPoint& pd = *pt.ExtractData<FEReactiveFatigueMaterialPoint>();
// get damage criterion for intact bonds at current time
pd.m_Xitrl = m_pIcrt->DamageCriterion(pt);
if (pd.m_Xitrl > pd.m_Ximax)
pd.m_Fit = m_pIdmg->cdf(pt,pd.m_Xitrl);
else
pd.m_Fit = pd.m_Fip;
// get damage criterion for fatigue bonds at current time
double Xftrl = m_pFcrt->DamageCriterion(pt);
for (int ig=0; ig < pd.m_fb.size(); ++ig) {
if (Xftrl > pd.m_fb[ig].m_Xfmax) {
pd.m_fb[ig].m_Xftrl = Xftrl;
pd.m_fb[ig].m_Fft = m_pFdmg->cdf(pt,pd.m_fb[ig].m_Xftrl);
}
else
pd.m_fb[ig].m_Fft = pd.m_fb[ig].m_Ffp;
}
// evaluate time derivative of intact bond criterion
pd.m_aXit = (pd.m_Xitrl - pd.m_Xip)/dt;
// solve for bond mass fractions iteratively
double eps = 1e-6;
int maxit = 10;
double wbi = 0;
int iter = 0;
do {
wbi = pd.m_wbt;
// get current and previous k value
double kn1 = k0*(pow(fabs(pd.m_aXit)*pd.m_wbt,beta));
double kn = k0*(pow(fabs(pd.m_aXip)*pd.m_wbp,beta));
// evaluate mass supply from fatigue of intact bonds
double dwf = ((kn1*dt + kn*dt)/(2 + kn1*dt))*pd.m_wip;
double Fdwf = m_pFdmg->cdf(pt,Xftrl);
// kinetics of intact bonds
pd.m_wit = (pd.m_Fip < 1) ? (pd.m_wip - dwf)*(1-pd.m_Fit)/(1-pd.m_Fip) : pd.m_wip;
pd.m_wbt = (pd.m_Fip < 1) ? pd.m_wbp + (pd.m_wip - dwf)*(pd.m_Fit - pd.m_Fip)/(1-pd.m_Fip) : pd.m_wbp;
// add or update new generation
if ((pd.m_fb.size() == 0) || pd.m_fb.back().m_time < tp.currentTime) {
// add generation of fatigued bonds
FatigueBond fb;
fb.m_Fft = Fdwf;
fb.m_wfp = dwf;
fb.m_Xftrl = Xftrl;
fb.m_time = tp.currentTime;
pd.m_fb.push_back(fb);
}
else {
pd.m_fb.back().m_Fft = Fdwf;
pd.m_fb.back().m_wfp = dwf;
pd.m_fb.back().m_Xftrl = Xftrl;
}
// damage kinetics of fatigued bonds
for (int ig=0; ig < pd.m_fb.size(); ++ig) {
pd.m_fb[ig].m_wft = (pd.m_fb[ig].m_Ffp < 1) ? pd.m_fb[ig].m_wfp*(1-pd.m_fb[ig].m_Fft)/(1-pd.m_fb[ig].m_Ffp) : 0;
pd.m_wbt += (pd.m_fb[ig].m_Ffp < 1) ? pd.m_fb[ig].m_wfp*(pd.m_fb[ig].m_Fft-pd.m_fb[ig].m_Ffp)/(1-pd.m_fb[ig].m_Ffp) : pd.m_fb[ig].m_wfp;
}
// roundoff corrections
if (pd.m_wit < 0) pd.m_wit = 0;
if (pd.m_wbt > 1) pd.m_wbt = 1;
// evaluate fatigue bond fraction
pd.m_wft = 0;
for (int ig=0; ig < pd.m_fb.size(); ++ig) pd.m_wft += pd.m_fb[ig].m_wft;
} while ((pd.m_wbt > 0) && (pd.m_wbt < 1) && (fabs(wbi-pd.m_wbt) > eps*pd.m_wbt) && (++iter<maxit));
pd.m_D = pd.m_wbt;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEElasticMultigeneration.h | .h | 4,680 | 140 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElasticMaterial.h"
//-----------------------------------------------------------------------------
// TODO: This was introduced so that the FEGenerationMaterial fits in the current
// framework, which assumes that all features classes are derived from base-classes.
class FEBIOMECH_API FEGenerationBase : public FEMaterialProperty
{
public:
FEGenerationBase(FEModel* fem);
//! calculate stress at material point
mat3ds Stress(FEMaterialPoint& pt);
//! calculate tangent stiffness at material point
tens4ds Tangent(FEMaterialPoint& pt);
//! calculate strain energy density at material point
double StrainEnergyDensity(FEMaterialPoint& pt);
// returns a pointer to a new material point object
FEMaterialPointData* CreateMaterialPointData() override;
public:
double btime; //!< generation birth time
FEElasticMaterial* m_pMat; //!< pointer to elastic material
FECORE_BASE_CLASS(FEGenerationBase)
};
//-----------------------------------------------------------------------------
//! Material defining a single generation of a multi-generation material
class FEGenerationMaterial : public FEGenerationBase
{
public:
FEGenerationMaterial(FEModel* pfem);
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
// forward declaration of material class
class FEElasticMultigeneration;
//-----------------------------------------------------------------------------
//! Multigenerational material point.
//! First generation exists at t=0. Second, third, etc. generations appear at t>0.
//! This material point stores the inverse of the relative deformation gradient of
//! second, third, etc. generations. These relate the reference configuration of
//! each generation relative to the first generation.
class FEMultigenerationMaterialPoint : public FEMaterialPointArray
{
public:
FEMultigenerationMaterialPoint();
FEMaterialPointData* Copy();
//! data serialization
void Serialize(DumpStream& ar);
void Init();
void Update(const FETimeInfo& timeInfo);
public:
// multigenerational material data
double m_tgen; //!< last generation time
int m_ngen; //!< number of active generations
FEElasticMultigeneration* m_pmat;
};
//-----------------------------------------------------------------------------
//! Multigenerational solid
class FEElasticMultigeneration : public FEElasticMaterial
{
public:
FEElasticMultigeneration(FEModel* pfem);
// returns a pointer to a new material point object
FEMaterialPointData* CreateMaterialPointData() override;
// return number of materials
int Materials() { return (int)m_MG.size(); }
// return a generation material component
FEGenerationBase* GetMaterial(int i) { return m_MG[i]; }
public:
//! calculate stress at material point
mat3ds Stress(FEMaterialPoint& pt) override;
//! calculate tangent stiffness at material point
tens4ds Tangent(FEMaterialPoint& pt) override;
//! calculate strain energy density at material point
double StrainEnergyDensity(FEMaterialPoint& pt) override;
int CheckGeneration(const double t);
public:
double StrongBondSED(FEMaterialPoint& pt) override;
double WeakBondSED(FEMaterialPoint& pt) override;
public:
std::vector<FEGenerationBase*> m_MG; //!< multigeneration data
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FE2DTransIsoVerondaWestmann.h | .h | 2,537 | 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 "FEUncoupledMaterial.h"
//-----------------------------------------------------------------------------
//! 2D transversely isotropic Veronda-Westmann
//! This class describes a transversely isotropic matrix where the base material
//! is Veronda-Westmann. The difference between this material and the FETransIsoVerondaWestmann
//! material is that in this material the fibers lie in the plane that is perpendicular
//! to the transverse axis.
class FE2DTransIsoVerondaWestmann : public FEUncoupledMaterial
{
enum { NSTEPS = 12 }; // nr of integration steps
public:
// material parameters
double m_c1; //!< Veronda-Westmann parameter c1
double m_c2; //!< Veronda-Westmann parameter c2
// fiber parameters
double m_c3;
double m_c4;
double m_c5;
double m_lam1;
double m_epsf;
public:
//! constructor
FE2DTransIsoVerondaWestmann(FEModel* pfem);
//! calculate deviatoric stress at material point
virtual mat3ds DevStress(FEMaterialPoint& pt) override;
//! calculate deviatoric tangent stiffness at material point
virtual tens4ds DevTangent(FEMaterialPoint& pt) override;
// declare parameter list
DECLARE_FECORE_CLASS();
protected:
static double m_cth[NSTEPS];
static double m_sth[NSTEPS];
double m_w[2];
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEContinuousFiberDistribution.cpp | .cpp | 7,218 | 248 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEContinuousFiberDistribution.h"
BEGIN_FECORE_CLASS(FEContinuousFiberDistribution, FEElasticMaterial)
// material properties
ADD_PROPERTY(m_pFmat, "fibers");
ADD_PROPERTY(m_pFDD, "distribution");
ADD_PROPERTY(m_pFint, "scheme");
ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEContinuousFiberDistribution::FEContinuousFiberDistribution(FEModel* pfem) : FEElasticMaterial(pfem)
{
m_pFmat = 0;
m_pFDD = 0;
m_pFint = 0;
}
//-----------------------------------------------------------------------------
FEContinuousFiberDistribution::~FEContinuousFiberDistribution() {}
//-----------------------------------------------------------------------------
FEMaterialPointData* FEContinuousFiberDistribution::CreateMaterialPointData()
{
FEMaterialPointData* mp = FEElasticMaterial::CreateMaterialPointData();
mp->SetNext(m_pFmat->CreateMaterialPointData());
return mp;
}
//-----------------------------------------------------------------------------
bool FEContinuousFiberDistribution::Init()
{
// initialize base class
if (FEElasticMaterial::Init() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
//! Serialization
void FEContinuousFiberDistribution::Serialize(DumpStream& ar)
{
FEElasticMaterial::Serialize(ar);
if (ar.IsShallow()) return;
}
//-----------------------------------------------------------------------------
//! calculate stress at material point
mat3ds FEContinuousFiberDistribution::Stress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
FEFiberMaterialPoint& fp = *mp.ExtractData<FEFiberMaterialPoint>();
// calculate stress
mat3ds s; s.zero();
// get the local coordinate system
mat3d Q = GetLocalCS(mp);
double IFD = IntegratedFiberDensity(mp);
fp.m_index = 0;
// obtain an integration point iterator
FEFiberIntegrationSchemeIterator* it = m_pFint->GetIterator(&mp);
if (it->IsValid())
{
do
{
// get the fiber direction for that fiber distribution
vec3d& N = it->m_fiber;
// evaluate ellipsoidally distributed material coefficients
double R = m_pFDD->FiberDensity(mp, N);
// convert fiber to global coordinates
vec3d n0 = Q*N;
// calculate the stress
double wn = it->m_weight;
s += m_pFmat->FiberStress(mp, fp.FiberPreStretch(n0))*(R*wn);
fp.m_index++;
}
while (it->Next());
}
// don't forget to delete the iterator
delete it;
// divide by IFD
return s / IFD;
}
//-----------------------------------------------------------------------------
//! calculate tangent stiffness at material point
tens4ds FEContinuousFiberDistribution::Tangent(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
FEFiberMaterialPoint& fp = *mp.ExtractData<FEFiberMaterialPoint>();
// get the local coordinate system
mat3d Q = GetLocalCS(mp);
double IFD = IntegratedFiberDensity(mp);
// initialize stress tensor
tens4ds c;
c.zero();
fp.m_index = 0;
FEFiberIntegrationSchemeIterator* it = m_pFint->GetIterator(&mp);
if (it->IsValid())
{
do
{
// get the fiber direction for that fiber distribution
vec3d& N = it->m_fiber;
// evaluate ellipsoidally distributed material coefficients
double R = m_pFDD->FiberDensity(mp, N);
// convert fiber to global coordinates
vec3d n0 = Q*N;
// calculate the tangent
c += m_pFmat->FiberTangent(mp, fp.FiberPreStretch(n0))*(R*it->m_weight);
fp.m_index++;
}
while (it->Next());
}
// don't forget to delete the iterator
delete it;
// divide by IFD
return c / IFD;
}
//-----------------------------------------------------------------------------
//! calculate strain energy density at material point
//double FEContinuousFiberDistribution::StrainEnergyDensity(FEMaterialPoint& pt) { return m_pFint->StrainEnergyDensity(pt); }
double FEContinuousFiberDistribution::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
FEFiberMaterialPoint& fp = *mp.ExtractData<FEFiberMaterialPoint>();
// get the local coordinate system
mat3d Q = GetLocalCS(mp);
double IFD = IntegratedFiberDensity(mp);
fp.m_index = 0;
double sed = 0.0;
FEFiberIntegrationSchemeIterator* it = m_pFint->GetIterator(&mp);
if (it->IsValid())
{
do
{
// get the fiber direction for that fiber distribution
vec3d& N = it->m_fiber;
// evaluate ellipsoidally distributed material coefficients
double R = m_pFDD->FiberDensity(mp, N);
// convert fiber to global coordinates
vec3d n0 = Q*N;
// calculate the stress
sed += m_pFmat->FiberStrainEnergyDensity(mp, fp.FiberPreStretch(n0))*(R*it->m_weight);
fp.m_index++;
}
while (it->Next());
}
// don't forget to delete the iterator
delete it;
// divide by IFD
return sed / IFD;
}
//-----------------------------------------------------------------------------
double FEContinuousFiberDistribution::IntegratedFiberDensity(FEMaterialPoint& mp)
{
double IFD = 0;
// NOTE: Pass nullptr to GetIterator to avoid issues with GK rule!
FEFiberIntegrationSchemeIterator* it = m_pFint->GetIterator(nullptr);
if (it->IsValid())
{
do
{
// get the fiber direction for that fiber distribution
vec3d& N = it->m_fiber;
double R = m_pFDD->FiberDensity(mp, N);
// integrate the fiber distribution
IFD += R * it->m_weight;
} while (it->Next());
}
// don't forget to delete the iterator
delete it;
// just in case
if (IFD == 0.0) IFD = 1.0;
return IFD;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEHolzapfelUnconstrained.h | .h | 2,248 | 57 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElasticMaterial.h"
#include <FECore/FEModelParam.h>
class FEHolzapfelUnconstrained: public FEElasticMaterial
{
public:
FEParamDouble m_c; // neo-Hookean c coefficient
FEParamDouble m_k1,m_k2; // fiber material constants
FEParamDouble m_kappa; // structure coefficient
FEParamDouble m_gdeg; // fiber angle in degrees
FEParamDouble m_k; // buklk modulus
public:
FEHolzapfelUnconstrained(FEModel* pfem) : FEElasticMaterial(pfem) {}
//! calculate deviatoric stress at material point
mat3ds Stress(FEMaterialPoint& pt) override;
//! calculate deviatoric tangent stiffness at material point
tens4ds Tangent(FEMaterialPoint& pt) override;
//! calculate deviatoric strain energy density at material point
double StrainEnergyDensity(FEMaterialPoint& pt) override;
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEBioMechPlot.h | .h | 59,850 | 1,684 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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/FEPlotData.h>
#include <FECore/FEElement.h>
#include <FECore/units.h>
//=============================================================================
// N O D E D A T A
//=============================================================================
//-----------------------------------------------------------------------------
//! Nodal displacements
//!
class FEPlotNodeDisplacement : public FEPlotNodeData
{
public:
FEPlotNodeDisplacement(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_LENGTH); }
bool Save(FEMesh& m, FEDataStream& a);
};
//! Nodal rotations
class FEPlotNodeRotation : public FEPlotNodeData
{
public:
FEPlotNodeRotation(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_RADIAN); }
bool Save(FEMesh& m, FEDataStream& a);
};
//! Nodal shell displacements
class FEPlotNodeShellDisplacement : public FEPlotNodeData
{
public:
FEPlotNodeShellDisplacement(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_LENGTH); }
bool Save(FEMesh& m, FEDataStream& a);
};
//! Nodal incremental displacement
class FEPlotNodeIncrementalDisplacement : public FEPlotNodeData
{
public:
FEPlotNodeIncrementalDisplacement(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_LENGTH); }
bool Save(FEMesh& m, FEDataStream& a);
private:
std::vector<vec3d> m_rp;
};
//-----------------------------------------------------------------------------
//! Shell directors
class FEPlotNodalShellDirector : public FEPlotNodeData
{
public:
FEPlotNodalShellDirector(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_LENGTH); }
bool Save(FEMesh& m, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal velocities
//!
class FEPlotNodeVelocity : public FEPlotNodeData
{
public:
FEPlotNodeVelocity(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_VELOCITY); }
bool Save(FEMesh& m, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal accelerations
//!
class FEPlotNodeAcceleration : public FEPlotNodeData
{
public:
FEPlotNodeAcceleration(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_ACCELERATION); }
bool Save(FEMesh& m, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal reaction forces
class FEPlotNodeReactionForces : public FEPlotNodeData
{
public:
FEPlotNodeReactionForces(FEModel* pfem) : FEPlotNodeData(pfem, PLT_VEC3F, FMT_NODE) { SetUnits(UNIT_FORCE); }
bool Save(FEMesh& m, FEDataStream& a);
};
//=============================================================================
// S U R F A C E D A T A
//=============================================================================
//-----------------------------------------------------------------------------
//! Contact gap
//!
class FEPlotContactGap : public FEPlotSurfaceData
{
public:
FEPlotContactGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_LENGTH); }
bool SetFilter(const char* sz) override;
bool Save(FESurface& surf, FEDataStream& a) override;
private:
std::string m_interfaceName;
};
//-----------------------------------------------------------------------------
//! Vector gap
//!
class FEPlotVectorGap : public FEPlotSurfaceData
{
public:
FEPlotVectorGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_LENGTH); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Contact pressure
//!
class FEPlotContactPressure : public FEPlotSurfaceData
{
public:
FEPlotContactPressure(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool SetFilter(const char* sz) override;
bool Save(FESurface& surf, FEDataStream& a) override;
private:
std::string m_interfaceName;
};
//-----------------------------------------------------------------------------
//! Contact traction
//!
class FEPlotContactTraction : public FEPlotSurfaceData
{
public:
FEPlotContactTraction(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool SetFilter(const char* sz) override;
bool Save(FESurface& surf, FEDataStream& a) override;
private:
std::string m_interfaceName;
};
//-----------------------------------------------------------------------------
//! Nodal contact gap
//!
class FEPlotNodalContactGap : public FEPlotSurfaceData
{
public:
FEPlotNodalContactGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_MULT){ SetUnits(UNIT_LENGTH); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal vector gap
//!
class FEPlotNodalVectorGap : public FEPlotSurfaceData
{
public:
FEPlotNodalVectorGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_MULT){ SetUnits(UNIT_LENGTH); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal contact pressure
//!
class FEPlotNodalContactPressure : public FEPlotSurfaceData
{
public:
FEPlotNodalContactPressure(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal contact traction
//!
class FEPlotNodalContactTraction : public FEPlotSurfaceData
{
public:
FEPlotNodalContactTraction(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Surface traction
//!
class FEPlotSurfaceTraction : public FEPlotSurfaceData
{
public:
FEPlotSurfaceTraction(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Nodal surface traction
//!
class FEPlotNodalSurfaceTraction : public FEPlotSurfaceData
{
public:
FEPlotNodalSurfaceTraction(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Stick status
//!
class FEPlotStickStatus : public FEPlotSurfaceData
{
public:
FEPlotStickStatus(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Contact force
//!
class FEPlotContactForce : public FEPlotSurfaceData
{
public:
FEPlotContactForce(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_REGION){ SetUnits(UNIT_FORCE); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Contact area
//!
class FEPlotContactArea : public FEPlotSurfaceData
{
public:
FEPlotContactArea(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION){ SetUnits(UNIT_AREA); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Contact penalty parameter
class FEPlotContactPenalty : public FEPlotSurfaceData
{
public:
FEPlotContactPenalty(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Contact status
class FEPlotContactStatus : public FEPlotSurfaceData
{
public:
FEPlotContactStatus(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Mortar gap
class FEPlotMortarContactGap : public FEPlotSurfaceData
{
public:
FEPlotMortarContactGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_NODE){ SetUnits(UNIT_LENGTH); }
bool Save(FESurface& S, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Enclosed volume
//!
class FEPlotEnclosedVolume : public FEPlotSurfaceData
{
private:
bool m_binit;
vector<FEElement*> m_elem;
vector<vec3d> m_area;
public:
FEPlotEnclosedVolume(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION){ m_binit = true; SetUnits(UNIT_VOLUME);
}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Enclosed volume change
//!
class FEPlotEnclosedVolumeChange : public FEPlotSurfaceData
{
private:
bool m_binit;
vector<FEElement*> m_elem;
vector<vec3d> m_area;
public:
FEPlotEnclosedVolumeChange(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION){ m_binit = true; SetUnits(UNIT_VOLUME);
}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Surface area
//!
class FEPlotSurfaceArea : public FEPlotSurfaceData
{
private:
FEModel* m_pfem;
bool m_binit;
vector<FEElement*> m_elem;
vector<vec3d> m_area;
public:
FEPlotSurfaceArea(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION){ m_binit = true; SetUnits(UNIT_AREA); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Surface facet area
//!
class FEPlotFacetArea : public FEPlotSurfaceData
{
private:
FEModel* m_pfem;
bool m_binit;
vector<FEElement*> m_elem;
vector<vec3d> m_area;
public:
FEPlotFacetArea(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM) { m_binit = true; SetUnits(UNIT_AREA); }
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Scalar surface load
//!
class FEPlotScalarSurfaceLoad : public FEPlotSurfaceData
{
public:
FEPlotScalarSurfaceLoad(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Total reaction force on surface
class FEPlotNetSurfaceReactionForce : public FEPlotSurfaceData
{
public:
FEPlotNetSurfaceReactionForce(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FESurface& surf, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Total reaction moment on surface
class FEPlotNetSurfaceReactionMoment : public FEPlotSurfaceData
{
public:
FEPlotNetSurfaceReactionMoment(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FESurface& surf, FEDataStream& a);
};
//=============================================================================
// D O M A I N D A T A
//=============================================================================
//-----------------------------------------------------------------------------
//! Velocity
class FEPlotElementVelocity : public FEPlotDomainData
{
public:
FEPlotElementVelocity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_VELOCITY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Acceleration
class FEPlotElementAcceleration : public FEPlotDomainData
{
public:
FEPlotElementAcceleration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_ACCELERATION); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element stresses
class FEPlotElementStress : public FEPlotDomainData
{
public:
FEPlotElementStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element stresses
class FEPlotElementPK2Stress : public FEPlotDomainData
{
public:
FEPlotElementPK2Stress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element stresses
class FEPlotElementPK1Stress : public FEPlotDomainData
{
public:
FEPlotElementPK1Stress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3F, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element stresses for mixture components
class FEPlotElementMixtureStress : public FEPlotDomainData
{
public:
FEPlotElementMixtureStress(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
int m_mat;
};
//-----------------------------------------------------------------------------
//! Element plastic yield stresses
class FEPlotElementPlasticYieldStress : public FEPlotDomainData
{
public:
FEPlotElementPlasticYieldStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element yield stress based on Drucker shear stress criterion
class FEPlotElementDruckerShear : public FEPlotDomainData
{
public:
FEPlotElementDruckerShear(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element yield stress based on Prager-Drucker criterion
class FEPlotElementPragerDruckerStress : public FEPlotDomainData
{
public:
FEPlotElementPragerDruckerStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element yield stress based on Deshpande-Fleck criterion
class FEPlotElementDeshpandeFleckStress : public FEPlotDomainData
{
public:
FEPlotElementDeshpandeFleckStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element uncoupled pressure
class FEPlotElementUncoupledPressure : public FEPlotDomainData
{
public:
FEPlotElementUncoupledPressure(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element norm for Cauchy stress
class FEPlotElementsnorm : public FEPlotDomainData
{
public:
FEPlotElementsnorm(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy density
class FEPlotStrainEnergyDensity : public FEPlotDomainData
{
public:
FEPlotStrainEnergyDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Deviatoric strain energy density
class FEPlotDevStrainEnergyDensity : public FEPlotDomainData
{
public:
FEPlotDevStrainEnergyDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Specific strain energy
class FEPlotSpecificStrainEnergy : public FEPlotDomainData
{
public:
FEPlotSpecificStrainEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy density in mixture components
class FEPlotMixtureStrainEnergyDensity : public FEPlotDomainData
{
public:
FEPlotMixtureStrainEnergyDensity(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
int m_mat;
};
//-----------------------------------------------------------------------------
//! Deviatoric strain energy density in mixture components
class FEPlotMixtureDevStrainEnergyDensity : public FEPlotDomainData
{
public:
FEPlotMixtureDevStrainEnergyDensity(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
int m_mat;
};
//-----------------------------------------------------------------------------
//! Specific strain energy in mixture components
class FEPlotMixtureSpecificStrainEnergy : public FEPlotDomainData
{
public:
FEPlotMixtureSpecificStrainEnergy(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
int m_mat;
};
//-----------------------------------------------------------------------------
//! Kinetic energy density
class FEPlotKineticEnergyDensity : public FEPlotDomainData
{
public:
FEPlotKineticEnergyDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Mass density
class FEPlotDensity : public FEPlotDomainData
{
public:
FEPlotDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_DENSITY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy
class FEPlotElementStrainEnergy : public FEPlotDomainData
{
public:
FEPlotElementStrainEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Kinetic energy
class FEPlotElementKineticEnergy : public FEPlotDomainData
{
public:
FEPlotElementKineticEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){ SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Center of mass
class FEPlotElementCenterOfMass : public FEPlotDomainData
{
public:
FEPlotElementCenterOfMass(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_LENGTH); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Linear momentum
class FEPlotElementLinearMomentum : public FEPlotDomainData
{
public:
FEPlotElementLinearMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Angular momentum
class FEPlotElementAngularMomentum : public FEPlotDomainData
{
public:
FEPlotElementAngularMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Stress power
class FEPlotElementStressPower : public FEPlotDomainData
{
public:
FEPlotElementStressPower(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy at current time
class FEPlotCurrentElementStrainEnergy : public FEPlotDomainData
{
public:
FEPlotCurrentElementStrainEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Kinetic energy at current time
class FEPlotCurrentElementKineticEnergy : public FEPlotDomainData
{
public:
FEPlotCurrentElementKineticEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Center of mass at current time
class FEPlotCurrentElementCenterOfMass : public FEPlotDomainData
{
public:
FEPlotCurrentElementCenterOfMass(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){ SetUnits(UNIT_LENGTH); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Linear momentum at current time
class FEPlotCurrentElementLinearMomentum : public FEPlotDomainData
{
public:
FEPlotCurrentElementLinearMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Angular momentum at current time
class FEPlotCurrentElementAngularMomentum : public FEPlotDomainData
{
public:
FEPlotCurrentElementAngularMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Relative volume
class FEPlotRelativeVolume : public FEPlotDomainData
{
public:
FEPlotRelativeVolume(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotSPRRelativeVolume : public FEPlotDomainData
{
public:
FEPlotSPRRelativeVolume(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_NODE) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
// NOTE: Deprecated, but maintained for backward compatibility
class FEPlotShellRelativeVolume : public FEPlotDomainData
{
public:
FEPlotShellRelativeVolume(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Material fibers
class FEPlotFiberVector : public FEPlotDomainData
{
public:
FEPlotFiberVector(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
private:
std::string m_matComp;
};
//-----------------------------------------------------------------------------
//! Material axes
class FEPlotMaterialAxes : public FEPlotDomainData
{
public:
FEPlotMaterialAxes(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3F, FMT_ITEM){}
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
private:
std::string m_matComp;
};
//-----------------------------------------------------------------------------
//! fiber stretch
class FEPlotFiberStretch : public FEPlotDomainData
{
public:
FEPlotFiberStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
private:
std::string m_matComp;
};
//-----------------------------------------------------------------------------
//! deviatoric fiber stretch
class FEPlotDevFiberStretch : public FEPlotDomainData
{
public:
FEPlotDevFiberStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
private:
std::string m_matComp;
};
//-----------------------------------------------------------------------------
//! Shell thicknesses
class FEPlotShellThickness : public FEPlotDomainData
{
public:
FEPlotShellThickness(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_MULT){ SetUnits(UNIT_LENGTH); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Shell directors
class FEPlotShellDirector : public FEPlotDomainData
{
public:
FEPlotShellDirector(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_MULT){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element elasticity tensor
class FEPlotElementElasticity : public FEPlotDomainData
{
public:
FEPlotElementElasticity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_TENS4FS, FMT_ITEM) { SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Element elasticity tensor
class FEPlotElementDevElasticity : public FEPlotDomainData
{
public:
FEPlotElementDevElasticity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_TENS4FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Damage reduction factor
class FEPlotDamage : public FEPlotDomainData
{
public:
FEPlotDamage(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Intact bond fraction (fatigue)
class FEPlotIntactBondFraction : public FEPlotDomainData
{
public:
FEPlotIntactBondFraction(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Fatigue bond fraction (fatigue)
class FEPlotFatigueBondFraction : public FEPlotDomainData
{
public:
FEPlotFatigueBondFraction(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Yielded bond fraction (fatigue)
class FEPlotYieldedBondFraction : public FEPlotDomainData
{
public:
FEPlotYieldedBondFraction(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Octahedral Plastic Strain
class FEPlotOctahedralPlasticStrain : public FEPlotDomainData
{
public:
FEPlotOctahedralPlasticStrain(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Reactive plasticity heat supply
class FEPlotReactivePlasticityHeatSupply : public FEPlotDomainData
{
public:
FEPlotReactivePlasticityHeatSupply(FEModel* pfem);
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& m, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Mixture volume fraction
class FEPlotMixtureVolumeFraction : public FEPlotDomainData
{
public:
FEPlotMixtureVolumeFraction(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& m, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the element nodal stresses for UT4 domains
class FEPlotUT4NodalStresses : public FEPlotDomainData
{
public:
FEPlotUT4NodalStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_NODE) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! class the projects stresses from integration points to nodes using
//! SPR (superconvergergent patch recovery)
class FEPlotSPRStresses : public FEPlotDomainData
{
public:
FEPlotSPRStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_NODE){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! class the projects stresses from integration points to nodes using
//! SPR (superconvergergent patch recovery)
class FEPlotSPRLinearStresses : public FEPlotDomainData
{
public:
FEPlotSPRLinearStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_NODE){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! class that projects the principal stresses from integration points to nodes
//! using the SPR projection method
class FEPlotSPRPrincStresses : public FEPlotDomainData
{
public:
FEPlotSPRPrincStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FD, FMT_NODE){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body displacement
class FEPlotRigidDisplacement : public FEPlotDomainData
{
public:
FEPlotRigidDisplacement(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_LENGTH); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body velocity
class FEPlotRigidVelocity : public FEPlotDomainData
{
public:
FEPlotRigidVelocity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_VELOCITY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body acceleration
class FEPlotRigidAcceleration : public FEPlotDomainData
{
public:
FEPlotRigidAcceleration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_ACCELERATION); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body rotation
class FEPlotRigidRotation : public FEPlotDomainData
{
public:
FEPlotRigidRotation(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body angular velocity
class FEPlotRigidAngularVelocity : public FEPlotDomainData
{
public:
FEPlotRigidAngularVelocity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body angular acceleration
class FEPlotRigidAngularAcceleration : public FEPlotDomainData
{
public:
FEPlotRigidAngularAcceleration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body kinetic energy
class FEPlotRigidKineticEnergy : public FEPlotDomainData
{
public:
FEPlotRigidKineticEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_REGION) { SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body linear momentum
class FEPlotRigidLinearMomentum : public FEPlotDomainData
{
public:
FEPlotRigidLinearMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body angular momentum
class FEPlotRigidAngularMomentum : public FEPlotDomainData
{
public:
FEPlotRigidAngularMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid Euler angles
class FEPlotRigidEuler : public FEPlotDomainData
{
public:
FEPlotRigidEuler(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_RADIAN); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rotation vector
class FEPlotRigidRotationVector : public FEPlotDomainData
{
public:
FEPlotRigidRotationVector(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the nodes
//! TODO: This only works with tet10 and hex8 -domains
class FEPlotNodalStresses : public FEPlotDomainData
{
public:
FEPlotNodalStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the nodes
class FEPlotShellTopStress : public FEPlotDomainData
{
public:
FEPlotShellTopStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the bottom shell nodes
class FEPlotShellBottomStress : public FEPlotDomainData
{
public:
FEPlotShellBottomStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the nodes
class FEPlotShellTopNodalStresses : public FEPlotDomainData
{
public:
FEPlotShellTopNodalStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the bottom shell nodes
class FEPlotShellBottomNodalStresses : public FEPlotDomainData
{
public:
FEPlotShellBottomNodalStresses(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_PRESSURE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects Lagrange strains from integration points to the nodes
class FEPlotNodalStrains : public FEPlotDomainData
{
public:
FEPlotNodalStrains(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_NONE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the nodes
class FEPlotShellTopStrain : public FEPlotDomainData
{
public:
FEPlotShellTopStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){ SetUnits(UNIT_NONE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects stresses from integration points to the bottom shell nodes
class FEPlotShellBottomStrain : public FEPlotDomainData
{
public:
FEPlotShellBottomStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){ SetUnits(UNIT_NONE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects Lagrange strains from integration points to the shell nodes
class FEPlotShellTopNodalStrains : public FEPlotDomainData
{
public:
FEPlotShellTopNodalStrains(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_NONE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that projects Lagrange strains from integration points to the shell nodes
class FEPlotShellBottomNodalStrains : public FEPlotDomainData
{
public:
FEPlotShellBottomNodalStrains(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_MULT){ SetUnits(UNIT_NONE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Deformation gradient
class FEPlotDeformationGradient : public FEPlotDomainData
{
public:
FEPlotDeformationGradient(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Lagrange strains
class FEPlotLagrangeStrain : public FEPlotDomainData
{
public:
FEPlotLagrangeStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//! NOTE: Deprecated, but maintained for backward compatibility
class FEPlotShellStrain : public FEPlotDomainData
{
public:
FEPlotShellStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Almansi strain
class FEPlotAlmansiStrain : public FEPlotDomainData
{
public:
FEPlotAlmansiStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
// Infinitesimal strain
class FEPlotInfStrain : public FEPlotDomainData
{
public:
FEPlotInfStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Lagrange strains
class FEPlotSPRLagrangeStrain : public FEPlotDomainData
{
public:
FEPlotSPRLagrangeStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_NODE){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//! SPR infinitesimal strains
class FEPlotSPRInfStrain : public FEPlotDomainData
{
public:
FEPlotSPRInfStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_NODE) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Right Cauchy-Green tensor
class FEPlotRightCauchyGreen : public FEPlotDomainData
{
public:
FEPlotRightCauchyGreen(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Left Cauchy-Green tensor
class FEPlotLeftCauchyGreen : public FEPlotDomainData
{
public:
FEPlotLeftCauchyGreen(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Right stretch
class FEPlotRightStretch : public FEPlotDomainData
{
public:
FEPlotRightStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Left stretch
class FEPlotLeftStretch : public FEPlotDomainData
{
public:
FEPlotLeftStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Right Hencky
class FEPlotRightHencky : public FEPlotDomainData
{
public:
FEPlotRightHencky(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Left Hencky
class FEPlotLeftHencky : public FEPlotDomainData
{
public:
FEPlotLeftHencky(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rate of deformation
class FEPlotRateOfDeformation : public FEPlotDomainData
{
public:
FEPlotRateOfDeformation(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body reaction force
class FEPlotRigidReactionForce : public FEPlotDomainData
{
public:
FEPlotRigidReactionForce(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_FORCE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Rigid body reaction torque
class FEPlotRigidReactionTorque : public FEPlotDomainData
{
public:
FEPlotRigidReactionTorque(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotStressError : public FEPlotDomainData
{
public:
FEPlotStressError(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the in-situ fiber stretch
class FEPlotFiberTargetStretch : public FEPlotDomainData
{
public:
FEPlotFiberTargetStretch(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the fiber stretch
class FEPlotPreStrainStretch : public FEPlotDomainData
{
public:
FEPlotPreStrainStretch(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the error in the fiber stretch
class FEPlotPreStrainStretchError : public FEPlotDomainData
{
public:
FEPlotPreStrainStretchError(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the pre-strain correction deformation gradient
class FEPlotPreStrainCorrection : public FEPlotDomainData
{
public:
FEPlotPreStrainCorrection(FEModel* fem) : FEPlotDomainData(fem, PLT_MAT3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Class that outputs the pre-strain correction deformation gradient
class FEPlotSPRPreStrainCorrection : public FEPlotDomainData
{
public:
FEPlotSPRPreStrainCorrection(FEModel* fem) : FEPlotDomainData(fem, PLT_MAT3F, FMT_NODE) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotPreStrainCompatibility : public FEPlotDomainData
{
public:
FEPlotPreStrainCompatibility(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementStretch : public FEPlotDomainData
{
public:
FEPlotDiscreteElementStretch(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementElongation : public FEPlotDomainData
{
public:
FEPlotDiscreteElementElongation(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementPercentElongation : public FEPlotDomainData
{
public:
FEPlotDiscreteElementPercentElongation(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotDiscreteElementDirection : public FEPlotDomainData
{
public:
FEPlotDiscreteElementDirection(FEModel* fem) : FEPlotDomainData(fem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotDiscreteElementLength : public FEPlotDomainData
{
public:
FEPlotDiscreteElementLength(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementForce : public FEPlotDomainData
{
public:
FEPlotDiscreteElementForce(FEModel* fem) : FEPlotDomainData(fem, PLT_VEC3F, FMT_ITEM) { SetUnits(UNIT_FORCE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementSignedForce : public FEPlotDomainData
{
public:
FEPlotDiscreteElementSignedForce(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotDiscreteElementStrainEnergy : public FEPlotDomainData
{
public:
FEPlotDiscreteElementStrainEnergy(FEModel* fem) : FEPlotDomainData(fem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
class FEPlotContinuousDamage_ : public FEPlotDomainData
{
public:
FEPlotContinuousDamage_(FEModel* fem, int n);
bool Save(FEDomain& dom, FEDataStream& a) override;
bool SetFilter(const char* sz) override;
private:
std::string m_prop;
int m_propIndex;
int m_comp;
};
class FEPlotContinuousDamage_D : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_D(FEModel* fem) : FEPlotContinuousDamage_(fem, 0) {}
};
class FEPlotContinuousDamage_D1 : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_D1(FEModel* fem) : FEPlotContinuousDamage_(fem, 1) {}
};
class FEPlotContinuousDamage_Ds : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_Ds(FEModel* fem) : FEPlotContinuousDamage_(fem, 2) {}
};
class FEPlotContinuousDamage_D2 : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_D2(FEModel* fem) : FEPlotContinuousDamage_(fem, 3) {}
};
class FEPlotContinuousDamage_D3 : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_D3(FEModel* fem) : FEPlotContinuousDamage_(fem, 4) {}
};
class FEPlotContinuousDamage_P : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_P(FEModel* fem) : FEPlotContinuousDamage_(fem, 5) {}
};
class FEPlotContinuousDamage_Psi0 : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_Psi0(FEModel* fem) : FEPlotContinuousDamage_(fem, 6) {}
};
class FEPlotContinuousDamage_beta : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_beta(FEModel* fem) : FEPlotContinuousDamage_(fem, 7) {}
};
class FEPlotContinuousDamage_gamma : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_gamma(FEModel* fem) : FEPlotContinuousDamage_(fem, 8) {}
};
class FEPlotContinuousDamage_D2beta : public FEPlotContinuousDamage_ {
public: FEPlotContinuousDamage_D2beta(FEModel* fem) : FEPlotContinuousDamage_(fem, 9) {}
};
//-----------------------------------------------------------------------------
//! Number of generations in reactive viscoelastic material point
class FEPlotRVEgenerations : public FEPlotDomainData
{
public:
FEPlotRVEgenerations(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { m_comp = -1; }
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Reforming bond mass fraction in reactive viscoelastic material point
class FEPlotRVEbonds : public FEPlotDomainData
{
public:
FEPlotRVEbonds(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { m_comp = -1; }
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Weak bond recruitment ratio in reactive viscoelastic material point
class FEPlotRVErecruitment : public FEPlotDomainData
{
public:
FEPlotRVErecruitment(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { m_comp = -1; }
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Reactive viscoelastic strain measure for bond-breaking trigger and bond recruitment
class FEPlotRVEstrain : public FEPlotDomainData
{
public:
FEPlotRVEstrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { m_comp = -1; }
bool SetFilter(const char* szfilter) override;
bool Save(FEDomain& dom, FEDataStream& a) override;
protected:
int m_comp;
};
//-----------------------------------------------------------------------------
//! Strain energy density of strong bonds in reactive viscoelastic material point
class FEPlotStrongBondSED : public FEPlotDomainData
{
public:
FEPlotStrongBondSED(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy density of weak bonds in reactive viscoelastic material point
class FEPlotWeakBondSED : public FEPlotDomainData
{
public:
FEPlotWeakBondSED(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy density of strong bonds in reactive viscoelastic material point
class FEPlotStrongBondDevSED : public FEPlotDomainData
{
public:
FEPlotStrongBondDevSED(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Strain energy density of weak bonds in reactive viscoelastic material point
class FEPlotWeakBondDevSED : public FEPlotDomainData
{
public:
FEPlotWeakBondDevSED(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! truss element stretch
class FEPlotTrussStretch : public FEPlotDomainData
{
public:
FEPlotTrussStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth deformation gradient (Kinematic Growth)
class FEPlotGrowthDeformationGradient : public FEPlotDomainData
{
public:
FEPlotGrowthDeformationGradient(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth Lagrange strains
class FEPlotGrowthLagrangeStrain : public FEPlotDomainData
{
public:
FEPlotGrowthLagrangeStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
// Growth infinitesimal strain
class FEPlotGrowthInfStrain : public FEPlotDomainData
{
public:
FEPlotGrowthInfStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth right stretch
class FEPlotGrowthRightStretch : public FEPlotDomainData
{
public:
FEPlotGrowthRightStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth left stretch
class FEPlotGrowthLeftStretch : public FEPlotDomainData
{
public:
FEPlotGrowthLeftStretch(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth right Hencky
class FEPlotGrowthRightHencky : public FEPlotDomainData
{
public:
FEPlotGrowthRightHencky(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth left Hencky
class FEPlotGrowthLeftHencky : public FEPlotDomainData
{
public:
FEPlotGrowthLeftHencky(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! Growth relative volume
class FEPlotGrowthRelativeVolume : public FEPlotDomainData
{
public:
FEPlotGrowthRelativeVolume(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element stress
class FEPlotBeamStress : public FEPlotDomainData
{
public:
FEPlotBeamStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element stress in reference frame
class FEPlotBeamReferenceStress : public FEPlotDomainData
{
public:
FEPlotBeamReferenceStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element stress couple
class FEPlotBeamStressCouple : public FEPlotDomainData
{
public:
FEPlotBeamStressCouple(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element stress couple in reference frame
class FEPlotBeamReferenceStressCouple : public FEPlotDomainData
{
public:
FEPlotBeamReferenceStressCouple(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element strain
class FEPlotBeamStrain : public FEPlotDomainData
{
public:
FEPlotBeamStrain(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
//-----------------------------------------------------------------------------
//! beam element curvature
class FEPlotBeamCurvature : public FEPlotDomainData
{
public:
FEPlotBeamCurvature(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) {}
bool Save(FEDomain& dom, FEDataStream& a);
};
// plot the current pressure value of the FEIdealGasPressure load
class FEIdealGasPressure;
class FEPlotIdealGasPressure : public FEPlotSurfaceData
{
public:
FEPlotIdealGasPressure(FEModel* fem) : FEPlotSurfaceData(fem, PLT_FLOAT, FMT_REGION) {}
bool Save(FESurface& surf, FEDataStream& a) override;
private:
bool Init() override;
bool m_binit = false;
FEIdealGasPressure* m_load = nullptr;
};
class FEPlotBodyForce : public FEPlotDomainData
{
public:
FEPlotBodyForce(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) { SetUnits(UNIT_SPECIFIC_FORCE); }
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotTotalLinearMomentum : public FEPlotDomainData
{
public:
FEPlotTotalLinearMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotTotalAngularMomentum : public FEPlotDomainData
{
public:
FEPlotTotalAngularMomentum(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
class FEPlotTotalEnergy : public FEPlotDomainData
{
public:
FEPlotTotalEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_REGION) { SetUnits(UNIT_ENERGY); }
bool Save(FEDomain& dom, FEDataStream& a);
};
//=============================================================================
// E D G E D A T A
//=============================================================================
class FEPlotEdgeContactGap : public FEPlotEdgeData
{
public:
FEPlotEdgeContactGap(FEModel* fem) : FEPlotEdgeData(fem, PLT_FLOAT, FMT_NODE) { SetUnits(UNIT_LENGTH); }
bool Save(FEEdge& edge, FEDataStream& a);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FERigidDamper.h | .h | 3,197 | 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 "FECore/vec3d.h"
#include "FERigidConnector.h"
//-----------------------------------------------------------------------------
//! The FERigidDamper class implements a linear damper that connects
//! two rigid bodies at arbitrary points (not necessarily nodes).
//! TODO: This inherits from FENLConstraint, which is not the appropriate base class
class FERigidDamper : public FERigidConnector
{
public:
//! constructor
FERigidDamper(FEModel* pfem);
//! destructor
~FERigidDamper() {}
//! initialization
bool Init() override;
//! calculates the joint forces
void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override;
//! calculates the joint stiffness
void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override;
//! calculate Lagrangian augmentation
bool Augment(int naug, const FETimeInfo& tp) override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! update state
void Update() override;
//! Reset data
void Reset() override;
//! evaluate relative translation
vec3d RelativeTranslation(const bool global) override;
//! evaluate relative rotation
vec3d RelativeRotation(const bool global) override;
public: // parameters
double m_c; //! damping constant
vec3d m_a0; //! initial absolute position vector of spring on body A
vec3d m_b0; //! initial absolute position vector of spring on body B
// output parameters
vec3d m_at; //!< current absolute position of spring on body A
vec3d m_bt; //!< current absolute position of spring on body B
protected:
vec3d m_qa0; //! initial relative position vector of spring on body A
vec3d m_qb0; //! initial relative position vector of spring on body B
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEBCPrescribedDeformation.h | .h | 2,479 | 82 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedBC.h>
#include <FECore/tens3d.h>
#include "febiomech_api.h"
//-----------------------------------------------------------------------------
class FEBIOMECH_API FEBCPrescribedDeformation : public FEPrescribedNodeSet
{
public:
FEBCPrescribedDeformation(FEModel* pfem);
void SetDeformationGradient(const mat3d& F);
void CopyFrom(FEBoundaryCondition* pbc) override;
protected:
void GetNodalValues(int nodelid, std::vector<double>& val) override;
protected:
double m_scale;
mat3d m_F;
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FEBIOMECH_API FEBCPrescribedDeformation2O : public FEPrescribedNodeSet
{
public:
FEBCPrescribedDeformation2O(FEModel* pfem);
void SetScale(double s, int lc = -1);
void SetReferenceNode(int n);
bool Init() override;
void SetDeformationGradient(const mat3d& F);
void SetDeformationHessian(const tens3drs& G);
void CopyFrom(FEBoundaryCondition* pbc) override;
protected:
void GetNodalValues(int nodelist, std::vector<double>& val) override;
protected:
double m_scale;
mat3d m_F;
tens3drs m_G;
int m_refNode;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEFiberExpPowUncoupled.h | .h | 2,498 | 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 "FEElasticFiberMaterialUC.h"
#include "FEFiberMaterial.h"
class FEUncoupledFiberExpPow;
//-----------------------------------------------------------------------------
//! Material class for single fiber, tension only
//! Exponential-power law
class FEFiberExpPowUC : public FEFiberMaterialUncoupled
{
public:
FEFiberExpPowUC(FEModel* pfem);
//! Cauchy stress
virtual mat3ds DevFiberStress(FEMaterialPoint& mp, const vec3d& a0) override;
// Spatial tangent
virtual tens4ds DevFiberTangent(FEMaterialPoint& mp, const vec3d& a0) override;
//! Strain energy density
virtual double DevFiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& a0) override;
protected:
double m_alpha; // coefficient of (In-1) in exponential
double m_beta; // power of (In-1) in exponential
FEParamDouble m_ksi; // fiber modulus
double m_mu; // shear modulus
// declare the parameter list
DECLARE_FECORE_CLASS();
friend class FEUncoupledFiberExpPow;
};
class FEUncoupledFiberExpPow : public FEElasticFiberMaterialUC_T<FEFiberExpPowUC>
{
public:
FEUncoupledFiberExpPow(FEModel* fem) : FEElasticFiberMaterialUC_T<FEFiberExpPowUC>(fem) {}
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEElasticEASShellDomain.h | .h | 6,549 | 172 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FESSIShellDomain.h"
#include "FEElasticDomain.h"
#include "FESolidMaterial.h"
//-----------------------------------------------------------------------------
//! Domain described by 3D shell elements
class FEBIOMECH_API FEElasticEASShellDomain : public FESSIShellDomain, public FEElasticDomain
{
public:
FEElasticEASShellDomain(FEModel* pfem);
//! \todo do I really need this?
FEElasticEASShellDomain& operator = (FEElasticEASShellDomain& d);
//! Initialize domain
bool Init() override;
//! Activate the domain
void Activate() override;
//! Unpack shell element data
void UnpackLM(FEElement& el, vector<int>& lm) override;
//! Set flag for update for dynamic quantities
void SetDynamicUpdateFlag(bool b);
//! serialization
void Serialize(DumpStream& ar) override;
//! get the material (overridden from FEDomain)
FEMaterial* GetMaterial() override { return m_pMat; }
//! set the material
void SetMaterial(FEMaterial* pmat) override;
// get the total dof list
const FEDofList& GetDOFList() const override;
public: // overrides from FEElasticDomain
//! calculates the residual
// void Residual(FESolver* psolver, vector<double>& R);
//! internal stress forces
void InternalForces(FEGlobalVector& R) override;
//! Calculates inertial forces for dynamic problems
void InertialForces(FEGlobalVector& R, vector<double>& F) override;
//! calculate body force
void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override;
// update stresses
void Update(const FETimeInfo& tp) override;
// update the element stress
void UpdateElementStress(int iel, const FETimeInfo& tp);
//! initialize elements for this domain
void PreSolveUpdate(const FETimeInfo& timeInfo) override;
//! calculates the global stiffness matrix for this domain
void StiffnessMatrix(FELinearSystem& LS) override;
// inertial stiffness
void MassMatrix(FELinearSystem& LS, double scale) override;
// body force stiffness
void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override;
// evaluate strain E and matrix hu and hw
void EvaluateEh(FEShellElementNew& el, const int n, const vec3d* Gcnt, mat3ds& E, vector<matrix>& hu, vector<matrix>& hw, vector<vec3d>& Nu, vector<vec3d>& Nw);
public:
// --- S T I F F N E S S ---
//! calculates the shell element stiffness matrix
void ElementStiffness(int iel, matrix& ke);
// --- R E S I D U A L ---
//! Calculates the internal stress vector for shell elements
void ElementInternalForce(FEShellElementNew& el, vector<double>& fe);
//! Calculate extenral body forces for shell elements
void ElementBodyForce(FEModel& fem, FEShellElementNew& el, vector<double>& fe);
//! Calculate extenral body forces for shell elements
void ElementBodyForce(FEBodyForce& BF, FEShellElementNew& el, vector<double>& fe);
//! Calculates the inertial force for shell elements
void ElementInertialForce(FEShellElementNew& el, vector<double>& fe);
//! calculates the solid element mass matrix
void ElementMassMatrix(FEShellElementNew& el, matrix& ke, double a);
//! calculates the stiffness matrix due to body forces
void ElementBodyForceStiffness(FEBodyForce& bf, FEShellElementNew& el, matrix& ke);
public:
// --- E A S M E T H O D ---
// Generate the G matrix for the EAS method
void GenerateGMatrix(FEShellElementNew& el, const int n, const double Jeta, matrix& G);
// Evaluate contravariant components of mat3ds tensor
void mat3dsCntMat61(const mat3ds s, const vec3d* Gcnt, matrix& S);
// Evaluate contravariant components of tens4ds tensor
void tens4dsCntMat66(const tens4ds c, const vec3d* Gcnt, matrix& C);
void tens4dmmCntMat66(const tens4dmm c, const vec3d* Gcnt, matrix& C);
// Evaluate the matrices and vectors relevant to the EAS method
void EvaluateEAS(FEShellElementNew& el, vector<double>& E, vector< vector<vec3d>>& HU, vector< vector<vec3d>>& HW, vector<mat3ds>& S, vector<tens4dmm>& c);
// Evaluate the strain using the ANS method
void CollocationStrainsANS(FEShellElementNew& el, vector<double>& E, vector< vector<vec3d>>& HU, vector< vector<vec3d>>& HW, matrix& NS, matrix& NN);
void EvaluateANS(FEShellElementNew& el, const int n, const vec3d* Gcnt, mat3ds& Ec, vector<matrix>& hu, vector<matrix>& hw, vector<double>& E, vector< vector<vec3d>>& HU, vector< vector<vec3d>>& HW);
// Update alpha in EAS method
void UpdateEAS(vector<double>& ui) override;
void UpdateIncrementsEAS(vector<double>& ui, const bool binc) override;
protected:
FESolidMaterial* m_pMat;
int m_nEAS;
bool m_update_dynamic; //!< flag for updating quantities only used in dynamic analysis
bool m_secant_stress; //!< use secant approximation to stress
bool m_secant_tangent; //!< flag for using secant tangent
FEDofList m_dofV;
FEDofList m_dofSV;
FEDofList m_dofSA;
FEDofList m_dofR;
FEDofList m_dof;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEElasticFiberMaterialUC.cpp | .cpp | 2,772 | 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.*/
#include "stdafx.h"
#include "FEElasticFiberMaterialUC.h"
#include <FECore/FEConstValueVec3.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEElasticFiberMaterialUC, FEUncoupledMaterial)
// NOTE: We need to make this optional since it should not
// be defined when used in a CFD material.
ADD_PROPERTY(m_fiber, "fiber")->SetFlags(FEProperty::Optional);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEElasticFiberMaterialUC::FEElasticFiberMaterialUC(FEModel* pfem) : FEUncoupledMaterial(pfem)
{
m_fiber = nullptr;
m_Us = mat3dd(1);
m_bUs = false;
}
// Get the fiber direction (in global coordinates) at a material point
vec3d FEElasticFiberMaterialUC::FiberVector(FEMaterialPoint& mp)
{
// get the material coordinate system
mat3d Q = GetLocalCS(mp);
// get the fiber vector in local coordinates
vec3d fiber = m_fiber->unitVector(mp);
// convert to global coordinates
vec3d a0 = Q*fiber;
// account for prior deformation in multigenerational formulation
vec3d a = FiberPreStretch(a0);
return a;
}
//-----------------------------------------------------------------------------
vec3d FEElasticFiberMaterialUC::FiberPreStretch(const vec3d& a0)
{
// account for prior deformation in multigenerational formulation
if (m_bUs) {
vec3d a = (m_Us*a0);
a.unit();
return a;
}
else
return a0;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FESpringRuptureCriterion.h | .h | 1,762 | 48 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMeshAdaptorCriterion.h>
class FESpringForceCriterion : public FEMeshAdaptorCriterion
{
public:
FESpringForceCriterion(FEModel* fem);
bool GetMaterialPointValue(FEMaterialPoint& mp, double& value) override;
DECLARE_FECORE_CLASS()
};
class FESpringStretchCriterion : public FEMeshAdaptorCriterion
{
public:
FESpringStretchCriterion(FEModel* fem);
bool GetMaterialPointValue(FEMaterialPoint& mp, double& value) override;
DECLARE_FECORE_CLASS()
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FENewtonianViscousSolid.cpp | .cpp | 3,109 | 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.*/
#include "stdafx.h"
#include "FENewtonianViscousSolid.h"
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FENewtonianViscousSolid, FEElasticMaterial)
ADD_PARAMETER(m_kappa, FE_RANGE_GREATER_OR_EQUAL( 0.0), "kappa")->setUnits("P.t")->setLongName("bulk viscosity");
ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL( 0.0), "mu" )->setUnits("P.t")->setLongName("shear viscosity");
ADD_PARAMETER(m_secant_tangent, "secant_tangent");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FENewtonianViscousSolid::FENewtonianViscousSolid(FEModel* pfem) : FEElasticMaterial(pfem)
{
m_kappa = 0.0;
m_mu = 0.0;
m_secant_tangent = false;
}
//-----------------------------------------------------------------------------
mat3ds FENewtonianViscousSolid::Stress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
mat3ds D = pt.RateOfDeformation();
// Identity
mat3dd I(1);
// calculate stress
mat3ds s = I*(D.tr()*(m_kappa - 2*m_mu/3)) + D*(2*m_mu);
return s;
}
//-----------------------------------------------------------------------------
tens4ds FENewtonianViscousSolid::Tangent(FEMaterialPoint& mp)
{
const FETimeInfo& tp = GetTimeInfo();
tens4ds Cv;
if (tp.timeIncrement > 0) {
mat3dd I(1);
double tmp = tp.alphaf*tp.gamma/(tp.beta*tp.timeIncrement);
Cv = (dyad1s(I)*(m_kappa - 2 * m_mu / 3) + dyad4s(I)*(2 * m_mu))*tmp;
}
else Cv.zero();
return Cv;
}
//-----------------------------------------------------------------------------
double FENewtonianViscousSolid::StrainEnergyDensity(FEMaterialPoint& mp)
{
return 0;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEBearingLoad.h | .h | 3,079 | 83 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include <FECore/FESurfaceMap.h>
//-----------------------------------------------------------------------------
//! The bearing load is a surface domain that sustains a parabolic or sinusoidal pressure boundary
//! condition that simulates the contact pressure in a bearing.
//!
class FEBearingLoad : public FESurfaceLoad
{
public:
enum P_PROFILE {
P_SINE, // sinusoidal pressure distribution
P_PARA // parabolic pressure distribution
};
public:
//! constructor
FEBearingLoad(FEModel* pfem);
//! initialization
bool Init() override;
//! update
void Update() override;
//! evaluate bearing pressure
double ScalarLoad(FESurfaceMaterialPoint& mp) override;
//! serialization
void Serialize(DumpStream& ar) override;
public:
//! calculate residual
void LoadVector(FEGlobalVector& R) override;
//! calculate stiffness
void StiffnessMatrix(FELinearSystem& LS) override;
protected:
double m_scale; //!< scale factor for bearing load
vec3d m_force; //!< bearing load
bool m_bsymm; //!< use symmetric formulation
bool m_blinear; //!< is the load linear (i.e. it will be calculated in the reference frame and assummed deformation independent)
bool m_bshellb; //!< flag for prescribing pressure on shell bottom
int m_profile; //!< profile of pressure distribution
private:
vec3d m_er; //!< unit vector along radial direction of bearing surface
FESurfaceMap* m_pc; //!< pressure value
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEFixedShellDisplacement.cpp | .cpp | 2,016 | 52 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEFixedShellDisplacement.h"
BEGIN_FECORE_CLASS(FEFixedShellDisplacement, FEFixedBC)
ADD_PARAMETER(m_dof_sx, "sx_dof")->setLongName("sx-displacement");
ADD_PARAMETER(m_dof_sy, "sy_dof")->setLongName("sy-displacement");
ADD_PARAMETER(m_dof_sz, "sz_dof")->setLongName("sz-displacement");
END_FECORE_CLASS();
FEFixedShellDisplacement::FEFixedShellDisplacement(FEModel* fem) : FEFixedBC(fem)
{
m_dof_sx = false;
m_dof_sy = false;
m_dof_sz = false;
}
bool FEFixedShellDisplacement::Init()
{
vector<int> dofs;
if (m_dof_sx) dofs.push_back(GetDOFIndex("sx"));
if (m_dof_sy) dofs.push_back(GetDOFIndex("sy"));
if (m_dof_sz) dofs.push_back(GetDOFIndex("sz"));
SetDOFList(dofs);
return FEFixedBC::Init();
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FESolidAnalysis.h | .h | 1,532 | 43 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEAnalysis.h>
#include "febiomech_api.h"
class FEBIOMECH_API FESolidAnalysis : public FEAnalysis
{
public:
enum SolidAnalysisType {
STATIC,
DYNAMIC
};
public:
FESolidAnalysis(FEModel* fem);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FERigidFollowerMoment.h | .h | 1,988 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECore/FEModelLoad.h"
#include "FERigidForce.h"
//-----------------------------------------------------------------------------
//! a follower moment on a rigid body
class FEBIOMECH_API FERigidFollowerMoment : public FERigidLoad
{
public:
//! constructor
FERigidFollowerMoment(FEModel* pfem);
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
//! Residual
void LoadVector(FEGlobalVector& R) override;
//! Stiffness matrix
void StiffnessMatrix(FELinearSystem& LS) override;
public:
int m_rid; //!< rigid body ID
vec3d m_m; //!< moment
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FECarreauYasudaViscousSolid.h | .h | 2,194 | 57 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElasticMaterial.h"
class FECarreauYasudaViscousSolid : public FEElasticMaterial
{
public:
FECarreauYasudaViscousSolid(FEModel* pfem) : FEElasticMaterial(pfem) {}
public:
FEParamDouble m_mu0; //!< shear viscosity at zero shear rate
FEParamDouble m_mui; //!< shear viscosity at infinite shear rate
FEParamDouble m_lam; //!< time constant
FEParamDouble m_n; //!< power-law index
FEParamDouble m_a; //!< exponent
public:
//! calculate stress at material point
virtual mat3ds Stress(FEMaterialPoint& pt) override;
//! calculate tangent stiffness at material point
virtual tens4ds Tangent(FEMaterialPoint& pt) override;
//! calculate strain energy density at material point
virtual double StrainEnergyDensity(FEMaterialPoint& pt) override;
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEElasticBeamMaterial.cpp | .cpp | 3,881 | 139 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEElasticBeamMaterial.h"
FEElasticBeamMaterialPoint::FEElasticBeamMaterialPoint()
{
}
void FEElasticBeamMaterialPoint::Init()
{
}
void FEElasticBeamMaterialPoint::Update(const FETimeInfo& timeInfo)
{
m_Rp = m_Rt;
m_Ri = quatd(0, 0, 0);
m_vp = m_vt;
m_ap = m_at;
m_wp = m_wt;
m_alp = m_alt;
}
//=======================================================================================
BEGIN_FECORE_CLASS(FEElasticBeamMaterial, FEMaterial)
ADD_PARAMETER(m_density, "density")->setUnits(UNIT_DENSITY);
ADD_PARAMETER(m_E , "E" )->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_G , "G" )->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_A , "A" )->setUnits(UNIT_AREA);
ADD_PARAMETER(m_A1, "A1")->setUnits(UNIT_AREA);
ADD_PARAMETER(m_A2, "A2")->setUnits(UNIT_AREA);
ADD_PARAMETER(m_I1, "I1");
ADD_PARAMETER(m_I2, "I2");
END_FECORE_CLASS();
FEElasticBeamMaterial::FEElasticBeamMaterial(FEModel* fem) : FEMaterial(fem)
{
m_density = 1.0;
m_A = m_A1 = m_A2 = 0.0;
m_G = m_E = 0.0;
m_I1 = m_I2 = 0;
AddDomainParameter(new FEBeamStress());
}
void FEElasticBeamMaterial::Stress(FEElasticBeamMaterialPoint& mp)
{
mat3d Q = mp.m_Q;
mat3d Qt = Q.transpose();
vec3d gamma = Qt * mp.m_Gamma;
vec3d kappa = Qt * mp.m_Kappa;
double J = m_I1 + m_I2;
// material vectors
vec3d N = Q*vec3d(m_G * m_A1 * gamma.x, m_G*m_A2*gamma.y, m_E*m_A*gamma.z);
vec3d M = Q*vec3d(m_E * m_I1 * kappa.x, m_E*m_I2*kappa.y, m_G* J*kappa.z);
// spatial vectors
quatd R = mp.m_Rt;
mp.m_t = R * N;
mp.m_m = R * M;
// Cauchy stress
vec3d E1 = Q.col(0);
vec3d E2 = Q.col(1);
vec3d E3 = Q.col(2);
vec3d t1 = R * E1;
vec3d t2 = R * E2;
vec3d t3 = R * E3;
vec3d t = mp.m_t;
mp.m_s = (dyad(t1) * (t * t1) + dyad(t2) * (t * t2) + dyad(t3) * (t * t3));
}
void FEElasticBeamMaterial::Tangent(FEElasticBeamMaterialPoint& mp, matrix& C)
{
mat3d E = mp.m_Q;
mat3d Et = E.transpose();
double J = m_I1 + m_I2;
mat3dd D1(m_G * m_A1, m_G * m_A2, m_E * m_A);
mat3dd D2(m_E * m_I1, m_E * m_I2, m_G * J);
mat3d C1 = E * D1 * Et;
mat3d C2 = E * D2 * Et;
quatd R = mp.m_Rt;
mat3d Q = R.RotationMatrix();
mat3d Qt = Q.transpose();
mat3d c1 = Q * C1 * Qt;
mat3d c2 = Q * C2 * Qt;
C.resize(6, 6);
C.zero();
C.add(0, 0, c1);
C.add(3, 3, c2);
}
FEMaterialPointData* FEElasticBeamMaterial::CreateMaterialPointData()
{
return new FEElasticBeamMaterialPoint();
}
FEBeamStress::FEBeamStress() : FEDomainParameter("stress") {}
FEParamValue FEBeamStress::value(FEMaterialPoint& mp)
{
FEElasticBeamMaterialPoint& pt = *mp.ExtractData<FEElasticBeamMaterialPoint>();
return pt.m_s;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEMuscleMaterial.cpp | .cpp | 12,286 | 474 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMuscleMaterial.h"
#include <FECore/FEConstValueVec3.h>
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
/////////////////////////////////////////////////////////////////////////
// FEMuscleMaterial
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FEMuscleMaterial, FEUncoupledMaterial)
ADD_PARAMETER(m_G1, "g1")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_G2, "g2")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_G3, "g3")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_P1, "p1");
ADD_PARAMETER(m_P2, "p2")->setUnits(UNIT_NONE);
ADD_PARAMETER(m_Lofl, "Lofl");
ADD_PARAMETER(m_smax, "smax")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_lam1, "lam_max");
ADD_PARAMETER(m_alpha, "activation");
ADD_PROPERTY(m_fiber, "fiber");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMuscleMaterial::FEMuscleMaterial(FEModel* pfem) : FEUncoupledMaterial(pfem)
{
m_G1 = 0;
m_G2 = 0;
m_G3 = 0;
m_alpha = 0.0;
m_fiber = nullptr;
}
//-----------------------------------------------------------------------------
//! Calculates the deviatoric stress at a material point.
//!
mat3ds FEMuscleMaterial::DevStress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// deformation gradient
mat3d &F = pt.m_F;
double J = pt.m_J;
// get the local coordinate systems
mat3d Q = GetLocalCS(mp);
// get the initial fiber direction
vec3d a0 = Q*m_fiber->unitVector(mp);
// calculate the current material axis lam*a = F*a0;
vec3d a = F*a0;
// normalize material axis and store fiber stretch
double la = a.unit();
double lat = la*pow(J, -1.0/3.0); // i.e. lambda tilde = sqrt(I4)
// calculate deviatoric left Cauchy-Green tensor: B = Jm23*F*Ft
mat3ds B = pt.DevLeftCauchyGreen();
// calculate square of B
mat3ds B2 = B.sqr();
// calculate Ba = B*a
vec3d Ba = B*a;
// ----- invariants of B -----
double I1 = B.tr();
double I2 = 0.5*(I1*I1 - B2.tr() );
double I4 = lat*lat;
double I5 = I4*(a*Ba);
// ----- calculate new invariants b1 and b2 of B ------
// note that we need to be carefull about roundoff errors
// since these functions may create numerical problems
double g = I5/(I4*I4) - 1;
double b1 = (g > 0 ? sqrt(g) : 0);
double b2 = acosh(0.5*(I1*I4 - I5)/lat);
// calculate omage (w)
double I4r = sqrt(I4);
double w = 0.5*(I1*I4 - I5)/sqrt(I4);
// set beta and ksi to their limit values
double beta = 1.0;
double ksi = -1.0/3.0;
// if w not equals unity, we can calculate beta and ksi
if (w > 1.0001)
{
beta = b2/sqrt(w*w-1);
ksi = (1.0/(w*w-1))*(1 - w*b2/sqrt(w*w-1));
}
// evaluate material parameters
double G1 = m_G1(mp);
double G2 = m_G2(mp);
double G3 = m_G3(mp);
double P1 = m_P1(mp);
double P2 = m_P2(mp);
double Lofl = m_Lofl(mp);
double lam1 = m_lam1(mp);
double alpha = m_alpha(mp);
double smax = m_smax(mp);
// ----- calculate strain derivatives -----
// We assume that W(I1, I4, I5, alpha) = F1(B1(I4, I5)) + F2(B2(I1,I4,I5)) + F3(lam(I4), alpha)
double W1, W2, W4, W5;
// calculate derivatives for F1
double F1D4 = -2*G1*(I5/(I4*I4*I4));
double F1D5 = G1/(I4*I4);
// calculate derivatives for F2
double F2D1 = G2*beta*lat;
double F2D4 = G2*beta*(I1*I4 + I5)*0.5*pow(I4, -1.5);
double F2D5 = -G2*beta/lat;
// calculate derivatives for F3
// these terms are proposed to fix the zero-stress problem
double F3D4 = 9.0*G3*0.125*log(I4)/I4;
// calculate passive fiber force
double Fp;
if (lat <= Lofl)
{
Fp = 0;
}
else if (lat < lam1)
{
Fp = P1*(exp(P2*(lat/Lofl - 1)) - 1);
}
else
{
double P3, P4;
P3 = P1*P2*exp(P2*(lam1/Lofl - 1));
P4 = P1*(exp(P2*(lam1/Lofl - 1)) - 1) - P3*lam1/Lofl;
Fp = P3*lat/Lofl + P4;
}
// calculate active fiber force
double Fa = 0;
if ((lat <= 0.4*Lofl) || (lat >= 1.6*Lofl))
{
// we have added this part to make sure that
// Fa is zero outside the range [0.4, 1.6] *m_Lofl
Fa = 0;
}
else
{
if (lat <= 0.6*Lofl)
{
Fa = 9*SQR(lat/Lofl - 0.4);
}
else if (lat >= 1.4*Lofl)
{
Fa = 9*SQR(lat/Lofl - 1.6);
}
else if ((lat >= 0.6*Lofl) && (lat <= 1.4*Lofl))
{
Fa = 1 - 4*SQR(1 - lat/Lofl);
}
}
// calculate total fiber force
double FfDl = smax*(Fp + alpha*Fa)/Lofl;
double FfD4 = 0.5*FfDl/lat;
// add all derivatives
W1 = F2D1;
W2 = 0;
W4 = F1D4 + F2D4 + F3D4 + FfD4;
W5 = F1D5 + F2D5;
// dyadic of a
mat3ds AxA = dyad(a);
// symmetric dyad of a and Ba
mat3ds ABA = dyads(a, Ba);
// ----- calculate stress -----
// calculate T
mat3ds T = B*(W1 + W2*I1) - B2*W2 + AxA*(I4*W4) + ABA*(I4*W5);
return T.dev()*(2.0/J);
}
//-----------------------------------------------------------------------------
//! Calculates the spatial deviatoric tangent at a material point
//!
tens4ds FEMuscleMaterial::DevTangent(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// deformation gradient
mat3d &F = pt.m_F;
double J = pt.m_J;
// get the local coordinate systems
mat3d Q = GetLocalCS(mp);
// get the initial fiber direction
vec3d a0 = Q*m_fiber->unitVector(mp);
// calculate the current material axis lam*a = F*a0;
vec3d a = F*a0;
// normalize material axis and store fiber stretch
double la = a.unit();
double lat = la*pow(J, -1.0/3.0); // i.e. lambda tilde
// get deviatoric left Cauchy-Green tensor
mat3ds B = pt.DevLeftCauchyGreen();
// calculate square of B
mat3ds B2 = B.sqr();
// calculate B*a
vec3d Ba = B*a;
// invariants of B
double I1, I2, I4, I5;
I1 = B.tr();
I2 = 0.5*(I1*I1 - B2.tr());
I4 = lat*lat;
I5 = I4*(a*Ba);
// calculate new invariants
double g = I5/(I4*I4) - 1;
double b1 = (g > 0 ? sqrt(g) : 0);
double b2 = acosh(0.5*(I1*I4 - I5)/lat);
// calculate omage (w)
double w = 0.5*(I1*I4 - I5)/lat;
// set beta and ksi to their limit values
double beta = 1.0;
double ksi = -1.0/3.0;
// if w not equals unity, we can calculate beta and ksi
if (w > 1.0001)
{
beta = b2/sqrt(w*w-1);
ksi = (1.0/(w*w-1))*(1 - w*b2/sqrt(w*w-1));
}
// evaluate material parameters
double G1 = m_G1(mp);
double G2 = m_G2(mp);
double G3 = m_G3(mp);
double P1 = m_P1(mp);
double P2 = m_P2(mp);
double Lofl = m_Lofl(mp);
double lam1 = m_lam1(mp);
double alpha = m_alpha(mp);
double smax = m_smax(mp);
// --- strain energy derivatives ---
// We assume that W(I1, I4, I5, alpha) = F1(B1(I4, I5)) + F2(B2(I1,I4,I5)) + F3(lam(I4), alpha)
double W1, W2, W4, W5;
// -- A. matrix contribution --
// calculate derivatives for F1
double F1D4 = -2*G1*(I5/(I4*I4*I4));
double F1D5 = G1/(I4*I4);
double F1D44 = 6*G1*(I5/(I4*I4*I4*I4));
double F1D45 = -2*G1/(I4*I4*I4);
// calculate derivatives for F2
double F2D1 = G2*beta*lat;
double F2D4 = G2*beta*(I1*I4 + I5)*0.5*pow(I4, -1.5);
double F2D5 = -G2*beta/lat;
double F2D11 = ksi*G2*I4*0.5;
double F2D44 = 2.0*G2*ksi*pow(0.25*(I1*I4+I5)/pow(I4, 1.5), 2) - G2*beta*(0.25*(I1*I4 + 3*I5) / pow(I4, 2.5));
double F2D55 = 0.5*G2*ksi/I4;
double F2D14 = G2*beta*0.5/lat + G2*ksi*(I1*I4+I5)*0.25/I4;
double F2D15 = -0.5*G2*ksi;
double F2D45 = G2*beta*0.5*pow(I4, -1.5) - G2*ksi*0.25*(I1*I4+I5)/(I4*I4);
// calculate derivatives for F3
// these terms are proposed to fix the zero-stress problem
double F3D4 = 9.0*G3*0.125*log(I4)/I4;
double F3D44 = 9.0*G3*0.125*(1 - log(I4))/(I4*I4);
// -- B. fiber contribution --
// calculate passive fiber force
double Fp, FpDl;
if (lat <= Lofl)
{
Fp = 0;
FpDl = 0;
}
else if (lat < lam1)
{
Fp = P1*(exp(P2*(lat/Lofl - 1)) - 1);
FpDl = P1*P2*exp(P2*(lat/Lofl-1))/Lofl;
}
else
{
double P3, P4;
P3 = P1*P2*exp(P2*(lam1/Lofl - 1));
P4 = P1*(exp(P2*(lam1/Lofl - 1)) - 1) - P3*lam1/Lofl;
Fp = P3*lat/Lofl + P4;
FpDl = P3/Lofl;
}
// calculate active fiber force
double Fa = 0, FaDl = 0;
if ((lat <= 0.4*Lofl) || (lat >= 1.6*Lofl))
{
// we have added this part to make sure that
// Fa is zero outside the range [0.4, 1.6] *m_Lofl
Fa = 0;
FaDl = 0;
}
else
{
if (lat <= 0.6*Lofl)
{
Fa = 9*SQR(lat/Lofl - 0.4);
FaDl = 18*(lat/Lofl - 0.4)/Lofl;
}
else if (lat >= 1.4*Lofl)
{
Fa = 9*SQR(lat/Lofl - 1.6);
FaDl = 18*(lat/Lofl - 1.6)/Lofl;
}
else if ((lat >= 0.6*Lofl) && (lat <= 1.4*Lofl))
{
Fa = 1 - 4*SQR(1 - lat/Lofl);
FaDl = 8*(1 - lat/Lofl)/Lofl;
}
}
// calculate total fiber force
double FfDl = smax*(Fp + alpha*Fa)/Lofl;
double FfD4 = 0.5*FfDl/lat;
double FfDll = smax*(FpDl + alpha*FaDl)/Lofl;
double FfD44 = 0.25*(FfDll - FfDl / lat)/I4;
// add all derivatives
W1 = F2D1;
W2 = 0;
W4 = F1D4 + F2D4 + F3D4 + FfD4;
W5 = F1D5 + F2D5;
// calculate second derivatives
double W11, W12, W22, W14, W24, W15, W25, W44, W45, W55;
W11 = F2D11;
W12 = 0;
W22 = 0;
W14 = F2D14;
W24 = 0;
W15 = F2D15;
W25 = 0;
W44 = F1D44 + F2D44 + F3D44 + FfD44;
W45 = F1D45 + F2D45;
W55 = F2D55;
// calculate dWdC:C
double WCC = W1*I1 + 2*W2*I2 + W4*I4 + 2*W5*I5;
// calculate C:d2WdCdC:C
double CW2CCC = (W11*I1 + W12*I1*I1 + W2*I1 + 2*W12*I2 + 2*W22*I1*I2 + W14*I4 + W24*I1*I4 + 2*W15*I5 + 2*W25*I1*I5)*I1
-(W12*I1 + 2*W22*I2 + W2 + W24*I4 + 2*W25*I5)*(I1*I1 - 2*I2)
+(W14*I1 + 2*W24*I2 + W44*I4 + 2*W45*I5)*I4 + (W15*I1 + 2*W25*I2 + W45*I4 + 2*W55*I5)*2*I5
+ 2*W5*I5;
// second order identity tensor
mat3dd ID(1);
// 4th order identity tensors
tens4ds IxI = dyad1s(ID);
tens4ds I = dyad4s(ID);
// dyad of a
mat3ds AxA = dyad(a);
// --- calculate elasticity tensor ---
// calculate push-forward of dI5/dC = I4*(a*Ba + Ba*a)
mat3ds I5C = dyads(a, Ba)*I4;
// calculate push-forward of d2I5/dCdC
tens4ds I5CC = dyad4s(AxA, B)*I4;
// calculate push forward of I
tens4ds Ib = dyad4s(B);
// calculate push forward of dW/dCdC:C
mat3ds WCCC =
B*(W11*I1 + W12*I1*I1 + W2*I1 + 2*W12*I2 + 2*W22*I1*I2 + W14*I4 + W24*I1*I4 + 2*W15*I5 + 2*W25*I1*I5) -
B2*(W12*I1 + 2*W22*I2 + W2 + W24*I4 + 2*W25*I5) +
AxA *((W14*I1 + 2*W24*I2 + W44*I4 + 2*W45*I5)*I4) +
I5C*(W15*I1 + 2*W25*I2 + W45*I4 + 2*W55*I5 + W5);
// calculate push-forward of dW2/dCdC
tens4ds W2CC =
dyad1s(B)*(W11 + 2.0*W12*I1 + W2 + W22*I1*I1) +
dyad1s(B, B2)*(-(W12+W22*I1)) + dyad1s(B2)*W22 - Ib*W2 +
dyad1s(B, AxA)*((W14 + W24*I1)*I4) +
dyad1s(B, I5C)*(W15 + W25*I1) +
dyad1s(B2, AxA)*(-W24*I4) +
dyad1s(AxA)*(W44*I4*I4) +
dyad1s(AxA, I5C)*(W45*I4) +
dyad1s(I5C)*W55 + I5CC*W5;
// let's put it all together
// cw
tens4ds cw = IxI*((4.0/(9.0*J))*(CW2CCC)) + W2CC*(4/J) - dyad1s(WCCC, ID)*(4.0/(3.0*J));
// deviatoric Cauchy-stress
mat3ds ABA = dyads(a, Ba);
mat3ds T = B * (W1 + W2 * I1) - B2 * W2 + AxA * (I4 * W4) + ABA * (I4 * W5);
mat3ds devs = T.dev() * (2.0 / J);
// elasticity tensor
tens4ds c = dyad1s(devs, ID)*(-2.0/3.0) + (I - IxI/3.0)*(4.0*WCC/(3.0*J)) + cw;
return tens4ds(c);
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FECGSolidSolver.cpp | .cpp | 44,617 | 1,520 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FECGSolidSolver.h"
#include "FECore/FEModel.h"
#include "FECore/FEAnalysis.h"
#include "FECore/FEMesh.h"
#include "FECore/log.h"
#include "FEContactInterface.h"
#include "FESSIShellDomain.h"
#include "FEUncoupledMaterial.h"
#include "FEResidualVector.h"
#include "FEElasticDomain.h"
#include "FE3FieldElasticSolidDomain.h"
#include "FE3FieldElasticShellDomain.h"
#include "FERigidBody.h"
#include "RigidBC.h"
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FENodalLoad.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FESurfaceLoad.h>
#include <FECore/FELinearConstraintManager.h>
#include "FEBodyForce.h"
#include "FECore/sys.h"
#include "FECore/vector.h"
#include "FEMechModel.h"
#include "FEBioMech.h"
#include "FESolidAnalysis.h"
#include <FECore/FENLConstraint.h>
//-----------------------------------------------------------------------------
// define the parameter list
BEGIN_FECORE_CLASS(FECGSolidSolver, FESolver)
ADD_PARAMETER(m_Dtol , "dtol");
ADD_PARAMETER(m_Etol , "etol");
ADD_PARAMETER(m_Rtol , "rtol");
ADD_PARAMETER(m_Rmin , "min_residual");
ADD_PARAMETER(m_beta , "beta");
ADD_PARAMETER(m_gamma , "gamma");
ADD_PARAMETER(m_LStol , "lstol");
ADD_PARAMETER(m_LSmin , "lsmin");
ADD_PARAMETER(m_LSiter, "lsiter");
ADD_PARAMETER(m_CGmethod, "cgmethod");
ADD_PARAMETER(m_precon, "preconditioner");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FECGSolidSolver::FECGSolidSolver(FEModel* pfem) : FESolver(pfem), m_rigidSolver(pfem), \
m_dofU(pfem), m_dofV(pfem), m_dofQ(pfem), m_dofRQ(pfem), m_dofSU(pfem), m_dofSV(pfem), m_dofSA(pfem)
{
// default values
m_Rtol = 0; // deactivate residual convergence
m_Dtol = 1e-6;
m_Etol = 0.01;
m_Rmin = 1.0e-20;
m_LStol = 0.9;
m_LSmin = 1e-15;
m_LSiter = 10;
m_niter = 0;
m_nreq = 0;
m_CGmethod = 0; // 0 = Hager-Zhang, 1 = steepest descent
m_precon = 0; // 0 = no preconditioner, 1 = diagonal stiffness
// default Newmark parameters for unconditionally stable time integration
m_beta = 0.25;
m_gamma = 0.5;
// Allocate degrees of freedom
DOFS& dofs = pfem->GetDOFS();
int varD = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT), VAR_VEC3);
dofs.SetDOFName(varD, 0, "x");
dofs.SetDOFName(varD, 1, "y");
dofs.SetDOFName(varD, 2, "z");
int varQ = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::ROTATION), VAR_VEC3);
dofs.SetDOFName(varQ, 0, "u");
dofs.SetDOFName(varQ, 1, "v");
dofs.SetDOFName(varQ, 2, "w");
int varQR = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION), VAR_VEC3);
dofs.SetDOFName(varQR, 0, "Ru");
dofs.SetDOFName(varQR, 1, "Rv");
dofs.SetDOFName(varQR, 2, "Rw");
int varV = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY), VAR_VEC3);
dofs.SetDOFName(varV, 0, "vx");
dofs.SetDOFName(varV, 1, "vy");
dofs.SetDOFName(varV, 2, "vz");
int varSU = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT), VAR_VEC3);
dofs.SetDOFName(varSU, 0, "sx");
dofs.SetDOFName(varSU, 1, "sy");
dofs.SetDOFName(varSU, 2, "sz");
int varSV = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_VELOCITY), VAR_VEC3);
dofs.SetDOFName(varSV, 0, "svx");
dofs.SetDOFName(varSV, 1, "svy");
dofs.SetDOFName(varSV, 2, "svz");
int varSA = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_ACCELERATION), VAR_VEC3);
dofs.SetDOFName(varSA, 0, "sax");
dofs.SetDOFName(varSA, 1, "say");
dofs.SetDOFName(varSA, 2, "saz");
// get the DOF indices
m_dofU.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT));
m_dofV.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY));
m_dofQ.AddVariable(FEBioMech::GetVariableName(FEBioMech::ROTATION));
m_dofRQ.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION));
m_dofSU.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT));
m_dofSV.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_VELOCITY));
m_dofSA.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_ACCELERATION));
}
//-----------------------------------------------------------------------------
void FECGSolidSolver::Clean()
{
}
//-----------------------------------------------------------------------------
bool FECGSolidSolver::CalculatePreconditioner()
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
vector<double> dummy(m_Mi);
FEGlobalVector Mi(fem, m_Mi, dummy);
matrix me;
vector <int> lm;
FETimeInfo& tp = fem.GetTime();
matrix ke;
vector <double> el_diagonal_stiffness;
for (int nd = 0; nd < mesh.Domains(); ++nd)
{
// check whether it is a solid domain
FEElasticSolidDomain* pbd = dynamic_cast<FEElasticSolidDomain*>(&mesh.Domain(nd));
if (pbd) // it is an elastic solid domain
{
FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(pbd->GetMaterial());
// loop over all the elements
for (int iel = 0; iel < pbd->Elements(); ++iel)
{
FESolidElement& el = pbd->Element(iel);
pbd->UnpackLM(el, lm);
//int nint = el.GaussPoints();
long int neln = el.Nodes();
// set up, zero and calculate the element stiffness matrix
ke.resize(neln * 3, neln * 3);
ke.zero();
pbd->ElementStiffness(tp, iel, ke);
// set up the diagonal stiffness vector and copy in the diagonal values from ke
el_diagonal_stiffness.assign(3 * neln, 0.0);
for (int i = 0; i < neln * 3; ++i)
{
el_diagonal_stiffness[i] = ke[i][i];
}
// assemble element stiffness vector into the global stiffness vector
Mi.Assemble(el.m_node, lm, el_diagonal_stiffness);
} // loop over elements
}
else if (dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd)))
{
FEElasticShellDomain* psd = dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd));
FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(psd->GetMaterial());
// loop over all the elements
for (int iel = 0; iel < psd->Elements(); ++iel)
{
FEShellElement& el = psd->Element(iel);
psd->UnpackLM(el, lm);
// create the element's stiffness matrix
FEElementMatrix ke(el);
int neln = el.Nodes();
int ndof = 6 * el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate element stiffness matrix
psd->ElementStiffness(iel, ke);
// pick out the diagonal stiffness values
el_diagonal_stiffness.assign(ndof, 0.0);
for (int i = 0; i < ndof; ++i)
{
el_diagonal_stiffness[i] = ke[i][i];
}
// assemble element matrix into inv_mass vector
Mi.Assemble(el.m_node, lm, el_diagonal_stiffness);
}
}
else
{
// TODO: we can only do solid domains right now.
return false;
}
}
// we need the inverse of the nodal stiffnesses later
// Also, make sure everything is positive.
for (int i = 0; i < m_Mi.size(); ++i)
{
if (m_Mi[i] < 0.0)
{
return false;
}
if (m_Mi[i] != 0.0) m_Mi[i] = 1.0 / m_Mi[i]; // note prescribed dofs will have zero mass so we need to skip them
}
return true;
}
//-----------------------------------------------------------------------------
//! Allocates and initializes the data structures used by the FESolidSolver
//
bool FECGSolidSolver::Init()
{
if (FESolver::Init() == false) return false;
// check parameters
if (m_Dtol < 0.0) { feLogError("dtol must be nonnegative."); return false; }
if (m_Etol < 0.0) { feLogError("etol must be nonnegative."); return false; }
if (m_Rtol < 0.0) { feLogError("rtol must be nonnegative."); return false; }
if (m_Rmin < 0.0) { feLogError("min_residual must be nonnegative."); return false; }
if (m_LStol < 0.) { feLogError("lstol must be nonnegative." ); return false; }
if (m_LSmin < 0.) { feLogError("lsmin must be nonnegative." ); return false; }
if (m_LSiter < 0 ) { feLogError("lsiter must be nonnegative."); return false; }
// get nr of equations
int neq = m_neq;
// allocate vectors
m_Fn.assign(neq, 0);
m_Fr.assign(neq, 0);
m_Ui.assign(neq, 0);
m_Ut.assign(neq, 0);
m_R0.assign(neq, 0);
m_R1.assign(neq, 0);
m_Mi.assign(neq, 0.0);
// we need to fill the total displacement vector m_Ut
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
gather(m_Ut, mesh, m_dofU[0]);
gather(m_Ut, mesh, m_dofU[1]);
gather(m_Ut, mesh, m_dofU[2]);
gather(m_Ut, mesh, m_dofQ[0]);
gather(m_Ut, mesh, m_dofQ[1]);
gather(m_Ut, mesh, m_dofQ[2]);
gather(m_Ut, mesh, m_dofSU[0]);
gather(m_Ut, mesh, m_dofSU[1]);
gather(m_Ut, mesh, m_dofSU[2]);
// calculate the inverse mass vector to use as a preconditioner
if (m_precon == 1)
{
if (CalculatePreconditioner() == false)
{
feLogError("Failed building preconditioner.");
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
//! This function initializes the equation system.
//! It is assumed that all free dofs up until now have been given an ID >= 0
//! and the fixed or rigid dofs an ID < 0.
//! After this operation the nodal ID array will contain the equation
//! number assigned to the corresponding degree of freedom. To distinguish
//! between free or unconstrained dofs and constrained ones the following rules
//! apply to the ID array:
//!
//! /
//! | >= 0 --> dof j of node i is a free dof
//! ID[i][j] < == -1 --> dof j of node i is a fixed (no equation assigned too)
//! | < -1 --> dof j of node i is constrained and has equation nr = -ID[i][j]-2
//! \
//!
bool FECGSolidSolver::InitEquations()
{
// get the mesh
FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel());
FEMesh& mesh = fem.GetMesh();
// initialize nr of equations
int neq = 0;
// give all free dofs an equation number
m_dofMap.clear();
DOFS& dofs = fem.GetDOFS();
for (int i = 0; i < mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.HasFlags(FENode::EXCLUDE) == false) {
for (int nv = 0; nv < dofs.Variables(); ++nv)
{
int n = dofs.GetVariableSize(nv);
for (int l = 0; l < n; ++l)
{
int nl = dofs.GetDOF(nv, l);
if (node.is_active(nl))
{
int bcj = node.get_bc(nl);
if (bcj == DOF_OPEN ) { node.m_ID[nl] = neq++; m_dofMap.push_back(nl); }
else if (bcj == DOF_FIXED ) { node.m_ID[nl] = -1; }
else if (bcj == DOF_PRESCRIBED) { node.m_ID[nl] = -neq - 2; neq++; m_dofMap.push_back(nl); }
else { assert(false); return false; }
}
else node.m_ID[nl] = -1;
}
}
}
}
// Next, we assign equation numbers to the rigid body degrees of freedom
m_nreq = neq;
int nrb = fem.RigidBodies();
for (int i = 0; i<nrb; ++i)
{
FERigidBody& RB = *fem.GetRigidBody(i);
for (int j = 0; j<6; ++j)
{
int bcj = RB.m_BC[j];
int lmj = RB.m_LM[j];
if (bcj == DOF_OPEN) { RB.m_LM[j] = neq; neq++; }
else if (bcj == DOF_PRESCRIBED) { RB.m_LM[j] = -neq - 2; neq++; }
else if (bcj == DOF_FIXED) { RB.m_LM[j] = -1; }
else { assert(false); return false; }
}
}
// store the number of equations
m_neq = neq;
// we assign the rigid body equation number to
// Also make sure that the nodes are NOT constrained!
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.m_rid >= 0)
{
FERigidBody& RB = *fem.GetRigidBody(node.m_rid);
node.m_ID[m_dofU[0] ] = (RB.m_LM[0] >= 0 ? -RB.m_LM[0] - 2 : RB.m_LM[0]);
node.m_ID[m_dofU[1] ] = (RB.m_LM[1] >= 0 ? -RB.m_LM[1] - 2 : RB.m_LM[1]);
node.m_ID[m_dofU[2] ] = (RB.m_LM[2] >= 0 ? -RB.m_LM[2] - 2 : RB.m_LM[2]);
node.m_ID[m_dofRQ[0]] = (RB.m_LM[3] >= 0 ? -RB.m_LM[3] - 2 : RB.m_LM[3]);
node.m_ID[m_dofRQ[1]] = (RB.m_LM[4] >= 0 ? -RB.m_LM[4] - 2 : RB.m_LM[4]);
node.m_ID[m_dofRQ[2]] = (RB.m_LM[5] >= 0 ? -RB.m_LM[5] - 2 : RB.m_LM[5]);
}
}
// All initialization is done
return true;
}
//-----------------------------------------------------------------------------
//! Prepares the data for the first BFGS-iteration.
void FECGSolidSolver::PrepStep()
{
FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel());
const FETimeInfo& tp = fem.GetTime();
// initialize counters
m_niter = 0; // nr of iterations
m_nrhs = 0; // nr of RHS evaluations
m_nref = 0; // nr of stiffness reformations
m_ntotref = 0;
m_naug = 0; // nr of augmentations
// allocate data vectors
m_R0.assign(m_neq, 0);
m_R1.assign(m_neq, 0);
m_ui.assign(m_neq, 0);
m_Ui.assign(m_neq, 0);
// zero total displacements
zero(m_Ui);
// store previous mesh state
// we need them for velocity and acceleration calculations
FEMesh& mesh = fem.GetMesh();
//for (int i = 0; i<mesh.Nodes(); ++i)
//{
// FENode& ni = mesh.Node(i);
// ni.m_rp = ni.m_rt;
// ni.m_vp = ni.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]);
// ni.m_ap = ni.m_at;
//}
// apply concentrated nodal forces
// since these forces do not depend on the geometry
// we can do this once outside the NR loop.
vector<double> dummy(m_neq, 0.0);
zero(m_Fn);
FEResidualVector Fn(*GetFEModel(), m_Fn, dummy);
// TODO: This function does not exist
// NodalLoads(Fn, tp);
// apply boundary conditions
// we save the prescribed displacements increments in the ui vector
vector<double>& ui = m_ui;
zero(ui);
int neq = m_neq;
int nbc = fem.BoundaryConditions();
for (int i = 0; i<nbc; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.PrepStep(ui);
}
// initialize rigid bodies
int NO = fem.RigidBodies();
for (int i = 0; i<NO; ++i) fem.GetRigidBody(i)->Init();
// calculate local rigid displacements
for (int i = 0; i < NO; ++i)
{
FERigidBody& rb = *fem.GetRigidBody(i);
for (int j = 0; j < 6; ++j)
{
FERigidPrescribedBC* dc = rb.m_pDC[j];
if (dc) dc->InitTimeStep();
}
}
// calculate global rigid displacements
for (int i = 0; i<NO; ++i)
{
FERigidBody* prb = fem.GetRigidBody(i);
if (prb)
{
FERigidBody& RB = *prb;
if (RB.m_prb == 0)
{
for (int j = 0; j<6; ++j) RB.m_du[j] = RB.m_dul[j];
}
else
{
double* dul = RB.m_dul;
vec3d dr = vec3d(dul[0], dul[1], dul[2]);
vec3d v = vec3d(dul[3], dul[4], dul[5]);
double w = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
quatd dq = quatd(w, v);
FERigidBody* pprb = RB.m_prb;
vec3d r0 = RB.m_rt;
quatd Q0 = RB.GetRotation();
dr = Q0*dr;
dq = Q0*dq*Q0.Inverse();
while (pprb)
{
vec3d r1 = pprb->m_rt;
dul = pprb->m_dul;
quatd Q1 = pprb->GetRotation();
dr = r0 + dr - r1;
// grab the parent's local displacements
vec3d dR = vec3d(dul[0], dul[1], dul[2]);
v = vec3d(dul[3], dul[4], dul[5]);
w = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
quatd dQ = quatd(w, v);
dQ = Q1*dQ*Q1.Inverse();
// update global displacements
quatd Qi = Q1.Inverse();
dr = dR + r1 + dQ*dr - r0;
dq = dQ*dq;
// move up in the chain
pprb = pprb->m_prb;
Q0 = Q1;
}
// set global displacements
double* du = RB.m_du;
du[0] = dr.x;
du[1] = dr.y;
du[2] = dr.z;
v = dq.GetVector();
w = dq.GetAngle();
du[3] = w*v.x;
du[4] = w*v.y;
du[5] = w*v.z;
}
}
}
// store rigid displacements in Ui vector
for (int i = 0; i<NO; ++i)
{
FERigidBody& RB = *fem.GetRigidBody(i);
for (int j = 0; j<6; ++j)
{
int I = -RB.m_LM[j] - 2;
if (I >= 0) ui[I] = RB.m_du[j];
}
}
FEAnalysis* pstep = fem.GetCurrentStep();
if (pstep->m_nanalysis == FESolidAnalysis::DYNAMIC)
{
feLogError("The CG-Solid solver cannot be used for dynamic analysis");
throw FatalError();
}
//{
// FEMesh& mesh = fem.GetMesh();
// // set the initial velocities of all rigid nodes
// for (int i = 0; i<mesh.Nodes(); ++i)
// {
// FENode& n = mesh.Node(i);
// if (n.m_rid >= 0)
// {
// FERigidBody& rb = *fem.GetRigidBody(n.m_rid);
// vec3d V = rb.m_vt;
// vec3d W = rb.m_wt;
// vec3d r = n.m_rt - rb.m_rt;
// vec3d v = V + (W ^ r);
// n.m_vp = v;
// n.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], v);
// vec3d a = (W ^ V)*2.0 + (W ^ (W ^ r));
// n.m_ap = n.m_at = a;
// }
// }
//}
// store the current rigid body reaction forces
for (int i = 0; i<fem.RigidBodies(); ++i)
{
FERigidBody& RB = *fem.GetRigidBody(i);
RB.m_Fp = RB.m_Fr;
RB.m_Mp = RB.m_Mr;
}
// intialize material point data
for (int i = 0; i<mesh.Domains(); ++i) mesh.Domain(i).PreSolveUpdate(tp);
// update model state
fem.Update();
// see if we need to do contact augmentations
m_baugment = false;
for (int i = 0; i<fem.SurfacePairConstraints(); ++i)
{
FEContactInterface& ci = dynamic_cast<FEContactInterface&>(*fem.SurfacePairConstraint(i));
if (ci.IsActive() && (ci.m_laugon == FECore::AUGLAG_METHOD)) m_baugment = true;
}
// see if we need to do incompressible augmentations
// TODO: Should I do these augmentations in a nlconstraint class instead?
int ndom = mesh.Domains();
for (int i = 0; i < ndom; ++i)
{
FEDomain* dom = &mesh.Domain(i);
FE3FieldElasticSolidDomain* dom3f = dynamic_cast<FE3FieldElasticSolidDomain*>(dom);
if (dom3f && dom3f->DoAugmentations()) m_baugment = true;
FE3FieldElasticShellDomain* dom3fs = dynamic_cast<FE3FieldElasticShellDomain*>(dom);
if (dom3fs && dom3fs->DoAugmentations()) m_baugment = true;
}
// see if we have to do nonlinear constraint augmentations
for (int i = 0; i<fem.NonlinearConstraints(); ++i)
{
FENLConstraint& ci = *fem.NonlinearConstraint(i);
if (ci.IsActive()) m_baugment = true;
}
}
//-----------------------------------------------------------------------------
bool FECGSolidSolver::SolveStep()
{
int i;
vector<double> u0(m_neq);
vector<double> Rold(m_neq);
// convergence norms
double normR1; // residual norm
double normE1; // energy norm
double normU; // displacement norm
double normu; // displacement increment norm
double normRi; // initial residual norm
double normEi; // initial energy norm
double normEm; // max energy norm
double normUi; // initial displacement norm
// initialize flags
bool breform = false; // reformation flag
bool sdstep = true; // set to true on a steepest descent iteration - if this fails we will give up
int cgits = 0; // count CG iterations to trigger periodic restart
int maxits = 100; // how many to do before restarting
// Get the current step
FEModel& fem = *GetFEModel();
FEAnalysis* pstep = fem.GetCurrentStep();
// prepare for the first iteration
const FETimeInfo& tp = fem.GetTime();
PrepStep();
// We need to try the prescribed displacements and make sure they don't cause a -ve Jacobian
// before we have moved any of the flexible nodes
// We also calculate the initial residual
// TODO: I think some of this update is duplicated in PrepStep and could just be done here
//if (Residual(m_R0) == false) return false;
try
{
Update(m_ui); // m_ui contains the prescribed displacements calculated in PrepStep
Residual(m_R0);
}
catch (...) // negative Jacobian if prescribed disps are too big
{
feLogError("Time step too big, prescribed displacements caused negative Jacobian");
return false;
}
// set the initial step length estimates to 1.0e-6
double s = 1e-6;
double olds = 1e-6;
double oldolds = 1e-6; // line search step lengths from the current iteration and the two previous ones
// loop until converged or when max nr of reformations reached
bool bconv = false; // convergence flag
do
{
feLog(" %d\n", m_niter+1);
// assume we'll converge.
bconv = true;
if ((m_niter>0)&&(breform==false)&&(m_CGmethod == 0)) // no need to restart CG
{
// calculate Hager- Zhang direction
double moddU=sqrt(u0*u0); // needed later for the step length calculation
// calculate yk
vector<double> RR(m_neq);
RR=m_R0-Rold;
// calculate dk.yk
double bdiv=u0*RR;
double betapcg;
if (bdiv==0.0) // use steepest descent method if necessary
{
betapcg=0.0;
sdstep = true;
}
else {
double RR2 = RR * RR; // yk^2
// use m_ui as a temporary vector
if (m_precon == 1)
{
for (i = 0; i < m_neq; ++i) {
// improved formula from L-CG DESCENT (*2 removed):
m_ui[i] = m_Mi[i] * (RR[i] - u0[i] * RR2 / bdiv); // yk-2*dk*yk^2/(dk.yk)
}
}
else
{
for (i = 0; i < m_neq; ++i) {
// formula from CG DESCENT (without *2 removed):
m_ui[i] = RR[i] - 2.0 * u0[i] * RR2 / bdiv; // yk-2*dk*yk^2/(dk.yk)
}
}
betapcg = m_ui * m_R0; // m_ui*gk+1
betapcg = -betapcg / bdiv;
if (m_precon == 1)
{
// improved truncation from L-CG DESCENT:
double dPd = 0.0;
for (i = 0; i < m_neq; ++i) {
if (m_Mi[i] != 0) { // m_Mi=0 for prescribed displacements, so skip those dofs
dPd += u0[i] * u0[i] / m_Mi[i];
}
}
double etak = 0.4 * (u0 * Rold) / dPd;
betapcg = max(etak, betapcg);
if (ISNAN(betapcg)) throw; // NANDetected(); TODO: update this error
}
else
{
// Original H-Z truncation formula
double modR = sqrt(m_R0 * m_R0);
double etak = -1.0 / (moddU * min(0.01, modR));
betapcg = max(etak, betapcg);
}
sdstep = false;
}
if (m_precon == 1) // use LMM preconditioner
{
for (i = 0; i < m_neq; ++i) // calculate new search direction m_ui
{
m_ui[i] = m_Mi[i] * m_R0[i] + betapcg * u0[i];
}
}
else
{
for (i = 0; i < m_neq; ++i) // calculate new search direction m_ui
{
m_ui[i] = m_R0[i] + betapcg * u0[i];
}
}
}
else
{
// use steepest descent for first iteration or when a restart is needed
if (m_precon == 1) // use LMM preconditioner
{
for (i = 0; i < m_neq; ++i) // calculate new search direction m_ui
{
m_ui[i] = m_Mi[i] * m_R0[i];
}
}
else m_ui = m_R0;
breform=false;
if (m_niter > 0) m_nref += 1;
sdstep = true;
}
Rold=m_R0; // store residual for use next time
u0=m_ui; // store direction for use on the next iteration
// check for nans
double du = m_ui*m_ui;
if (ISNAN(du)) throw NANInSolutionDetected();
// perform a linesearch
// the geometry is also updated in the line search
// use the step length from two steps previously as the initial guess
// note that it has its own linesearch, different from the BFGS one
s = LineSearchCG(oldolds);
if (s != -1) {// update the old step lengths for use as an initial guess in two iterations' time
if (m_niter < 1) oldolds = s; // if this is the first iteration, use current step length
else oldolds = olds; // otherwise use the previous one
if (s > 0) olds = s; // and store the current step to be used for the iteration after next
// update total incremental displacements
int neq = (int)m_Ui.size();
for (i = 0; i < neq; ++i) m_Ui[i] += s * m_ui[i];
}
else { // the line search has failed and we need to restart
breform = true;
feLogWarning("Line search failed. Restarting conjugate gradient algorithm");
oldolds = 1e-6;
olds = 1e-6;
}
// set initial convergence norms if on the first iteration
if (m_niter == 0)
{
normRi = fabs(m_R0 * m_R0);
normEi = fabs(m_ui * m_R0)*s;
normUi = fabs(m_ui * m_ui)*s*s;
normEm = normEi;
}
// calculate norms (using actual step from line search=s*m_ui)
normR1 = m_R1*m_R1;
normu = (m_ui*m_ui)*(s*s);
normU = m_Ui*m_Ui;
normE1 = s*fabs(m_ui*m_R1);
// check residual norm
if ((m_Rtol > 0) && (normR1 > m_Rtol*normRi)) bconv = false;
// check displacement norm
if ((m_Dtol > 0) && (normu > (m_Dtol*m_Dtol)*normU )) bconv = false;
// check energy norm
if ((m_Etol > 0) && (normE1 > m_Etol*normEi)) bconv = false;
// check linestep size
if ((m_LStol > 0) && (s < m_LSmin)) bconv = false;
// check energy divergence
if (normE1 > normEm) bconv = false;
// print convergence summary
feLog(" Nonlinear solution status: time= %lg\n", tp.currentTime);
feLog("\tright hand side evaluations = %d\n", m_nrhs);
feLog("\tconjugate gradient restarts = %d\n", m_nref);
if (m_LStol > 0) feLog("\tstep from line search = %15le\n", s);
feLog("\tconvergence norms : INITIAL CURRENT REQUIRED\n");
feLog("\t residual %15le %15le %15le \n", normRi, normR1, m_Rtol*normRi);
feLog("\t energy %15le %15le %15le \n", normEi, normE1, m_Etol*normEi);
feLog("\t displacement %15le %15le %15le \n", normUi, normu ,(m_Dtol*m_Dtol)*normU );
// see if we may have a small residual
if ((bconv == false) && (normR1 < m_Rmin))
{
// check for almost zero-residual on the first iteration
// this might be an indication that there is no force on the system
feLogWarning("No force acting on the system.");
bconv = true;
}
// check if we have converged.
if (bconv == false)
{
if (fabs(s) < m_LSmin)
{
// check for zero linestep size
feLogWarning("Zero linestep size. Restarting conjugate gradient algorithm");
feLogWarning("\tstep from line search = %15le\n", s);
breform = true;
oldolds = 1e-6; // reset step lengths for restart
olds = 1e-6;
}
// check for diverging
else if (normE1 > 1000*normEm) // less strict divergence check than for BFGS
// as norms tend to increase at first as deformation propagates
{
// check for diverging
feLogWarning("Solution is diverging. Restarting conjugate gradient algorithm");
normEm = normE1;
normEi = normE1;
normRi = normR1;
breform = true;
oldolds = 1e-6; // reset step lengths for restart
olds = 1e-6;
}
// zero displacement increments
// we must set this to zero before the next iteration
// because we assume that the prescribed displacements are stored
// in the m_ui vector.
zero(m_ui);
// copy last calculated residual
m_R0 = m_R1;
//Rold = m_R1; // store residual for use next time
}
else if (m_baugment)
{
// we have converged, so let's see if the augmentations have converged as well
feLog("\n........................ augmentation # %d\n", m_naug+1);
// do the augmentations
bconv = Augment();
// update counter
++m_naug;
// we reset the reformations counter
m_nref = 0;
// If we havn't converged we prepare for the next iteration
if (!bconv)
{
// Since the Lagrange multipliers have changed, we can't just copy
// the last residual but have to recalculate the residual
// we also recalculate the stresses in case we are doing augmentations
// for incompressible materials
fem.Update();
Residual(m_R0);
}
}
// increase iteration number
m_niter++;
// do minor iterations callbacks
fem.DoCallback(CB_MINOR_ITERS);
}
while ((bconv == false)&&((s!=-1)||(sdstep==false))); // give up if a steepest descent iteration fails
// if converged we update the total displacements
if (bconv)
{
m_Ut += m_Ui;
}
return bconv;
}
//-----------------------------------------------------------------------------
void FECGSolidSolver::Update(std::vector<double>& u)
{
UpdateKinematics(u);
GetFEModel()->Update();
}
//-----------------------------------------------------------------------------
//! Update the kinematics of the model, such as nodal positions, velocities,
//! accelerations, etc.
void FECGSolidSolver::UpdateKinematics(vector<double>& ui)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// update rigid bodies
UpdateRigidBodies(ui);
// total displacements
vector<double> U(m_Ut.size());
for (size_t i=0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
// update flexible nodes
// translational dofs
scatter(U, mesh, m_dofU[0]);
scatter(U, mesh, m_dofU[1]);
scatter(U, mesh, m_dofU[2]);
// rotational dofs
scatter(U, mesh, m_dofQ[0]);
scatter(U, mesh, m_dofQ[1]);
scatter(U, mesh, m_dofQ[2]);
// shell dofs
scatter(U, mesh, m_dofSU[0]);
scatter(U, mesh, m_dofSU[1]);
scatter(U, mesh, m_dofSU[2]);
// make sure the prescribed displacements are fullfilled
int ndis = fem.BoundaryConditions();
for (int i=0; i<ndis; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.Update();
}
// enforce the linear constraints
// TODO: do we really have to do this? Shouldn't the algorithm
// already guarantee that the linear constraints are satisfied?
FELinearConstraintManager& LCM = fem.GetLinearConstraintManager();
if (LCM.LinearConstraints() > 0)
{
LCM.Update();
}
// Update the spatial nodal positions
// Don't update rigid nodes since they are already updated
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.m_rid == -1)
node.m_rt = node.m_r0 + node.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]);
}
}
//-----------------------------------------------------------------------------
double FECGSolidSolver::LineSearchCG(double s)
{
// s is now passed from the solver routine instead of defaulting to 1.0
double smin = s;
double FA, FB, FC, AA, AB, r, r0;
bool failed = false;
double A[12] = {}; // vectors to store line search results
double F[12] = {};
double lspow[5]; // used for quadratic fitting calculation
double B[3][4];
double Y[3]; // RHS vector for curve fitting
double coeffs[3];
double temp, term;
// max nr of line search iterations
int nmax = m_LSiter;
int n = 0;
int i, j,k;
// initial energy
FA = m_ui*m_R0;
AA = 0.0;
r0 = FA;
F[0] = FA;
A[0] = 0.0;
double rmin = fabs(FA);
vector<double> ul(m_ui.size()); // temporary vector for trial displacements
// so we can set AA = 0 and FA= r0
// AB=s and we need to evaluate FB (called r1)
// n is a count of the number of linesearch attempts
// calculate residual at this point, reducing s if necessary
do
{
// Update geometry using the initial guess s
vcopys(ul, m_ui, s);
failed = false;
try
{
Update(ul);
Residual(m_R1);
}
catch (...) // negative Jacobian if s is much too big
{
//feLog("reducing s at initial evaluation");
//feLog("\tstep from line search = %15le\n", s);
failed = true;
if (s > 10 * m_LSmin) s = 0.1 * s; // make s smaller and try again until we don't get a -ve J
else {
feLogError("Direction invalid, line search failed");
s= -1;
failed = false;
}
}
} while (failed == true);
if (s != -1) {
// calculate energies
FB = m_ui * m_R1;
AB = s;
F[1] = FB;
A[1] = AB;
if (fabs(FB) < rmin) { // remember best values in case we need them later
rmin = FB;
smin = s;
}
do
{
// make sure that r1 does not happen to be really close to zero,
// since in that case we won't find any better solution.
if (fabs(FB) < 1.e-20) r = 0; // we've hit the converged solution and don't need to do any more
else r = fabs(FB / r0);
if (r > m_LStol) // we need to search and find a better value of s
{
if (n < 4) { // use linear fitting algorithm
if (fabs(FB - FA) < fabs(FB * 0.01)) { // if FB=FA (or nearly) the next step won't work, so make s bigger
if (AB != 0) s = max(AA, AB) * 200; // try a much bigger value
else if (AA != 0) s = AA * 200;
else s = 1e-6; // should never happen!
}
else {
s = (AA * FB - AB * FA) / (FB - FA); // use linear interpolation for first few attempts
//s = min(s, 1e-3); // limit how much s can grow to avoid over-extrapolating
}
}
else { // use quadratic curve fit to try to find a minimum if multiple linear attempts have failed
// calculate powers to fill matrix
for (i = 0; i <= 4; i++) {
lspow[i] = 0;
for (j = 0; j < n; j++) {
lspow[i] = lspow[i] + pow(A[j], i);
}
}
// calculate rhs
for (i = 0; i <= 2; i++) {
Y[i] = 0;
for (j = 0; j < n; j++) {
Y[i] = Y[i] + pow(A[j], i) * F[j];
}
}
// fill matrix
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
B[i][j] = lspow[i + j];
}
}
for (i = 0; i <= 2; i++) {
B[i][3] = Y[i];
}
// solve by Gaussian elimination
for (i = 0; i < 3; i++) {
for (k = i + 1; k < 3; k++) {
if (fabs(B[i][i]) < fabs(B[k][i])) {
//Swap
for (j = 0; j < 4; j++) {
temp = B[i][j];
B[i][j] = B[k][j];
B[k][j] = temp;
}
}
}
// eliminate
for (k = i + 1; k < 3; k++) {
term = B[k][i] / B[i][i];
for (j = 0; j < 4; j++) {
B[k][j] = B[k][j] - term * B[i][j];
}
}
}
//back substitute
for (i = 2; i >= 0; i--) {
coeffs[i] = B[i][3];
for (j = i + 1; j < 3; j++) {
coeffs[i] = coeffs[i] - B[i][j] * coeffs[j];
}
coeffs[i] = coeffs[i] / B[i][i];
}
s = -coeffs[1]*0.5/coeffs[2]; // quadratic estimate
//feLog("\tQuadratic curve fit coeffs s %15le %15le %15le %15le\n", coeffs[0], coeffs[1], coeffs[2], s);
}
if (s == 0) { // check just in case
feLog("\tZero step length FA FB AA AB %15le %15le %15le %15le\n", FA, FB, AA, AB);
}
// calculate residual at this point, reducing s if necessary
do
{
// Update geometry using the initial guess s
//feLog("\tFA FB AA AB s %15le %15le %15le %15le %15le\n", FA, FB, AA, AB, s);
vcopys(ul, m_ui, s);
failed = false;
try
{
Update(ul);
Residual(m_R1);
}
catch (...)
{
feLog("reducing s at FC");
feLog("\tstep from line search = %15le\n", s);
failed = true;
s = 0.1 * s;
}
} while ((failed == true) && (s > m_LSmin));
// calculate energies
FC = m_ui * m_R1;
r = fabs(FC / r0);
if (fabs(FC) > 100 * min(fabs(FA), fabs(FB))) // it was a bad guess and we need to go back a bit
{
s = 0.1 * s;
// calculate residual at this point, reducing s more if necessary
do
{
// Update geometry using the initial guess s
vcopys(ul, m_ui, s);
failed = false;
try
{
Update(ul);
Residual(m_R1);
}
catch (...)
{
feLog("reducing s after bad guess");
feLog("\tstep from line search = %15le\n", s);
failed = true;
s = 0.1 * s;
}
} while (failed == true);
// calculate energies
FC = m_ui * m_R1;
r = fabs(FC / r0);
}
if (fabs(FA) < fabs(FB)) // use the new value and the closest of the previous ones
{
FB = FC;
AB = s;
}
else
{
FA = FC;
AA = s;
}
F[n + 2] = FC;
A[n + 2] = s;
++n;
feLog("\tF %15le %15le %15le %15le %15le\n", F[0], F[1], F[2], F[3], F[4]);
feLog("\tA %15le %15le %15le %15le %15le\n", A[0], A[1], A[2], A[3], A[4]);
if (n > 3) {
feLog("\tF %15le %15le %15le %15le %15le\n", F[5], F[6], F[7], F[8], F[9]);
feLog("\tA %15le %15le %15le %15le %15le\n", A[5], A[6], A[7], A[8], A[9]);
}
}
} while ((((r > m_LStol) && (n <= 5)) || ((r >= 1) && (n > 3))) && (n < nmax));
// try to find a better solution within m_LStol, but if we haven't after five tries, accept any improvement
if (n >= nmax)
{
// max nr of iterations reached.
s = -1;// this signals to the main algorithm that the line search has failed and a restart is needed
}
}
return s;
}
//-----------------------------------------------------------------------------
//! calculates the residual vector
//! Note that the concentrated nodal forces are not calculated here.
//! This is because they do not depend on the geometry
//! so we only calculate them once (in Quasin) and then add them here.
bool FECGSolidSolver::Residual(vector<double>& R)
{
// get the time information
FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel());
const FETimeInfo& tp = fem.GetTime();
// initialize residual with concentrated nodal loads
R = m_Fn;
// zero nodal reaction forces
zero(m_Fr);
// setup the global vector
FEResidualVector RHS(fem, R, m_Fr);
// zero rigid body reaction forces
int NRB = fem.RigidBodies();
for (int i = 0; i<NRB; ++i)
{
FERigidBody& RB = *fem.GetRigidBody(i);
RB.m_Fr = RB.m_Mr = vec3d(0, 0, 0);
}
// get the mesh
FEMesh& mesh = fem.GetMesh();
// calculate the internal (stress) forces
for (int i = 0; i<mesh.Domains(); ++i)
{
FEElasticDomain& dom = dynamic_cast<FEElasticDomain&>(mesh.Domain(i));
dom.InternalForces(RHS);
}
// calculate inertial forces for dynamic problems
if (fem.GetCurrentStep()->m_nanalysis == FESolidAnalysis::DYNAMIC) InertialForces(RHS);
// calculate contact forces
if (fem.SurfacePairConstraints() > 0)
{
ContactForces(RHS);
}
// calculate nonlinear constraint forces
// note that these are the linear constraints
// enforced using the augmented lagrangian
NonLinearConstraintForces(RHS, tp);
// forces due to point constraints
// for (i=0; i<(int) fem.m_PC.size(); ++i) fem.m_PC[i]->Residual(this, R);
// add model loads
int NML = fem.ModelLoads();
for (int i = 0; i<NML; ++i)
{
FEModelLoad& mli = *fem.ModelLoad(i);
if (mli.IsActive())
{
mli.LoadVector(RHS);
}
}
// set the nodal reaction forces
// TODO: Is this a good place to do this?
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
node.set_load(m_dofU[0], 0);
node.set_load(m_dofU[1], 0);
node.set_load(m_dofU[2], 0);
int n;
if ((n = -node.m_ID[m_dofU[0]] - 2) >= 0) node.set_load(m_dofU[0], -m_Fr[n]);
if ((n = -node.m_ID[m_dofU[1]] - 2) >= 0) node.set_load(m_dofU[1], -m_Fr[n]);
if ((n = -node.m_ID[m_dofU[2]] - 2) >= 0) node.set_load(m_dofU[2], -m_Fr[n]);
}
// increase RHS counter
m_nrhs++;
return true;
}
//-----------------------------------------------------------------------------
//! Calculates the contact forces
void FECGSolidSolver::ContactForces(FEGlobalVector& R)
{
FEModel& fem = *GetFEModel();
const FETimeInfo& tp = fem.GetTime();
for (int i = 0; i<fem.SurfacePairConstraints(); ++i)
{
FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i));
if (pci->IsActive()) pci->LoadVector(R, tp);
}
}
//-----------------------------------------------------------------------------
//! calculate the nonlinear constraint forces
void FECGSolidSolver::NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp)
{
FEModel& fem = *GetFEModel();
int N = fem.NonlinearConstraints();
for (int i = 0; i<N; ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
if (plc->IsActive()) plc->LoadVector(R, tp);
}
}
//-----------------------------------------------------------------------------
//! This function calculates the inertial forces for dynamic problems
void FECGSolidSolver::InertialForces(FEGlobalVector& R)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// allocate F
vector<double> F(3 * mesh.Nodes());
zero(F);
// calculate F
double dt = fem.GetTime().timeIncrement;
double a = 1.0 / (m_beta*dt);
double b = a / dt;
double c = 1.0 - 0.5 / m_beta;
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
vec3d& rt = node.m_rt;
vec3d& rp = node.m_rp;
vec3d& vp = node.m_vp;
vec3d& ap = node.m_ap;
F[3 * i] = b*(rt.x - rp.x) - a*vp.x + c * ap.x;
F[3 * i + 1] = b*(rt.y - rp.y) - a*vp.y + c * ap.y;
F[3 * i + 2] = b*(rt.z - rp.z) - a*vp.z + c * ap.z;
}
// now multiply F with the mass matrix
for (int nd = 0; nd < mesh.Domains(); ++nd)
{
FEElasticDomain& dom = dynamic_cast<FEElasticDomain&>(mesh.Domain(nd));
dom.InertialForces(R, F);
}
}
//-----------------------------------------------------------------------------
// \todo I'd like to do something different with this. Right now, if a nodal load
// it applied to a rigid body, the load has to be translated to a force and
// torque applied to the rigid body. Perhaps we should really define two types
// of nodal loads, one for the deformable body and for the rigid body. This can
// be done in a pre-processor phase. That way, standard assembly routines can be
// used to assemble to loads into the global vector.
void FECGSolidSolver::AssembleResidual(int node_id, int dof, double f, vector<double>& R)
{
// get the mesh
FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel());
FEMesh& mesh = fem.GetMesh();
// get the equation number
FENode& node = mesh.Node(node_id);
int n = node.m_ID[dof];
// assemble into global vector
if (n >= 0) R[n] += f;
else if (node.m_rid >= 0)
{
// this is a rigid body node
FERigidBody& RB = *fem.GetRigidBody(node.m_rid);
// get the relative position
vec3d a = node.m_rt - RB.m_rt;
int* lm = RB.m_LM;
if (dof == m_dofU[0])
{
if (lm[0] >= 0) R[lm[0]] += f;
if (lm[4] >= 0) R[lm[4]] += a.z*f;
if (lm[5] >= 0) R[lm[5]] += -a.y*f;
}
else if (dof == m_dofU[1])
{
if (lm[1] >= 0) R[lm[1]] += f;
if (lm[3] >= 0) R[lm[3]] += -a.z*f;
if (lm[5] >= 0) R[lm[5]] += a.x*f;
}
else if (dof == m_dofU[2])
{
if (lm[2] >= 0) R[lm[2]] += f;
if (lm[3] >= 0) R[lm[3]] += a.y*f;
if (lm[4] >= 0) R[lm[4]] += -a.x*f;
}
}
}
//-----------------------------------------------------------------------------
//! Updates the rigid body data
void FECGSolidSolver::UpdateRigidBodies(vector<double>& ui)
{
// get the number of rigid bodies
FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel());
const int NRB = fem.RigidBodies();
// first calculate the rigid body displacement increments
for (int i = 0; i<NRB; ++i)
{
// get the rigid body
FERigidBody& RB = *fem.GetRigidBody(i);
int *lm = RB.m_LM;
double* du = RB.m_du;
if (RB.m_prb == 0)
{
for (int j = 0; j<6; ++j)
{
du[j] = (lm[j] >= 0 ? m_Ui[lm[j]] + ui[lm[j]] : 0);
}
}
}
// for prescribed displacements, the displacement increments are evaluated differently
// TODO: Is this really necessary? Why can't the ui vector contain the correct values?
for (int i = 0; i < NRB; ++i)
{
FERigidBody& RB = *fem.GetRigidBody(i);
if (RB.m_prb == nullptr)
{
for (int j = 0; j < 6; ++j)
{
FERigidPrescribedBC* dc = RB.m_pDC[j];
if (dc)
{
int I = dc->GetBC();
RB.m_du[I] = dc->Value() - RB.m_Up[I];
}
}
}
}
// update the rigid bodies
for (int i = 0; i<NRB; ++i)
{
// get the rigid body
FERigidBody& RB = *fem.GetRigidBody(i);
double* du = RB.m_du;
// This is the "new" update algorithm which addressesses a couple issues
// with the old method, namely that prescribed rotational dofs aren't update correctly.
// Unfortunately, it seems to produce worse convergence in some cases, especially with line search
// and it doesn't work when rigid bodies are used in a hierarchy
if (RB.m_prb) du = RB.m_dul;
RB.m_Ut[0] = RB.m_Up[0] + du[0];
RB.m_Ut[1] = RB.m_Up[1] + du[1];
RB.m_Ut[2] = RB.m_Up[2] + du[2];
RB.m_Ut[3] = RB.m_Up[3] + du[3];
RB.m_Ut[4] = RB.m_Up[4] + du[4];
RB.m_Ut[5] = RB.m_Up[5] + du[5];
RB.m_rt = RB.m_r0 + vec3d(RB.m_Ut[0], RB.m_Ut[1], RB.m_Ut[2]);
vec3d Rt(RB.m_Ut[3], RB.m_Ut[4], RB.m_Ut[5]);
RB.SetRotation(quatd(Rt));
}
// we need to update the position of rigid nodes
fem.UpdateRigidMesh();
// Since the rigid nodes are repositioned we need to update the displacement DOFS
FEMesh& mesh = fem.GetMesh();
int N = mesh.Nodes();
for (int i=0; i<N; ++i)
{
FENode& node = mesh.Node(i);
if (node.m_rid >= 0)
{
vec3d ut = node.m_rt - node.m_r0;
node.set_vec3d(m_dofU[0], m_dofU[1], m_dofU[2], ut);
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FELinearTrussDomain.h | .h | 3,566 | 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 <FECore/FETrussDomain.h>
#include "FEElasticDomain.h"
#include "FETrussMaterial.h"
#include <FECore/FEDofList.h>
#include "febiomech_api.h"
//-----------------------------------------------------------------------------
//! Domain described by 3D truss elements
class FEBIOMECH_API FELinearTrussDomain : public FETrussDomain, public FEElasticDomain
{
public:
//! Constructor
FELinearTrussDomain(FEModel* pfem);
//! Initialize data
bool Init() override;
//! Reset data
void Reset() override;
//! Initialize elements
void PreSolveUpdate(const FETimeInfo& timeInfo) override;
//! Unpack truss element data
void UnpackLM(FEElement& el, vector<int>& lm) override;
//! get the material
FEMaterial* GetMaterial() override { return m_pMat; }
//! set the material
void SetMaterial(FEMaterial* pmat) override;
//! Activate domain
void Activate() override;
//! get the dof list
const FEDofList& GetDOFList() const override;
public: // overloads from FEElasticDomain
//! update the truss stresses
void Update(const FETimeInfo& tp) override;
//! internal stress forces
void InternalForces(FEGlobalVector& R) override;
//! calculate body force
void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override;
//! Calculates inertial forces for dynamic problems
void InertialForces(FEGlobalVector& R, vector<double>& F) override;
//! calculates the global stiffness matrix for this domain
void StiffnessMatrix(FELinearSystem& LS) override;
//! intertial stiffness matrix
void MassMatrix(FELinearSystem& LS, double scale) override;
//! body force stiffness matrix
void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override;
//! elemental mass matrix
void ElementMassMatrix(FETrussElement& el, matrix& ke);
protected:
//! calculates the truss element stiffness matrix
void ElementStiffness(FETrussElement&, matrix& ke);
//! Calculates the internal stress vector for truss elements
void ElementInternalForces(FETrussElement& el, vector<double>& fe);
//! Calculates the inertial contribution for truss elements
void ElementInertialForces(FETrussElement& el, vector<double>& fe);
protected:
FETrussMaterial* m_pMat;
double m_a0;
FEDofList m_dofU;
FEDofList m_dofV;
FEDofList m_dofR;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEElasticMaterialPoint.h | .h | 3,376 | 104 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMaterialPoint.h>
#include <FECore/tens4d.h>
#include <FECore/FEMaterialPointProperty.h>
#include "febiomech_api.h"
//-----------------------------------------------------------------------------
//! This class defines material point data for elastic materials.
class FEBIOMECH_API FEElasticMaterialPoint : public FEMaterialPointData
{
public:
//! constructor
FEElasticMaterialPoint(FEMaterialPointData* mp = nullptr);
//! Initialize material point data
void Init() override;
//! create a shallow copy
FEMaterialPointData* Copy() override;
//! serialize material point data
void Serialize(DumpStream& ar) override;
public:
mat3ds Strain() const;
mat3ds SmallStrain() const;
mat3ds AlmansiStrain() const;
mat3ds RightCauchyGreen() const;
mat3ds LeftCauchyGreen () const;
mat3ds DevRightCauchyGreen() const;
mat3ds DevLeftCauchyGreen () const;
mat3ds RightStretch() const;
mat3ds LeftStretch () const;
mat3ds RightStretchInverse() const;
mat3ds LeftStretchInverse () const;
mat3ds RightHencky() const;
mat3ds LeftHencky () const;
mat3d Rotation() const;
mat3ds RateOfDeformation() const { return m_L.sym(); }
mat3ds pull_back(const mat3ds& A) const;
mat3ds push_forward(const mat3ds& A) const;
tens4ds pull_back(const tens4ds& C) const;
tens4ds push_forward(const tens4ds& C) const;
public:
bool m_buncoupled; //!< set to true if this material point was created by an uncoupled material
// deformation data at intermediate time
mat3d m_F; //!< deformation gradient
double m_J; //!< determinant of F
vec3d m_v; //!< velocity
vec3d m_a; //!< acceleration
mat3d m_L; //!< spatial velocity gradient
// solid material data
mat3ds m_s; //!< Cauchy stress
// uncoupled pressure
double m_p; //!< only for uncoupled materials
// current time data
double m_Wt; //!< strain energy density at current time
// previous time data
double m_Wp; //!< strain energy density
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FECoupledMooneyRivlin.cpp | .cpp | 3,951 | 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.*/
#include "stdafx.h"
#include "FECoupledMooneyRivlin.h"
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FECoupledMooneyRivlin, FEElasticMaterial)
ADD_PARAMETER(m_c1, FE_RANGE_GREATER(0.0), "c1")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_c2, "c2")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_K , FE_RANGE_GREATER(0.0), "k" )->setUnits(UNIT_PRESSURE);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! calculate stress at material point
mat3ds FECoupledMooneyRivlin::Stress(FEMaterialPoint& mp)
{
// get the elastic material point data
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// determinant of deformation gradient
double J = pt.m_J;
// calculate left Cauchy-Green tensor
mat3ds B = pt.LeftCauchyGreen();
// calculate square of B
mat3ds B2 = B.sqr();
// Invariants of B (= invariants of C)
double I1 = B.tr();
// identity tensor
mat3dd I(1.0);
// calculate stress
return (B*(m_c1+I1*m_c2) - B2*m_c2 - I*(m_c1+2.0*m_c2))*(2.0/J) + I*(m_K*log(J)/J);
}
//-----------------------------------------------------------------------------
//! calculate tangent at material point
tens4ds FECoupledMooneyRivlin::Tangent(FEMaterialPoint& mp)
{
// get material point data
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// calculate left Cauchy-Green tensor: B = F*Ft
mat3ds B = pt.LeftCauchyGreen();
// Invariants of B (= invariants of C)
double J = pt.m_J;
// some useful tensors
mat3dd I(1.0);
tens4ds IxI = dyad1s(I);
tens4ds IoI = dyad4s(I);
tens4ds BxB = dyad1s(B);
tens4ds BoB = dyad4s(B);
// strain energy derivates
double W2 = m_c2;
// spatial tangent
tens4ds c = BxB*(4.0*W2/J) - BoB*(4.0*W2/J) + IoI*(4.0*(m_c1+2.0*m_c2)/J) + IxI*(m_K/J) - IoI*(2.0*m_K*log(J)/J);
return c;
}
//-----------------------------------------------------------------------------
//! calculate strain energy density at material point
double FECoupledMooneyRivlin::StrainEnergyDensity(FEMaterialPoint& mp)
{
// get the elastic material point data
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// determinant of deformation gradient
double J = pt.m_J;
double lnJ = log(J);
// calculate left Cauchy-Green tensor
mat3ds B = pt.LeftCauchyGreen();
// calculate square of B
mat3ds B2 = B.sqr();
// Invariants of B (= invariants of C)
double I1 = B.tr();
double I2 = (I1*I1 - B2.tr())/2.;
double sed = m_c1*(I1-3) + m_c2*(I2-3)
- 2*(m_c1+2*m_c2)*lnJ + m_K*lnJ*lnJ/2.;
return sed;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEEFDUncoupled.h | .h | 2,031 | 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 "FEUncoupledMaterial.h"
//-----------------------------------------------------------------------------
//! Material class for the uncoupled ellipsoidal fiber distribution
class FEEFDUncoupled : public FEUncoupledMaterial
{
public:
FEEFDUncoupled(FEModel* pfem);
//! deviatoric Cauchy stress
mat3ds DevStress(FEMaterialPoint& pt) override;
//! deviatoric spatial tangent
tens4ds DevTangent(FEMaterialPoint& pt) override;
//! calculate deviatoric strain energy density
double DevStrainEnergyDensity(FEMaterialPoint& mp) override;
public:
FEParamDouble m_beta[3]; // power in power-law relation
FEParamDouble m_ksi[3]; // coefficient in power-law relation
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEElasticBeamDomain.cpp | .cpp | 19,511 | 771 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEElasticBeamDomain.h"
#include <FECore/FELinearSystem.h>
#include "FEElasticBeamMaterial.h"
#include "FEBioMech.h"
#include "FEBodyForce.h"
#include <FECore/FEMesh.h>
#include <FECore/FEModel.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FESolver.h>
#include <FECore/fecore_debug.h>
FEElasticBeamDomain::FEElasticBeamDomain(FEModel* fem) : FEBeamDomain(fem), FEElasticDomain(fem),
m_dofs(fem), m_dofQ(fem), m_dofV(fem), m_dofW(fem), m_dofA(fem)
{
m_mat = nullptr;
if (fem)
{
m_dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT));
m_dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::ROTATION));
m_dofQ.AddVariable(FEBioMech::GetVariableName(FEBioMech::ROTATION));
m_dofV.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY));
m_dofW.AddVariable(FEBioMech::GetVariableName(FEBioMech::BEAM_ANGULAR_VELOCITY));
m_dofA.AddVariable(FEBioMech::GetVariableName(FEBioMech::BEAM_ANGULAR_ACCELERATION));
}
}
// return number of beam elements
int FEElasticBeamDomain::Elements() const
{
return (int)m_Elem.size();
}
//! return a reference to an element
FEElement& FEElasticBeamDomain::ElementRef(int i) { return m_Elem[i]; }
const FEElement& FEElasticBeamDomain::ElementRef(int i) const { return m_Elem[i]; }
FEBeamElement& FEElasticBeamDomain::Element(int i) { return m_Elem[i]; }
// create function
bool FEElasticBeamDomain::Create(int elements, FE_Element_Spec espec)
{
m_Elem.resize(elements);
for (int i = 0; i < elements; ++i)
{
FEBeamElement& el = m_Elem[i];
el.SetLocalID(i);
el.SetMeshPartition(this);
}
// set element type
int etype = (espec.eshape == ET_LINE3 ? FE_BEAM3G2 : FE_BEAM2G2);
ForEachElement([=](FEElement& el) { el.SetType(etype); });
return true;
}
bool FEElasticBeamDomain::Init()
{
if (FEBeamDomain::Init() == false) return false;
// initialize elements
for (int i = 0; i < Elements(); ++i)
{
FEBeamElement& el = m_Elem[i];
vec3d r0[FEElement::MAX_NODES];
int ne = el.Nodes();
for (int j = 0; j < ne; ++j) r0[j] = Node(el.m_lnode[j]).m_r0;
// NOTE: This assumes the beam is initially straight!
// This also assumes that nodes 0 and 1 define the boundary nodes.
el.m_L0 = (r0[1] - r0[0]).Length();
// construct beam coordinate system
vec3d E3 = r0[1] - r0[0]; E3.Normalize();
vec3d E1, E2;
if (fabs(E3 * vec3d(1, 0, 0)) > 0.5) E2 = E3 ^ vec3d(0, 1, 0);
else E2 = E3 ^ vec3d(1,0,0);
E2.Normalize();
E1 = E2 ^ E3;
el.m_E = mat3d(E1, E2, E3);
}
return true;
}
//! Get the list of dofs on this domain
const FEDofList& FEElasticBeamDomain::GetDOFList() const
{
return m_dofs;
}
void FEElasticBeamDomain::SetMaterial(FEMaterial* pm)
{
FEDomain::SetMaterial(pm);
m_mat = dynamic_cast<FEElasticBeamMaterial*>(pm);
assert(m_mat);
}
FEMaterial* FEElasticBeamDomain::GetMaterial()
{
return m_mat;
}
void FEElasticBeamDomain::PreSolveUpdate(const FETimeInfo& tp)
{
for (int iel = 0; iel < Elements(); ++iel)
{
FEBeamElement& el = Element(iel);
if (el.isActive())
{
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n) el.GetMaterialPoint(n)->Update(tp);
}
}
}
//! calculate the internal forces
void FEElasticBeamDomain::InternalForces(FEGlobalVector& R)
{
for (int iel = 0; iel < Elements(); ++iel)
{
FEBeamElement& el = Element(iel);
int ne = el.Nodes();
int ndof = ne * 6;
vector<double> fe(ndof, 0.0);
ElementInternalForces(el, fe);
vector<int> lm(6*ne);
UnpackLM(el, lm);
R.Assemble(lm, fe);
}
}
void FEElasticBeamDomain::ElementInternalForces(FEBeamElement& el, std::vector<double>& fe)
{
// reference length of beam
double L0 = el.m_L0;
// loop over integration points
int nint = el.GaussPoints();
int ne = el.Nodes();
double* w = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
// shape functions
double* H = el.H(n);
double* Hr = el.Hr(n);
// get stress from beam element
vec3d t = mp.m_t; // stress
vec3d m = mp.m_m; // moment
vec3d G0 = mp.m_G0; // = dphi_0/dS
mat3da S(G0); // skew-symmetric matrix from Grad (TODO: check sign!)
// J = dS / dr
double J = L0 / 2.0;
// shape function derivative (at integration point)
double G[FEElement::MAX_NODES];
for (int i = 0; i < ne; ++i) G[i] = Hr[i] / J;
double wJ = w[n] * J;
for (int i = 0; i < ne; ++i)
{
// build ksi matrix
mat3dd I(1.0);
matrix ksi(6, 6); ksi.zero();
ksi.add(0, 0, (I * G[i]));
ksi.add(3, 3, (I * G[i]));
ksi.add(3, 0, (-S * H[i]));
vector<double> R{ t.x, t.y, t.z, m.x, m.y, m.z };
vector<double> P(6);
P = ksi * R;
// assemble
// note the negative sign: this is because we need to subtract
// the internal forces from the external forces.
for (int j = 0; j < 6; ++j) fe[i * 6 + j] -= P[j] * wJ;
}
}
}
//! Calculate global stiffness matrix
void FEElasticBeamDomain::StiffnessMatrix(FELinearSystem& LS)
{
for (int iel = 0; iel < Elements(); ++iel)
{
FEBeamElement& el = Element(iel);
int ne = el.Nodes();
int ndof = ne * 6;
vector<int> lm;
UnpackLM(el, lm);
FEElementMatrix ke(el, lm); ke.zero();
ElementStiffnessMatrix(el, ke);
LS.Assemble(ke);
}
}
void FEElasticBeamDomain::ElementStiffnessMatrix(FEBeamElement& el, FEElementMatrix& ke)
{
// reference length of beam
double L0 = el.m_L0;
// loop over integration points
int nint = el.GaussPoints();
int ne = el.Nodes();
double* w = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
// copy local coordinate system (Probably don't need to do this every time)
mp.m_Q = el.m_E;
// get stress from beam element
vec3d t = mp.m_t; // stress traction
vec3d m = mp.m_m; // moment
mat3da St(t);
mat3da Sm(m);
// shape functions
double* H = el.H(n);
double* Hr = el.Hr(n);
// J = dS / dr
double J = L0 / 2.0;
// shape function derivative (at integration point)
double G[FEElement::MAX_NODES];
for (int i = 0; i < ne; ++i) G[i] = Hr[i] / J;
double wJ = w[n] * J;
vec3d G0 = mp.m_G0; // = dphi_0/dS
mat3da S(G0); // skew-symmetric matrix from Grad (TODO: check sign!)
for (int a = 0; a < ne; ++a)
for (int b = 0; b < ne; ++b)
{
// build ksi matrix
mat3dd I(1.0);
matrix ksi_a(6, 6); ksi_a.zero();
matrix ksi_bT(6, 6); ksi_bT.zero();
ksi_a.add(0, 0, (I * G[a]));
ksi_a.add(3, 3, (I * G[a]));
ksi_a.add(3, 0, (-S * H[a]));
// we assemble the transpose for b
ksi_bT.add(0, 0, (I * G[b]));
ksi_bT.add(3, 3, (I * G[b]));
ksi_bT.add(0, 3, (S * H[b]));
// spatial tangent
matrix c(6, 6);
m_mat->Tangent(mp, c);
// material stiffness
matrix Se(6, 6);
Se = ksi_a * c * ksi_bT;
// geometrical stiffness
mat3d P = (t & G0) - I * (t * G0);
matrix Te(6, 6); Te.zero();
Te.add(0, 3, (-St * (G[a] * H[b])));
Te.add(3, 0, (St * (H[a] * G[b])));
Te.add(3, 3, P * (H[a] * H[b]) - Sm*(G[a]*H[b]) );
// assemble into ke
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 6; ++j)
{
ke[6 * a + i][6 * b + j] += (Se(i, j) + Te(i, j)) * wJ;
}
}
}
}
void FEElasticBeamDomain::IncrementalUpdate(std::vector<double>& ui, bool finalFlag)
{
// We need this for the incremental update of prescribed rotational dofs
int niter = GetFEModel()->GetCurrentStep()->GetFESolver()->m_niter;
// update the rotations at the material points
for (int i = 0; i < Elements(); ++i)
{
FEBeamElement& el = Element(i);
int ne = el.Nodes();
int ni = el.GaussPoints();
// initial length
double L0 = el.m_L0;
double J = L0 / 2.0;
// get the nodal values of the incremental rotations
// NOTE: The ui vector does not contain the prescribed displacement updates!!
vector<vec3d> dri(ne);
for (int j = 0; j < ne; ++j)
{
FENode& node = Node(el.m_lnode[j]);
std::vector<int>& id = node.m_ID;
int eq[3] = { id[m_dofs[3]], id[m_dofs[4]], id[m_dofs[5]] };
vec3d d(0, 0, 0);
if (eq[0] >= 0) d.x = ui[eq[0]];
if (eq[1] >= 0) d.y = ui[eq[1]];
if (eq[2] >= 0) d.z = ui[eq[2]];
// for prescribed nodes, determine the rotation increment
if ((eq[0] < 0) && (eq[1] < 0) && (eq[2] < 0))
{
if (niter == 0)
{
vec3d Rp, Rt;
int n;
n = -eq[0] - 1; if (n >= 0) { Rt.x = node.get(m_dofs[3]); Rp.x = node.get_prev(m_dofs[3]); }
n = -eq[1] - 1; if (n >= 0) { Rt.y = node.get(m_dofs[4]); Rp.y = node.get_prev(m_dofs[4]); }
n = -eq[2] - 1; if (n >= 0) { Rt.z = node.get(m_dofs[5]); Rp.z = node.get_prev(m_dofs[5]); }
quatd Qp(Rp), Qt(Rt);
quatd dQ = Qp.Conjugate() * Qt;
d = dQ.GetRotationVector();
}
}
dri[j] = d;
}
// evaluate at integration points
for (int n = 0; n < ni; ++n)
{
// get the material point
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
// evaluate at integration point
vec3d dr = el.Evaluate(&dri[0], n);
// use shape function derivatives
double* Hr = el.Hr(n);
vec3d drdS(0, 0, 0);
for (int a = 0; a < ne; ++a) drdS += dri[a] * (Hr[a] / J);
// calculate exponential map
mat3d dR; dR.exp(dr);
// extract quaternion
quatd dq(dR);
// update rotations
mp.m_Rt = (dq*mp.m_Ri) * mp.m_Rp;
// update spatial curvature
mat3da Wn(mp.m_kn);
mat3d W = dR * Wn * dR.transpose(); // this should be a skew-symmetric matrix!
vec3d w2(-W[1][2], W[0][2], -W[0][1]);
double g1 = 1, g2 = 1;
double a = dr.norm();
if (a != 0)
{
g1 = sin(a) / a;
g2 = sin(0.5 * a) / (0.5 * a);
}
vec3d e(dr); e.unit();
vec3d w1 = drdS*g1 + e*((1.0 - g1)*(e*drdS)) + (dr ^ drdS)*(0.5*g2*g2);
// update curvature
mp.m_k = w1 + w2;
if (finalFlag)
{
mp.m_Ri = dq * mp.m_Ri;
mp.m_kn = mp.m_k;
}
}
}
}
void FEElasticBeamDomain::Update(const FETimeInfo& tp)
{
int NE = Elements();
for (int i = 0; i < NE; ++i)
{
FEBeamElement& el = Element(i);
UpdateElement(el);
}
}
void FEElasticBeamDomain::UpdateElement(FEBeamElement& el)
{
// get the nodal positions
constexpr int NMAX = FEElement::MAX_NODES;
vec3d rt[NMAX], vt[NMAX], at[NMAX], wt[NMAX], alt[NMAX];
int ne = el.Nodes();
for (int i = 0; i < ne; ++i)
{
FENode& node = Node(el.m_lnode[i]);
rt[i] = node.m_rt;
vt[i] = node.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]);
at[i] = node.m_at;
wt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
alt[i] = node.get_vec3d(m_dofA[0], m_dofA[1], m_dofA[2]);
}
// initial length
double L0 = el.m_L0;
double J = L0 / 2;
FEElasticBeamMaterial& mat = *m_mat;
double rho = mat.m_density;
double A_rho = mat.m_A * rho;
double I1 = rho * mat.m_I1;
double I2 = rho * mat.m_I2;
double I3 = I1 + I2;
vec3d E1 = el.m_E.col(0);
vec3d E2 = el.m_E.col(1);
vec3d E3 = el.m_E.col(2);
mat3d I0 = (E1 & E1)*I1 + (E2 & E2)*I2 + (E3 & E3) * I3; // material inertia tensor
// loop over all integration points
int nint = el.GaussPoints();
for (int n = 0; n < nint; ++n)
{
// get the material point
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
// update quantities for dynamics
mp.m_vt = el.Evaluate(vt, n);
mp.m_at = el.Evaluate(at, n);
mp.m_dpt = mp.m_at * A_rho;
// (spatial) rotational quantities
vec3d w = el.Evaluate(wt, n);
vec3d al = el.Evaluate(alt, n);
mp.m_wt = w;
mp.m_alt = al;
// calculate the spatial inertia tensor
mat3d R = mp.m_Rt.RotationMatrix();
mat3d I = R * I0 * R.transpose();
// calculate rate of angular momentum
mp.m_dht = I * al + (w ^ (I * w));
// evaluate G0 = dphi0/dS
double* Hr = el.Hr(n);
vec3d G0(0, 0, 0);
for (int a = 0; a < ne; ++a)
{
G0 += rt[a] * (Hr[a] / J);
}
// update G0 = dphi0/dS
mp.m_G0 = G0;
quatd q = mp.m_Rt;
quatd qi = q.Conjugate();
// calculate material strain measures
mp.m_Gamma = qi * G0 - E3;
mp.m_Kappa = qi * mp.m_k; // m_k is updated in IncrementalUpdate(std::vector<double>& ui)
// evaluate the (spatial) stress
mp.m_Q = el.m_E;
m_mat->Stress(mp);
}
}
//! Calculates the inertial forces (for dynamic problems)
void FEElasticBeamDomain::InertialForces(FEGlobalVector& R, std::vector<double>& F)
{
for (auto& el : m_Elem)
{
int neln = el.Nodes();
vector<double> fe(6 * neln, 0.0);
ElementInertialForce(el, fe);
vector<int> lm(6 * neln);
UnpackLM(el, lm);
R.Assemble(lm, fe);
}
}
void FEElasticBeamDomain::ElementInertialForce(FEBeamElement& el, std::vector<double>& fe)
{
int nint = el.GaussPoints();
int neln = el.Nodes();
double* gw = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
double* H = el.H(n);
double J = el.m_L0 / 2.0;
double Jw = J * gw[n];
vec3d dp = mp.m_dpt;
vec3d dh = mp.m_dht;
for (int i = 0; i < neln; ++i)
{
fe[6*i ] -= H[i]*dp.x*Jw;
fe[6*i + 1] -= H[i]*dp.y*Jw;
fe[6*i + 2] -= H[i]*dp.z*Jw;
fe[6*i + 3] -= H[i]*dh.x*Jw;
fe[6*i + 4] -= H[i]*dh.y*Jw;
fe[6*i + 5] -= H[i]*dh.z*Jw;
}
}
}
//! Calculates the mass matrix (for dynamic problems)
void FEElasticBeamDomain::MassMatrix(FELinearSystem& LS, double scale)
{
for (auto& el : m_Elem)
{
int neln = el.Nodes();
FEElementMatrix ke(6 * neln, 6 * neln); ke.zero();
ElementMassMatrix(el, ke);
vector<int> lm(6 * neln);
UnpackLM(el, lm);
ke.SetIndices(lm);
ke.SetNodes(el.m_node);
LS.Assemble(ke);
}
}
// tanx = tan(x)/x
double tanx(double x)
{
double r = (fabs(x) < 1e-9 ? 1.0 : tan(x) / x);
return r;
}
void FEElasticBeamDomain::ElementMassMatrix(FEBeamElement& el, FEElementMatrix& ke)
{
int nint = el.GaussPoints();
int neln = el.Nodes();
double* gw = el.GaussWeights();
FEElasticBeamMaterial& mat = *m_mat;
double rho = mat.m_density;
double A_rho = mat.m_A * rho;
double I1 = rho * mat.m_I1;
double I2 = rho * mat.m_I2;
double I3 = I1 + I2;
vec3d E1 = el.m_E.col(0);
vec3d E2 = el.m_E.col(1);
vec3d E3 = el.m_E.col(2);
mat3d I0 = (E1 & E1) * I1 + (E2 & E2) * I2 + (E3 & E3) * I3; // material inertia tensor
FETimeInfo& ti = GetFEModel()->GetTime();
double h = ti.timeIncrement;
double b = ti.beta;
double g = ti.gamma;
double h2bi = 1.0 / (h * h * b);
double hg = h * g;
// When evaluating at time 0 (to determine initial accelerations), we need
// to make a minor change.
if (ti.currentTime == 0.0) { h2bi = hg = 1.0; }
for (int n = 0; n < nint; ++n)
{
FEElasticBeamMaterialPoint& mp = *(el.GetMaterialPoint(n)->ExtractData<FEElasticBeamMaterialPoint>());
vec3d ri = mp.m_Ri.GetRotationVector();
vec3d e = ri.Normalized();
double th = ri.norm();
mat3da ts(ri);
mat3dd I(1.0);
mat3ds exe = dyad(e);
mat3d T = exe + (I - exe)*(1.0/tanx(th*0.5)) - ts*0.5;
double* H = el.H(n);
double J = el.m_L0 / 2.0;
double Jw = J * gw[n];
mat3d Rt = mp.m_Rt.RotationMatrix();
mat3d Rp = mp.m_Rp.RotationMatrix();
vec3d Wt = Rt.transpose() * mp.m_wt;
vec3d At = Rt.transpose() * mp.m_alt;
mat3da W_hat(Wt);
mat3da Hs(I0 * At + (Wt ^ (I0 * Wt)));
mat3da IW(I0 * Wt);
double M11 = A_rho * Jw * h2bi;
mat3d M22 = (-Rt * Hs + Rt * (I0 - IW * hg + (W_hat * I0) * hg)*h2bi)* Rp.transpose()* T;
for (int i=0; i<neln; ++i)
for (int j = 0; j < neln; ++j)
{
mat3d m1; m1.zero();
m1[0][0] = M11 * H[i] * H[j];
m1[1][1] = M11 * H[i] * H[j];
m1[2][2] = M11 * H[i] * H[j];
mat3d m2;
m2 = M22 * (H[i] * H[j] * Jw);
int I = 6*i, J = 6*j;
ke.add(I, J, m1);
ke.add(I + 3, J + 3, m2);
}
}
}
void FEElasticBeamDomain::BodyForce(FEGlobalVector& R, FEBodyForce& bf)
{
for (int iel = 0; iel < Elements(); ++iel)
{
FEBeamElement& el = Element(iel);
int ne = el.Nodes();
int ndof = ne * 6;
vector<double> fe(ndof, 0.0);
ElementBodyForce(el, fe, bf);
vector<int> lm(6 * ne);
UnpackLM(el, lm);
R.Assemble(lm, fe);
}
}
void FEElasticBeamDomain::ElementBodyForce(FEBeamElement& el, std::vector<double>& fe, FEBodyForce& bf)
{
// reference length of beam
double L0 = el.m_L0;
FEElasticBeamMaterial& mat = *m_mat;
double rho = mat.m_density;
double A_rho = mat.m_A * rho;
// loop over integration points
int nint = el.GaussPoints();
int ne = el.Nodes();
double* w = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEElasticBeamMaterialPoint& ebm = *(mp.ExtractData<FEElasticBeamMaterialPoint>());
// shape functions
double* H = el.H(n);
// J = dS / dr
double J = L0 / 2.0;
double wJA = w[n] * J * A_rho;
vec3d fn = bf.force(mp);
for (int i = 0; i < ne; ++i)
{
fe[i * 6 ] += H[i] * fn.x * wJA;
fe[i * 6 + 1] += H[i] * fn.y * wJA;
fe[i * 6 + 2] += H[i] * fn.z * wJA;
}
}
}
void FEElasticBeamDomain::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf)
{
for (int iel = 0; iel < Elements(); ++iel)
{
FEBeamElement& el = Element(iel);
int ne = el.Nodes();
int ndof = ne * 6;
FEElementMatrix ke(ndof, ndof);
ke.zero();
ElementBodyForceStiffness(el, ke, bf);
vector<int> lm(ndof);
UnpackLM(el, lm);
ke.SetIndices(lm);
LS.Assemble(ke);
}
}
void FEElasticBeamDomain::ElementBodyForceStiffness(FEBeamElement& el, FEElementMatrix& ke, FEBodyForce& bf)
{
// reference length of beam
double L0 = el.m_L0;
FEElasticBeamMaterial& mat = *m_mat;
double rho = mat.m_density;
double A_rho = mat.m_A * rho;
// loop over integration points
int nint = el.GaussPoints();
int ne = el.Nodes();
double* w = el.GaussWeights();
for (int n = 0; n < nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEElasticBeamMaterialPoint& ebm = *(mp.ExtractData<FEElasticBeamMaterialPoint>());
// shape functions
double* H = el.H(n);
// J = dS / dr
double J = L0 / 2.0;
double wJA = w[n] * J * A_rho;
mat3d k = bf.stiffness(mp);
for (int a = 0; a < ne; ++a)
for (int b = 0; b < ne; ++b)
{
for (int i=0; i<3; ++i)
for (int j = 0; j < 3; ++j)
{
ke(a * 6 + i, b * 6 + j) -= H[a] * k[i][j] * H[b] * wJA;
}
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEMassDamping.h | .h | 1,776 | 48 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FEBioMech/FEBodyForce.h>
class FEMassDamping : public FEBodyForce
{
public:
FEMassDamping(FEModel* fem);
//! calculate the body force at a material point
vec3d force(FEMaterialPoint& pt) override;
//! calculate the divergence of the body force at a material point
double divforce(FEMaterialPoint& pt) override;
//! calculate constribution to stiffness matrix
mat3d stiffness(FEMaterialPoint& pt) override;
private:
double m_C;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FERigidBody.cpp | .cpp | 11,057 | 401 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FERigidBody.h"
#include <FECore/FEMaterial.h>
#include <FECore/FESolidDomain.h>
#include <FECore/FEModel.h>
#include "RigidBC.h"
#include "FERigidMaterial.h"
#include "FERigidSolidDomain.h"
#include "FERigidShellDomain.h"
#include <FECore/log.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FERigidBody, FECoreBase)
ADD_PARAMETER(m_Fr.x, "Fx");
ADD_PARAMETER(m_Fr.y, "Fy");
ADD_PARAMETER(m_Fr.z, "Fz");
ADD_PARAMETER(m_Mr.x, "Mx");
ADD_PARAMETER(m_Mr.y, "My");
ADD_PARAMETER(m_Mr.z, "Mz");
ADD_PARAMETER(m_euler, "euler");
ADD_PARAMETER(m_r0, "initial_position");
ADD_PARAMETER(m_rt, "position");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FERigidBody::FERigidBody(FEModel* pfem) : FECoreBase(pfem)
{
m_bpofr = false;
for (int i=0; i<6; ++i)
{
m_pDC[i] = 0;
m_LM[i] = -1;
m_BC[i] = DOF_OPEN;
}
m_prb = 0;
// zero total displacements
m_Ut[0] = m_Up[0] = 0;
m_Ut[1] = m_Up[1] = 0;
m_Ut[2] = m_Up[2] = 0;
m_Ut[3] = m_Up[3] = 0;
m_Ut[4] = m_Up[4] = 0;
m_Ut[5] = m_Up[5] = 0;
// initialize velocity and acceleration of center of mass
m_vt = m_at = vec3d(0,0,0);
// initialize orientation
m_qt = quatd(0, vec3d(0,0,1));
m_euler = vec3d(0,0,0);
// initialize angular velocity and acceleration
m_wt = m_alt = vec3d(0,0,0);
// initialize reaction forces
m_Fr = m_Fp = vec3d(0,0,0);
m_Mr = m_Mp = vec3d(0,0,0);
}
//-----------------------------------------------------------------------------
FERigidBody::~FERigidBody()
{
}
//-----------------------------------------------------------------------------
//! Reset rigid body data (called from FEM::Reset)
void FERigidBody::Reset()
{
// zero total displacements
m_Ut[0] = m_Up[0] = 0;
m_Ut[1] = m_Up[1] = 0;
m_Ut[2] = m_Up[2] = 0;
m_Ut[3] = m_Up[3] = 0;
m_Ut[4] = m_Up[4] = 0;
m_Ut[5] = m_Up[5] = 0;
// initialize velocity and acceleration of center of mass
m_vp = m_vt = vec3d(0,0,0);
m_ap = m_at = vec3d(0,0,0);
// initialize orientation
m_qp = m_qt = quatd(0, vec3d(0,0,1));
m_euler = vec3d(0,0,0);
// initialize angular velocity and acceleration
m_wp = m_wt = vec3d(0,0,0);
m_alp = m_alt = vec3d(0,0,0);
// initialize angular momentum and its time rate of change
m_hp = m_ht = vec3d(0,0,0);
m_dhp = m_dht = vec3d(0,0,0);
// initialize center of mass
m_rt = m_r0;
// reset reaction force and torque
m_Fr = vec3d(0,0,0);
m_Mr = vec3d(0,0,0);
}
//-----------------------------------------------------------------------------
//! This function is called at the start of each time step and is used to update
//! some variables.
bool FERigidBody::Init()
{
// clear reaction forces
m_Fr = m_Mr = vec3d(0,0,0);
// store previous state
m_rp = m_rt;
m_vp = m_vt;
m_ap = m_at;
m_qp = m_qt;
m_wp = m_wt;
m_alp = m_alt;
m_hp = m_ht;
m_dhp = m_dht;
m_Up[0] = m_Ut[0];
m_Up[1] = m_Ut[1];
m_Up[2] = m_Ut[2];
m_Up[3] = m_Ut[3];
m_Up[4] = m_Ut[4];
m_Up[5] = m_Ut[5];
// zero incremental displacements
m_du[0] = m_dul[0] = 0.0;
m_du[1] = m_dul[1] = 0.0;
m_du[2] = m_dul[2] = 0.0;
m_du[3] = m_dul[3] = 0.0;
m_du[4] = m_dul[4] = 0.0;
m_du[5] = m_dul[5] = 0.0;
return true;
}
//-----------------------------------------------------------------------------
//! Set the rigid body's center of mass directly
void FERigidBody::SetCOM(vec3d rc)
{
m_r0 = m_rp = m_rt = rc;
}
//-----------------------------------------------------------------------------
//! Update the mass of the rigid body
void FERigidBody::UpdateMass()
{
// total mass of rigid body
m_mass = 0;
// loop over all domains
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
for (int nd = 0; nd < mesh.Domains(); ++nd)
{
FEDomain& dom = mesh.Domain(nd);
FERigidMaterial* pm = dynamic_cast<FERigidMaterial*>(dom.GetMaterial());
if (pm && (pm->GetRigidBodyID() == m_nID))
{
FERigidSolidDomain* pbd = dynamic_cast<FERigidSolidDomain*>(&dom);
if (pbd) m_mass += pbd->CalculateMass();
FERigidShellDomain* psd = dynamic_cast<FERigidShellDomain*>(&dom);
if (psd) m_mass += psd->CalculateMass();
}
}
if (m_mass == 0)
{
feLogWarning("Zero mass for rigid body \"%s.\"", GetName().c_str());
}
}
//-----------------------------------------------------------------------------
//! Calculates the rigid body's total mass, center of mass, and mass moment
//! of inertia about the center of mass
//!
void FERigidBody::UpdateCOM()
{
// center of mass
vec3d rc(0,0,0);
// loop over all domains
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
for (int nd=0; nd < mesh.Domains(); ++nd)
{
FEDomain& dom = mesh.Domain(nd);
FERigidMaterial* pm = dynamic_cast<FERigidMaterial*>(dom.GetMaterial());
if (pm && (pm->GetRigidBodyID() == m_nID))
{
FERigidSolidDomain* pbd = dynamic_cast<FERigidSolidDomain*>(&dom);
if (pbd) rc += pbd->CalculateCOM();
FERigidShellDomain* psd = dynamic_cast<FERigidShellDomain*>(&dom);
if (psd) rc += psd->CalculateCOM();
}
}
// normalize com
if (m_mass != 0) rc /= m_mass;
// store com
SetCOM(rc);
}
//-----------------------------------------------------------------------------
void FERigidBody::UpdateMOI()
{
// initialize some data
mat3d moi(0, 0, 0, 0, 0, 0, 0, 0, 0); // mass moment of inertia about origin
// loop over all domains
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
for (int nd = 0; nd < mesh.Domains(); ++nd)
{
FEDomain& dom = mesh.Domain(nd);
FERigidMaterial* pm = dynamic_cast<FERigidMaterial*>(dom.GetMaterial());
if (pm && (pm->GetRigidBodyID() == m_nID))
{
FERigidSolidDomain* pbd = dynamic_cast<FERigidSolidDomain*>(&dom);
if (pbd) moi += pbd->CalculateMOI();
FERigidShellDomain* psd = dynamic_cast<FERigidShellDomain*>(&dom);
if (psd) moi += psd->CalculateMOI();
}
}
// use parallel axis theorem to transfer moi to com
// and store moi
mat3dd I(1); // identity tensor
vec3d rc = m_r0;
m_moi = moi.sym() - m_mass*((rc*rc)*I - dyad(rc));
}
//-----------------------------------------------------------------------------
vec3d FERigidBody::CayleyIncrementalCompoundRotation()
{
// incremental rotation in spatial frame
quatd q = m_qt*m_qp.Inverse();
q.MakeUnit(); // clean-up roundoff errors
double theta = 2*tan(q.GetAngle()/2); // get theta from Cayley transform
vec3d e = q.GetVector();
return e*theta;
}
//-----------------------------------------------------------------------------
void FERigidBody::Serialize(DumpStream& ar)
{
if (ar.IsShallow())
{
if (ar.IsSaving())
{
ar << m_mass;
ar << m_moi;
ar << m_Fr << m_Mr;
ar << m_rp << m_rt;
ar << m_vp << m_vt;
ar << m_ap << m_at;
ar << m_qp << m_qt << m_euler;
ar << m_wp << m_wt;
ar << m_alp << m_alt;
for (int i=0; i<6; ++i)
{
ar << m_Up[i];
ar << m_Ut[i];
ar << m_du[i];
ar << m_dul[i];
}
}
else
{
ar >> m_mass;
ar >> m_moi;
ar >> m_Fr >> m_Mr;
ar >> m_rp >> m_rt;
ar >> m_vp >> m_vt;
ar >> m_ap >> m_at;
ar >> m_qp >> m_qt >> m_euler;
ar >> m_wp >> m_wt;
ar >> m_alp >> m_alt;
for (int i=0; i<6; ++i)
{
ar >> m_Up[i];
ar >> m_Ut[i];
ar >> m_du[i];
ar >> m_dul[i];
}
}
}
else
{
ar & m_nID & m_mat & m_mass & m_moi & m_Fr & m_Mr;
ar & m_Fp & m_Mp;
ar & m_r0 & m_rp & m_rt & m_vp & m_vt & m_ap & m_at;
ar & m_qp & m_qt & m_euler & m_wp & m_wt & m_alp & m_alt;
ar & m_hp & m_ht & m_dhp & m_dht;
ar & m_bpofr;
if (ar.IsSaving())
{
ar.write(m_BC , sizeof(int), 6);
ar.write(m_LM , sizeof(int), 6);
ar.write(m_Up , sizeof(double), 6);
ar.write(m_Ut , sizeof(double), 6);
ar.write(m_du , sizeof(double), 6);
ar.write(m_dul, sizeof(double), 6);
}
else
{
ar.read(m_BC , sizeof(int), 6);
ar.read(m_LM , sizeof(int ), 6);
ar.read(m_Up , sizeof(double), 6);
ar.read(m_Ut , sizeof(double), 6);
ar.read(m_du , sizeof(double), 6);
ar.read(m_dul, sizeof(double), 6);
}
for (int i = 0; i < 6; ++i) ar & m_pDC[i];
// TODO: should I store parent rigid body (m_prb)
}
}
//-----------------------------------------------------------------------------
// return the (instantaneous) helical axis relative to the ground
void FERigidBody::InstantaneousHelicalAxis(vec3d& omega, vec3d& s, double& tdot)
{
double dt = GetFEModel()->GetTime().timeIncrement;
// incremental rotation in spatial frame
omega = (m_wp + m_wt)/2;
vec3d rdot = (m_vt + m_vp)/2;
double rdm = rdot.norm();
vec3d n(omega); n.unit();
tdot = rdot*n;
vec3d r = (m_rt + m_rp)/2; // midpoint value of r
vec3d w(omega);
double w2 = w.norm2();
s = (w2 > 0) ? (w ^ (rdot - n*tdot + (r ^ w)))/(w*w) : vec3d(0,0,0);
if ((w2 == 0) && (rdm > 0)) {
tdot = rdm/dt;
n = rdot.Normalize();
omega = n;
}
}
//-----------------------------------------------------------------------------
// return the (finite) helical axis relative to the ground
void FERigidBody::FiniteHelicalAxis(vec3d& omega, vec3d& s, double& tdot)
{
// incremental rotation in spatial frame
quatd dQ = m_qt*m_qp.Inverse();
// clean-up roundoff errors
dQ.MakeUnit();
vec3d rdot = m_rt - m_rp;
double rdm = rdot.norm();
vec3d w = dQ.GetRotationVector();
vec3d n(w); n.unit();
omega = w;
tdot = rdot*n;
vec3d r = (m_rt + m_rp)/2; // midpoint value of r
double w2 = w*w;
s = (w2 > 0) ? (w ^ (rdot - n*tdot + (r ^ w)))/(w*w) : vec3d(0,0,0);
if ((w2 == 0) && (rdm > 0)) {
tdot = rdm;
n = rdot.Normalize();
omega = n;
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEYeoh.h | .h | 2,060 | 60 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEUncoupledMaterial.h"
#include <FECore/FEModelParam.h>
//-----------------------------------------------------------------------------
//! Yeoh material
class FEYeoh : public FEUncoupledMaterial
{
public:
enum { MAX_TERMS = 6 };
public:
FEYeoh(FEModel* pfem) : FEUncoupledMaterial(pfem) {}
public:
FEParamDouble m_c[MAX_TERMS]; //!< Yeoh coefficients
public:
//! calculate deviatoric stress at material point
mat3ds DevStress(FEMaterialPoint& pt) override;
//! calculate deviatoric tangent stiffness at material point
tens4ds DevTangent(FEMaterialPoint& pt) override;
//! calculate deviatoric strain energy density
double DevStrainEnergyDensity(FEMaterialPoint& mp) override;
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioMech/FEFixedDisplacement.cpp | .cpp | 1,964 | 52 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEFixedDisplacement.h"
BEGIN_FECORE_CLASS(FEFixedDisplacement, FEFixedBC)
ADD_PARAMETER(m_dofx, "x_dof")->setLongName("x-displacement");
ADD_PARAMETER(m_dofy, "y_dof")->setLongName("y-displacement");
ADD_PARAMETER(m_dofz, "z_dof")->setLongName("z-displacement");
END_FECORE_CLASS();
FEFixedDisplacement::FEFixedDisplacement(FEModel* fem) : FEFixedBC(fem)
{
m_dofx = false;
m_dofy = false;
m_dofz = false;
}
bool FEFixedDisplacement::Init()
{
vector<int> dofs;
if (m_dofx) dofs.push_back(GetDOFIndex("x"));
if (m_dofy) dofs.push_back(GetDOFIndex("y"));
if (m_dofz) dofs.push_back(GetDOFIndex("z"));
SetDOFList(dofs);
return FEFixedBC::Init();
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEFiberKiousisUncoupled.cpp | .cpp | 4,985 | 164 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEFiberKiousisUncoupled.h"
#include <limits>
#include <FECore/log.h>
// define the material parameters
BEGIN_FECORE_CLASS(FEUncoupledFiberKiousis, FEElasticFiberMaterialUC)
ADD_PARAMETER(m_d1, "d1");
ADD_PARAMETER(m_d2, "d2");
ADD_PARAMETER(m_n , "n" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEUncoupledFiberKiousis::FEUncoupledFiberKiousis(FEModel* pfem) : FEElasticFiberMaterialUC(pfem)
{
m_d1 = 0;
m_d2 = 1;
m_n = 2;
}
//-----------------------------------------------------------------------------
mat3ds FEUncoupledFiberKiousis::DevFiberStress(FEMaterialPoint& mp, const vec3d& n0)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// deformation gradient
double J = pt.m_J;
mat3d F = pt.m_F*pow(J,-1.0/3.0);
// loop over all integration points
const double eps = 0;
mat3ds C = pt.DevRightCauchyGreen();
mat3ds s;
double d1 = m_d1(mp);
double d2 = m_d2(mp);
double n = m_n(mp);
// Calculate In = n0*C*n0
double In_d2 = n0*(C*n0) - d2;
// only take fibers in tension into consideration
if (In_d2 >= eps)
{
// get the global spatial fiber direction in current configuration
vec3d nt = F*n0;
// calculate the outer product of nt
mat3ds N = dyad(nt);
// calculate the fiber stress
s = N*(2.0*d1*pow(In_d2, n-1)/J);
}
else
{
s.zero();
}
return s.dev();
}
//-----------------------------------------------------------------------------
tens4ds FEUncoupledFiberKiousis::DevFiberTangent(FEMaterialPoint& mp, const vec3d& n0)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// deformation gradient
double J = pt.m_J;
mat3d F = pt.m_F*pow(J,-1.0/3.0);
// loop over all integration points
const double eps = 0;
mat3ds C = pt.DevRightCauchyGreen();
mat3ds s;
tens4ds c;
// Calculate In = n0*C*n0
double In_d2 = n0*(C*n0) - m_d2(mp);
double n = m_n(mp);
// only take fibers in tension into consideration
if (In_d2 >= eps)
{
// get the global spatial fiber direction in current configuration
vec3d nt = F*n0;
// calculate the outer product of nt
mat3ds N = dyad(nt);
tens4ds NxN = dyad1s(N);
// calculate the fiber stress
s = N*(2.0*m_d1(mp)*pow(In_d2, n-1)/J);
// calculate the fiber tangent
c = NxN*(4.0*(n-1)*m_d1(mp)*pow(In_d2, n-2)/J);
// This is the final value of the elasticity tensor
mat3dd I(1);
tens4ds IxI = dyad1s(I);
tens4ds I4 = dyad4s(I);
c += ((I4+IxI/3.0)*s.tr() - dyad1s(I,s))*(2./3.)
- (ddots(IxI, c)-IxI*(c.tr()/3.))/3.;
}
else
{
c.zero();
}
return c;
}
//-----------------------------------------------------------------------------
double FEUncoupledFiberKiousis::DevFiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& n0)
{
double sed = 0.0;
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// loop over all integration points
mat3ds C = pt.DevRightCauchyGreen();
// Calculate In = n0*C*n0
double In_d2 = n0*(C*n0) - m_d2(mp);
double n = m_n(mp);
// only take fibers in tension into consideration
const double eps = 0;
if (In_d2 >= eps)
{
// calculate strain energy derivative
sed = m_d1(mp)/n*pow(In_d2, n);
}
return sed;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEFiberEFDNeoHookean.cpp | .cpp | 6,670 | 225 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFiberNeoHookean.h"
#include "FEFiberEFDNeoHookean.h"
// define the material parameters
BEGIN_FECORE_CLASS(FEFiberEFDNeoHookean, FEElasticMaterial)
ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_v, FE_RANGE_RIGHT_OPEN(-1.0, 0.5), "v");
ADD_PARAMETER(m_a, 3, "a");
ADD_PARAMETER(m_ac, "active_contraction")->setUnits(UNIT_PRESSURE);
ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional);
END_FECORE_CLASS();
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
//////////////////////////////////////////////////////////////////////
// FEFiberNeoHookean
//////////////////////////////////////////////////////////////////////
FEFiberEFDNeoHookean::FEFiberEFDNeoHookean(FEModel* pfem) : FEElasticMaterial(pfem)
{
m_nres = 0;
m_a[0] = m_a[1] = m_a[2] = 0;
m_ac = 0;
}
bool FEFiberEFDNeoHookean::Init()
{
if (FEElasticMaterial::Init() == false) return false;
m_bfirst = true;
if (m_bfirst)
{
// select the integration rule
const int nint = (m_nres == 0? NSTL : NSTH );
const double* phi = (m_nres == 0? PHIL : PHIH );
const double* the = (m_nres == 0? THETAL: THETAH);
const double* w = (m_nres == 0? AREAL : AREAH );
for (int n=0; n<nint; ++n)
{
m_cth[n] = cos(the[n]);
m_sth[n] = sin(the[n]);
m_cph[n] = cos(phi[n]);
m_sph[n] = sin(phi[n]);
m_w[n] = w[n];
}
m_bfirst = false;
}
return true;
}
mat3ds FEFiberEFDNeoHookean::Stress(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
mat3d &F = pt.m_F;
double detF = pt.m_J;
double detFi = 1.0/detF;
double lndetF = log(detF);
// calculate left Cauchy-Green tensor
// (we commented out the matrix components we do not need)
double b[3][3];
b[0][0] = F[0][0]*F[0][0]+F[0][1]*F[0][1]+F[0][2]*F[0][2];
b[0][1] = F[0][0]*F[1][0]+F[0][1]*F[1][1]+F[0][2]*F[1][2];
b[0][2] = F[0][0]*F[2][0]+F[0][1]*F[2][1]+F[0][2]*F[2][2];
// b[1][0] = F[1][0]*F[0][0]+F[1][1]*F[0][1]+F[1][2]*F[0][2];
b[1][1] = F[1][0]*F[1][0]+F[1][1]*F[1][1]+F[1][2]*F[1][2];
b[1][2] = F[1][0]*F[2][0]+F[1][1]*F[2][1]+F[1][2]*F[2][2];
// b[2][0] = F[2][0]*F[0][0]+F[2][1]*F[0][1]+F[2][2]*F[0][2];
// b[2][1] = F[2][0]*F[1][0]+F[2][1]*F[1][1]+F[2][2]*F[1][2];
b[2][2] = F[2][0]*F[2][0]+F[2][1]*F[2][1]+F[2][2]*F[2][2];
// lame parameters
double lam = m_v*m_E/((1+m_v)*(1-2*m_v));
double mu = 0.5*m_E/(1+m_v);
// calculate stress
mat3ds s;
s.xx() = (mu*(b[0][0] - 1) + lam*lndetF)*detFi;
s.yy() = (mu*(b[1][1] - 1) + lam*lndetF)*detFi;
s.zz() = (mu*(b[2][2] - 1) + lam*lndetF)*detFi;
s.xy() = mu*b[0][1]*detFi;
s.yz() = mu*b[1][2]*detFi;
s.xz() = mu*b[0][2]*detFi;
// --- F I B E R C O N T R I B U T I O N ---
if (m_ac)
{
// select the integration rule
const int nint = (m_nres == 0? NSTL : NSTH );
const double* phi = (m_nres == 0? PHIL : PHIH );
const double* the = (m_nres == 0? THETAL: THETAH);
const double* w = (m_nres == 0? AREAL : AREAH );
// get the local coordinate systems
mat3d Q = GetLocalCS(mp);
// loop over all integration points
double nr[3], n0[3], nt[3];
double at;
for (int n=0; n<nint; ++n)
{
// set the local fiber direction
nr[0] = m_cth[n]*m_sph[n];
nr[1] = m_sth[n]*m_sph[n];
nr[2] = m_cph[n];
// get the global material fiber direction
n0[0] = Q[0][0]*nr[0] + Q[0][1]*nr[1] + Q[0][2]*nr[2];
n0[1] = Q[1][0]*nr[0] + Q[1][1]*nr[1] + Q[1][2]*nr[2];
n0[2] = Q[2][0]*nr[0] + Q[2][1]*nr[1] + Q[2][2]*nr[2];
// get the global spatial fiber direction
nt[0] = F[0][0]*n0[0] + F[0][1]*n0[1] + F[0][2]*n0[2];
nt[1] = F[1][0]*n0[0] + F[1][1]*n0[1] + F[1][2]*n0[2];
nt[2] = F[2][0]*n0[0] + F[2][1]*n0[1] + F[2][2]*n0[2];
// add active contraction stuff
at = m_ac *sqrt(SQR(m_a[0]*nr[0]) + SQR(m_a[1]*nr[1]) + SQR(m_a[2]*nr[2]));
s.xx() += at*nt[0]*nt[0];
s.yy() += at*nt[1]*nt[1];
s.zz() += at*nt[2]*nt[2];
s.xy() += at*nt[0]*nt[1];
s.yz() += at*nt[1]*nt[2];
s.xz() += at*nt[0]*nt[2];
}
}
return s;
}
tens4ds FEFiberEFDNeoHookean::Tangent(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
// deformation gradient
mat3d &F = pt.m_F;
double detF = pt.m_J;
// lame parameters
double lam = m_v*m_E/((1+m_v)*(1-2*m_v));
double mu = 0.5*m_E/(1+m_v);
double lam1 = lam / detF;
double mu1 = (mu - lam*log(detF)) / detF;
double D[6][6] = {0};
D[0][0] = lam1+2.*mu1; D[0][1] = lam1 ; D[0][2] = lam1 ;
D[1][0] = lam1 ; D[1][1] = lam1+2.*mu1; D[1][2] = lam1 ;
D[2][0] = lam1 ; D[2][1] = lam1 ; D[2][2] = lam1+2.*mu1;
D[3][3] = mu1;
D[4][4] = mu1;
D[5][5] = mu1;
return tens4ds(D);
}
double FEFiberEFDNeoHookean::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>();
double J = pt.m_J;
double lnJ = log(J);
// calculate left Cauchy-Green tensor
mat3ds b = pt.LeftCauchyGreen();
double I1 = b.tr();
// lame parameters
double lam = m_v*m_E/((1+m_v)*(1-2*m_v));
double mu = 0.5*m_E/(1+m_v);
// calculate strain energy density
double sed = mu*((I1-3)/2.0 - lnJ) + lam*lnJ*lnJ/2.0;
// --- F I B E R C O N T R I B U T I O N ---
// active contraction does not contribute to the strain energy density
return sed;
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FEWrinkleOgdenMaterial.cpp | .cpp | 9,681 | 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.*/
#include "stdafx.h"
#include "FEWrinkleOgdenMaterial.h"
#include "FECore/mat2d.h"
//-----------------------------------------------------------------------------
// define the material parameters
BEGIN_FECORE_CLASS(FEWrinkleOgdenMaterial, FEMembraneMaterial)
ADD_PARAMETER(m_u, FE_RANGE_GREATER(0.0), "mu");
ADD_PARAMETER(m_a, FE_RANGE_GREATER_OR_EQUAL(2.0), "alpha");
ADD_PARAMETER(m_bwrinkle, "wrinkle");
ADD_PARAMETER(m_l0, 2, "prestretch");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
void eig(double *A, double *B, double *C);
void eigen2d(double l[2], double r[4], double m[4]);
//-----------------------------------------------------------------------------
FEWrinkleOgdenMaterial::FEWrinkleOgdenMaterial(FEModel* pfem) : FEMembraneMaterial(pfem)
{
m_a = 0;
m_u = 0;
m_l0[0] = m_l0[1] = 0.0;
m_bwrinkle = true;
}
//-----------------------------------------------------------------------------
void FEWrinkleOgdenMaterial::principals(FEMaterialPoint& mp, double l[2], double v[4])
{
FEMembraneMaterialPoint& pt = *mp.ExtractData<FEMembraneMaterialPoint>();
// get the def gradient
double* g = pt.g;
// extract the 2D component
mat2d Fm(1 + g[0], g[3], g[1], 1 + g[4]);
// 2D right Cauchy-Green tensor
mat2d Cm = Fm.transpose()*Fm;
// get eigenvalues and vectors
eig(l, v, Cm[0]);
// get principal stretches
l[0] = sqrt(l[0]) + m_l0[0];
l[1] = sqrt(l[1]) + m_l0[1];
// lambda0 should be the bigger stretch
if (l[1] > l[0])
{
double t = l[0]; l[0] = l[1]; l[1] = t;
t = v[0]; v[0] = v[2]; v[2] = t;
t = v[1]; v[1] = v[3]; v[3] = t;
}
}
//-----------------------------------------------------------------------------
void FEWrinkleOgdenMaterial::Stress(FEMaterialPoint& mp, double s[3])
{
// get the principal strains and vectors
double l[2], ec[4];
principals(mp, l, ec);
// evaluate stress based on principal stretches
// note that we calculate the 2PK stress in principal directions
double S[2][2] = {0};
if (m_bwrinkle && (l[0] < 0.999)) // biaxial compression (wrinkling in both directions)
{
// stress is zero
}
else if (m_bwrinkle && (l[1] < 1.0/sqrt(l[0]))) // uniaxial tension (wrinkling in one direction)
{
S[0][0] = m_u*(pow(l[0], m_a-2.0)-pow(l[0],-2.0-0.5*m_a));
}
else // biaxial tension (no wrinkling)
{
S[0][0] = m_u*(-pow(l[0], -m_a-2.0)*pow(l[1], -m_a) + pow(l[0], m_a-2.0));
S[1][1] = m_u*(-pow(l[1], -m_a-2.0)*pow(l[0], -m_a) + pow(l[1], m_a-2.0));
}
// setup coordinate transformation matrix to
// transform from principal coordinates to element coordinates
double Q[2][2] = {
{ ec[0], ec[1]},
{-ec[1], ec[0]}};
// now we convert back to element matrix
double Sv[2][2];
for (int i=0; i<2; ++i)
for (int j=0; j<2; ++j)
{
Sv[i][j] = 0;
for (int k=0; k<2; ++k)
for (int l=0; l<2; ++l) Sv[i][j] += Q[k][i]*S[k][l]*Q[l][j];
}
// copy stress components
s[0] = Sv[0][0]; s[1] = Sv[1][1]; s[2] = Sv[0][1];
}
//-----------------------------------------------------------------------------
void FEWrinkleOgdenMaterial::Tangent(FEMaterialPoint &mp, double D[3][3])
{
// get the principal strains and vectors
double l[2], ec[4];
principals(mp, l, ec);
// evaluate stress based on principal stretches
// note that we calculate the 2PK stress in principal directions
double S[2] = {0};
if (m_bwrinkle && (l[0] < 0.999)) // biaxial compression (wrinkling in both directions)
{
// no stress
}
else if (m_bwrinkle && (l[1] < 1.0/sqrt(l[0]))) // uniaxial tension (wrinkling in one direction)
{
S[0] = m_u*(pow(l[0], m_a-2.0)-pow(l[0],-2.0-0.5*m_a));
}
else // biaxial tension (no wrinkling)
{
S[0] = m_u*(-pow(l[0], -m_a-2.0)*pow(l[1], -m_a) + pow(l[0], m_a-2.0));
S[1] = m_u*(-pow(l[1], -m_a-2.0)*pow(l[0], -m_a) + pow(l[1], m_a-2.0));
}
// evaluate tangent based on principal stretches
double Cp[2][2] = {0}, ks = 0;
/* if (m_bwrinkle && (l[0] < 1)) // biaxial compression (wrinkling in both directions)
{
// tangent is zero
}
else if (m_bwrinkle && (l[1] < sqrt(l[0]))) // uniaxial tension (wrinkling in uniaxial)
{
Cp[0][0] = m_u*((2+m_a*0.5)*pow(l[0], -3-m_a*0.5) + (m_a-2.0)*pow(l[0], m_a-3.0))/l[0];
}
else // biaxial tension (no wrinkling)
*/ {
Cp[0][0] = m_u*((m_a + 2)*pow(l[1], -m_a)*pow(l[0], -m_a-3) + (m_a+2)*pow(l[0], m_a-3))/l[0];
Cp[1][1] = m_u*((m_a + 2)*pow(l[0], -m_a)*pow(l[1], -m_a-3) + (m_a+2)*pow(l[1], m_a-3))/l[1];
Cp[0][1] = Cp[1][0] = m_u*m_a*pow(l[0], -m_a-2)*pow(l[1], -m_a-2);
if (fabs(l[0] - l[1]) < 1e-9)
ks = (Cp[0][0] - Cp[0][1])/(2*l[0]);
else
ks = (S[0] - S[1])/(l[0]*l[0] - l[1]*l[1]);
}
double ct = ec[0], st = ec[1];
double T[2][3] = {{ct*ct, st*st, st*ct},{st*st, ct*ct, -st*ct}};
double z[3] = {2*ct*st, -2*ct*st, st*st - ct*ct};
// transform to element coordinate system
for (int i=0; i<3; ++i)
for (int j=0; j<3; ++j)
{
D[i][j] = 0;
for (int k=0; k<2; k++)
for (int l=0; l<2; ++l)
D[i][j] += T[k][i]*Cp[k][l]*T[l][j];
D[i][j] += ks*z[i]*z[j];
}
}
//-----------------------------------------------------------------------------
void eig(double *A, double *B, double *C)
{
/* calculate eigenvalues A and vectors B of 2x2 matrix C */
double tr,det,t2,pm;
int i,j;
if (((C[1]<1e-6)&&(C[1]>-1e-6))&&((C[2]<1e-6)&&(C[2]>-1e-6))){ /* not equal to zero, plus a tolerance */
A[0]=C[0];A[1]=C[3];
B[0]=1;B[1]=0;B[2]=0;B[3]=1;
}
else{
tr=C[0]+C[3];
det=C[0]*C[3]-C[1]*C[2];
t2=tr/2;
pm=pow((tr*tr/4-det),0.5);
if (pm<1e-4){
A[0]=t2;A[1]=t2;
B[0]=1;B[1]=0;B[2]=0;B[3]=1;
}
else {
A[0]=t2+pm;A[1]=t2-pm;
/* calculate eigenvectors B */
if ((C[1]>1e-9)||(C[1]<-1e-9)){ /* not equal to zero, plus a tolerance for rounding errors */
B[0]=A[0]-C[3];
B[1]=C[1];
B[2]=A[1]-C[3];
B[3]=C[1];
/* normalise eigenvectors to unit length, reusing tr temporarily */
for (i=0;i<2;i++){
j=i*2;
tr=pow((B[j]*B[j]+B[j+1]*B[j+1]),0.5);
B[j]=B[j]/tr;B[j+1]=B[j+1]/tr;
}
}
else if ((C[2]>1e-9)||(C[2]<-1e-9)){
B[0]=C[2];
B[1]=A[0]-C[0];
B[2]=C[2];
B[3]=A[1]-C[0];
/* normalise eigenvectors to unit length, reusing tr temporarily */
for (i=0;i<2;i++){
j=i*2;
tr=pow((B[j]*B[j]+B[j+1]*B[j+1]),0.5);
B[j]=B[j]/tr;B[j+1]=B[j+1]/tr;
}
}
else {
B[0]=1;B[1]=0;B[2]=0;B[3]=1;
}
}
}
}
#define ROTATE(a, i, j, k, l) g=a[i][j]; h=a[k][l];a[i][j]=g-s*(h+g*tau); a[k][l] = h + s*(g - h*tau);
void eigen2d(double l[2], double r[4], double m[4])
{
const int NMAX = 50;
double sm, tresh, g, h, t, c, tau, s, th;
int i, j, k;
// copy the matrix components since we will be overwriting them
double a[2][2] = {
{m[0], m[1]},
{m[2], m[3]}
};
// the v matrix contains the eigen vectors
// intialize to identity
double v[2][2] = {
{ 1, 0 },
{ 0, 1 }
};
// initialize b and d to the diagonal of a
double b[2] = {a[0][0], a[1][1]};
double d[2] = {a[0][0], a[1][1]};
double z[2] = {0};
const double eps = 0;//1.0e-15;
// loop
int n, nrot = 0;
for (n=0; n<NMAX; ++n)
{
// sum off-diagonal elements
sm = fabs(a[0][1]);
if (sm <= eps) break;
// set the treshold
if (n < 2) tresh = 0.2*sm/9.0; else tresh = 0.0;
// loop over off-diagonal elements
for (i=0; i<1; ++i)
{
for (j=i+1; j<2; ++j)
{
g = 100.0*fabs(a[i][j]);
// after four sweeps, skip the rotation if the off-diagonal element is small
if ((n > 3) && ((fabs(d[i])+g) == fabs(d[i]))
&& ((fabs(d[j])+g) == fabs(d[j])))
{
a[i][j] = 0.0;
}
else if (fabs(a[i][j]) > tresh)
{
h = d[j] - d[i];
if ((fabs(h)+g) == fabs(h))
t = a[i][j]/h;
else
{
th = 0.5*h/a[i][j];
t = 1.0/(fabs(th) + sqrt(1+th*th));
if (th < 0.0) t = -t;
}
c = 1.0/sqrt(1.0 + t*t);
s = t*c;
tau = s/(1.0+c);
h = t*a[i][j];
z[i] -= h;
z[j] += h;
d[i] -= h;
d[j] += h;
a[i][j] = 0;
for (k= 0; k<=i-1; ++k) { ROTATE(a, k, i, k, j) }
for (k=i+1; k<=j-1; ++k) { ROTATE(a, i, k, k, j) }
for (k=j+1; k< 2; ++k) { ROTATE(a, i, k, j, k) }
for (k= 0; k< 2; ++k) { ROTATE(v, k, i, k, j) }
++nrot;
}
}
}
for (i=0; i<2; ++i)
{
b[i] += z[i];
d[i] = b[i];
z[i] = 0.0;
}
}
// we sure we converged
assert(n < NMAX);
// copy eigenvalues
l[0] = d[0];
l[1] = d[1];
// copy eigenvectors
if (r)
{
r[0] = v[0][0]; r[1] = v[1][0];
r[2] = v[0][1]; r[3] = v[1][1];
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioMech/FESpringMaterial.h | .h | 3,298 | 101 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDiscreteElasticMaterial.h"
#include <FECore/FEFunction1D.h>
#include "febiomech_api.h"
//-----------------------------------------------------------------------------
//! material class for discrete elements
class FEBIOMECH_API FESpringMaterial : public FEDiscreteElasticMaterial
{
public:
FESpringMaterial(FEModel* pfem) : FEDiscreteElasticMaterial(pfem) {}
vec3d Force(FEDiscreteMaterialPoint& mp) override;
mat3d Stiffness(FEDiscreteMaterialPoint& mp) override;
virtual double StrainEnergy(FEDiscreteMaterialPoint& mp) override;
virtual double force (double dl) = 0;
virtual double stiffness(double dl) = 0;
virtual double strainEnergy(double dl) = 0;
};
//-----------------------------------------------------------------------------
//! linear spring
class FEBIOMECH_API FELinearSpring : public FESpringMaterial
{
public:
FELinearSpring(FEModel* pfem);
double force (double dl) override;
double stiffness(double dl) override;
double strainEnergy(double dl) override;
public:
double m_E; //!< spring constant
// declare the parameter list
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
//! tension-only linear spring
class FEBIOMECH_API FETensionOnlyLinearSpring : public FESpringMaterial
{
public:
FETensionOnlyLinearSpring(FEModel* pfem) : FESpringMaterial(pfem){}
double force (double dl) override;
double stiffness(double dl) override;
double strainEnergy(double dl) override;
public:
double m_E; //!< spring constant
// declare the parameter list
DECLARE_FECORE_CLASS();
};
//-----------------------------------------------------------------------------
class FEBIOMECH_API FEExperimentalSpring : public FESpringMaterial
{
public:
FEExperimentalSpring(FEModel* fem);
double force(double dl) override;
double stiffness(double dl) override;
double strainEnergy(double dl) override;
public:
double m_E;
double m_sM, m_sm;
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.