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 | FEBioFluid/FERealGas.cpp | .cpp | 16,475 | 446 | /*This file 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 "FERealGas.h"
#include <FECore/log.h>
#include <FECore/FEFunction1D.h>
#include "FEFluidMaterialPoint.h"
#include "FEThermoFluidMaterialPoint.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FERealGas, FEElasticFluid)
// material parameters
ADD_PARAMETER(m_nva , FE_RANGE_GREATER_OR_EQUAL(0), "nva")->setLongName("no. of p virial coeffs");
ADD_PARAMETER(m_nvc , FE_RANGE_GREATER_OR_EQUAL(0), "nvc")->setLongName("no. of cv virial coeffs");
ADD_PROPERTY(m_a0 , "a0")->SetLongName("normalized specific free energy 0");
ADD_PROPERTY(m_A[0], "A1", FEProperty::Optional)->SetLongName("1st p virial coeff");
ADD_PROPERTY(m_A[1], "A2", FEProperty::Optional)->SetLongName("2nd p virial coeff");
ADD_PROPERTY(m_A[2], "A3", FEProperty::Optional)->SetLongName("3rd p virial coeff");
ADD_PROPERTY(m_A[3], "A4", FEProperty::Optional)->SetLongName("4th p virial coeff");
ADD_PROPERTY(m_A[4], "A5", FEProperty::Optional)->SetLongName("5th p virial coeff");
ADD_PROPERTY(m_A[5], "A6", FEProperty::Optional)->SetLongName("6th p virial coeff");
ADD_PROPERTY(m_A[6], "A7", FEProperty::Optional)->SetLongName("7th p virial coeff");
ADD_PROPERTY(m_C[0], "C0")->SetLongName("1st cv virial coeff");
ADD_PROPERTY(m_C[1], "C1", FEProperty::Optional)->SetLongName("2nd cv virial coeff");
ADD_PROPERTY(m_C[2], "C2", FEProperty::Optional)->SetLongName("3rd cv virial coeff");
ADD_PROPERTY(m_C[3], "C3", FEProperty::Optional)->SetLongName("4th cv virial coeff");
END_FECORE_CLASS();
FERealGas::FERealGas(FEModel* pfem) : FEElasticFluid(pfem)
{
m_nva = 0;
m_nvc = 1;
m_R = m_Pr = m_Tr = 0;
m_a0 = nullptr;
m_A[0] = m_A[1] = m_A[2] = m_A[3] = m_A[4] = m_A[5] = m_A[6] = nullptr;
m_C[0] = m_C[1] = m_C[2] = m_C[3] = nullptr;
}
//-----------------------------------------------------------------------------
//! initialization
bool FERealGas::Init()
{
m_R = GetGlobalConstant("R");
m_Tr = GetGlobalConstant("T");
m_Pr = GetGlobalConstant("P");
if (m_R <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; }
if (m_Tr <= 0) { feLogError("A positive referential absolute temperature T must be defined in Globals section"); return false; }
if (m_Pr <= 0) { feLogError("A positive referential absolute pressure P must be defined in Globals section"); return false; }
m_pMat = dynamic_cast<FEThermoFluid*>(GetParent());
m_rhor = m_pMat->ReferentialDensity();
// check if we should assume ideal gas
if (m_nva == 0) {
m_A[0] = fecore_alloc(FEConstFunction, GetFEModel());
m_A[0]->SetParameter("value", 1.0);
m_nva = 1;
}
m_a0->Init();
for (int k=0; k<m_nva; ++k)
if (m_A[k]) m_A[k]->Init();
for (int k=0; k<m_nvc; ++k)
if (m_C[k]) m_C[k]->Init();
return true;
}
//-----------------------------------------------------------------------------
void FERealGas::Serialize(DumpStream& ar)
{
FEElasticFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_R & m_Pr & m_Tr & m_rhor;
}
//-----------------------------------------------------------------------------
//! gauge pressure
double FERealGas::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double p = 0;
for (int k=1; k<=m_nva; ++k)
p += m_A[k-1]->value(That)*pow(y,k);
return p*m_Pr;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J
double FERealGas::Tangent_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double dpJ = m_A[0]->value(That);
for (int k=2; k<=m_nva; ++k)
dpJ += k*m_A[k-1]->value(That)*pow(y,k-1);
return -dpJ*m_Pr*That/pow(J,2);
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to strain J
double FERealGas::Tangent_Strain_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double dpJ2 = 2*m_A[0]->value(That);
for (int k=2; k<=m_nva; ++k)
dpJ2 += k*m_A[k-1]->value(That)*(2*y+(k-1)*That/J)*pow(y,k-2);
return dpJ2*m_Pr*That/pow(J,3);
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to temperature T
double FERealGas::Tangent_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double y = That/J - 1;
double dpT = 0;
for (int k=1; k<=m_nva; ++k)
dpT += (m_A[k-1]->derive(That)*y + k/J*m_A[k-1]->value(That))*pow(y,k-1);
return dpT*m_Pr/m_Tr;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to temperature T
double FERealGas::Tangent_Temperature_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double y = That/J - 1;
double dpT2 = m_A[0]->deriv2(That)*y + 2/J*m_A[0]->derive(That);
for (int k=2; k<=m_nva; ++k)
dpT2 += (m_A[k-1]->deriv2(That)*pow(y,2) + 2*k/J*m_A[k-1]->derive(That)*y
+ k*(k-1)/pow(J,2)*m_A[k-1]->value(That))*pow(y,k-2);
return dpT2*m_Pr/pow(m_Tr,2);
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J and temperature T
double FERealGas::Tangent_Strain_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double dpJT = m_A[0]->value(That) + That*m_A[0]->derive(That);
for (int k=2; k<=m_nva; ++k)
dpJT += k*(That*m_A[k-1]->derive(That)*y + m_A[k-1]->value(That)*(k*x-1))*pow(y,k-2);
return -dpJT*m_Pr/(m_Tr*pow(J, 2));
}
//-----------------------------------------------------------------------------
//! specific free energy
double FERealGas::SpecificFreeEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double x2 = x*x, x3 = x2*x, x4 = x3*x, x5 = x4*x, x6 = x5*x;
double lnx = log(x);
double A[MAX_NVA], f[MAX_NVA];
f[0] = 1 + x*(lnx-1);
f[1] = -1 + x*(x-2*lnx);
f[2] = 1 + x*(1.5+3*lnx) - 3*x2 + x3/2;
f[3] = -1 - x*(10./3.+4*lnx) + 6*x2 - 2*x3 + x4/3;
f[4] = 1 + x*(65./12.+5*lnx) - 10*x2 + 5*x3 - 5*x4/3 + x5/4;
f[5] = -1 - x*(77./10.+6*lnx) + 15*x2 - 10*x3 + 5*x4 - 1.5*x5 + x6/5;
f[6] = 1 + x*(203./20.+7*lnx) - 21*x2 + 35*x3/2 - 35*x4/3 + 21*x5/4 - 7*x6/5;
for (int k=0; k<m_nva; ++k)
A[k] = m_A[k]->value(That);
double a = m_a0->value(That);
for (int k=0; k<m_nva; ++k)
a += A[k]*J*f[k];
return a*m_Pr/m_rhor;
}
//-----------------------------------------------------------------------------
//! specific entropy
double FERealGas::SpecificEntropy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double x2 = x*x, x3 = x2*x, x4 = x3*x, x5 = x4*x, x6 = x5*x;
double lnx = log(x);
double A[MAX_NVA], dA[MAX_NVA], f[MAX_NVA], df[MAX_NVA];
f[0] = 1 + x*(lnx-1);
f[1] = -1 + x*(x-2*lnx);
f[2] = 1 + x*(1.5+3*lnx) - 3*x2 + x3/2;
f[3] = -1 - x*(10./3.+4*lnx) + 6*x2 - 2*x3 + x4/3;
f[4] = 1 + x*(65./12.+5*lnx) - 10*x2 + 5*x3 - 5*x4/3 + x5/4;
f[5] = -1 - x*(77./10.+6*lnx) + 15*x2 - 10*x3 + 5*x4 - 1.5*x5 + x6/5;
f[6] = 1 + x*(203./20.+7*lnx) - 21*x2 + 35*x3/2 - 35*x4/3 + 21*x5/4 - 7*x6/5;
df[0] = lnx;
df[1] = 2*(-1 + x - lnx);
df[2] = 1.5*(3 - 4*x + x2 + 2*lnx);
df[3] = 2./3.*(-11 + 18*x - 9*x2 + 2*x3 - 6*lnx);
df[4] = 5./12.*(25 - 48*x + 36*x2 - 16*x3 + 3*x4 + 12*lnx);
df[5] = -13.7 + 30*x - 30*x2 + 20*x3 - 7.5*x4 + 1.2*x5 - 6*lnx;
df[6] = 7./60.*(147 - 360*x + 450*x2 - 400*x3 + 225*x4 - 72*x5 + 10*x6 + 60*lnx);
for (int k=0; k<m_nva; ++k) {
A[k] = m_A[k]->value(That);
dA[k] = m_A[k]->derive(That);
}
double s = -m_a0->derive(That);
for (int k=0; k<m_nva; ++k)
s -= A[k]*df[k] + J*dA[k]*f[k];
return s*m_Pr/(m_Tr*m_rhor);
}
//-----------------------------------------------------------------------------
//! specific strain energy
double FERealGas::SpecificStrainEnergy(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
// get the specific free energy
double a = SpecificFreeEnergy(mp);
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double a0 = m_a0->value(That)*m_Pr/m_rhor;
// the specific strain energy is the difference between these two values
return a - a0;
}
//-----------------------------------------------------------------------------
//! isochoric specific heat capacity
double FERealGas::IsochoricSpecificHeatCapacity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double y = That/J - 1;
double cv = m_C[0]->value(That);
for (int k=1; k<m_nvc; ++k)
cv += m_C[k]->value(That)*pow(y,k);
return cv*m_Pr/(m_Tr*m_rhor);
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to strain J
double FERealGas::Tangent_cv_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double dcvJ = 0;
for (int k=1; k<m_nvc; ++k)
dcvJ -= m_C[k]->value(That)*pow(y,k-1);
return dcvJ*m_Pr/(m_Tr*m_rhor)*x/J;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to temperature T
double FERealGas::Tangent_cv_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double x = That/J;
double y = x - 1;
double dcvT = m_C[0]->derive(That);
for (int k=1; k<m_nvc; ++k)
dcvT += (m_C[k]->derive(That)*y+k/J*m_C[k]->value(That))*pow(y,k-1);
return dcvT*m_Pr/(pow(m_Tr,2)*m_rhor);
}
//-----------------------------------------------------------------------------
//! isobaric specific heat capacity
double FERealGas::IsobaricSpecificHeatCapacity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double cv = IsochoricSpecificHeatCapacity(mp);
double p = Pressure(mp); // current gauge pressure
double dpT = Tangent_Temperature(mp);
// evaluate dpT/dpJ in the reference configuration
double efsafe = fp.m_ef;
double Tsafe = tf.m_T;
fp.m_ef = 0;
tf.m_T = 0;
double r = Tangent_Temperature(mp)/Tangent_Strain(mp);
// restore values before continuing
fp.m_ef = efsafe;
tf.m_T = Tsafe;
// evaluate isobaric specific heat capacity
double cp = cv + r/m_rhor*(p - (m_Tr + tf.m_T)*dpT);
return cp;
}
//-----------------------------------------------------------------------------
//! dilatation from temperature and pressure
bool FERealGas::Dilatation(const double T, const double p, double& e)
{
double errrel = 1e-6;
double errabs = 1e-6;
int maxiter = 100;
switch (m_nva) {
case 0:
return false;
break;
case 1:
{
double q = T/m_Tr;
double x = p/m_Pr/m_A[0]->value(q);
e = (q+1)/(x+1) - 1;
return true;
}
break;
case 2:
{
double q = T/m_Tr;
double A1 = m_A[0]->value(q);
double A2 = m_A[1]->value(q);
double det = A1*A1 + 4*A2*p/m_Pr;
if (det < 0) return false;
det = sqrt(det);
// only one root of this quadratic equation is valid.
double x = (-A1+det)/(2*A2);
e = (q+1)/(x+1) - 1;
return true;
}
break;
default:
{
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
FEThermoFluidMaterialPoint* ft = new FEThermoFluidMaterialPoint(fp);
ft->m_T = T;
bool convgd = false;
bool done = false;
int iter = 0;
FEMaterialPoint mp(ft);
do {
++iter;
fp->m_ef = e;
double f = Pressure(mp) - p;
double df = Tangent_Strain(mp);
double de = (df != 0) ? -f/df : 0;
e += de;
if ((fabs(de) < errrel*fabs(e)) ||
(fabs(f/m_Pr) < errabs)) { convgd = true; done = true; }
if (iter > maxiter) done = true;
} while (!done);
delete ft;
return convgd;
}
break;
}
return false;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FESoluteBackflowStabilization.cpp | .cpp | 5,548 | 157 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FESoluteBackflowStabilization.h"
#include "FEFluidSolutes.h"
#include "FEBioFluidSolutes.h"
#include <FECore/FENodeNodeList.h>
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FESoluteBackflowStabilization, FESurfaceLoad)
ADD_PARAMETER(m_isol , "solute_id")->setEnums("$(solutes)");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FESoluteBackflowStabilization::FESoluteBackflowStabilization(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_isol = -1;
m_dofC = pfem->GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
}
//-----------------------------------------------------------------------------
//! allocate storage
void FESoluteBackflowStabilization::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
}
//-----------------------------------------------------------------------------
//! initialize
bool FESoluteBackflowStabilization::Init()
{
// determine the nr of concentration equations
FEModel& fem = *GetFEModel();
DOFS& fedofs = fem.GetDOFS();
m_dofW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_VELOCITY));
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
if ((m_isol < 1) || (m_isol > MAX_CDOFS)) return false;
m_dof.AddDofs(m_dofW);
m_dof.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
FESurface* ps = &GetSurface();
ps->UpdateNodeNormals();
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FESoluteBackflowStabilization::Activate()
{
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_isol - 1;
m_ndof.assign(ps->Nodes(),DOF_OPEN);
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
m_ndof[i] = node.get_bc(dofc);
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FESoluteBackflowStabilization::Update()
{
// determine backflow conditions
MarkBackFlow();
// prescribe solute backflow constraint at the nodes
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_isol - 1;
for (int i=0; i<ps->Nodes(); ++i)
{
if (m_ndof[i] == DOF_OPEN) {
FENode& node = ps->Node(i);
// set node as having prescribed DOF (concentration at previous time)
if (node.get_bc(dofc) == DOF_PRESCRIBED) node.set(dofc,node.get_prev(dofc));
}
}
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface
void FESoluteBackflowStabilization::MarkBackFlow()
{
const FETimeInfo& tp = GetTimeInfo();
// Mark all nodes on this surface to have open concentration DOF
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_isol - 1;
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
if (m_ndof[i] == DOF_OPEN) {
node.set_bc(dofc, DOF_OPEN);
if (node.m_ID[dofc] < -1) node.m_ID[dofc] = -node.m_ID[dofc] - 2;
// check velocity normal to surface at this node
vec3d v = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
double vn = v*ps->NodeNormal(i);
if (vn < 0) {
node.set_bc(dofc, DOF_PRESCRIBED);
node.m_ID[dofc] = -node.m_ID[dofc] - 2;
}
}
}
}
//-----------------------------------------------------------------------------
//! calculate residual
void FESoluteBackflowStabilization::LoadVector(FEGlobalVector& R)
{
}
//-----------------------------------------------------------------------------
//! serialization
void FESoluteBackflowStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofW & m_dofC;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIDomain.cpp | .cpp | 1,564 | 36 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEMultiphasicFSIDomain.h"
#include "FECore/FESolidDomain.h"
#include "FECore/FEModel.h"
//-----------------------------------------------------------------------------
FEMultiphasicFSIDomain::FEMultiphasicFSIDomain(FEModel* pfem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBiphasicFSI.h | .h | 5,016 | 145 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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/FEElasticMaterial.h>
#include "FEFluidFSI.h"
#include "FEFluidSupply.h"
#include <FEBioMix/FEHydraulicPermeability.h>
#include <FEBioMix/FEBiphasic.h>
#include <FEBioMech/FEBodyForce.h>
//-----------------------------------------------------------------------------
//! FSI material point class.
//
class FEBIOFLUID_API FEBiphasicFSIMaterialPoint : public FEMaterialPointData
{
public:
//! constructor
FEBiphasicFSIMaterialPoint(FEMaterialPointData* pt);
//! create a shallow copy
FEMaterialPointData* Copy();
//! data serialization
void Serialize(DumpStream& ar);
//! Data initialization
void Init();
public:
// Biphasic FSI material data
mat3d m_Lw; //!< grad of m_wt
vec3d m_gradJ; //!< gradient of J
double m_phi0; //!< solid volume fraction in reference configuration
mat3ds m_ss; //!< solid stress
};
//-----------------------------------------------------------------------------
//! Base class for FluidFSI materials.
class FEBIOFLUID_API FEBiphasicFSI : public FEFluidFSI, public FEBiphasicInterface
{
public:
FEBiphasicFSI(FEModel* pfem);
// returns a pointer to a new material point object
FEMaterialPointData* CreateMaterialPointData() override;
//! performs initialization
bool Init() override;
public:
//! calculate inner stress at material point
mat3ds Stress(FEMaterialPoint& pt);
//! return the permeability tensor as a matrix
void Permeability(double k[3][3], FEMaterialPoint& pt);
//! return the permeability as a tensor
mat3ds Permeability(FEMaterialPoint& pt);
//! return the inverse permeability as a tensor
mat3ds InvPermeability(FEMaterialPoint& pt);
//! return the tangent permeability tensor
tens4dmm Permeability_Tangent(FEMaterialPoint& pt);
//! return the permeability property
FEHydraulicPermeability* GetPermeability() { return m_pPerm; }
//! porosity
double Porosity(FEMaterialPoint& pt);
//! Solid Volume
double SolidVolumeFrac(FEMaterialPoint& pt);
//! porosity gradient
vec3d gradPorosity(FEMaterialPoint& pt);
//! porosity gradient
vec3d gradPhifPhis(FEMaterialPoint& pt);
//! solid density
double TrueSolidDensity(FEMaterialPoint& mp) { return Solid()->Density(mp); }
//! true fluid density
double TrueFluidDensity(FEMaterialPoint& mp) { return Fluid()->Density(mp); }
//! solid density
double SolidDensity(FEMaterialPoint& mp);
//! fluid density
double FluidDensity(FEMaterialPoint& mp);
public: // overridden from FEBiphasicInterface
double GetReferentialSolidVolumeFraction(const FEMaterialPoint& mp) override {
const FEBiphasicFSIMaterialPoint* pt = (mp.ExtractData<FEBiphasicFSIMaterialPoint>());
return pt->m_phi0;
}
//! solid referential apparent density
double SolidReferentialApparentDensity(FEMaterialPoint& pt) override;
//! solid referential volume fraction
double SolidReferentialVolumeFraction(FEMaterialPoint& pt) override;
FEFluidSupply* FluidSupply() { return m_pSupp; }
public: // material parameters
double m_rhoTw; //!< true fluid density
FEParamDouble m_phi0; //!< solid volume fraction in reference configuration
vector<FEBodyForce*> m_bf; //!< body forces acting on this biphasic material
protected: // material properties
FEHydraulicPermeability* m_pPerm; //!< pointer to permeability material
FEFluidSupply* m_pSupp; //!< pointer to (optional) fluid supply material
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidDomain.h | .h | 3,179 | 83 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <vector>
#include "febiofluid_api.h"
class FEModel;
class FELinearSystem;
class FEBodyForce;
class FEGlobalVector;
class FETimeInfo;
//-----------------------------------------------------------------------------
//! Abstract interface class for fluid domains.
//! An fluid domain is used by the fluid mechanics solver.
//! This interface defines the functions that have to be implemented by a
//! fluid domain. There are basically two categories: residual functions
//! that contribute to the global residual vector. And stiffness matrix
//! function that calculate contributions to the global stiffness matrix.
class FEBIOFLUID_API FEFluidDomain
{
public:
FEFluidDomain(FEModel* pfem);
virtual ~FEFluidDomain(){}
// --- R E S I D U A L ---
//! calculate the internal forces
virtual void InternalForces(FEGlobalVector& R) = 0;
//! Calculate the body force vector
virtual void BodyForce(FEGlobalVector& R, FEBodyForce& bf) = 0;
//! calculate the interial forces (for dynamic problems)
virtual void InertialForces(FEGlobalVector& R) = 0;
// --- S T I F F N E S S M A T R I X ---
//! Calculate global stiffness matrix (only contribution from internal force derivative)
//! \todo maybe I should rename this the InternalStiffness matrix?
virtual void StiffnessMatrix (FELinearSystem& LS) = 0;
//! Calculate stiffness contribution of body forces
virtual void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) = 0;
//! calculate the mass matrix (for dynamic problems)
virtual void MassMatrix(FELinearSystem& LS) = 0;
//! transient analysis
void SetTransientAnalysis() { m_btrans = true; }
void SetSteadyStateAnalysis() { m_btrans = false; }
protected:
bool m_btrans; // flag for transient (true) or steady-state (false) analysis
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidNormalTraction.h | .h | 2,301 | 67 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEFluidNormalTraction is a fluid surface that has a normal
//! viscous traction prescribed on it.
//!
class FEBIOFLUID_API FEFluidNormalTraction : public FESurfaceLoad
{
public:
//! constructor
FEFluidNormalTraction(FEModel* pfem);
//! initialization
bool Init() override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
private:
FEParamDouble m_traction; //!< magnitude of traction load
private:
FEDofList m_dofW; // relative fluid velocity dofs
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FECarreauYasudaFluid.cpp | .cpp | 4,212 | 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.*/
#include "stdafx.h"
#include "FECarreauYasudaFluid.h"
#include "FEFluid.h"
// define the material parameters
BEGIN_FECORE_CLASS(FECarreauYasudaFluid, FEViscousFluid)
ADD_PARAMETER(m_mu0, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu0")->setUnits("P.t")->setLongName("zero shear rate viscosity");
ADD_PARAMETER(m_mui, FE_RANGE_GREATER_OR_EQUAL(0.0), "mui")->setUnits("P.t")->setLongName("infinite shear rate viscosity");
ADD_PARAMETER(m_lam, FE_RANGE_GREATER_OR_EQUAL(0.0), "lambda")->setUnits(UNIT_TIME)->setLongName("relaxation time");
ADD_PARAMETER(m_n , FE_RANGE_GREATER_OR_EQUAL(0.0), "n")->setLongName("power index");
ADD_PARAMETER(m_a , FE_RANGE_GREATER_OR_EQUAL(0.0), "a")->setLongName("power denominator");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FECarreauYasudaFluid::FECarreauYasudaFluid(FEModel* pfem) : FEViscousFluid(pfem)
{
m_mu0 = 0;
m_mui = 0;
m_lam = 0;
m_n = 1;
m_a = 2;
}
//-----------------------------------------------------------------------------
//! viscous stress
mat3ds FECarreauYasudaFluid::Stress(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double mu = ShearViscosity(pt);
mat3ds s = D*(2*mu);
return s;
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to strain J
mat3ds FECarreauYasudaFluid::Tangent_Strain(FEMaterialPoint& mp)
{
return mat3ds(0,0,0,0,0,0);
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to rate of deformation tensor D
tens4ds FECarreauYasudaFluid::Tangent_RateOfDeformation(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
double lamga = pow(m_lam*gdot,m_a);
double mu = m_mui + (m_mu0 - m_mui)*pow(1+lamga, (m_n-1)/m_a);
double dmu = (m_a >= 2) ? 2*(m_mu0 - m_mui)*(m_n-1)*pow(m_lam,m_a)*pow(gdot,m_a-2)
*pow(1+lamga, (m_n-m_a-1)/m_a) : 0;
mat3dd I(1.0);
tens4ds c = dyad1s(D)*(2*dmu) + dyad4s(I)*(2*mu);
return c;
}
//-----------------------------------------------------------------------------
//! dynamic viscosity
double FECarreauYasudaFluid::ShearViscosity(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
double lamga = pow(m_lam*gdot,m_a);
double mu = m_mui + (m_mu0 - m_mui)*pow(1+lamga, (m_n-1)/m_a);
return mu;
}
//-----------------------------------------------------------------------------
//! bulk viscosity
double FECarreauYasudaFluid::BulkViscosity(FEMaterialPoint& pt)
{
return 2*ShearViscosity(pt)/3.;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEConstFluidBodyForce.h | .h | 2,134 | 57 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEModelParam.h>
#include <FECore/FEMaterialPoint.h>
#include <FEBioMech/FEBodyForce.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! This class is the base class for body forces
//! Derived classes need to implement the force and stiffness functions.
//
class FEBIOFLUID_API FEConstFluidBodyForce : public FEBodyForce
{
public:
//! constructor
FEConstFluidBodyForce(FEModel* pfem);
public:
//! calculate the body force at a material point
vec3d force(FEMaterialPoint& pt) override;
//! calculate the body force at a material point
double divforce(FEMaterialPoint& pt) override { return 0; }
//! calculate constribution to stiffness matrix
mat3d stiffness(FEMaterialPoint& pt) override;
protected:
FEParamVec3 m_force;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidTractionLoad.h | .h | 2,144 | 62 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEFluidTractionLoad is a fluid surface that has a prescribed
//! viscous traction vector on it.
//!
class FEBIOFLUID_API FEFluidTractionLoad : public FESurfaceLoad
{
public:
//! constructor
FEFluidTractionLoad(FEModel* pfem);
//! initialization
bool Init() override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
private:
double m_scale; //!< magnitude of traction load
FEParamVec3 m_TC; //!< traction boundary cards
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETangentialFlowStabilization.cpp | .cpp | 6,177 | 185 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FETangentialFlowStabilization.h"
#include "FEFluidMaterial.h"
#include "FEBioFluid.h"
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FETangentialFlowStabilization, FESurfaceLoad)
ADD_PARAMETER(m_beta, "beta");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FETangentialFlowStabilization::FETangentialFlowStabilization(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_beta = 1.0;
// get the degrees of freedom
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.Clear();
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dof.Clear();
m_dof.AddDofs(m_dofW);
}
}
//-----------------------------------------------------------------------------
//! allocate storage
void FETangentialFlowStabilization::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
}
//-----------------------------------------------------------------------------
//! initialize
bool FETangentialFlowStabilization::Init()
{
if (FESurfaceLoad::Init() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FETangentialFlowStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofW;
}
//-----------------------------------------------------------------------------
vec3d FETangentialFlowStabilization::FluidVelocity(FESurfaceMaterialPoint& mp, double alpha)
{
FESurfaceElement& el = *mp.SurfaceElement();
vec3d vt[FEElement::MAX_NODES];
int neln = el.Nodes();
for (int j = 0; j<neln; ++j) {
FENode& node = m_psurf->Node(el.m_lnode[j]);
vt[j] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*alpha + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1 - alpha);
}
return el.eval(vt, mp.m_index);
}
//-----------------------------------------------------------------------------
void FETangentialFlowStabilization::LoadVector(FEGlobalVector& R)
{
const FETimeInfo& tp = GetTimeInfo();
m_psurf->LoadVector(R, m_dofW, false, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
FESurfaceElement& el = *mp.SurfaceElement();
// get the density
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
FEFluidMaterial* fluid = pm->ExtractProperty<FEFluidMaterial>();
double rho = fluid->ReferentialDensity();
// tangent vectors
vec3d r0[FEElement::MAX_NODES];
m_psurf->GetReferenceNodalCoordinates(el, r0);
vec3d dxr = el.eval_deriv1(r0, mp.m_index);
vec3d dxs = el.eval_deriv2(r0, mp.m_index);
// normal and area element
vec3d n = dxr ^ dxs;
double da = n.unit();
// fluid velocity
vec3d v = FluidVelocity(mp, tp.alphaf);
// tangential traction = -beta*density*|tangential velocity|*(tangential velocity)
mat3dd I(1.0);
vec3d vtau = (I - dyad(n))*v;
double vmag = vtau.norm();
// force vector (change sign for inflow vs outflow)
vec3d f = vtau*(-m_beta*rho*vmag*da);
double H = dof_a.shape;
fa[0] = H * f.x;
fa[1] = H * f.y;
fa[2] = H * f.z;
});
}
//-----------------------------------------------------------------------------
void FETangentialFlowStabilization::StiffnessMatrix(FELinearSystem& LS)
{
const FETimeInfo& tp = GetTimeInfo();
m_psurf->LoadStiffness(LS, m_dofW, m_dofW, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) {
FESurfaceElement& el = *mp.SurfaceElement();
// get the density
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
FEFluidMaterial* fluid = pm->ExtractProperty<FEFluidMaterial>();
double rho = fluid->ReferentialDensity();
// fluid velocity
vec3d v = FluidVelocity(mp, tp.alphaf);
// tangent vectors
vec3d r0[FEElement::MAX_NODES];
m_psurf->GetReferenceNodalCoordinates(el, r0);
vec3d dxr = el.eval_deriv1(r0, mp.m_index);
vec3d dxs = el.eval_deriv2(r0, mp.m_index);
vec3d n = dxr ^ dxs;
double da = n.unit();
mat3dd I(1.0);
vec3d vtau = (I - dyad(n))*v;
double vmag = vtau.unit();
mat3d K = (I - dyad(n) + dyad(vtau))*(-m_beta*rho*vmag*da);
// shape functions and derivatives
double H_i = dof_a.shape;
double H_j = dof_b.shape;
// calculate stiffness component
mat3d Kww = K*(H_i*H_j*tp.alphaf);
Kab.zero();
// dw/dw
Kab.sub(0, 0, Kww);
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluid.cpp | .cpp | 4,666 | 140 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEThermoFluid.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
// define the material parameters
BEGIN_FECORE_CLASS(FEThermoFluid, FEFluidMaterial)
// material properties
ADD_PROPERTY(m_pElastic, "elastic");
ADD_PROPERTY(m_pConduct, "conduct");
END_FECORE_CLASS();
//============================================================================
// FEThermoFluid
//============================================================================
//-----------------------------------------------------------------------------
//! FEThermoFluid constructor
FEThermoFluid::FEThermoFluid(FEModel* pfem) : FEFluidMaterial(pfem)
{
m_pElastic = 0;
m_pConduct = 0;
}
//-----------------------------------------------------------------------------
void FEThermoFluid::Serialize(DumpStream& ar)
{
FEFluidMaterial::Serialize(ar);
if (ar.IsShallow()) return;
}
//-----------------------------------------------------------------------------
//! returns a pointer to a new material point object
FEMaterialPointData* FEThermoFluid::CreateMaterialPointData()
{
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
return new FEThermoFluidMaterialPoint(fp);
}
//-----------------------------------------------------------------------------
//! evaluate temperature
double FEThermoFluid::Temperature(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tp = *mp.ExtractData<FEThermoFluidMaterialPoint>();
return tp.m_T;
}
//-----------------------------------------------------------------------------
//! bulk modulus
double FEThermoFluid::BulkModulus(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& vt = *mp.ExtractData<FEFluidMaterialPoint>();
return -(vt.m_ef+1)*Tangent_Pressure_Strain(mp);
}
//-----------------------------------------------------------------------------
//! heat flux
vec3d FEThermoFluid::HeatFlux(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tp = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double k = m_pConduct->ThermalConductivity(mp);
vec3d q = -tp.m_gradT*k;
return q;
}
//-----------------------------------------------------------------------------
//! The stress of a fluid material is the sum of the fluid pressure
//! and the viscous stress.
mat3ds FEThermoFluid::Stress(FEMaterialPoint& mp)
{
// calculate solid material stress
mat3ds s = GetViscous()->Stress(mp);
double p = m_pElastic->Pressure(mp);
// add fluid pressure
s.xx() -= p;
s.yy() -= p;
s.zz() -= p;
return s;
}
//-----------------------------------------------------------------------------
//! The tangent of stress with respect to strain J of a fluid material is the
//! sum of the tangent of the fluid pressure and that of the viscous stress.
mat3ds FEThermoFluid::Tangent_Strain(FEMaterialPoint& mp)
{
// get tangent of viscous stress
mat3ds sJ = GetViscous()->Tangent_Strain(mp);
// add tangent of fluid pressure
double dp = m_pElastic->Tangent_Strain(mp);
sJ.xx() -= dp;
sJ.yy() -= dp;
sJ.zz() -= dp;
return sJ;
}
//-----------------------------------------------------------------------------
//! calculate strain energy density (per reference volume)
double FEThermoFluid::StrainEnergyDensity(FEMaterialPoint& mp)
{
double sed = m_rhor*m_pElastic->SpecificStrainEnergy(mp);
return sed;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSITraction.h | .h | 2,488 | 71 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include "FEFluid.h"
//-----------------------------------------------------------------------------
//! This surface load represents the traction applied on the solid at the
//! interface between a fluid and solid in an FSI analysis.
class FEBIOFLUID_API FEFluidFSITraction : public FESurfaceLoad
{
public:
//! constructor
FEFluidFSITraction(FEModel* pfem);
//! calculate pressure stiffness
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! serialize data
void Serialize(DumpStream& ar) override;
//! initialization
bool Init() override;
private:
double GetFluidDilatation(FESurfaceMaterialPoint& mp, double alpha);
mat3ds GetFluidStress(FESurfaceMaterialPoint& mp);
protected:
vector<double> m_s; //!< scale factor
vector<FEElement*> m_elem; //!< list of fluid-FSI elements
// degrees of freedom
FEDofList m_dofU, m_dofSU, m_dofW;
int m_dofEF;
protected:
bool m_bshellb; //!< flag for prescribing traction on shell bottom
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesDomain3D.h | .h | 4,538 | 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 <FECore/FESolidDomain.h>
#include "FEFluidDomain.h"
#include "FEFluidSolutes.h"
#include <FECore/FEDofList.h>
//-----------------------------------------------------------------------------
//! domain described by 3D volumetric elements
//!
class FEBIOFLUID_API FEFluidSolutesDomain3D : public FESolidDomain, public FEFluidDomain
{
public:
//! constructor
FEFluidSolutesDomain3D(FEModel* pfem);
~FEFluidSolutesDomain3D() {}
//! assignment operator
FEFluidSolutesDomain3D& operator = (FEFluidSolutesDomain3D& d);
//! initialize elements
void PreSolveUpdate(const FETimeInfo& timeInfo) override;
public: // overrides from FEDomain
//! get the material
FEMaterial* GetMaterial() override { return m_pMat; }
//! set the material
void SetMaterial(FEMaterial* pm) override;
//! get the total dofs
const FEDofList& GetDOFList() const override;
public: // overrides from FEElasticDomain
//! initialize class
bool Init() override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! Reset data
void Reset() override;
//! activate
void Activate() override;
//! initialize material points in the domain
void InitMaterialPoints() override;
// update stresses
void Update(const FETimeInfo& tp) override;
// update the element stress
void UpdateElementStress(int iel, const FETimeInfo& tp);
//! internal stress forces
void InternalForces(FEGlobalVector& R) override;
//! body forces
void BodyForce(FEGlobalVector& R, FEBodyForce& BF) override;
//! inertial forces for dynamic problems
void InertialForces(FEGlobalVector& R) override;
//! calculates the global stiffness matrix for this domain
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculates inertial stiffness
void MassMatrix(FELinearSystem& LS) override;
//! body force stiffness
void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override;
public:
// --- S T I F F N E S S ---
//! calculates the solid element stiffness matrix
void ElementStiffness(FESolidElement& el, matrix& ke);
//! calculates the solid element mass matrix
void ElementMassMatrix(FESolidElement& el, matrix& ke);
//! calculates the stiffness matrix due to body forces
void ElementBodyForceStiffness(FEBodyForce& bf, FESolidElement& el, matrix& ke);
// --- R E S I D U A L ---
//! Calculates the internal stress vector for solid elements
void ElementInternalForce(FESolidElement& el, vector<double>& fe);
//! Calculates external body forces for solid elements
void ElementBodyForce(FEBodyForce& BF, FESolidElement& elem, vector<double>& fe);
//! Calculates the inertial force vector for solid elements
void ElementInertialForce(FESolidElement& el, vector<double>& fe);
protected:
FEFluidSolutes* m_pMat;
protected:
FEDofList m_dofW;
FEDofList m_dofAW;
FEDofList m_dof;
int m_dofEF;
int m_dofAEF;
int m_dofC;
int m_dofAC;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSIDomainFactory.cpp | .cpp | 2,147 | 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.*/
#include "stdafx.h"
#include "FEFluidFSIDomainFactory.h"
#include "FEBiphasicFSI.h"
#include <FECore/FESolidDomain.h>
//-----------------------------------------------------------------------------
FEDomain* FEFluidFSIDomainFactory::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat)
{
FEModel* pfem = pmat->GetFEModel();
FE_Element_Class eclass = spec.eclass;
FE_Element_Shape eshape = spec.eshape;
FEDomain* pd = nullptr;
if (dynamic_cast<FEBiphasicFSI*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) pd = fecore_new<FESolidDomain>("biphasic-FSI-3D", pfem);
else return 0;
}
else if (dynamic_cast<FEFluidFSI*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) pd = fecore_new<FESolidDomain>("fluid-FSI-3D", pfem);
else return 0;
}
if (pd) pd->SetMaterial(pmat);
return pd;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPrescribedFluidVelocity.cpp | .cpp | 1,958 | 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 "FEPrescribedFluidVelocity.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(FEPrescribedFluidVelocity, FEBoundaryCondition)
ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list:relative fluid velocity)");
ADD_PARAMETER(m_scale, "value")->setUnits(UNIT_VELOCITY)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE);
ADD_PARAMETER(m_brelative, "relative");
END_FECORE_CLASS();
FEPrescribedFluidVelocity::FEPrescribedFluidVelocity(FEModel* fem) : FEPrescribedDOF(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidSolutesPressure.cpp | .cpp | 7,941 | 211 | /*This file 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 "FEInitialFluidSolutesPressure.h"
#include "FEBioFluidSolutes.h"
#include "FEFluidSolutes.h"
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEInitialFluidSolutesPressure, FEInitialCondition)
// material properties
ADD_PARAMETER(m_Pdata, "value" )->setUnits(UNIT_PRESSURE);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEInitialFluidSolutesPressure::FEInitialFluidSolutesPressure(FEModel* fem) : FENodalIC(fem)
{
m_dofEF = -1;
m_dofC = -1;
m_Rgas = 0;
m_Tabs = 0;
m_Fc = 0;
}
//-----------------------------------------------------------------------------
bool FEInitialFluidSolutesPressure::Init()
{
if (SetPDOF("ef") == false) return false;
m_e.assign(m_nodeSet->Size(), 0.0);
FEDofList dofs(GetFEModel());
if (dofs.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_DILATATION)) == false) return false;
SetDOFList(dofs);
m_dofC = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
m_Rgas = GetFEModel()->GetGlobalConstant("R");
m_Tabs = GetFEModel()->GetGlobalConstant("T");
m_Fc = GetFEModel()->GetGlobalConstant("Fc");
return FENodalIC::Init();
}
//-----------------------------------------------------------------------------
void FEInitialFluidSolutesPressure::SetPDOF(int ndof) { m_dofEF = ndof; }
//-----------------------------------------------------------------------------
bool FEInitialFluidSolutesPressure::SetPDOF(const char* szdof)
{
FEModel* fem = GetFEModel();
int ndof = fem->GetDOFIndex(szdof);
assert(ndof >= 0);
if (ndof < 0) return false;
SetPDOF(ndof);
return true;
}
//-----------------------------------------------------------------------------
void FEInitialFluidSolutesPressure::Activate()
{
// prescribe this dilatation at the nodes
FEModel* fem = GetFEModel();
FENodeList nodeList = m_nodeSet->GetNodeList();
int N = nodeList.Size();
std::vector<vector<double>> efNodes(N, vector<double>());
FEMesh& mesh = *m_nodeSet->GetMesh();
// evaluate average prescribed pressure and temperature in each element
// project them from int points to nodes
for (int i=0; i<mesh.Elements(); ++i)
{
FEElement& el = *mesh.Element(i);
FESolidElement* se = dynamic_cast<FESolidElement*>(&el);
// get material
FEMaterial* pm = GetFEModel()->GetMaterial(el.GetMatID());
FEFluid* pfl = pm->ExtractProperty<FEFluid>();
FESoluteInterface* psi = pm->ExtractProperty<FESoluteInterface>();
if (pfl) {
double efi[FEElement::MAX_INTPOINTS] = {0};
double efo[FEElement::MAX_NODES] = {0};
if (psi) {
const int nsol = psi->Solutes();
std::vector<double> kappa(nsol,0);
double osc = 0, p = 0, epot = 0;
const int nint = se->GaussPoints();
// get the average osmotic coefficient and partition coefficients in the solid element
for (int j=0; j<nint; ++j) {
FEMaterialPoint* pt = se->GetMaterialPoint(j);
osc += psi->GetOsmoticCoefficient()->OsmoticCoefficient(*pt);
p += m_Pdata(*pt);
epot += psi->GetElectricPotential(*pt);
for (int k=0; k<nsol; ++k)
kappa[k] += psi->GetSolute(k)->m_pSolub->Solubility(*pt);
}
osc /= nint;
p /= nint;
epot /= nint;
double ex = exp(-m_Fc*epot/m_Rgas/m_Tabs);
for (int k=0; k<nsol; ++k) kappa[k] *= pow(ex,psi->GetSolute(k)->ChargeNumber())/nint;
// loop over element nodes
for (int j=0; j<el.Nodes(); ++j) {
double osm = 0;
FENode& node = mesh.Node(el.m_lnode[j]);
// calculate osmolarity at this node, using nodal effective solute concentrations
for (int k=0; k<nsol; ++k)
osm += node.get(m_dofC+psi->GetSolute(k)->GetSoluteID()-1)*kappa[k];
bool good = pfl->Dilatation(0, p - m_Rgas*m_Tabs*osc*osm, efo[j]);
assert(good);
}
}
else {
double p = 0;
const int nint = se->GaussPoints();
// get the average osmotic coefficient and partition coefficients in the solid element
for (int j=0; j<nint; ++j) {
FEMaterialPoint* pt = se->GetMaterialPoint(j);
p += m_Pdata(*pt);
}
p /= nint;
// loop over element nodes
for (int j=0; j<el.Nodes(); ++j) {
FENode& node = mesh.Node(el.m_lnode[j]);
bool good = pfl->Dilatation(0, p, efo[j]);
assert(good);
}
}
for (int j=0; j<el.Nodes(); ++j)
efNodes[el.m_lnode[j]].push_back(efo[j]);
}
//If no solid element, insert all 0s
else {
for (int j=0; j<el.Nodes(); ++j)
efNodes[el.m_lnode[j]].push_back(0);
}
}
//For each node, average the nodal ef
for (int i=0; i<mesh.Nodes(); ++i)
{
double ef = 0;
for (int j = 0; j < efNodes[i].size(); ++j)
ef += efNodes[i][j];
ef /= efNodes[i].size();
// store value for now
m_e[i] = ef;
}
FEStepComponent::Activate();
if (m_dofs.IsEmpty()) return;
int dofs = (int)m_dofs.Size();
std::vector<double> val(dofs, 0.0);
for (int i = 0; i<N; ++i)
{
FENode& node = *m_nodeSet->Node(i);
// get the nodal values
GetNodalValues(i, val);
for (int j = 0; j < dofs; ++j)
{
node.set(m_dofs[j], val[j]);
}
}
}
//-----------------------------------------------------------------------------
void FEInitialFluidSolutesPressure::GetNodalValues(int inode, std::vector<double>& values)
{
values[0] = m_e[inode];
}
//-----------------------------------------------------------------------------
void FEInitialFluidSolutesPressure::Serialize(DumpStream& ar)
{
FENodalIC::Serialize(ar);
if (ar.IsLoading())
m_e.assign(m_nodeSet->Size(), 0.0);
ar & m_e;
if (ar.IsShallow()) return;
ar & m_dofEF;
ar & m_dofC;
ar & m_Rgas & m_Tabs & m_Fc;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBioFluidData.h | .h | 10,142 | 321 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECore/NodeDataRecord.h"
#include "FECore/ElementDataRecord.h"
//=============================================================================
// N O D E D A T A
//=============================================================================
//-----------------------------------------------------------------------------
class FENodeFluidXVel : public FELogNodeData
{
public:
FENodeFluidXVel(FEModel* pfem) : FELogNodeData(pfem){}
double value(const FENode& node) override;
};
//-----------------------------------------------------------------------------
class FENodeFluidYVel : public FELogNodeData
{
public:
FENodeFluidYVel(FEModel* pfem) : FELogNodeData(pfem){}
double value(const FENode& node) override;
};
//-----------------------------------------------------------------------------
class FENodeFluidZVel : public FELogNodeData
{
public:
FENodeFluidZVel(FEModel* pfem) : FELogNodeData(pfem){}
double value(const FENode& node) override;
};
//=============================================================================
// E L E M E N T D A T A
//=============================================================================
//-----------------------------------------------------------------------------
class FELogElemFluidPosX : public FELogElemData
{
public:
FELogElemFluidPosX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogElemFluidPosY : public FELogElemData
{
public:
FELogElemFluidPosY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogElemFluidPosZ : public FELogElemData
{
public:
FELogElemFluidPosZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogElasticFluidPressure : public FELogElemData
{
public:
FELogElasticFluidPressure(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVolumeRatio : public FELogElemData
{
public:
FELogFluidVolumeRatio(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidDensity : public FELogElemData
{
public:
FELogFluidDensity(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressPower : public FELogElemData
{
public:
FELogFluidStressPower(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVelocityX : public FELogElemData
{
public:
FELogFluidVelocityX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVelocityY : public FELogElemData
{
public:
FELogFluidVelocityY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVelocityZ : public FELogElemData
{
public:
FELogFluidVelocityZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidAccelerationX : public FELogElemData
{
public:
FELogFluidAccelerationX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidAccelerationY : public FELogElemData
{
public:
FELogFluidAccelerationY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidAccelerationZ : public FELogElemData
{
public:
FELogFluidAccelerationZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVorticityX : public FELogElemData
{
public:
FELogFluidVorticityX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVorticityY : public FELogElemData
{
public:
FELogFluidVorticityY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidVorticityZ : public FELogElemData
{
public:
FELogFluidVorticityZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressXX : public FELogElemData
{
public:
FELogFluidStressXX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressYY : public FELogElemData
{
public:
FELogFluidStressYY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressZZ : public FELogElemData
{
public:
FELogFluidStressZZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressXY : public FELogElemData
{
public:
FELogFluidStressXY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressYZ : public FELogElemData
{
public:
FELogFluidStressYZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStressXZ : public FELogElemData
{
public:
FELogFluidStressXZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStress1 : public FELogElemData
{
public:
FELogFluidStress1(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStress2 : public FELogElemData
{
public:
FELogFluidStress2(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidStress3 : public FELogElemData
{
public:
FELogFluidStress3(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidMaxShearStress : public FELogElemData
{
public:
FELogFluidMaxShearStress(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefXX : public FELogElemData
{
public:
FELogFluidRateOfDefXX(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefYY : public FELogElemData
{
public:
FELogFluidRateOfDefYY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefZZ : public FELogElemData
{
public:
FELogFluidRateOfDefZZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefXY : public FELogElemData
{
public:
FELogFluidRateOfDefXY(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefYZ : public FELogElemData
{
public:
FELogFluidRateOfDefYZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
//-----------------------------------------------------------------------------
class FELogFluidRateOfDefXZ : public FELogElemData
{
public:
FELogFluidRateOfDefXZ(FEModel* pfem) : FELogElemData(pfem){}
double value(FEElement& el);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEConstFluidBodyForce.cpp | .cpp | 1,750 | 46 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEConstFluidBodyForce.h"
BEGIN_FECORE_CLASS(FEConstFluidBodyForce, FEBodyForce);
ADD_PARAMETER(m_force, "force")->setUnits(UNIT_SPECIFIC_FORCE);
END_FECORE_CLASS();
FEConstFluidBodyForce::FEConstFluidBodyForce(FEModel* pfem) : FEBodyForce(pfem)
{
}
vec3d FEConstFluidBodyForce::force(FEMaterialPoint& pt)
{
return m_force(pt);
}
mat3d FEConstFluidBodyForce::stiffness(FEMaterialPoint& pt)
{
return mat3ds(0, 0, 0, 0, 0, 0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIAnalysis.cpp | .cpp | 1,704 | 38 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEMultiphasicFSIAnalysis.h"
BEGIN_FECORE_CLASS(FEMultiphasicFSIAnalysis, FEAnalysis)
// The analysis parameter is already defined in the FEAnalysis base class.
// Here, we just need to set the enum values for the analysis parameter.
FindParameterFromData(&m_nanalysis)->setEnums("STEADY-STATE\0DYNAMIC\0");
END_FECORE_CLASS()
FEMultiphasicFSIAnalysis::FEMultiphasicFSIAnalysis(FEModel* fem) : FEAnalysis(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEConductivityRealVapor.h | .h | 3,043 | 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) 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 "FEFluidThermalConductivity.h"
#include <FECore/FEFunction1D.h>
//-----------------------------------------------------------------------------
//! Base class for fluid thermal conductivity materials.
class FEBIOFLUID_API FEConductivityRealVapor : public FEFluidThermalConductivity
{
public:
enum { MAX_NVC = 4 };
public:
FEConductivityRealVapor(FEModel* pfem);
virtual ~FEConductivityRealVapor() {}
public:
//! initialization
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
//! calculate thermal conductivity at material point
double ThermalConductivity(FEMaterialPoint& pt) override;
//! tangent of thermal conductivity with respect to strain J
double Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of thermal conductivity with respect to temperature T
double Tangent_Temperature(FEMaterialPoint& mp) override;
public:
double m_Kr; //!< thermal conductivity at reference temperature
double m_Tr; //!< reference temperature
double m_Tc; //!< normalized critical temperature (Tc/Tr)
double m_alpha; //!< exponent alpha used for calculating temperature map
int m_nvc; //!< number of virial coefficients for isochoric specific heat capacity
FEFunction1D* m_esat; //!< dilatation on saturation curve
FEFunction1D* m_Ksat; //!< normalized thermal conductivity vs normalized temperature on saturation curve
FEFunction1D* m_C[MAX_NVC]; //!< non-dimensional conductivity virial coefficient
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidPressureBC.h | .h | 2,404 | 73 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedBC.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEThermoFluidPressure is a thermofluid surface that has prescribed fluid pressure
//!
class FEBIOFLUID_API FEThermoFluidPressureBC : public FEPrescribedSurface
{
public:
//! constructor
FEThermoFluidPressureBC(FEModel* pfem);
//! set the dilatation
void Update() override;
//! initialize
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
public:
// return the value for node i, dof j
void GetNodalValues(int nodelid, std::vector<double>& val) override;
// copy data from another class
void CopyFrom(FEBoundaryCondition* pbc) override;
FESurface* GetSurface() { return m_psurf; }
private:
FEParamDouble m_p; //!< prescribed fluid pressure
vector<double> m_e;
private:
double m_Rgas;
double m_Tabs;
int m_dofEF;
int m_dofT;
FESurface* m_psurf;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesRCRBC.h | .h | 3,150 | 84 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedBC.h>
#include "FEFluidSolutes.h"
//-----------------------------------------------------------------------------
//! FEFluidRCRBC is a fluid surface load that implements a 3-element Windkessel model
//!
class FEBIOFLUID_API FEFluidSolutesRCRBC : public FEPrescribedSurface
{
public:
//! constructor
FEFluidSolutesRCRBC(FEModel* pfem);
//! set the dilatation
void Update() override;
//! evaluate flow rate
double FlowRate();
//! initialize
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
public:
// return the value for node i, dof j
void GetNodalValues(int nodelid, std::vector<double>& val) override;
// copy data from another class
void CopyFrom(FEBoundaryCondition* pbc) override;
private:
double m_R; //!< flow resistance
double m_Rd; //!< distal resistance
double m_p0; //!< initial fluid pressure
double m_C; //!< capacitance
double m_pd; //!< downstream pressure
private:
double m_pn; //!< fluid pressure at current time point
double m_pp; //!< fluid pressure at previous time point
double m_qn; //!< flow rate at current time point
double m_qp; //!< flow rate at previous time point
double m_pdn; //!< downstream fluid pressure at current time point
double m_pdp; //!< downstream fluid pressure at previous time point
double m_tp; //!< previous time
vector<double> m_e; //!< fluid dilatation
double m_Rgas;
double m_Tabs;
FEDofList m_dofW;
int m_dofEF;
int m_dofC;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidVelocity.h | .h | 2,538 | 76 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FESurfaceMap.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEFluidVelocity is a fluid surface that has a velocity
//! prescribed on it. This routine simultaneously prescribes a
//! surface load and nodal prescribed velocities
//! TODO: This is not a surface load!
class FEBIOFLUID_API FEFluidVelocity : public FESurfaceLoad
{
public:
//! constructor
FEFluidVelocity(FEModel* pfem);
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! set the velocity
void Update() override;
//! initialization
bool Init() override;
//! activate
void Activate() override;
//! serialization
void Serialize(DumpStream& ar) override;
private:
double m_scale; //!< average velocity
FEParamVec3 m_velocity; //!< velocity boundary cards
private:
bool m_bpv; //!< flag for prescribing nodal values
FEDofList m_dofW;
FEDofList m_dofEF;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidModule.h | .h | 2,160 | 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.*/
#pragma once
#include <FECore/FEModule.h>
#include "febiofluid_api.h"
class FEBIOFLUID_API FEFluidModule : public FEModule
{
public:
FEFluidModule();
void InitModel(FEModel* fem) override;
};
class FEBIOFLUID_API FEFluidFSIModule : public FEModule
{
public:
FEFluidFSIModule();
void InitModel(FEModel* fem) override;
};
class FEBIOFLUID_API FEMultiphasicFSIModule : public FEModule
{
public:
FEMultiphasicFSIModule();
void InitModel(FEModel* fem) override;
};
class FEBIOFLUID_API FEThermoFluidModule : public FEModule
{
public:
FEThermoFluidModule();
void InitModel(FEModel* fem) override;
};
class FEBIOFLUID_API FEPolarFluidModule : public FEModule
{
public:
FEPolarFluidModule();
void InitModel(FEModel* fem) override;
};
class FEBIOFLUID_API FEFluidSolutesModule : public FEModule
{
public:
FEFluidSolutesModule();
void InitModel(FEModel* fem) override;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBackFlowFSIStabilization.cpp | .cpp | 6,472 | 190 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBackFlowFSIStabilization.h"
#include "FEFluidMaterial.h"
#include "FEBioFluid.h"
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FEBackFlowFSIStabilization, FESurfaceLoad)
ADD_PARAMETER(m_beta, "beta");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FEBackFlowFSIStabilization::FEBackFlowFSIStabilization(FEModel* pfem) : FESurfaceLoad(pfem), m_dofU(pfem), m_dofW(pfem)
{
m_beta = 1.0;
// get the degrees of freedom
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofU.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::DISPLACEMENT));
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dof.Clear();
m_dof.AddDofs(m_dofU);
m_dof.AddDofs(m_dofW);
}
}
//-----------------------------------------------------------------------------
//! initialize
bool FEBackFlowFSIStabilization::Init()
{
if (FESurfaceLoad::Init() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FEBackFlowFSIStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofU & m_dofW;
}
//-----------------------------------------------------------------------------
void FEBackFlowFSIStabilization::StiffnessMatrix(FELinearSystem& LS)
{
const FETimeInfo& tp = GetTimeInfo();
m_psurf->LoadStiffness(LS, m_dof, m_dof, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) {
FESurfaceElement& el = *mp.SurfaceElement();
// get the density
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
FEFluidMaterial* fluid = pm->ExtractProperty<FEFluidMaterial>();
double rho = fluid->ReferentialDensity();
// tangent vectors
vec3d rt[FEElement::MAX_NODES];
m_psurf->GetNodalCoordinates(el, tp.alphaf, rt);
vec3d dxr = el.eval_deriv1(rt, mp.m_index);
vec3d dxs = el.eval_deriv2(rt, mp.m_index);
vec3d n = dxr ^ dxs;
double da = n.unit();
// Fluid velocity
vec3d v = FluidVelocity(mp, tp.alphaf);
double vn = v*n;
Kab.zero();
if (m_beta*vn < 0) {
// shape functions and derivatives
double H_i = dof_a.shape;
double H_j = dof_b.shape;
double Gr_j = dof_b.shape_deriv_r;
double Gs_j = dof_b.shape_deriv_s;
mat3d K = dyad(n)*(m_beta*rho * 2 * vn*da);
double tnt = m_beta*rho*vn*vn;
// calculate stiffness component
mat3d Kww = K*(H_i * H_j)*tp.alphaf;
vec3d g = (dxr*Gs_j - dxs*Gr_j)*(H_i * tnt*tp.alphaf);
mat3d Kwu; Kwu.skew(g);
Kab.sub(3, 0, Kwu);
Kab.sub(3, 3, Kww);
}
});
}
//-----------------------------------------------------------------------------
vec3d FEBackFlowFSIStabilization::FluidVelocity(FESurfaceMaterialPoint& mp, double alpha)
{
vec3d vt[FEElement::MAX_NODES];
FESurfaceElement& el = *mp.SurfaceElement();
int neln = el.Nodes();
for (int j = 0; j<neln; ++j) {
FENode& node = m_psurf->Node(el.m_lnode[j]);
vt[j] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*alpha + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1 - alpha);
}
return el.eval(vt, mp.m_index);
}
//-----------------------------------------------------------------------------
void FEBackFlowFSIStabilization::LoadVector(FEGlobalVector& R)
{
const FETimeInfo& tp = GetTimeInfo();
m_psurf->LoadVector(R, m_dofW, false, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
FESurfaceElement& el = *mp.SurfaceElement();
// get the density
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
FEFluidMaterial* fluid = pm->ExtractProperty<FEFluidMaterial>();
double rho = fluid->ReferentialDensity();
// tangent vectors
vec3d rt[FEElement::MAX_NODES];
m_psurf->GetNodalCoordinates(el, tp.alphaf, rt);
vec3d dxr = el.eval_deriv1(rt, mp.m_index);
vec3d dxs = el.eval_deriv2(rt, mp.m_index);
// normal and area element
vec3d n = dxr ^ dxs;
double da = n.unit();
// fluid velocity
vec3d v = FluidVelocity(mp, tp.alphaf);
double vn = v*n;
if (m_beta*vn < 0) {
// force vector (change sign for inflow vs outflow)
vec3d f = n*(m_beta*rho*vn*vn*da);
double H = dof_a.shape;
fa[0] = H * f.x;
fa[1] = H * f.y;
fa[2] = H * f.z;
}
else
{
fa[0] = fa[1] = fa[2] = 0.0;
}
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidSolver.cpp | .cpp | 41,812 | 1,230 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include <assert.h>
#include "FEBioPolarFluid.h"
#include "FEPolarFluidSolver.h"
#include "FEPolarFluidDomain.h"
#include "FEFluidDomain.h"
#include "FEFluidResistanceBC.h"
#include "FEBackFlowStabilization.h"
#include "FEFluidNormalVelocity.h"
#include "FEFluidVelocity.h"
#include "FEFluidRotationalVelocity.h"
#include "FEPolarFluidAnalysis.h"
#include "FEBodyMoment.h"
#include <FEBioMech/FEBodyForce.h>
#include <FEBioMech/FEContactInterface.h>
#include <FEBioMech/FEResidualVector.h>
#include <FECore/FEModel.h>
#include <FECore/log.h>
#include <FECore/DOFS.h>
#include <FECore/FEGlobalMatrix.h>
#include <FECore/sys.h>
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FENodalLoad.h>
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FELinearConstraintManager.h>
#include <FECore/FENLConstraint.h>
#include <FECore/DumpStream.h>
//-----------------------------------------------------------------------------
// define the parameter list
BEGIN_FECORE_CLASS(FEPolarFluidSolver, FENewtonSolver)
ADD_PARAMETER(m_Vtol , "vtol" );
ADD_PARAMETER(m_Gtol , "gtol" );
ADD_PARAMETER(m_Ftol , "ftol" );
ADD_PARAMETER(m_Etol , "etol" );
ADD_PARAMETER(m_Rtol , "rtol" );
ADD_PARAMETER(m_rhoi , "rhoi" );
ADD_PARAMETER(m_pred , "predictor" );
ADD_PARAMETER(m_minJf, "min_volume_ratio");
ADD_PARAMETER(m_order, "order" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! FEPolarFluidSolver Construction
//
FEPolarFluidSolver::FEPolarFluidSolver(FEModel* pfem) : FENewtonSolver(pfem), \
m_dofW(pfem), m_dofAW(pfem), m_dofG(pfem), m_dofAG(pfem), m_dofEF(pfem)
{
// default values
m_Rtol = 0.001;
m_Etol = 0.01;
m_Vtol = 0.001;
m_Gtol = 0.001;
m_Ftol = 0.001;
m_Rmin = 1.0e-20;
m_Rmax = 0; // not used if zero
m_minJf = 0;
m_nveq = 0;
m_ngeq = 0;
m_nfeq = 0;
m_niter = 0;
// assume non-symmetric
m_msymm = REAL_UNSYMMETRIC;
// default Newmark parameters for rhoi = 0
m_rhoi = 0;
m_alphaf = 1;
m_alpham = 1.5;
m_beta = 0.5625;
m_gamma = 1;
m_pred = 0;
m_order = 1;
// Preferred strategy is Broyden's method
SetDefaultStrategy(QN_BROYDEN);
// turn off checking for a zero diagonal
CheckZeroDiagonal(false);
// get the dof indices
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.AddVariable(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::RELATIVE_FLUID_ACCELERATION));
m_dofG.AddVariable(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::FLUID_ANGULAR_VELOCITY));
m_dofAG.AddVariable(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::FLUID_ANGULAR_ACCELERATION));
m_dofEF.AddVariable(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::FLUID_DILATATION));
m_dofAEF = pfem->GetDOFIndex(FEBioPolarFluid::GetVariableName(FEBioPolarFluid::FLUID_DILATATION_TDERIV), 0);
}
}
//-----------------------------------------------------------------------------
FEPolarFluidSolver::~FEPolarFluidSolver()
{
}
//-----------------------------------------------------------------------------
//! Generate warnings if needed
void FEPolarFluidSolver:: SolverWarnings()
{
// Generate warning if rigid connectors are used with symmetric stiffness
if (m_msymm == REAL_SYMMETRIC) {
feLogWarning("Fluid analyses require non-symmetric stiffness matrix.\nSet symmetric_stiffness flag to 0 in Control section.");
}
}
//-----------------------------------------------------------------------------
//! Allocates and initializes the data structures used by the FEPolarFluidSolver
//
bool FEPolarFluidSolver::Init()
{
// initialize base class
if (FENewtonSolver::Init() == false) return false;
// check parameters
if (m_Vtol < 0.0) { feLogError("vtol must be nonnegative."); return false; }
if (m_Gtol < 0.0) { feLogError("gtol must be nonnegative."); return false; }
if (m_Ftol < 0.0) { feLogError("ftol 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_rhoi == -1) {
m_alphaf = m_alpham = m_beta = m_gamma = 1.0;
}
else if ((m_rhoi >= 0) && (m_rhoi <= 1)) {
m_alphaf = 1.0/(1+m_rhoi);
if (m_order == 1)
m_alpham = (3-m_rhoi)/(1+m_rhoi)/2; // 1st-order system
else
m_alpham = (2-m_rhoi)/(1+m_rhoi); // 2nd-order system
m_beta = pow(1 + m_alpham - m_alphaf,2)/4;
m_gamma = 0.5 + m_alpham - m_alphaf;
}
else { feLogError("rhoi must be -1 or between 0 and 1.\n"); return false; }
// allocate vectors
int neq = m_neq;
m_Fr.assign(neq, 0);
m_Ui.assign(neq, 0);
m_Ut.assign(neq, 0);
m_vi.assign(m_nveq,0);
m_Vi.assign(m_nveq,0);
m_gi.assign(m_ngeq,0);
m_Gi.assign(m_ngeq,0);
m_fi.assign(m_nfeq,0);
m_Fi.assign(m_nfeq,0);
// we need to fill the total DOF vector m_Ut
// TODO: I need to find an easier way to do this
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
gather(m_Ut, mesh, m_dofW[0]);
gather(m_Ut, mesh, m_dofW[1]);
gather(m_Ut, mesh, m_dofW[2]);
gather(m_Ut, mesh, m_dofG[0]);
gather(m_Ut, mesh, m_dofG[1]);
gather(m_Ut, mesh, m_dofG[2]);
gather(m_Ut, mesh, m_dofEF[0]);
// set flag for transient or steady-state analyses
FEAnalysis* pstep = fem.GetCurrentStep();
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEPolarFluidDomain* pfdom = dynamic_cast<FEPolarFluidDomain*>(&dom);
if (fdom) {
if (pstep->m_nanalysis == FEPolarFluidAnalysis::STEADY_STATE)
fdom->SetSteadyStateAnalysis();
else
fdom->SetTransientAnalysis();
}
else if (pfdom) {
if (pstep->m_nanalysis == FEPolarFluidAnalysis::STEADY_STATE)
pfdom->SetSteadyStateAnalysis();
else
pfdom->SetTransientAnalysis();
}
}
SolverWarnings();
return true;
}
//-----------------------------------------------------------------------------
//! Initialize equations
bool FEPolarFluidSolver::InitEquations()
{
// Add the solution variables
AddSolutionVariable(&m_dofW , 1, "velocity" , m_Vtol);
AddSolutionVariable(&m_dofG , 1, "angular velocity", m_Gtol);
AddSolutionVariable(&m_dofEF, 1, "dilatation" , m_Ftol);
// base class initialization
if (FENewtonSolver::InitEquations() == false) return false;
// determine the number of velocity and dilatation equations
FEMesh& mesh = GetFEModel()->GetMesh();
m_nveq = m_ngeq = m_nfeq = 0;
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& n = mesh.Node(i);
if (n.m_ID[m_dofW[0] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[1] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[2] ] != -1) m_nveq++;
if (n.m_ID[m_dofG[0] ] != -1) m_ngeq++;
if (n.m_ID[m_dofG[1] ] != -1) m_ngeq++;
if (n.m_ID[m_dofG[2] ] != -1) m_ngeq++;
if (n.m_ID[m_dofEF[0]] != -1) m_nfeq++;
}
// Next, we add any Lagrange Multipliers
FEModel& fem = *GetFEModel();
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* lmc = fem.NonlinearConstraint(i);
if (lmc->IsActive())
{
m_neq += lmc->InitEquations(m_neq);
}
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i);
if (spc->IsActive())
{
m_neq += spc->InitEquations(m_neq);
}
}
// All initialization is done
return true;
}
//-----------------------------------------------------------------------------
//! Initialize equations
bool FEPolarFluidSolver::InitEquations2()
{
// Add the solution variables
AddSolutionVariable(&m_dofW , -1, "velocity", m_Vtol);
AddSolutionVariable(&m_dofG , -1, "angular velocity", m_Gtol);
AddSolutionVariable(&m_dofEF, -1, "dilatation", m_Ftol);
// base class initialization
if (FENewtonSolver::InitEquations2() == false) return false;
// determined the nr of velocity and dilatation equations
FEMesh& mesh = GetFEModel()->GetMesh();
m_nveq = m_ngeq = m_nfeq = 0;
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& n = mesh.Node(i);
if (n.m_ID[m_dofW[0] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[1] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[2] ] != -1) m_nveq++;
if (n.m_ID[m_dofG[0] ] != -1) m_ngeq++;
if (n.m_ID[m_dofG[1] ] != -1) m_ngeq++;
if (n.m_ID[m_dofG[2] ] != -1) m_ngeq++;
if (n.m_ID[m_dofEF[0]] != -1) m_nfeq++;
}
// Next, we add any Lagrange Multipliers
FEModel& fem = *GetFEModel();
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* lmc = fem.NonlinearConstraint(i);
if (lmc->IsActive())
{
m_neq += lmc->InitEquations(m_neq);
}
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i);
if (spc->IsActive())
{
m_neq += spc->InitEquations(m_neq);
}
}
return true;
}
//-----------------------------------------------------------------------------
void FEPolarFluidSolver::GetVelocityData(vector<double> &vi, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(vi);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofW[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
nid = n.m_ID[m_dofW[1]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
nid = n.m_ID[m_dofW[2]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
}
}
//-----------------------------------------------------------------------------
void FEPolarFluidSolver::GetAngularVelocityData(vector<double> &xi, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(xi);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofG[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofG[1]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofG[2]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
}
}
//-----------------------------------------------------------------------------
void FEPolarFluidSolver::GetDilatationData(vector<double> &ei, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(ei);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofEF[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
ei[m++] = ui[nid];
assert(m <= (int) ei.size());
}
}
}
//-----------------------------------------------------------------------------
//! Save data to dump file
void FEPolarFluidSolver::Serialize(DumpStream& ar)
{
// Serialize parameters
FENewtonSolver::Serialize(ar);
ar & m_nrhs;
ar & m_niter;
ar & m_nref & m_ntotref;
ar & m_neq & m_nveq & m_ngeq & m_nfeq;
ar & m_Fr & m_Ui & m_Ut;
ar & m_Vi & m_Gi & m_Fi;
if (ar.IsLoading())
{
m_Fr.assign(m_neq, 0);
m_Vi.assign(m_nveq,0);
m_Gi.assign(m_ngeq,0);
m_Fi.assign(m_nfeq,0);
}
if (ar.IsShallow()) return;
ar & m_rhoi & m_alphaf & m_alpham;
ar & m_beta & m_gamma;
ar & m_pred;
}
//-----------------------------------------------------------------------------
//! Update the kinematics of the model, such as nodal positions, velocities,
//! accelerations, etc.
void FEPolarFluidSolver::UpdateKinematics(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
// get the mesh
FEMesh& mesh = fem.GetMesh();
// update nodes
vector<double> U(m_Ut.size());
for (size_t i=0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
scatter3(U, mesh, m_dofW[0], m_dofW[1], m_dofW[2]);
scatter3(U, mesh, m_dofG[0], m_dofG[1], m_dofG[2]);
scatter(U, mesh, m_dofEF[0]);
// force dilatations to remain greater than -1
if (m_minJf > 0) {
const int NN = mesh.Nodes();
for (int i=0; i<NN; ++i)
{
FENode& node = mesh.Node(i);
if (node.get(m_dofEF[0]) <= -1.0)
node.set(m_dofEF[0], m_minJf - 1.0);
}
}
// make sure the prescribed BCs are fulfilled
int nvel = fem.BoundaryConditions();
for (int i=0; i<nvel; ++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 time derivatives of velocity and dilatation
// for dynamic simulations
FEAnalysis* pstep = fem.GetCurrentStep();
if (pstep->m_nanalysis == FEPolarFluidAnalysis::DYNAMIC)
{
int N = mesh.Nodes();
double dt = fem.GetTime().timeIncrement;
double cgi = 1 - 1.0/m_gamma;
for (int i=0; i<N; ++i)
{
FENode& n = mesh.Node(i);
// relative fluid velocity material time derivative
vec3d wt = n.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d wp = n.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d awt = n.get_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
vec3d awp = n.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
awt = awp*cgi + (wt - wp)/(m_gamma*dt);
n.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awt);
// fluid angular velocity material time derivative
vec3d gt = n.get_vec3d(m_dofG[0], m_dofG[1], m_dofG[2]);
vec3d gp = n.get_vec3d_prev(m_dofG[0], m_dofG[1], m_dofG[2]);
vec3d agt = n.get_vec3d(m_dofAG[0], m_dofAG[1], m_dofAG[2]);
vec3d agp = n.get_vec3d_prev(m_dofAG[0], m_dofAG[1], m_dofAG[2]);
agt = agp*cgi + (gt - gp)/(m_gamma*dt);
n.set_vec3d(m_dofAG[0], m_dofAG[1], m_dofAG[2], agt);
// dilatation time derivative
double eft = n.get(m_dofEF[0]);
double efp = n.get_prev(m_dofEF[0]);
double aefp = n.get_prev(m_dofAEF);
double aeft = aefp*cgi + (eft - efp)/(m_gamma*dt);
n.set(m_dofAEF, aeft);
}
}
// update nonlinear constraints (needed for updating Lagrange Multiplier)
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* nlc = fem.NonlinearConstraint(i);
if (nlc->IsActive()) nlc->Update(m_Ui, ui);
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i);
if (spc->IsActive()) spc->Update(m_Ui, ui);
}
}
//-----------------------------------------------------------------------------
//! Update DOF increments
void FEPolarFluidSolver::UpdateIncrements(vector<double>& Ui, vector<double>& ui, bool emap)
{
FEModel& fem = *GetFEModel();
// get the mesh
FEMesh& mesh = fem.GetMesh();
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
if (plc && plc->IsActive()) plc->UpdateIncrements(Ui, ui);
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* psc = fem.SurfacePairConstraint(i);
if (psc && psc->IsActive()) psc->UpdateIncrements(Ui, ui);
}
// TODO: This is a hack!
// The problem is that I only want to call the domain's IncrementalUpdate during
// the quasi-Newtoon loop. However, this function is also called after the loop
// converges. The emap parameter is used here to detect wether we are inside the
// loop (emap == false), or not (emap == true).
if (emap == false)
{
for (int i = 0; i < mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
dom.IncrementalUpdate(ui, true);
}
}
}
//-----------------------------------------------------------------------------
//! Updates the current state of the model
void FEPolarFluidSolver::Update(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
tp.currentIteration = m_niter;
// update kinematics
UpdateKinematics(ui);
// update model state
UpdateModel();
}
//-----------------------------------------------------------------------------
//! Update nonlinear constraints
void FEPolarFluidSolver::UpdateConstraints()
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
tp.currentIteration = m_niter;
// Update all nonlinear constraints
for (int i = 0; i<fem.NonlinearConstraints(); ++i)
{
FENLConstraint* pci = fem.NonlinearConstraint(i);
if (pci->IsActive()) pci->Update();
}
}
//-----------------------------------------------------------------------------
void FEPolarFluidSolver::Update2(const vector<double>& ui)
{
// get the mesh
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// update nodes
vector<double> U(m_Ut.size());
for (size_t i = 0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
scatter3(U, mesh, m_dofW[0], m_dofW[1], m_dofW[2]);
scatter3(U, mesh, m_dofG[0], m_dofG[1], m_dofG[2]);
scatter(U, mesh, m_dofEF[0]);
// Update the prescribed nodes
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.m_rid == -1)
{
vec3d dv(0, 0, 0);
for (int j = 0; j < node.m_ID.size(); ++j)
{
int nj = -node.m_ID[j] - 2; if (nj >= 0) node.set(j, node.get(j) + ui[nj]);
}
}
}
// update model state
UpdateModel();
}
//-----------------------------------------------------------------------------
bool FEPolarFluidSolver::InitStep(double time)
{
FEModel& fem = *GetFEModel();
// get time integration parameters
FETimeInfo& tp = fem.GetTime();
tp.alpha = m_alphaf;
tp.beta = m_beta;
tp.gamma = m_gamma;
tp.alphaf = m_alphaf;
tp.alpham = m_alpham;
// evaluate load curve values at current (or intermediate) time
double t = tp.currentTime;
// double dt = tp.timeIncrement;
// double ta = (t > 0) ? t - (1-m_alpha)*dt : m_alpha*dt;
// return FESolver::InitStep(ta);
return FESolver::InitStep(t);
}
//-----------------------------------------------------------------------------
//! Prepares the data for the first BFGS-iteration.
void FEPolarFluidSolver::PrepStep()
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
double dt = tp.timeIncrement;
tp.currentIteration = m_niter;
// zero total DOFs
zero(m_Ui);
zero(m_Vi);
zero(m_Gi);
zero(m_Fi);
// store previous mesh state
// we need them for strain 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_dp = ni.m_dt = ni.m_d0;
ni.UpdateValues();
switch (m_pred) {
case 0:
{
// initial guess at start of new time step (default)
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ni.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awp*(m_gamma-1)/m_gamma);
vec3d agp = ni.get_vec3d_prev(m_dofAG[0], m_dofAG[1], m_dofAG[2]);
ni.set_vec3d(m_dofAG[0], m_dofAG[1], m_dofAG[2], agp*(m_gamma-1)/m_gamma);
ni.set(m_dofAEF, ni.get_prev(m_dofAEF)*(m_gamma-1)/m_gamma);
}
break;
case 1:
{
// initial guess at start of new time step (Zero Ydot)
vec3d wp = ni.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
vec3d gp = ni.get_vec3d_prev(m_dofG[0], m_dofG[1], m_dofG[2]);
vec3d agp = ni.get_vec3d_prev(m_dofAG[0], m_dofAG[1], m_dofAG[2]);
ni.set_vec3d(m_dofW[0], m_dofW[1], m_dofW[2], wp + awp*dt*(1-m_gamma)*m_alphaf);
ni.set_vec3d(m_dofG[0], m_dofG[1], m_dofG[2], gp + agp*dt*(1-m_gamma)*m_alphaf);
ni.set(m_dofEF[0], ni.get_prev(m_dofEF[0]) + ni.get_prev(m_dofAEF)*dt*(1-m_gamma)*m_alphaf);
}
break;
case 2:
{
// initial guess at start of new time step (Same Ydot)
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ni.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awp);
vec3d agp = ni.get_vec3d_prev(m_dofAG[0], m_dofAG[1], m_dofAG[2]);
ni.set_vec3d(m_dofAG[0], m_dofAG[1], m_dofAG[2], agp);
ni.set(m_dofAEF, ni.get_prev(m_dofAEF));
vec3d wp = ni.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
ni.set_vec3d(m_dofW[0], m_dofW[1], m_dofW[2], wp + awp*dt);
vec3d gp = ni.get_vec3d_prev(m_dofG[0], m_dofG[1], m_dofG[2]);
ni.set_vec3d(m_dofG[0], m_dofG[1], m_dofG[2], gp + agp*dt);
ni.set(m_dofEF[0], ni.get_prev(m_dofEF[0]) + ni.get_prev(m_dofAEF)*dt);
}
break;
default:
break;
}
}
// apply prescribed velocities
// we save the prescribed velocity increments in the ui vector
vector<double>& ui = m_ui;
zero(ui);
int nbc = fem.BoundaryConditions();
for (int i=0; i<nbc; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.PrepStep(ui);
}
// do the linear constraints
fem.GetLinearConstraintManager().PrepStep();
// initialize material point data
// NOTE: do this before the stresses are updated
// TODO: does it matter if the stresses are updated before
// the material point data is initialized
// update domain data
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive()) dom.PreSolveUpdate(tp);
}
// update stresses
UpdateModel();
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
if (plc && plc->IsActive()) plc->PrepStep();
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* psc = fem.SurfacePairConstraint(i);
if (psc && psc->IsActive()) psc->PrepStep();
}
// apply prescribed DOFs for specialized surface loads
int nsl = fem.ModelLoads();
for (int i = 0; i < nsl; ++i)
{
FEModelLoad& pml = *fem.ModelLoad(i);
if (pml.IsActive()) pml.PrepStep();
}
// 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 have to do nonlinear constraint augmentations
if (fem.NonlinearConstraints() != 0) m_baugment = true;
}
//-----------------------------------------------------------------------------
bool FEPolarFluidSolver::Quasin()
{
// convergence norms
double normR1; // residual norm
double normE1; // energy norm
double normV; // velocity norm
double normv; // velocity increment norm
double normG; // angular velocity norm
double normg; // angular velocity increment norm
double normRi = 0; // initial residual norm
double normVi = 0; // initial velocity norm
double normGi = 0; // initial angular velocity norm
double normEi = 0; // initial energy norm
double normEm = 0; // max energy norm
double normFi = 0; // initial dilatation norm
double normF; // current dilatation norm
double normf; // incremement dilatation norm
FEModel& fem = *GetFEModel();
// prepare for the first iteration
const FETimeInfo& tp = fem.GetTime();
PrepStep();
// init QN method
if (QNInit() == false) return false;
// 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;
// solve the equations (returns line search; solution stored in m_ui)
double s = QNSolve();
// extract the velocity and dilatation increments
GetVelocityData(m_vi, m_ui);
GetAngularVelocityData(m_gi, m_ui);
GetDilatationData(m_fi, m_ui);
// set initial convergence norms
if (m_niter == 0)
{
normRi = fabs(m_R0*m_R0);
normEi = fabs(m_ui*m_R0);
normVi = fabs(m_vi*m_vi);
normGi = fabs(m_gi*m_gi);
normFi = fabs(m_fi*m_fi);
normEm = normEi;
}
// update all degrees of freedom
for (int i=0; i<m_neq; ++i) m_Ui[i] += s*m_ui[i];
// update velocities
for (int i = 0; i<m_nveq; ++i) m_Vi[i] += s*m_vi[i];
// update angular velocities
for (int i = 0; i<m_ngeq; ++i) m_Gi[i] += s*m_gi[i];
// update dilatations
for (int i = 0; i<m_nfeq; ++i) m_Fi[i] += s*m_fi[i];
// update other increments (e.g., Lagrange multipliers)
UpdateIncrements(m_Ui, m_ui, false);
// calculate the norms
normR1 = m_R1*m_R1;
normv = (m_vi*m_vi)*(s*s);
normV = m_Vi*m_Vi;
normg = (m_gi*m_gi)*(s*s);
normG = m_Gi*m_Gi;
normf = (m_fi*m_fi)*(s*s);
normF = m_Fi*m_Fi;
normE1 = s*fabs(m_ui*m_R1);
// check for nans
if (ISNAN(normR1)) throw NANInResidualDetected();
// check residual norm
if ((m_Rtol > 0) && (normR1 > m_Rtol*normRi)) bconv = false;
// check velocity norm
if ((m_Vtol > 0) && (normv > (m_Vtol*m_Vtol)*normV )) bconv = false;
// check angular velocity norm
if ((m_Gtol > 0) && (normg > (m_Gtol*m_Gtol)*normG )) bconv = false;
// check dilatation norm
if ((m_Ftol > 0) && (normf > (m_Ftol*m_Ftol)*normF )) bconv = false;
// check energy norm
if ((m_Etol > 0) && (normE1 > m_Etol*normEi)) bconv = false;
// check linestep size
if ((m_lineSearch->m_LStol > 0) && (s < m_lineSearch->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("\tstiffness updates = %d\n", m_qnstrategy->m_nups);
feLog("\tright hand side evaluations = %d\n", m_nrhs);
feLog("\tstiffness matrix reformations = %d\n", m_nref);
if (m_lineSearch->m_LStol > 0) feLog("\tstep from line search = %lf\n", 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 velocity %15le %15le %15le \n", normVi, normv ,(m_Vtol*m_Vtol)*normV );
feLog("\t angular velocity %15le %15le %15le \n", normGi, normg ,(m_Gtol*m_Gtol)*normG );
feLog("\t dilatation %15le %15le %15le \n", normFi, normf ,(m_Ftol*m_Ftol)*normF );
// 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;
}
// see if we have exceeded the max residual
if ((bconv == false) && (m_Rmax > 0) && (normR1 >= m_Rmax))
{
// doesn't look like we're getting anywhere, so let's retry the time step
throw MaxResidualError();
}
// check if we have converged.
// If not, calculate the BFGS update vectors
if (bconv == false)
{
if (s < m_lineSearch->m_LSmin)
{
// check for zero linestep size
feLogWarning("Zero linestep size. Stiffness matrix will now be reformed");
QNForceReform(true);
}
else if ((normE1 > normEm) && m_bdivreform)
{
// check for diverging
feLogWarning("Problem is diverging. Stiffness matrix will now be reformed");
normEm = normE1;
normEi = normE1;
normRi = normR1;
normVi = normv;
normGi = normg;
normFi = normf;
QNForceReform(true);
}
// Do the QN update (This may also do a stiffness reformation if necessary)
bool bret = QNUpdate();
// something went wrong with the update, so we'll need to break
if (bret == false) break;
}
else if (m_baugment)
{
// Do augmentations
bconv = DoAugmentations();
}
// increase iteration number
m_niter++;
// do minor iterations callbacks
fem.DoCallback(CB_MINOR_ITERS);
}
while (bconv == false);
// if converged we update the total velocities
if (bconv)
{
m_Ut += m_Ui;
zero(m_Ui);
}
return bconv;
}
//-----------------------------------------------------------------------------
//! Calculates global stiffness matrix.
bool FEPolarFluidSolver::StiffnessMatrix(FELinearSystem& LS)
{
FEModel& fem = *GetFEModel();
const FETimeInfo& tp = fem.GetTime();
// get the mesh
FEMesh& mesh = fem.GetMesh();
// calculate the stiffness matrix for each domain
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive()) {
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEPolarFluidDomain* pfdom = dynamic_cast<FEPolarFluidDomain*>(&dom);
if (fdom) fdom->StiffnessMatrix(LS);
else if (pfdom) pfdom->StiffnessMatrix(LS);
}
}
// calculate the body force stiffness matrix for each domain
int NBL = fem.ModelLoads();
for (int j = 0; j<NBL; ++j)
{
FEBodyForce* pbf = dynamic_cast<FEBodyForce*>(fem.ModelLoad(j));
if (pbf && pbf->IsActive())
{
for (int i = 0; i<pbf->Domains(); ++i)
{
FEFluidDomain& fdom = dynamic_cast<FEFluidDomain&>(*pbf->Domain(i));
FEPolarFluidDomain& pfdom = dynamic_cast<FEPolarFluidDomain&>(*pbf->Domain(i));
if (&fdom) fdom.BodyForceStiffness(LS, *pbf);
else if (&pfdom) pfdom.BodyForceStiffness(LS, *pbf);
}
}
FEBodyMoment* pbm = dynamic_cast<FEBodyMoment*>(fem.ModelLoad(j));
if (pbm && pbm->IsActive())
{
for (int i = 0; i<pbm->Domains(); ++i)
{
FEPolarFluidDomain& pfdom = dynamic_cast<FEPolarFluidDomain&>(*pbm->Domain(i));
if (&pfdom) pfdom.BodyMomentStiffness(LS, *pbm);
}
}
}
// calculate the body force stiffness matrix for each domain
for (int j = 0; j<fem.ModelLoads(); ++j)
{
FEModelLoad* pml = fem.ModelLoad(j);
if (pml && pml->IsActive()) pml->StiffnessMatrix(LS);
}
// Add mass matrix
// loop over all domains (except rigid)
for (int i = 0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEPolarFluidDomain* pfdom = dynamic_cast<FEPolarFluidDomain*>(&dom);
if (fdom) fdom->MassMatrix(LS);
else if (pfdom) pfdom->MassMatrix(LS);
}
}
// calculate contact stiffness
ContactStiffness(LS);
// calculate nonlinear constraint stiffness
// note that this is the contribution of the
// constraints enforced with augmented lagrangian
NonLinearConstraintStiffness(LS, tp);
return true;
}
//-----------------------------------------------------------------------------
//! Calculate the stiffness contribution due to nonlinear constraints
void FEPolarFluidSolver::NonLinearConstraintStiffness(FELinearSystem& LS, 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->StiffnessMatrix(LS, tp);
}
}
//-----------------------------------------------------------------------------
//! This function calculates the contact stiffness matrix
void FEPolarFluidSolver::ContactStiffness(FELinearSystem& LS)
{
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->StiffnessMatrix(LS, tp);
}
}
//-----------------------------------------------------------------------------
//! Calculates the contact forces
void FEPolarFluidSolver::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);
}
}
//-----------------------------------------------------------------------------
//! 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 FEPolarFluidSolver::Residual(vector<double>& R)
{
FEModel& fem = *GetFEModel();
// get the time information
const FETimeInfo& tp = fem.GetTime();
// initialize residual with concentrated nodal loads
zero(R);
// zero nodal reaction forces
zero(m_Fr);
// setup the global vector
FEResidualVector RHS(fem, R, m_Fr);
// get the mesh
FEMesh& mesh = fem.GetMesh();
// calculate the internal (stress) forces
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEPolarFluidDomain* pfdom = dynamic_cast<FEPolarFluidDomain*>(&dom);
if (fdom) fdom->InternalForces(RHS);
else if (pfdom) pfdom->InternalForces(RHS);
}
}
// calculate the body forces
for (int j = 0; j<fem.ModelLoads(); ++j)
{
FEBodyForce* pbf = dynamic_cast<FEBodyForce*>(fem.ModelLoad(j));
if (pbf && pbf->IsActive())
{
for (int i = 0; i<pbf->Domains(); ++i)
{
FEFluidDomain& fdom = dynamic_cast<FEFluidDomain&>(*pbf->Domain(i));
FEPolarFluidDomain& pfdom = dynamic_cast<FEPolarFluidDomain&>(*pbf->Domain(i));
if (&fdom) fdom.BodyForce(RHS, *pbf);
else if (&pfdom) pfdom.BodyForce(RHS, *pbf);
}
}
FEBodyMoment* pbm = dynamic_cast<FEBodyMoment*>(fem.ModelLoad(j));
if (pbm && pbm->IsActive())
{
for (int i = 0; i<pbm->Domains(); ++i)
{
FEPolarFluidDomain& pfdom = dynamic_cast<FEPolarFluidDomain&>(*pbm->Domain(i));
if (&pfdom) pfdom.BodyMoment(RHS, *pbm);
}
}
}
// apply external loads
for (int j = 0; j<fem.ModelLoads(); ++j)
{
FEModelLoad* pml = fem.ModelLoad(j);
if (pml->IsActive()) pml->LoadVector(RHS);
}
// calculate inertial forces
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEPolarFluidDomain* pfdom = dynamic_cast<FEPolarFluidDomain*>(&dom);
if (fdom) fdom->InertialForces(RHS);
else if (pfdom) pfdom->InertialForces(RHS);
}
}
// calculate contact forces
ContactForces(RHS);
// calculate nonlinear constraint forces
// note that these are the linear constraints
// enforced using the augmented lagrangian
NonLinearConstraintForces(RHS, tp);
// 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_dofW[0], 0);
node.set_load(m_dofW[1], 0);
node.set_load(m_dofW[2], 0);
int n;
if ((n = -node.m_ID[m_dofW[0]] - 2) >= 0) node.set_load(m_dofW[0], -m_Fr[n]);
if ((n = -node.m_ID[m_dofW[1]] - 2) >= 0) node.set_load(m_dofW[1], -m_Fr[n]);
if ((n = -node.m_ID[m_dofW[2]] - 2) >= 0) node.set_load(m_dofW[2], -m_Fr[n]);
}
// increase RHS counter
m_nrhs++;
return true;
}
//-----------------------------------------------------------------------------
//! calculate the nonlinear constraint forces
void FEPolarFluidSolver::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);
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPrescribedFluidAngularVelocity.h | .h | 1,505 | 35 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedDOF.h>
class FEPrescribedFluidAngularVelocity : public FEPrescribedDOF
{
public:
FEPrescribedFluidAngularVelocity(FEModel* fem);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidNormalVelocity.cpp | .cpp | 11,704 | 384 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidNormalVelocity.h"
#include "FECore/FEElemElemList.h"
#include "FECore/FEGlobalMatrix.h"
#include "FECore/FEGlobalVector.h"
#include "FECore/log.h"
#include "FECore/LinearSolver.h"
#include "FEBioFluid.h"
#include <FECore/FEParabolicMap.h>
#include <FECore/FEFacetSet.h>
#include <FECore/FEMesh.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidNormalVelocity, FESurfaceLoad)
ADD_PARAMETER(m_velocity, "velocity" )->setUnits(UNIT_VELOCITY);
ADD_PARAMETER(m_bpv , "prescribe_nodal_velocities");
ADD_PARAMETER(m_bpar , "parabolic");
ADD_PARAMETER(m_brim , "prescribe_rim_pressure" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidNormalVelocity::FEFluidNormalVelocity(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem), m_dofEF(pfem)
{
m_velocity = 0.0;
m_bpv = true;
m_bpar = false;
m_brim = false;
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dofEF.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION));
}
}
//-----------------------------------------------------------------------------
double FEFluidNormalVelocity::NormalVelocity(FESurfaceMaterialPoint& mp)
{
FESurfaceElement& el = *mp.SurfaceElement();
double vn = 0;
double* N = mp.m_shape;
if (N == nullptr) return 0;
int neln = el.Nodes();
for (int i = 0; i < neln; ++i)
{
vn += N[i] * m_VN[el.m_lnode[i]];
}
return vn;
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the prescribed normal velocity
void FEFluidNormalVelocity::LoadVector(FEGlobalVector& R)
{
const FETimeInfo& tp = GetTimeInfo();
m_psurf->LoadVector(R, m_dofEF, false, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
FESurfaceElement& el = *mp.SurfaceElement();
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
m_psurf->GetNodalCoordinates(el, tp.alphaf, rt);
// calculate the tangent vectors
vec3d dxr = el.eval_deriv1(rt, mp.m_index);
vec3d dxs = el.eval_deriv2(rt, mp.m_index);
// normal velocity
double vn = NormalVelocity(mp);
double da = (dxr ^ dxs).norm();
double H = dof_a.shape;
fa[0] = H * vn * da;
});
}
//-----------------------------------------------------------------------------
double FEFluidNormalVelocity::ScalarLoad(FESurfaceMaterialPoint& mp)
{
return m_velocity(mp);
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidNormalVelocity::Init()
{
if (FESurfaceLoad::Init() == false) return false;
m_dof.Clear();
m_dof.AddDofs(m_dofW);
m_dof.AddDofs(m_dofEF);
return true;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEFluidNormalVelocity::Activate()
{
FESurface& surface = GetSurface();
// This is needed to reproduce the same behavior as feb3.
FESurfaceMap VC(FE_DOUBLE);
VC.Create(surface.GetFacetSet(), 1.0);
// evaluate surface normals
vector<vec3d> sn(surface.Elements(), vec3d(0, 0, 0));
m_nu.resize(surface.Nodes(), vec3d(0, 0, 0));
m_VN.resize(surface.Nodes(), 0.0);
vector<int> nf(surface.Nodes(), 0);
vec3d r0[FEElement::MAX_NODES];
for (int iel = 0; iel< surface.Elements(); ++iel)
{
FESurfaceElement& el = surface.Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i = 0; i<neln; ++i) {
r0[i] = surface.Node(el.m_lnode[i]).m_r0;
m_VN[el.m_lnode[i]] += VC.value<double>(iel, i);
++nf[el.m_lnode[i]];
}
double* Nr, *Ns;
vec3d dxr, dxs;
// repeat over integration points
for (int n = 0; n<nint; ++n)
{
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the tangent vectors at integration point
dxr = dxs = vec3d(0, 0, 0);
for (int i = 0; i<neln; ++i)
{
dxr += r0[i] * Nr[i];
dxs += r0[i] * Ns[i];
}
sn[iel] = dxr ^ dxs;
sn[iel].unit();
}
// evaluate nodal normals by averaging surface normals
for (int i = 0; i<neln; ++i)
m_nu[el.m_lnode[i]] += sn[iel];
}
for (int i = 0; i< surface.Nodes(); ++i) {
m_nu[i].unit();
m_VN[i] /= nf[i];
}
// Set up data structure for setting rim pressure
if (m_brim) {
// find rim nodes (rim)
FEElemElemList EEL;
EEL.Create(&surface);
vector<bool> boundary(surface.Nodes(), false);
for (int i=0; i< surface.Elements(); ++i) {
FESurfaceElement& el = surface.Element(i);
for (int j=0; j<el.facet_edges(); ++j) {
FEElement* nel = EEL.Neighbor(i, j);
if (nel == nullptr) {
int en[3] = {-1,-1,-1};
el.facet_edge(j, en);
boundary[en[0]] = true;
boundary[en[1]] = true;
if (en[2] > -1) boundary[en[2]] = true;
}
}
}
// store boundary nodes for which the velocity DOFs are fixed
// which defines the rim on which the dilatation needs to be prescribed
m_rim.reserve(surface.Nodes());
for (int i=0; i<surface.Nodes(); ++i)
if (boundary[i]) {
FENode& node = surface.Node(i);
if ((node.get_bc(m_dofW[0]) == DOF_FIXED) &&
(node.get_bc(m_dofW[1]) == DOF_FIXED) &&
(node.get_bc(m_dofW[2]) == DOF_FIXED))
m_rim.push_back(i);
}
if (m_rim.size() == surface.Nodes())
{
feLogError("Unable to set rim pressure\n");
}
}
// Set parabolic velocity profile if requested.
// Note that this may override any maps assigned to velocity
if (m_bpar)
{
if (SetParabolicVelocity() == false)
{
feLogError("Unable to set parabolic velocity\n");
}
}
if (m_bpv) {
for (int i = 0; i < surface.Nodes(); ++i)
{
FENode& node = surface.Node(i);
// mark node as having prescribed DOF
if (node.get_bc(m_dofW[0]) != DOF_FIXED) node.set_bc(m_dofW[0], DOF_PRESCRIBED);
if (node.get_bc(m_dofW[1]) != DOF_FIXED) node.set_bc(m_dofW[1], DOF_PRESCRIBED);
if (node.get_bc(m_dofW[2]) != DOF_FIXED) node.set_bc(m_dofW[2], DOF_PRESCRIBED);
}
}
if (m_brim) {
for (int i=0; i<m_rim.size(); ++i) {
FENode& node = surface.Node(m_rim[i]);
// mark node as having prescribed DOF
if (node.get_bc(m_dofEF[0]) != DOF_FIXED) node.set_bc(m_dofEF[0], DOF_PRESCRIBED);
}
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the velocities
void FEFluidNormalVelocity::Update()
{
// prescribe this velocity at the nodes
FESurface* ps = &GetSurface();
// The velocity map is read in as surface data with MULT format.
// However, we need to have (unique) values at the nodes
// so we need to convert this to nodal data.
int N = ps->Nodes();
m_VN.assign(N, 0.0);
vector<int> tag(N, 0);
for (int i = 0; i < ps->Elements(); ++i)
{
FESurfaceElement& el = ps->Element(i);
for (int j = 0; j < el.Nodes(); ++j)
{
FEMaterialPoint mp;
mp.m_elem = ⪙
mp.m_index = j + 0x10000;
double vnj = m_velocity(mp);
m_VN[el.m_lnode[j]] += vnj;
tag[el.m_lnode[j]]++;
}
}
for (int i = 0; i < N; ++i)
{
if (tag[i] != 0) m_VN[i] /= (double)tag[i];
}
if (m_bpv) {
for (int i=0; i<ps->Nodes(); ++i)
{
// evaluate the velocity
vec3d v = m_nu[i]*m_VN[i];
FENode& node = ps->Node(i);
if (node.get_bc(m_dofW[0]) == DOF_PRESCRIBED) node.set(m_dofW[0], v.x);
if (node.get_bc(m_dofW[1]) == DOF_PRESCRIBED) node.set(m_dofW[1], v.y);
if (node.get_bc(m_dofW[2]) == DOF_PRESCRIBED) node.set(m_dofW[2], v.z);
}
}
if (m_brim) SetRimPressure();
ForceMeshUpdate();
}
//-----------------------------------------------------------------------------
//! Evaluate normal velocities by solving Poiseuille flow across the surface
bool FEFluidNormalVelocity::SetParabolicVelocity()
{
FEFacetSet* surf = GetSurface().GetFacetSet(); assert(surf);
if (surf == nullptr) return false;
FEParabolicMap gen(GetFEModel());
gen.SetFacetSet(surf);
// only consider fluid dofs
gen.SetDOFConstraint(m_dofW);
FEDataMap* map = gen.Generate();
if (map == nullptr)
{
assert(false);
return false;
}
GetMesh().AddDataMap(map);
FEMappedValue* val = fecore_alloc(FEMappedValue, GetFEModel());
val->setDataMap(map);
if (m_velocity.isConst() == false) return false;
double vn = m_velocity.constValue();
val->setScaleFactor(vn);
m_velocity.setValuator(val);
return true;
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe rim pressure
bool FEFluidNormalVelocity::SetRimPressure()
{
FESurface* ps = &GetSurface();
// evaluate dilatation everywhere but rim
double es = 0;
int neq = 0;
for (int i=0; i<ps->Nodes(); ++i) {
FENode& node = ps->Node(i);
if (node.get_bc(m_dofEF[0]) == DOF_OPEN) {
es += node.get(m_dofEF[0]);
++neq;
}
}
es /= neq;
// set the rim pressure (dilatation)
for (int i=0; i<m_rim.size(); ++i) {
FENode& node = ps->Node(m_rim[i]);
node.set(m_dofEF[0],es);
}
return true;
}
//-----------------------------------------------------------------------------
//! serializatsion
void FEFluidNormalVelocity::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_nu & m_VN;
ar & m_rim;
ar & m_dofW & m_dofEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FETempDependentConductivity.cpp | .cpp | 3,946 | 109 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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.*/
//
// FEFluidConstantConductivity.cpp
// FEBioFluid
//
// Created by Gerard Ateshian on 2/28/20.
// Copyright © 2020 febio.org. All rights reserved.
//
#include "FETempDependentConductivity.h"
#include "FEThermoFluidMaterialPoint.h"
#include <FECore/log.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FETempDependentConductivity, FEFluidThermalConductivity)
// parameters
ADD_PARAMETER(m_Kr, "Kr")->setLongName("referential thermal conductivity")->setUnits(UNIT_THERMAL_CONDUCTIVITY);
// properties
ADD_PROPERTY(m_Khat, "Khat")->SetLongName("normalized thermal conductivity");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FETempDependentConductivity::FETempDependentConductivity(FEModel* pfem) : FEFluidThermalConductivity(pfem)
{
m_Khat = nullptr;
m_Kr = 0;
m_Tr = 0;
}
//-----------------------------------------------------------------------------
//! initialization
bool FETempDependentConductivity::Init()
{
m_Tr = GetGlobalConstant("T");
if (m_Tr <= 0) { feLogError("A positive referential absolute temperature T must be defined in Globals section"); return false; }
m_Khat->Init();
return FEFluidThermalConductivity::Init();
}
//-----------------------------------------------------------------------------
void FETempDependentConductivity::Serialize(DumpStream& ar)
{
FEFluidThermalConductivity::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Kr & m_Tr;
ar & m_Khat;
if (ar.IsLoading()) {
m_Khat->Init();
}
}
//-----------------------------------------------------------------------------
//! calculate thermal conductivity at material point
double FETempDependentConductivity::ThermalConductivity(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (tf.m_T+m_Tr)/m_Tr;
return m_Khat->value(That)*m_Kr;
}
//-----------------------------------------------------------------------------
//! tangent of thermal conductivity with respect to strain J
double FETempDependentConductivity::Tangent_Strain(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of thermal conductivity with respect to temperature T
double FETempDependentConductivity::Tangent_Temperature(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (tf.m_T+m_Tr)/m_Tr;
return m_Khat->derive(That)*m_Kr/m_Tr;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBiphasicFSIDomain.cpp | .cpp | 1,469 | 34 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBiphasicFSIDomain.h"
//-----------------------------------------------------------------------------
FEBiphasicFSIDomain::FEBiphasicFSIDomain(FEModel* pfem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FENewtonianRealVapor.cpp | .cpp | 8,982 | 261 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENewtonianRealVapor.h"
#include "FEFluid.h"
#include "FEBiphasicFSI.h"
#include "FEThermoFluid.h"
#include "FERealVapor.h"
#include <FECore/log.h>
// define the material parameters
BEGIN_FECORE_CLASS(FENewtonianRealVapor, FEViscousFluid)
ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu" )->setUnits(UNIT_VISCOSITY)->setLongName("referential shear viscosity");
// properties
ADD_PROPERTY(m_esat , "esat",FEProperty::Optional)->SetLongName("saturation dilatation");
ADD_PROPERTY(m_musat, "musat",FEProperty::Optional)->SetLongName("normalized saturation shear viscosity");
ADD_PROPERTY(m_C[0] , "C0", FEProperty::Optional)->SetLongName("1st mu virial coeff");
ADD_PROPERTY(m_C[1] , "C1", FEProperty::Optional)->SetLongName("2nd mu virial coeff");
ADD_PROPERTY(m_C[2] , "C2", FEProperty::Optional)->SetLongName("3rd mu virial coeff");
ADD_PROPERTY(m_C[3] , "C3", FEProperty::Optional)->SetLongName("4th mu virial coeff");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FENewtonianRealVapor::FENewtonianRealVapor(FEModel* pfem) : FEViscousFluid(pfem)
{
m_kappa = 0;
m_mu = 0;
m_Tr = 0;
m_nvc = 0;
m_esat = nullptr;
m_musat = nullptr;
for (int k=0; k<MAX_NVC; ++k) m_C[k] = nullptr;
}
//-----------------------------------------------------------------------------
//! initialization
bool FENewtonianRealVapor::Init()
{
if (m_musat) {
m_Tr = GetGlobalConstant("T");
if (m_Tr <= 0) { feLogError("A positive referential absolute temperature T must be defined in Globals section"); return false; }
}
if (m_esat) m_esat->Init();
else {
FECoreBase* pMat = GetAncestor();
FEThermoFluid* pFluid = dynamic_cast<FEThermoFluid*>(pMat);
if (pFluid) {
FERealVapor* pRV = dynamic_cast<FERealVapor*>(pFluid->GetElastic());
if (pRV) {
m_esat = pRV->m_esat;
m_esat->Init();
m_Tc = pRV->m_Tc;
m_alpha = pRV->m_alpha;
}
else return false;
}
else return false;
}
if (m_musat) m_musat->Init();
m_nvc = 0;
for (int k=0; k<MAX_NVC; ++k) {
if (m_C[k]) {
m_C[k]->Init();
++m_nvc;
}
}
return FEViscousFluid::Init();
}
//-----------------------------------------------------------------------------
void FENewtonianRealVapor::Serialize(DumpStream& ar)
{
FEViscousFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Tr;
}
//-----------------------------------------------------------------------------
//! viscous stress
mat3ds FENewtonianRealVapor::Stress(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double mu = ShearViscosity(pt);
double kappa = BulkViscosity(pt);
mat3ds s = mat3dd(1.0)*(D.tr()*(kappa - 2.*mu/3.)) + D*(2*mu);
return s;
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to strain J
mat3ds FENewtonianRealVapor::Tangent_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
mat3ds D = pf.RateOfDeformation();
// evaluate ∂µ/∂J
double dmuJ = TangentShearViscosityStrain(mp);
double dkpJ = TangentBulkViscosityStrain(mp);
mat3ds dsJ = mat3dd(1.0)*(D.tr()*(dkpJ - 2.*dmuJ/3.)) + D*(2*dmuJ);
return dsJ;
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to rate of deformation tensor D
tens4ds FENewtonianRealVapor::Tangent_RateOfDeformation(FEMaterialPoint& mp)
{
mat3dd I(1.0);
double mu = ShearViscosity(mp);
double kappa = BulkViscosity(mp);
tens4ds c = dyad1s(I)*(kappa - 2.*mu/3.) + dyad4s(I)*(2*mu);
return c;
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to temperature T
mat3ds FENewtonianRealVapor::Tangent_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
mat3ds D = pf.RateOfDeformation();
// evaluate ∂µ/∂T
double dmuT = TangentShearViscosityTemperature(mp);
double dkpT = TangentBulkViscosityTemperature(mp);
mat3ds dsT = mat3dd(1.0)*(D.tr()*(dkpT - 2.*dmuT/3.)) + D*(2*dmuT);
return dsT;
}
//-----------------------------------------------------------------------------
//! dynamic shear viscosity
double FENewtonianRealVapor::ShearViscosity(FEMaterialPoint& mp)
{
double mu = 1.0;
if (m_musat) {
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double J = 1 + pf.m_ef;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
mu = m_musat->value(q);
double Jsat = exp(m_esat->value(q));
double x = 1 - Jsat/J;
for (int k=0; k<m_nvc; ++k) mu += m_C[k]->value(q)*pow(x,k+1);
}
return mu*m_mu;
}
//-----------------------------------------------------------------------------
//! dynamic shear viscosity tangent w.r.t. temperature
double FENewtonianRealVapor::TangentShearViscosityTemperature(FEMaterialPoint& mp)
{
double d = 1e-6*m_Tr;
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
// evaluate ∂µ/∂T
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
FEThermoFluidMaterialPoint* ft = new FEThermoFluidMaterialPoint(fp);
fp->m_ef = pf.m_ef;
ft->m_T = tf.m_T+d;
FEMaterialPoint tmp(ft);
double mup = ShearViscosity(tmp);
ft->m_T = tf.m_T-d;
double mum = ShearViscosity(tmp);
delete ft;
double dmuT = (mup - mum)/(2*d);
return dmuT;
}
//-----------------------------------------------------------------------------
//! dynamic shear viscosity tangent w.r.t. J
double FENewtonianRealVapor::TangentShearViscosityStrain(FEMaterialPoint& mp)
{
double d = 1e-6;
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
// evaluate ∂µ/∂J
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
FEThermoFluidMaterialPoint* ft = new FEThermoFluidMaterialPoint(fp);
fp->m_ef = pf.m_ef+d;
ft->m_T = tf.m_T;
FEMaterialPoint tmp(ft);
double mup = ShearViscosity(tmp);
fp->m_ef = pf.m_ef-d;
double mum = ShearViscosity(tmp);
delete ft;
double dmuJ = (mup - mum)/(2*d);
return dmuJ;
}
//-----------------------------------------------------------------------------
//! bulk viscosity
double FENewtonianRealVapor::BulkViscosity(FEMaterialPoint& mp)
{
double kappa = 0;
return kappa;
}
//-----------------------------------------------------------------------------
//! bulk viscosity tangent w.r.t. temperature
double FENewtonianRealVapor::TangentBulkViscosityTemperature(FEMaterialPoint& mp)
{
double dkpT = 0;
return dkpT;
}
//-----------------------------------------------------------------------------
//! bulk viscosity tangent w.r.t. J
double FENewtonianRealVapor::TangentBulkViscosityStrain(FEMaterialPoint& mp)
{
double dkpJ = 0;
return dkpJ;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSIDomain.cpp | .cpp | 1,462 | 36 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidFSIDomain.h"
//-----------------------------------------------------------------------------
FEFluidFSIDomain::FEFluidFSIDomain(FEModel* pfem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEConstraintNormalFlow.h | .h | 2,992 | 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/FEAugLagLinearConstraint.h>
#include <FECore/FESurface.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! The FEConstraintNormalFlow class implements a fluid surface with zero
//! tangential velocity as a linear constraint.
class FEBIOFLUID_API FEConstraintNormalFlow : public FESurfaceConstraint
{
public:
//! constructor
FEConstraintNormalFlow(FEModel* pfem);
//! destructor
~FEConstraintNormalFlow() {}
//! Activation
void Activate() override;
//! initialization
bool Init() override;
// allocate equations
int InitEquations(int neq) override;
protected:
void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override;
void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override;
void PrepStep() override;
//! Get the surface
FESurface* GetSurface() override { return &m_surf; }
public:
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! add the linear constraint contributions to the residual
void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override;
//! add the linear constraint contributions to the stiffness matrix
void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override;
//! do the augmentation
bool Augment(int naug, const FETimeInfo& tp) override;
//! build connectivity for matrix profile
void BuildMatrixProfile(FEGlobalMatrix& M) override;
protected:
FESurface m_surf;
FELinearConstraintSet m_lc;
bool m_binit;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidVelocity.cpp | .cpp | 2,433 | 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) 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 "FEInitialFluidVelocity.h"
#include "FEBioFluid.h"
#include <FECore/FEMaterialPoint.h>
#include <FECore/FENode.h>
BEGIN_FECORE_CLASS(FEInitialFluidVelocity, FENodalIC)
ADD_PARAMETER(m_v0, "value")->setUnits(UNIT_VELOCITY);
END_FECORE_CLASS();
FEInitialFluidVelocity::FEInitialFluidVelocity(FEModel* fem) : FENodalIC(fem)
{
m_v0 = vec3d(0, 0, 0);
}
// set the initial value
void FEInitialFluidVelocity::SetValue(const vec3d& v0)
{
m_v0 = v0;
}
// initialization
bool FEInitialFluidVelocity::Init()
{
FEDofList dofs(GetFEModel());
if (dofs.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY)) == false) return false;
SetDOFList(dofs);
return true;
}
// return the values for node i
void FEInitialFluidVelocity::GetNodalValues(int inode, std::vector<double>& values)
{
assert(values.size() == 3);
const FENodeSet& nset = *GetNodeSet();
const FENode& node = *nset.Node(inode);
FEMaterialPoint mp;
mp.m_r0 = node.m_r0;
mp.m_index = inode;
vec3d v0 = m_v0(mp);
values[0] = v0.x;
values[1] = v0.y;
values[2] = v0.z;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBinghamFluid.cpp | .cpp | 3,895 | 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.*/
#include "stdafx.h"
#include "FEBinghamFluid.h"
#include "FEFluid.h"
// define the material parameters
BEGIN_FECORE_CLASS(FEBinghamFluid, FEViscousFluid)
ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu" )->setLongName("shear viscosity");
ADD_PARAMETER(m_tauy, FE_RANGE_GREATER_OR_EQUAL(0.0), "tauy")->setLongName("yield stress");
ADD_PARAMETER(m_n , FE_RANGE_GREATER_OR_EQUAL(0.0), "n" )->setLongName("exponent");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FEBinghamFluid::FEBinghamFluid(FEModel* pfem) : FEViscousFluid(pfem)
{
m_mu = 0;
m_tauy = 0;
m_n = 1;
}
//-----------------------------------------------------------------------------
//! viscous stress
mat3ds FEBinghamFluid::Stress(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double mu = ShearViscosity(pt);
mat3ds s = D*(2*mu);
return s;
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to strain J
mat3ds FEBinghamFluid::Tangent_Strain(FEMaterialPoint& mp)
{
return mat3ds(0,0,0,0,0,0);
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to rate of deformation tensor D
tens4ds FEBinghamFluid::Tangent_RateOfDeformation(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
tens4ds c;
mat3dd I(1.0);
if (gdot > 0) {
double mu = m_mu + m_tauy/gdot*(1-exp(-m_n*gdot));
double dmu = m_tauy/pow(gdot,2)*((1+m_n*gdot)*exp(-m_n*gdot)-1);
c = dyad1s(D)*(4/gdot*dmu) + dyad4s(I)*(2*mu);
}
else {
double mu = m_mu + m_tauy*m_n;
c = dyad4s(I)*(2*mu);
}
return c;
}
//-----------------------------------------------------------------------------
//! dynamic viscosity
double FEBinghamFluid::ShearViscosity(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
double mu = (gdot > 0) ? m_mu + m_tauy/gdot*(1-exp(-m_n*gdot)) : m_mu + m_tauy*m_n;
return mu;
}
//-----------------------------------------------------------------------------
//! bulk viscosity
double FEBinghamFluid::BulkViscosity(FEMaterialPoint& pt)
{
return 2*ShearViscosity(pt)/3.;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluid.cpp | .cpp | 6,308 | 198 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluid.h"
#include "FEFluidMaterialPoint.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
#include "FELinearElasticFluid.h"
#include "FENonlinearElasticFluid.h"
#include "FELogNonlinearElasticFluid.h"
#include "FEIdealGasIsentropic.h"
// define the material parameters
BEGIN_FECORE_CLASS(FEFluid, FEFluidMaterial)
// material parameters
ADD_PARAMETER(m_k , FE_RANGE_GREATER_OR_EQUAL(0.0), "k")->setUnits(UNIT_PRESSURE);
ADD_PROPERTY(m_pElastic, "elastic", FEProperty::Optional);
END_FECORE_CLASS();
//============================================================================
// FEFluid
//============================================================================
//-----------------------------------------------------------------------------
//! FEFluid constructor
FEFluid::FEFluid(FEModel* pfem) : FEFluidMaterial(pfem)
{
m_k = 0;
m_pElastic = nullptr;
}
//-----------------------------------------------------------------------------
//! FEFluid initialization
bool FEFluid::Init()
{
m_Tr = GetGlobalConstant("T");
if (m_pElastic == nullptr) {
m_pElastic = fecore_alloc(FELinearElasticFluid, GetFEModel());
}
FELinearElasticFluid* pLN = dynamic_cast<FELinearElasticFluid*>(m_pElastic);
FENonlinearElasticFluid* pNL = dynamic_cast<FENonlinearElasticFluid*>(m_pElastic);
FELogNonlinearElasticFluid* pLNL = dynamic_cast<FELogNonlinearElasticFluid*>(m_pElastic);
FEIdealGasIsentropic* pIGH = dynamic_cast<FEIdealGasIsentropic*>(m_pElastic);
if (pLN) {
pLN->m_k = m_k;
pLN->m_rhor = m_rhor;
return pLN->Init();
}
else if (pNL) {
pNL->m_k = m_k;
pNL->m_rhor = m_rhor;
return pNL->Init();
}
else if (pLNL) {
pLNL->m_k = m_k;
pLNL->m_rhor = m_rhor;
return pLNL->Init();
}
else if (pIGH) {
pIGH->m_k = m_k;
pIGH->m_rhor = m_rhor;
return pIGH->Init();
}
return false;
}
//-----------------------------------------------------------------------------
void FEFluid::Serialize(DumpStream& ar)
{
FEFluidMaterial::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Tr;
}
//-----------------------------------------------------------------------------
//! returns a pointer to a new material point object
FEMaterialPointData* FEFluid::CreateMaterialPointData()
{
return new FEFluidMaterialPoint();
}
//-----------------------------------------------------------------------------
//! bulk modulus
double FEFluid::BulkModulus(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& vt = *mp.ExtractData<FEFluidMaterialPoint>();
return -(vt.m_ef+1)*Tangent_Pressure_Strain(mp);
}
//-----------------------------------------------------------------------------
//! elastic pressure
double FEFluid::Pressure(FEMaterialPoint& mp)
{
return m_pElastic->Pressure(mp);
}
//-----------------------------------------------------------------------------
//! elastic pressure from dilatation
double FEFluid::Pressure(const double e, const double T)
{
return m_pElastic->Pressure(e, T);
}
//-----------------------------------------------------------------------------
double FEFluid::Tangent_Pressure_Strain(FEMaterialPoint& mp)
{
return m_pElastic->Tangent_Strain(mp);
}
//-----------------------------------------------------------------------------
double FEFluid::Tangent_Pressure_Strain_Strain(FEMaterialPoint& mp)
{
return m_pElastic->Tangent_Strain_Strain(mp);
}
//-----------------------------------------------------------------------------
//! The stress of a fluid material is the sum of the fluid pressure
//! and the viscous stress.
mat3ds FEFluid::Stress(FEMaterialPoint& mp)
{
// calculate solid material stress
mat3ds s = GetViscous()->Stress(mp);
double p = Pressure(mp);
// add fluid pressure
s.xx() -= p;
s.yy() -= p;
s.zz() -= p;
return s;
}
//-----------------------------------------------------------------------------
//! The tangent of stress with respect to strain J of a fluid material is the
//! sum of the tangent of the fluid pressure and that of the viscous stress.
mat3ds FEFluid::Tangent_Strain(FEMaterialPoint& mp)
{
// get tangent of viscous stress
mat3ds sJ = GetViscous()->Tangent_Strain(mp);
// add tangent of fluid pressure
double dp = Tangent_Pressure_Strain(mp);
sJ.xx() -= dp;
sJ.yy() -= dp;
sJ.zz() -= dp;
return sJ;
}
//-----------------------------------------------------------------------------
//! calculate strain energy density (per reference volume)
double FEFluid::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double sed = m_k*(fp.m_ef-log(fp.m_ef+1));
return sed;
}
//-----------------------------------------------------------------------------
//! invert pressure-dilatation relation
bool FEFluid::Dilatation(const double T, const double p, double& e)
{
e = -p/m_k;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FESolutesMaterial.cpp | .cpp | 9,127 | 280 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FESolutesMaterial.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
#include <FECore/log.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FESolutesMaterial, FEMaterial)
ADD_PROPERTY(m_pSolute, "solute", FEProperty::Optional);
ADD_PROPERTY(m_pOsmC , "osmotic_coefficient");
ADD_PROPERTY(m_pReact , "reaction" , FEProperty::Optional);
END_FECORE_CLASS();
//============================================================================
// FEFluidSolutesMaterialPoint
//============================================================================
FESolutesMaterial::Point::Point(FEMaterialPointData* pt) : FEMaterialPointData(pt)
{
m_vft = vec3d(0.0, 0.0, 0.0);
m_JfdotoJf = 0.0;
}
//-----------------------------------------------------------------------------
FEMaterialPointData* FESolutesMaterial::Point::Copy()
{
FESolutesMaterial::Point* pt = new FESolutesMaterial::Point(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
//-----------------------------------------------------------------------------
void FESolutesMaterial::Point::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_vft & m_JfdotoJf;
ar & m_nsol;
ar & m_c & m_ca & m_gradc & m_j & m_cdot & m_k & m_dkdJ;
ar & m_dkdc;
}
//-----------------------------------------------------------------------------
void FESolutesMaterial::Point::Init()
{
m_nsol = 0;
m_c.clear();
m_ca.clear();
m_gradc.clear();
m_j.clear();
m_cdot.clear();
m_k.clear();
m_dkdJ.clear();
m_dkdc.clear();
FEMaterialPointData::Init();
}
//-----------------------------------------------------------------------------
double FESolutesMaterial::Point::Osmolarity() const
{
double ew = 0.0;
for (int isol = 0; isol < (int)m_ca.size(); ++isol)
{
ew += m_ca[isol];
}
return ew;
}
//============================================================================
// FESolutesMaterial
//============================================================================
//-----------------------------------------------------------------------------
//! FEFluidSolutes constructor
FESolutesMaterial::FESolutesMaterial(FEModel* pfem) : FEMaterial(pfem)
{
m_Rgas = 0; m_Tabs = 0; m_Fc = 0;
m_pOsmC = 0;
}
//-----------------------------------------------------------------------------
// returns a pointer to a new material point object
FEMaterialPointData* FESolutesMaterial::CreateMaterialPointData()
{
FEFluidMaterialPoint* fpt = new FEFluidMaterialPoint();
return new FESolutesMaterial::Point(fpt);
}
//-----------------------------------------------------------------------------
// initialize
bool FESolutesMaterial::Init()
{
// set the solute IDs first, since they are referenced in FESolute::Init()
for (int i = 0; i<Solutes(); ++i) {
m_pSolute[i]->SetSoluteLocalID(i);
}
// call the base class.
// This also initializes all properties
if (FEMaterial::Init() == false) return false;
int zmin = 0, zmax = 0;
m_Rgas = GetGlobalConstant("R");
m_Tabs = GetGlobalConstant("T");
m_Fc = GetGlobalConstant("Fc");
if (m_Rgas <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; }
if (m_Tabs <= 0) { feLogError("A positive absolute temperature T must be defined in Globals section"); return false; }
if ((zmin || zmax) && (m_Fc <= 0)) {
feLogError("A positive Faraday constant Fc must be defined in Globals section");
return false;
}
return true;
}
//-----------------------------------------------------------------------------
void FESolutesMaterial::Serialize(DumpStream& ar)
{
FEMaterial::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Rgas & m_Tabs & m_Fc;
}
//-----------------------------------------------------------------------------
//! partition coefficient
double FESolutesMaterial::PartitionCoefficient(FEMaterialPoint& pt, const int sol)
{
// solubility
double khat = m_pSolute[sol]->m_pSolub->Solubility(pt);
double kappa = khat;
return kappa;
}
//-----------------------------------------------------------------------------
//! partition coefficients and their derivatives
void FESolutesMaterial::PartitionCoefficientFunctions(FEMaterialPoint& mp, vector<double>& kappa,
vector<double>& dkdJ,
vector< vector<double> >& dkdc)
{
int isol, jsol;
FEFluidMaterialPoint& fpt = *(mp.ExtractData<FEFluidMaterialPoint>());
FESolutesMaterial::Point& spt = *mp.ExtractData<FESolutesMaterial::Point>();
const int nsol = (int)m_pSolute.size();
vector<double> c(nsol);
vector<int> z(nsol);
vector<double> khat(nsol);
vector<double> dkhdJ(nsol);
vector< vector<double> > dkhdc(nsol, vector<double>(nsol));
kappa.resize(nsol);
for (isol=0; isol<nsol; ++isol) {
// get the effective concentration, its gradient and its time derivative
c[isol] = spt.m_c[isol];
// evaluate the solubility and its derivatives w.r.t. J and c
khat[isol] = m_pSolute[isol]->m_pSolub->Solubility(mp);
dkhdJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain(mp);
for (jsol=0; jsol<nsol; ++jsol) {
dkhdc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration(mp,jsol);
dkdc[isol][jsol]=dkhdc[isol][jsol];
}
kappa[isol] = khat[isol];
dkdJ[isol] = dkhdJ[isol];
}
}
//-----------------------------------------------------------------------------
//! actual concentration
double FESolutesMaterial::Concentration(FEMaterialPoint& pt, const int sol)
{
FESolutesMaterial::Point& spt = *pt.ExtractData<FESolutesMaterial::Point>();
// effective concentration
double c = spt.m_c[sol];
return c;
}
//-----------------------------------------------------------------------------
//! actual concentration
double FESolutesMaterial::ConcentrationActual(FEMaterialPoint& pt, const int sol)
{
FESolutesMaterial::Point& spt = *pt.ExtractData<FESolutesMaterial::Point>();
// effective concentration
double ca = spt.m_c[sol];
// partition coefficient
double kappa = PartitionCoefficient(pt, sol);
ca = kappa*ca;
return ca;
}
//-----------------------------------------------------------------------------
//! actual fluid pressure
double FESolutesMaterial::PressureActual(FEMaterialPoint& pt)
{
int i;
FEFluidMaterialPoint& fpt = *pt.ExtractData<FEFluidMaterialPoint>();
const int nsol = (int)m_pSolute.size();
// effective pressure
double p = fpt.m_pf;
// effective concentration
vector<double> c(nsol);
for (i=0; i<nsol; ++i)
c[i] = Concentration(pt, i);
// osmotic coefficient
double osmc = m_pOsmC->OsmoticCoefficient(pt);
// actual pressure
double pa = 0;
for (i=0; i<nsol; ++i) pa += c[i];
pa = p + m_Rgas*m_Tabs*osmc*pa;
return pa;
}
//-----------------------------------------------------------------------------
//! Calculate solute molar flux
vec3d FESolutesMaterial::SoluteFlux(FEMaterialPoint& pt, const int sol)
{
FESolutesMaterial::Point& spt = *pt.ExtractData<FESolutesMaterial::Point>();
// concentration gradient
vec3d gradc = spt.m_gradc[sol];
// solute free diffusivity
double D0 = m_pSolute[sol]->m_pDiff->Free_Diffusivity(pt);
double c = spt.m_c[sol];
vec3d v = spt.m_vft;
// solute flux j
vec3d j = -gradc*D0 + v*c;
return j;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSISolver.cpp | .cpp | 49,054 | 1,424 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include <assert.h>
#include "FEBioFSI.h"
#include "FEFluidFSISolver.h"
#include "FEFluidFSIDomain.h"
#include "FEFluidDomain.h"
#include "FEBiphasicFSIDomain.h"
#include <FEBioMech/FEElasticDomain.h>
#include <FEBioMech/FEPressureLoad.h>
#include <FEBioMech/FERigidConnector.h>
#include <FEBioMech/FESlidingElasticInterface.h>
#include <FEBioMech/FESSIShellDomain.h>
#include <FEBioMech/FEResidualVector.h>
#include <FEBioMech/FE3FieldElasticSolidDomain.h>
#include <FEBioMech/FE3FieldElasticShellDomain.h>
#include <FEBioMech/FEUncoupledMaterial.h>
#include <FEBioMech/FEBodyForce.h>
#include <FEBioMech/FESolidLinearSystem.h>
#include <FECore/FEModel.h>
#include <FECore/log.h>
#include <FECore/DOFS.h>
#include <FECore/FEGlobalMatrix.h>
#include <FECore/sys.h>
#include <FECore/FEBoundaryCondition.h>
#include <FECore/FEModelLoad.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FELinearConstraintManager.h>
#include <FECore/DumpStream.h>
#include "FEFluidFSIAnalysis.h"
//-----------------------------------------------------------------------------
// define the parameter list
BEGIN_FECORE_CLASS(FEFluidFSISolver, FENewtonSolver)
ADD_PARAMETER(m_Dtol , "dtol" );
ADD_PARAMETER(m_Vtol , "vtol" );
ADD_PARAMETER(m_Ftol , "ftol" );
ADD_PARAMETER(m_Etol, FE_RANGE_GREATER_OR_EQUAL(0.0), "etol");
ADD_PARAMETER(m_Rtol, FE_RANGE_GREATER_OR_EQUAL(0.0), "rtol");
ADD_PARAMETER(m_rhoi , "rhoi" );
ADD_PARAMETER(m_pred , "predictor" );
ADD_PARAMETER(m_minJf, "min_volume_ratio");
ADD_PARAMETER(m_order, "order" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! FEFluidFSISolver Construction
//
FEFluidFSISolver::FEFluidFSISolver(FEModel* pfem) : FENewtonSolver(pfem), m_rigidSolver(pfem), \
m_dofU(pfem), m_dofV(pfem), m_dofSU(pfem), m_dofSV(pfem), m_dofSA(pfem),m_dofQ(pfem),m_dofRQ(pfem), m_dofVF(pfem),m_dofAF(pfem),m_dofW(pfem), m_dofAW(pfem), m_dofEF(pfem)
{
// default values
m_Rtol = 0.001;
m_Etol = 0.01;
m_Dtol = 0.001;
m_Vtol = 0.001;
m_Ftol = 0.001;
m_Rmin = 1.0e-20;
m_Rmax = 0; // not used if zero
m_minJf = 0;
m_ndeq = 0;
m_nveq = 0;
m_nfeq = 0;
m_niter = 0;
m_nreq = 0;
// assume non-symmetric
m_msymm = REAL_UNSYMMETRIC;
// default Newmark parameters for rhoi = 0
m_rhoi = 0;
m_alphaf = 1;
m_alpham = 1.5;
m_beta = 0.5625;
m_gamma = 1;
m_pred = 0;
m_order = 2;
// Preferred strategy is Broyden's method
SetDefaultStrategy(QN_BROYDEN);
// turn off checking for a zero diagonal
CheckZeroDiagonal(false);
// get the dof indices
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::DISPLACEMENT));
m_dofV.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::VELOCITY));
m_dofSU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::SHELL_DISPLACEMENT));
m_dofSV.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::SHELL_VELOCITY));
m_dofSA.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::SHELL_ACCELERATION));
m_dofQ.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::ROTATION));
m_dofRQ.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RIGID_ROTATION));
m_dofW.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RELATIVE_FLUID_ACCELERATION));
m_dofVF.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::FLUID_VELOCITY));
m_dofAF.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::FLUID_ACCELERATION));
m_dofEF.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::FLUID_DILATATION));
m_dofAEF = pfem->GetDOFIndex(FEBioFSI::GetVariableName(FEBioFSI::FLUID_DILATATION_TDERIV), 0);
}
}
//-----------------------------------------------------------------------------
FEFluidFSISolver::~FEFluidFSISolver()
{
}
//-----------------------------------------------------------------------------
//! Generate warnings if needed
void FEFluidFSISolver:: SolverWarnings()
{
FEModel& fem = *GetFEModel();
// Generate warning if rigid connectors are used with symmetric stiffness
if (m_msymm == REAL_SYMMETRIC) {
for (int i=0; i<fem.NonlinearConstraints(); ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
FERigidConnector* prc = dynamic_cast<FERigidConnector*>(plc);
if (prc) {
feLogWarning("Rigid connectors require non-symmetric stiffness matrix.\nSet symmetric_stiffness flag to 0 in Control section.");
break;
}
}
// Generate warning if sliding-elastic contact is used with symmetric stiffness
if (fem.SurfacePairConstraints() > 0)
{
// loop over all contact interfaces
for (int i = 0; i<fem.SurfacePairConstraints(); ++i)
{
FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i));
FESlidingElasticInterface* pbw = dynamic_cast<FESlidingElasticInterface*>(pci);
if (pbw) {
feLogWarning("The sliding-elastic contact algorithm runs better with a non-symmetric stiffness matrix.\nYou may set symmetric_stiffness 0 to false in Control section.");
break;
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Allocates and initializes the data structures used by the FEFluidFSISolver
//
bool FEFluidFSISolver::Init()
{
// initialize base class
if (FENewtonSolver::Init() == false) return false;
// check parameters
if (m_Dtol < 0.0) { feLogError("dtol must be nonnegative."); return false; }
if (m_Vtol < 0.0) { feLogError("vtol must be nonnegative."); return false; }
if (m_Ftol < 0.0) { feLogError("ftol 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_rhoi == -1) {
m_alphaf = m_alpham = m_beta = m_gamma = 1.0;
}
else if ((m_rhoi >= 0) && (m_rhoi <= 1)) {
m_alphaf = 1.0/(1+m_rhoi);
if (m_order == 1)
m_alpham = (3-m_rhoi)/(1+m_rhoi)/2; // 1st-order system
else
m_alpham = (2-m_rhoi)/(1+m_rhoi); // 2nd-order system
m_beta = pow(1 + m_alpham - m_alphaf,2)/4;
m_gamma = 0.5 + m_alpham - m_alphaf;
}
else { feLogError("rhoi must be -1 or between 0 and 1.\n"); return false; }
// allocate vectors
int neq = m_neq;
m_Fn.assign(neq, 0);
m_Fr.assign(neq, 0);
m_Ui.assign(neq, 0);
m_Ut.assign(neq, 0);
m_di.assign(m_ndeq,0);
m_Di.assign(m_ndeq,0);
m_vi.assign(m_nveq,0);
m_Vi.assign(m_nveq,0);
m_fi.assign(m_nfeq,0);
m_Fi.assign(m_nfeq,0);
// we need to fill the total DOF vector m_Ut
// TODO: I need to find an easier way to do this
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_dofSU[0]);
gather(m_Ut, mesh, m_dofSU[1]);
gather(m_Ut, mesh, m_dofSU[2]);
gather(m_Ut, mesh, m_dofW[0]);
gather(m_Ut, mesh, m_dofW[1]);
gather(m_Ut, mesh, m_dofW[2]);
gather(m_Ut, mesh, m_dofEF[0]);
// set flag for transient or steady-state analyses
FEAnalysis* pstep = fem.GetCurrentStep();
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(&dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(&dom);
if (fdom) {
if (pstep->m_nanalysis == FEFluidFSIAnalysis::STEADY_STATE)
fdom->SetSteadyStateAnalysis();
else
fdom->SetTransientAnalysis();
}
else if (fsidom) {
if (pstep->m_nanalysis == FEFluidFSIAnalysis::STEADY_STATE)
fsidom->SetSteadyStateAnalysis();
else
fsidom->SetTransientAnalysis();
}
else if (bfsidom) {
if (pstep->m_nanalysis == FEFluidFSIAnalysis::STEADY_STATE)
bfsidom->SetSteadyStateAnalysis();
else
bfsidom->SetTransientAnalysis();
}
}
}
SolverWarnings();
return true;
}
//-----------------------------------------------------------------------------
//! Initialize equations
bool FEFluidFSISolver::InitEquations()
{
// base class initialization
if (FENewtonSolver::InitEquations() == false) return false;
if (m_eq_scheme == EQUATION_SCHEME::BLOCK)
{
// merge the second and third partition
if (m_part.size() == 3)
{
vector<int> newPart(2);
newPart[0] = m_part[0];
newPart[1] = m_part[1] + m_part[2];
m_part = newPart;
}
}
// store the number of equations we currently have
m_nreq = m_neq;
// Next, we assign equation numbers to the rigid body degrees of freedom
int neq = m_rigidSolver.InitEquations(m_neq);
if (neq == -1) return false;
else m_neq = neq;
// determine the number of velocity and dilatation equations
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
m_ndeq = m_nveq = m_nfeq = 0;
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& n = mesh.Node(i);
if (n.m_ID[m_dofU[0] ] != -1) m_ndeq++;
if (n.m_ID[m_dofU[1] ] != -1) m_ndeq++;
if (n.m_ID[m_dofU[2] ] != -1) m_ndeq++;
if (n.m_ID[m_dofSU[0]] != -1) m_ndeq++;
if (n.m_ID[m_dofSU[1]] != -1) m_ndeq++;
if (n.m_ID[m_dofSU[2]] != -1) m_ndeq++;
if (n.m_ID[m_dofW[0] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[1] ] != -1) m_nveq++;
if (n.m_ID[m_dofW[2] ] != -1) m_nveq++;
if (n.m_ID[m_dofEF[0]] != -1) m_nfeq++;
}
// Next, we add any Lagrange Multipliers
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* lmc = fem.NonlinearConstraint(i);
if (lmc->IsActive())
{
m_neq += lmc->InitEquations(m_neq);
}
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i);
if (spc->IsActive())
{
m_neq += spc->InitEquations(m_neq);
}
}
// All initialization is done
return true;
}
//-----------------------------------------------------------------------------
void FEFluidFSISolver::GetDisplacementData(vector<double> &xi, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(xi);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofU[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofU[1]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofU[2]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofSU[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofSU[1]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
nid = n.m_ID[m_dofSU[2]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
xi[m++] = ui[nid];
assert(m <= (int) xi.size());
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSISolver::GetVelocityData(vector<double> &vi, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(vi);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofW[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
nid = n.m_ID[m_dofW[1]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
nid = n.m_ID[m_dofW[2]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
vi[m++] = ui[nid];
assert(m <= (int) vi.size());
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSISolver::GetDilatationData(vector<double> &ei, vector<double> &ui)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(ei);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofEF[0]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
ei[m++] = ui[nid];
assert(m <= (int) ei.size());
}
}
}
//-----------------------------------------------------------------------------
//! Save data to dump file
void FEFluidFSISolver::Serialize(DumpStream& ar)
{
// Serialize parameters
FENewtonSolver::Serialize(ar);
// serialize rigid solver
m_rigidSolver.Serialize(ar);
if (ar.IsShallow()) {
ar & m_Ui & m_Ut & m_Fr;
ar & m_Di & m_Vi & m_Fi;
}
else {
ar & m_nrhs;
ar & m_niter;
ar & m_nref & m_ntotref;
ar & m_nreq & m_ndeq & m_nfeq & m_nveq;
ar & m_rhoi & m_alphaf & m_alpham;
ar & m_beta & m_gamma;
ar & m_pred;
m_Fr.assign(m_neq, 0);
m_Di.assign(m_ndeq,0);
m_Vi.assign(m_nveq,0);
m_Fi.assign(m_nfeq,0);
}
}
//-----------------------------------------------------------------------------
//! Update the kinematics of the model, such as nodal positions, velocities,
//! accelerations, etc.
void FEFluidFSISolver::UpdateKinematics(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
// get the mesh
FEMesh& mesh = fem.GetMesh();
// update rigid bodies
m_rigidSolver.UpdateRigidBodies(m_Ui, ui);
// update nodes
vector<double> U(m_Ut.size());
for (size_t i=0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ui[i] + m_Ut[i];
scatter3(U, mesh, m_dofU[0], m_dofU[1], m_dofU[2]);
scatter3(U, mesh, m_dofSU[0], m_dofSU[1], m_dofSU[2]);
scatter3(U, mesh, m_dofW[0], m_dofW[1], m_dofW[2]);
scatter(U, mesh, m_dofEF[0]);
// force dilatations to remain greater than -1
if (m_minJf > 0) {
const int NN = mesh.Nodes();
for (int i=0; i<NN; ++i)
{
FENode& node = mesh.Node(i);
if (node.get(m_dofEF[0]) <= -1.0)
node.set(m_dofEF[0], m_minJf - 1.0);
}
}
// make sure the prescribed BCs are fulfilled
int nvel = fem.BoundaryConditions();
for (int i=0; i<nvel; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.Update();
}
// apply prescribed DOFs for specialized surface loads
int nml = fem.ModelLoads();
for (int i=0; i<nml; ++i)
{
FEModelLoad& pml = *fem.ModelLoad(i);
if (pml.IsActive()) pml.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]);
node.m_dt = node.m_d0 + node.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2])
- node.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]);
}
}
// update time derivatives of velocity and dilatation
// for dynamic simulations
FEAnalysis* pstep = fem.GetCurrentStep();
if (pstep->m_nanalysis == FEFluidFSIAnalysis::DYNAMIC)
{
int N = mesh.Nodes();
double dt = fem.GetTime().timeIncrement;
double a = 1.0 / (m_beta*dt);
double b = a / dt;
double c = 1.0 - 0.5/m_beta;
double cgi = 1 - 1.0/m_gamma;
for (int i=0; i<N; ++i)
{
FENode& n = mesh.Node(i);
// solid acceleration
n.m_at = (n.m_rt - n.m_rp)*b - n.m_vp*a + n.m_ap*c;
// solid velocity
vec3d vt = n.m_vp + (n.m_ap*(1.0 - m_gamma) + n.m_at*m_gamma)*dt;
n.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], vt);
// shell kinematics
vec3d qt = n.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]);
vec3d qp = n.get_vec3d_prev(m_dofSU[0], m_dofSU[1], m_dofSU[2]);
vec3d vqp = n.get_vec3d_prev(m_dofSV[0], m_dofSV[1], m_dofSV[2]);
vec3d aqp = n.get_vec3d_prev(m_dofSA[0], m_dofSA[1], m_dofSA[2]);
vec3d aqt = (qt - qp)*b - vqp*a + aqp*c;
vec3d vqt = vqp + (aqp*(1.0 - m_gamma) + aqt*m_gamma)*dt;
n.set_vec3d(m_dofSA[0], m_dofSA[1], m_dofSA[2], aqt);
n.set_vec3d(m_dofSV[0], m_dofSV[1], m_dofSV[2], vqt);
// relative fluid velocity material time derivative (in solid frame)
vec3d wt = n.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d wp = n.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d awt = n.get_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
vec3d awp = n.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
awt = awp*cgi + (wt - wp)/(m_gamma*dt);
n.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awt);
// fluid velocity
vec3d vft = vt + wt;
n.set_vec3d(m_dofVF[0], m_dofVF[1], m_dofVF[2], vft);
// material time derivative of fluid velocity (in solid frame)
vec3d aft = n.m_at + awt;
n.set_vec3d(m_dofAF[0], m_dofAF[1], m_dofAF[2], aft);
// dilatation time derivative
double eft = n.get(m_dofEF[0]);
double efp = n.get_prev(m_dofEF[0]);
double aefp = n.get_prev(m_dofAEF);
double aeft = aefp*cgi + (eft - efp)/(m_gamma*dt);
n.set(m_dofAEF, aeft);
}
int _a = 0;
}
// update nonlinear constraints (needed for updating Lagrange Multiplier)
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* nlc = fem.NonlinearConstraint(i);
if (nlc->IsActive()) nlc->Update(m_Ui, ui);
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i);
if (spc->IsActive()) spc->Update(m_Ui, ui);
}
}
//-----------------------------------------------------------------------------
//! Update DOF increments
void FEFluidFSISolver::UpdateIncrements(vector<double>& Ui, vector<double>& ui, bool emap)
{
FEModel& fem = *GetFEModel();
// get the mesh
FEMesh& mesh = fem.GetMesh();
// update rigid bodies
m_rigidSolver.UpdateIncrements(Ui, ui, emap);
// extract the velocity and dilatation increments
GetDisplacementData(m_di, ui);
GetVelocityData(m_vi, ui);
GetDilatationData(m_fi, ui);
// update displacements
for (int i = 0; i<m_ndeq; ++i) m_Di[i] += m_di[i];
// update velocities
for (int i = 0; i<m_nveq; ++i) m_Vi[i] += m_vi[i];
// update dilatations
for (int i = 0; i<m_nfeq; ++i) m_Fi[i] += m_fi[i];
// update flexible nodes
int n;
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
// displacement dofs
// current position = initial + total at prev conv step + total increment so far + current increment
if ((n = node.m_ID[m_dofU[0]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofU[1]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofU[2]]) >= 0) Ui[n] += ui[n];
// rotational dofs
if ((n = node.m_ID[m_dofSU[0]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofSU[1]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofSU[2]]) >= 0) Ui[n] += ui[n];
// fluid relative velocity
if ((n = node.m_ID[m_dofW[0]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofW[1]]) >= 0) Ui[n] += ui[n];
if ((n = node.m_ID[m_dofW[2]]) >= 0) Ui[n] += ui[n];
// fluid dilatation
if ((n = node.m_ID[m_dofEF[0]]) >= 0) Ui[n] += ui[n];
}
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
if (plc && plc->IsActive()) plc->UpdateIncrements(Ui, ui);
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* psc = fem.SurfacePairConstraint(i);
if (psc && psc->IsActive()) psc->UpdateIncrements(Ui, ui);
}
// TODO: This is a hack!
// The problem is that I only want to call the domain's IncrementalUpdate during
// the quasi-Newtoon loop. However, this function is also called after the loop
// converges. The emap parameter is used here to detect wether we are inside the
// loop (emap == false), or not (emap == true).
if (emap == false)
{
for (int i = 0; i < mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
dom.IncrementalUpdate(ui, true);
}
}
}
//-----------------------------------------------------------------------------
//! Updates the current state of the model
void FEFluidFSISolver::Update(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
tp.currentIteration = m_niter;
// update EAS
UpdateEAS(ui);
UpdateIncrementsEAS(ui, true);
// update kinematics
UpdateKinematics(ui);
// update element stresses
UpdateModel();
}
//-----------------------------------------------------------------------------
//! Update EAS
void FEFluidFSISolver::UpdateEAS(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// update EAS on shell domains
for (int i=0; i<mesh.Domains(); ++i) {
FESSIShellDomain* sdom = dynamic_cast<FESSIShellDomain*>(&mesh.Domain(i));
if (sdom && sdom->IsActive()) sdom->UpdateEAS(ui);
}
}
//-----------------------------------------------------------------------------
//! Update EAS
void FEFluidFSISolver::UpdateIncrementsEAS(vector<double>& ui, const bool binc)
{
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// update EAS on shell domains
for (int i=0; i<mesh.Domains(); ++i) {
FESSIShellDomain* sdom = dynamic_cast<FESSIShellDomain*>(&mesh.Domain(i));
if (sdom && sdom->IsActive()) sdom->UpdateIncrementsEAS(ui, binc);
}
}
//-----------------------------------------------------------------------------
bool FEFluidFSISolver::InitStep(double time)
{
FEModel& fem = *GetFEModel();
// get time integration parameters
FETimeInfo& tp = fem.GetTime();
tp.alpha = m_alphaf;
tp.beta = m_beta;
tp.gamma = m_gamma;
tp.alphaf = m_alphaf;
tp.alpham = m_alpham;
// evaluate load curve values at current (or intermediate) time
double t = tp.currentTime;
// double dt = tp.timeIncrement;
// double ta = (t > 0) ? t - (1-m_alpha)*dt : m_alpha*dt;
// return FESolver::InitStep(ta);
return FESolver::InitStep(t);
}
//-----------------------------------------------------------------------------
//! Prepares the data for the first BFGS-iteration.
void FEFluidFSISolver::PrepStep()
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
double dt = tp.timeIncrement;
tp.currentIteration = m_niter;
// zero total DOFs
zero(m_Ui);
zero(m_Vi);
zero(m_Di);
zero(m_Fi);
// store previous mesh state
// we need them for strain 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;
ni.m_dp = ni.m_dt = ni.m_d0;
ni.UpdateValues();
switch (m_pred) {
case 0:
{
// initial guess at start of new time step (default)
// solid
ni.m_at = ni.m_ap*(1-0.5/m_beta) - ni.m_vp/(m_beta*dt);
vec3d vs = ni.m_vp + (ni.m_at*m_gamma + ni.m_ap*(1-m_gamma))*dt;
ni.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], vs);
// solid shell
vec3d aqp = ni.get_vec3d_prev(m_dofSA[0], m_dofSA[1], m_dofSA[2]);
vec3d vqp = ni.get_vec3d_prev(m_dofSV[0], m_dofSV[1], m_dofSV[2]);
vec3d aqt = aqp*(1-0.5/m_beta) - vqp/(m_beta*dt);
ni.set_vec3d(m_dofSA[0], m_dofSA[1], m_dofSA[2], aqt);
vec3d vqt = vqp + (aqt*m_gamma + aqp*(1-m_gamma))*dt;
ni.set_vec3d(m_dofSV[0], m_dofSV[1], m_dofSV[2], vqt);
// fluid
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ni.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awp*(m_gamma-1)/m_gamma);
ni.set(m_dofAEF, ni.get_prev(m_dofAEF)*(m_gamma-1)/m_gamma);
}
break;
case 1:
{
// initial guess at start of new time step (Zero Ydot)
ni.m_at = vec3d(0,0,0);
ni.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2],vec3d(0,0,0));
ni.set(m_dofAEF, 0);
ni.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], ni.m_vp + ni.m_ap*dt*(1-m_gamma)*m_alphaf);
vec3d wp = ni.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ni.set_vec3d(m_dofW[0], m_dofW[1], m_dofW[2], wp + awp*dt*(1-m_gamma)*m_alphaf);
ni.set(m_dofEF[0], ni.get_prev(m_dofEF[0]) + ni.get_prev(m_dofAEF)*dt*(1-m_gamma)*m_alphaf);
}
break;
case 2:
{
// initial guess at start of new time step (Same Ydot)
vec3d awp = ni.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ni.set_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2], awp);
ni.set(m_dofAEF, ni.get_prev(m_dofAEF));
ni.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], ni.m_vp + ni.m_ap*dt);
vec3d wp = ni.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
ni.set_vec3d(m_dofW[0], m_dofW[1], m_dofW[2], wp + awp*dt);
ni.set(m_dofEF[0], ni.get_prev(m_dofEF[0]) + ni.get_prev(m_dofAEF)*dt);
}
break;
default:
break;
}
}
// apply prescribed velocities
// we save the prescribed velocity increments in the ui vector
vector<double>& ui = m_ui;
zero(ui);
int nbc = fem.BoundaryConditions();
for (int i=0; i<nbc; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive()) bc.PrepStep(ui);
}
// apply prescribed DOFs for specialized surface loads
int nsl = fem.ModelLoads();
for (int i = 0; i < nsl; ++i)
{
FEModelLoad& pml = *fem.ModelLoad(i);
if (pml.IsActive()) pml.PrepStep();
}
// do the linear constraints
fem.GetLinearConstraintManager().PrepStep();
// initialize rigid bodies
m_rigidSolver.PrepStep(tp, ui);
// initialize material point data
// NOTE: do this before the stresses are updated
// TODO: does it matter if the stresses are updated before
// the material point data is initialized
// update domain data
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive()) dom.PreSolveUpdate(tp);
}
// update model state
UpdateModel();
for (int i = 0; i < fem.NonlinearConstraints(); ++i)
{
FENLConstraint* plc = fem.NonlinearConstraint(i);
if (plc && plc->IsActive()) plc->PrepStep();
}
for (int i = 0; i < fem.SurfacePairConstraints(); ++i)
{
FESurfacePairConstraint* psc = fem.SurfacePairConstraint(i);
if (psc && psc->IsActive()) psc->PrepStep();
}
// 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
if (fem.NonlinearConstraints() != 0) m_baugment = true;
}
//-----------------------------------------------------------------------------
bool FEFluidFSISolver::Quasin()
{
FEModel& fem = *GetFEModel();
vector<double> u0(m_neq);
vector<double> Rold(m_neq);
// convergence norms
double normR1; // residual norm
double normE1; // energy norm
double normD; // displacement norm
double normd; // displacement increment norm
double normV; // velocity norm
double normv; // velocity increment norm
double normRi = 0; // initial residual norm
double normDi = 0; // initial displacement norm
double normVi = 0; // initial velocity norm
double normEi = 0; // initial energy norm
double normEm = 0; // max energy norm
double normFi = 0; // initial dilatation norm
double normF; // current dilatation norm
double normf; // incremement dilatation norm
// prepare for the first iteration
const FETimeInfo& tp = fem.GetTime();
PrepStep();
// init QN method
if (QNInit() == false) return false;
// 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;
// solve the equations
SolveEquations(m_ui, m_R0);
// do the line search
double s = DoLineSearch();
// set initial convergence norms
if (m_niter == 0)
{
normRi = fabs(m_R0*m_R0);
normEi = fabs(m_ui*m_R0);
normDi = fabs(m_di*m_di);
normVi = fabs(m_vi*m_vi);
normFi = fabs(m_fi*m_fi);
normEm = normEi;
}
// calculate actual displacement increment
// NOTE: We don't apply the line search directly to m_ui since we need the unscaled search direction for the QN update below
int neq = (int)m_Ui.size();
vector<double> ui(m_ui);
for (int i = 0; i<neq; ++i) ui[i] *= s;
// update increments (including Lagrange multipliers)
UpdateIncrements(m_Ui, ui, false);
// calculate the norms
normR1 = m_R1*m_R1;
normd = m_di*m_di;
normD = m_Di*m_Di;
normv = m_vi*m_vi;
normV = m_Vi*m_Vi;
normf = m_fi*m_fi;
normF = m_Fi*m_Fi;
normE1 = fabs(ui*m_R1);
// check for nans
if (ISNAN(normR1)) throw NANInResidualDetected();
if (ISNAN(normv)) throw NANInResidualDetected();
if (ISNAN(normd)) throw NANInResidualDetected();
if (ISNAN(normf)) throw NANInResidualDetected();
// check residual norm
if ((m_Rtol > 0) && (normR1 > m_Rtol*normRi)) bconv = false;
// check displacement norm
if ((m_Dtol > 0) && (normd > (m_Dtol*m_Dtol)*normD )) bconv = false;
// check velocity norm
if ((m_Vtol > 0) && (normv > (m_Vtol*m_Vtol)*normV )) bconv = false;
// check dilatation norm
if ((m_Ftol > 0) && (normf > (m_Ftol*m_Ftol)*normF )) bconv = false;
// check energy norm
if ((m_Etol > 0) && (normE1 > m_Etol*normEi)) bconv = false;
// check linestep size
if ((m_lineSearch->m_LStol > 0) && (s < m_lineSearch->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("\tstiffness updates = %d\n", m_qnstrategy->m_nups);
feLog("\tright hand side evaluations = %d\n", m_nrhs);
feLog("\tstiffness matrix reformations = %d\n", m_nref);
if (m_lineSearch->m_LStol > 0) feLog("\tstep from line search = %lf\n", 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", normDi, normd ,(m_Dtol*m_Dtol)*normD );
feLog("\t velocity %15le %15le %15le \n", normVi, normv ,(m_Vtol*m_Vtol)*normV );
feLog("\t dilatation %15le %15le %15le \n", normFi, normf ,(m_Ftol*m_Ftol)*normF );
// 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;
}
// see if we have exceeded the max residual
if ((bconv == false) && (m_Rmax > 0) && (normR1 >= m_Rmax))
{
// doesn't look like we're getting anywhere, so let's retry the time step
throw MaxResidualError();
}
// check if we have converged.
// If not, calculate the BFGS update vectors
if (bconv == false)
{
if (s < m_lineSearch->m_LSmin)
{
// check for zero linestep size
feLogWarning("Zero linestep size. Stiffness matrix will now be reformed");
QNForceReform(true);
}
else if ((normE1 > normEm) && m_bdivreform)
{
// check for diverging
feLogWarning("Problem is diverging. Stiffness matrix will now be reformed");
normEm = normE1;
normEi = normE1;
normRi = normR1;
normDi = normd;
normVi = normv;
normFi = normf;
QNForceReform(true);
}
// Do the QN update (This may also do a stiffness reformation if necessary)
bool bret = QNUpdate();
// something went wrong with the update, so we'll need to break
if (bret == false) break;
}
else if (m_baugment)
{
// Do augmentations
bconv = DoAugmentations();
}
// increase iteration number
m_niter++;
// do minor iterations callbacks
fem.DoCallback(CB_MINOR_ITERS);
}
while (bconv == false);
// if converged we update the total velocities
if (bconv)
{
UpdateIncrementsEAS(m_Ui, false);
UpdateIncrements(m_Ut, m_Ui, true);
zero(m_Ui);
zero(m_Di); zero(m_Vi); zero(m_Fi);
}
return bconv;
}
//-----------------------------------------------------------------------------
//! Calculates global stiffness matrix.
bool FEFluidFSISolver::StiffnessMatrix()
{
FEModel& fem = *GetFEModel();
const FETimeInfo& tp = fem.GetTime();
// get the mesh
FEMesh& mesh = fem.GetMesh();
FESolidLinearSystem LS(&fem, &m_rigidSolver, *m_pK, m_Fd, m_ui, (m_msymm == REAL_SYMMETRIC), m_alphaf, m_nreq);
// calculate the stiffness matrix for each domain
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive()) {
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(&dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(&dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(&dom);
if (fdom) fdom->StiffnessMatrix(LS);
else if (fsidom) fsidom->StiffnessMatrix(LS);
else if (bfsidom) bfsidom->StiffnessMatrix(LS);
else if (edom) edom->StiffnessMatrix(LS);
}
}
// calculate the body force stiffness matrix for each domain
// but not for solid domains (since they have no mass in FSI)
int NML = fem.ModelLoads();
for (int j = 0; j<NML; ++j)
{
FEBodyForce* pbf = dynamic_cast<FEBodyForce*>(fem.ModelLoad(j));
if (pbf && pbf->IsActive())
{
for (int i = 0; i<pbf->Domains(); ++i)
{
FEDomain* dom = pbf->Domain(i);
if (dom->IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(dom);
if (fdom) fdom->BodyForceStiffness(LS, *pbf);
else if (fsidom) fsidom->BodyForceStiffness(LS, *pbf);
else if (bfsidom) bfsidom->BodyForceStiffness(LS, *pbf);
else if (edom)
{
FESolidMaterial* mat = dynamic_cast<FESolidMaterial*>(dom->GetMaterial());
if (mat && (mat->IsRigid()==false)) edom->BodyForceStiffness(LS, *pbf);
}
}
}
}
}
// TODO: add body force stiffness for rigid bodies
// Add mass matrix
// FEAnalysis* pstep = fem.GetCurrentStep();
// if (pstep->m_nanalysis == FEFluidFSIAnalysis::DYNAMIC)
{
// scale factor
double dt = tp.timeIncrement;
double a = tp.alpham / (m_beta*dt*dt);
// loop over all domains (except rigid)
for (int i = 0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(&dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(&dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(&dom);
if (fdom) fdom->MassMatrix(LS);
else if (fsidom) fsidom->MassMatrix(LS);
else if (bfsidom) bfsidom->MassMatrix(LS);
else if (edom)
{
FESolidMaterial* mat = dynamic_cast<FESolidMaterial*>(dom.GetMaterial());
if (mat && (mat->IsRigid() == false)) edom->MassMatrix(LS, a);
}
}
}
m_rigidSolver.RigidMassMatrix(LS, tp);
}
// calculate contact stiffness
ContactStiffness(LS);
// calculate the stiffness contributions for the loads
for (int i = 0; i < fem.ModelLoads(); ++i) fem.ModelLoad(i)->StiffnessMatrix(LS);
// calculate nonlinear constraint stiffness
// note that this is the contribution of the
// constraints enforced with augmented lagrangian
NonLinearConstraintStiffness(LS, tp);
// add contributions from rigid bodies
m_rigidSolver.StiffnessMatrix(*m_pK, tp);
return true;
}
//-----------------------------------------------------------------------------
//! Calculate the stiffness contribution due to nonlinear constraints
void FEFluidFSISolver::NonLinearConstraintStiffness(FELinearSystem& LS, 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->StiffnessMatrix(LS, tp);
}
}
//-----------------------------------------------------------------------------
//! This function calculates the contact stiffness matrix
void FEFluidFSISolver::ContactStiffness(FELinearSystem& LS)
{
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->StiffnessMatrix(LS, tp);
}
}
//-----------------------------------------------------------------------------
//! Calculates the contact forces
void FEFluidFSISolver::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);
}
}
//-----------------------------------------------------------------------------
//! 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 FEFluidFSISolver::Residual(vector<double>& R)
{
FEModel& fem = *GetFEModel();
// get the time information
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
m_rigidSolver.Residual();
// get the mesh
FEMesh& mesh = fem.GetMesh();
// calculate the internal (stress) forces
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(&dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(&dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(&dom);
if (fdom) fdom->InternalForces(RHS);
else if (fsidom) fsidom->InternalForces(RHS);
else if (bfsidom) bfsidom->InternalForces(RHS);
else if (edom)
{
FESolidMaterial* mat = dynamic_cast<FESolidMaterial*>(dom.GetMaterial());
if (mat && (mat->IsRigid() == false)) edom->InternalForces(RHS);
}
}
}
// calculate the body forces
for (int j = 0; j<fem.ModelLoads(); ++j)
{
FEBodyForce* pbf = dynamic_cast<FEBodyForce*>(fem.ModelLoad(j));
if (pbf && pbf->IsActive())
{
for (int i = 0; i<pbf->Domains(); ++i)
{
FEDomain* dom = pbf->Domain(i);
if (dom->IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(dom);
if (fdom) fdom->BodyForce(RHS, *pbf);
else if (fsidom) fsidom->BodyForce(RHS, *pbf);
else if (bfsidom) bfsidom->BodyForce(RHS, *pbf);
else if (edom)
{
FESolidMaterial* mat = dynamic_cast<FESolidMaterial*>(dom->GetMaterial());
if (mat && (mat->IsRigid()==false)) edom->BodyForce(RHS, *pbf);
}
}
}
}
}
// allocate F
vector<double> F;
FEAnalysis* pstep = fem.GetCurrentStep();
// calculate inertial forces
for (int i=0; i<mesh.Domains(); ++i)
{
FEDomain& dom = mesh.Domain(i);
if (dom.IsActive())
{
FEFluidDomain* fdom = dynamic_cast<FEFluidDomain*>(&dom);
FEFluidFSIDomain* fsidom = dynamic_cast<FEFluidFSIDomain*>(&dom);
FEBiphasicFSIDomain* bfsidom = dynamic_cast<FEBiphasicFSIDomain*>(&dom);
FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(&dom);
if (fdom) fdom->InertialForces(RHS);
else if (fsidom) fsidom->InertialForces(RHS);
else if (bfsidom) bfsidom->InertialForces(RHS);
else if (edom && (pstep->m_nanalysis == FEFluidFSIAnalysis::DYNAMIC))
{
FESolidMaterial* mat = dynamic_cast<FESolidMaterial*>(dom.GetMaterial());
if (mat && (mat->IsRigid()==false)) edom->InertialForces(RHS, F);
}
}
}
// update rigid bodies
if (pstep->m_nanalysis == FEFluidFSIAnalysis::DYNAMIC) m_rigidSolver.InertialForces(RHS, tp);
// 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);
}
// calculate contact forces
ContactForces(RHS);
// calculate nonlinear constraint forces
// note that these are the linear constraints
// enforced using the augmented lagrangian
NonLinearConstraintForces(RHS, tp);
// 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;
}
//-----------------------------------------------------------------------------
//! calculate the nonlinear constraint forces
void FEFluidFSISolver::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);
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidRotationalVelocity.cpp | .cpp | 3,678 | 111 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidRotationalVelocity.h"
#include "FECore/FEElemElemList.h"
#include "FECore/FEGlobalMatrix.h"
#include "FECore/FEGlobalVector.h"
#include "FECore/log.h"
#include "FECore/LinearSolver.h"
#include <FECore/FENode.h>
#include "FEBioFluid.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidRotationalVelocity, FEPrescribedNodeSet)
ADD_PARAMETER(m_w, "angular_speed");
ADD_PARAMETER(m_n, "axis" );
ADD_PARAMETER(m_p, "origin" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidRotationalVelocity::FEFluidRotationalVelocity(FEModel* pfem) : FEPrescribedNodeSet(pfem)
{
m_w = 0.0;
m_n = vec3d(0,0,1);
m_p = vec3d(0,0,0);
// Set the dof list
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
FEDofList dofs(pfem);
dofs.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
SetDOFList(dofs);
}
}
//-----------------------------------------------------------------------------
// copy data from another class
void FEFluidRotationalVelocity::CopyFrom(FEBoundaryCondition* pbc)
{
FEFluidRotationalVelocity* rv = dynamic_cast<FEFluidRotationalVelocity*>(pbc);
m_w = rv->m_w;
m_n = rv->m_n;
m_p = rv->m_p;
CopyParameterListState(rv->GetParameterList());
}
//-----------------------------------------------------------------------------
// return nodal value
void FEFluidRotationalVelocity::GetNodalValues(int nodelid, std::vector<double>& val)
{
vec3d n(m_n); n.unit();
vec3d v = (n ^ m_r[nodelid])*m_w;
val[0] = v.x;
val[1] = v.y;
val[2] = v.z;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidRotationalVelocity::Init()
{
// evaluate nodal radial positions
vec3d n(m_n); n.unit();
const FENodeSet& nset = *GetNodeSet();
int N = nset.Size();
m_r.resize(N,vec3d(0,0,0));
for (int i=0; i<N; ++i) {
vec3d x = nset.Node(i)->m_r0 - m_p;
m_r[i] = x - n*(x*n);
}
return FEPrescribedNodeSet::Init();
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidRotationalVelocity::Serialize(DumpStream& ar)
{
FEPrescribedNodeSet::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_r;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIDomain.h | .h | 3,241 | 80 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "febiofluid_api.h"
class FEModel;
class FELinearSystem;
class FEBodyForce;
class FEGlobalVector;
class FETimeInfo;
//-----------------------------------------------------------------------------
//! Abstract interface class for multiphasic-FSI domains.
//! A multiphasic-FSI domain is used by the multiphasic-FSI solver.
//! This interface defines the functions that have to be implemented by a
//! multiphasic-FSI domain. There are basically two categories: residual functions
//! that contribute to the global residual vector. And stiffness matrix
//! function that calculate contributions to the global stiffness matrix.
class FEBIOFLUID_API FEMultiphasicFSIDomain
{
public:
FEMultiphasicFSIDomain(FEModel* pfem);
virtual ~FEMultiphasicFSIDomain(){}
// --- R E S I D U A L ---
//! calculate the internal forces
virtual void InternalForces(FEGlobalVector& R) = 0;
//! Calculate the body force vector
virtual void BodyForce(FEGlobalVector& R, FEBodyForce& bf) = 0;
//! calculate the interial forces (for dynamic problems)
virtual void InertialForces(FEGlobalVector& R) = 0;
// --- S T I F F N E S S M A T R I X ---
//! Calculate global stiffness matrix (only contribution from internal force derivative)
//! \todo maybe I should rename this the InternalStiffness matrix?
virtual void StiffnessMatrix (FELinearSystem& LS) = 0;
//! Calculate stiffness contribution of body forces
virtual void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) = 0;
//! calculate the mass matrix (for dynamic problems)
virtual void MassMatrix(FELinearSystem& LS) = 0;
//! transient analysis
void SetTransientAnalysis() { m_btrans = true; }
void SetSteadyStateAnalysis() { m_btrans = false; }
protected:
bool m_btrans; // flag for transient (true) or steady-state (false) analysis
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidDilatation.cpp | .cpp | 1,737 | 42 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEInitialFluidDilatation.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEInitialFluidDilatation, FEInitialCondition)
ADD_PARAMETER(m_data, "value")->setUnits(UNIT_NONE);
END_FECORE_CLASS();
FEInitialFluidDilatation::FEInitialFluidDilatation(FEModel* fem) : FEInitialDOF(fem)
{
}
bool FEInitialFluidDilatation::Init()
{
if (SetDOF("ef") == false) return false;
return FEInitialDOF::Init();
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBiphasicFSITraction.h | .h | 2,544 | 69 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include "FEFluid.h"
//-----------------------------------------------------------------------------
//! This surface load represents the traction applied on the solid at the
//! interface between a fluid and solid in an FSI analysis.
class FEBIOFLUID_API FEBiphasicFSITraction : public FESurfaceLoad
{
public:
//! constructor
FEBiphasicFSITraction(FEModel* pfem);
//! calculate pressure stiffness
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! serialize data
void Serialize(DumpStream& ar) override;
//! initialization
bool Init() override;
private:
double GetFluidDilatation(FESurfaceMaterialPoint& mp, double alpha);
mat3ds GetFluidStress(FESurfaceMaterialPoint& mp);
protected:
vector<double> m_s; //!< scale factor
vector<FEElement*> m_elem; //!< list of fluid-FSI elements
// degrees of freedom
FEDofList m_dofU, m_dofSU, m_dofW;
int m_dofEF;
protected:
bool m_bshellb; //!< flag for prescribing traction on shell bottom
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidConstantConductivity.cpp | .cpp | 1,763 | 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.*/
//
// FEFluidConstantConductivity.cpp
// FEBioFluid
//
// Created by Gerard Ateshian on 2/28/20.
// Copyright © 2020 febio.org. All rights reserved.
//
#include "FEFluidConstantConductivity.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEFluidConstantConductivity, FEFluidThermalConductivity)
// material parameters
ADD_PARAMETER(m_K , FE_RANGE_GREATER_OR_EQUAL(0.0), "K")->setUnits("W/L.T");
END_FECORE_CLASS();
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidMaterial.h | .h | 3,868 | 109 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMaterial.h>
#include <FEBioMech/FEBodyForce.h>
#include "FEFluidMaterialPoint.h"
#include "FEViscousFluid.h"
#include "FEViscousPolarFluid.h"
//-----------------------------------------------------------------------------
//! Base class for fluid materials.
class FEBIOFLUID_API FEFluidMaterial : public FEMaterial
{
public:
FEFluidMaterial(FEModel* pfem);
virtual ~FEFluidMaterial() {}
public:
//! calculate stress at material point
virtual mat3ds Stress(FEMaterialPoint& pt) = 0;
//! tangent of stress with respect to strain J
virtual mat3ds Tangent_Strain(FEMaterialPoint& mp) = 0;
//! elastic fluid pressure
virtual double Pressure(FEMaterialPoint& mp) = 0;
//! tangent of elastic pressure with respect to strain J
virtual double Tangent_Pressure_Strain(FEMaterialPoint& mp) = 0;
//! 2nd tangent of elastic pressure with respect to strain J
virtual double Tangent_Pressure_Strain_Strain(FEMaterialPoint& mp) = 0;
//! bulk modulus
virtual double BulkModulus(FEMaterialPoint& mp) = 0;
//! strain energy density
virtual double StrainEnergyDensity(FEMaterialPoint& mp) = 0;
//! invert effective pressure-dilatation relation
virtual bool Dilatation(const double T, const double p, double& e) = 0;
//! evaluate temperature
virtual double Temperature(FEMaterialPoint& mp) = 0;
//! return viscous part
FEViscousFluid* GetViscous() { return m_pViscous; }
//! tangent of stress with respect to rate of deformation tensor D
tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) { return m_pViscous->Tangent_RateOfDeformation(mp); }
//! referential fluid density
double ReferentialDensity() { return m_rhor; }
//! calculate current fluid density
double Density(FEMaterialPoint& pt);
//! kinematic viscosity
double KinematicViscosity(FEMaterialPoint& mp);
//! acoustic speed
double AcousticSpeed(FEMaterialPoint& mp);
//! kinetic energy density
double KineticEnergyDensity(FEMaterialPoint& mp);
//! strain + kinetic energy density
double EnergyDensity(FEMaterialPoint& mp);
//! fluid pressure from state variables
virtual double Pressure(const double ef, const double T) = 0;
private: // material properties
FEViscousFluid* m_pViscous; //!< pointer to viscous part of fluid material
public:
double m_rhor; //!< referential fluid density
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidResistanceLoad.cpp | .cpp | 6,059 | 199 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidResistanceLoad.h"
#include "FEBioFluid.h"
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidResistanceLoad, FESurfaceLoad)
ADD_PARAMETER(m_R , "R")->setUnits("F.t/L^5");
ADD_PARAMETER(m_p0, "pressure_offset")->setUnits(UNIT_PRESSURE);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidResistanceLoad::FEFluidResistanceLoad(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_R = 0.0;
m_pfluid = nullptr;
m_p0 = 0;
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dofEF = pfem->GetDOFIndex(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION), 0);
m_dof.Clear();
m_dof.AddDofs(m_dofW);
m_dof.AddDof(m_dofEF);
}
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidResistanceLoad::Init()
{
if (FESurfaceLoad::Init() == false) return false;
// get fluid from first surface element
// assuming the entire surface bounds the same fluid
FESurfaceElement& el = m_psurf->Element(0);
FEElement* pe = el.m_elem[0].pe;
if (pe == nullptr) return false;
// get the material
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
m_pfluid = pm->ExtractProperty<FEFluidMaterial>();
if (m_pfluid == nullptr) return false;
return true;
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidResistanceLoad::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofW & m_dofEF;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEFluidResistanceLoad::Activate()
{
FESurface* ps = &GetSurface();
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
// mark node as having prescribed DOF
node.set_bc(m_dofEF, DOF_PRESCRIBED);
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEFluidResistanceLoad::Update()
{
// evaluate the flow rate
double Q = FlowRate();
// calculate the resistance pressure
double p = m_R*Q;
// calculate the dilatation
double e = 0;
bool good = m_pfluid->Dilatation(0,p+m_p0, e);
assert(good);
// prescribe this dilatation at the nodes
FESurface* ps = &GetSurface();
for (int i=0; i<ps->Nodes(); ++i)
{
if (ps->Node(i).m_ID[m_dofEF] < -1)
{
FENode& node = ps->Node(i);
// set node as having prescribed DOF
node.set(m_dofEF, e);
}
}
GetFEModel()->SetMeshUpdateFlag(true);
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface at the current time
double FEFluidResistanceLoad::FlowRate()
{
double Q = 0;
vec3d rt[FEElement::MAX_NODES];
vec3d vt[FEElement::MAX_NODES];
const FETimeInfo& tp = GetTimeInfo();
double alpha = tp.alpha;
double alphaf = tp.alphaf;
for (int iel=0; iel<m_psurf->Elements(); ++iel)
{
FESurfaceElement& el = m_psurf->Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i=0; i<neln; ++i) {
FENode& node = m_psurf->GetMesh()->Node(el.m_node[i]);
rt[i] = node.m_rt;
vt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
}
double* Nr, *Ns;
double* N;
double* w = el.GaussWeights();
vec3d dxr, dxs, v;
// repeat over integration points
for (int n=0; n<nint; ++n)
{
N = el.H(n);
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the velocity and tangent vectors at integration point
dxr = dxs = v = vec3d(0,0,0);
for (int i=0; i<neln; ++i)
{
v += vt[i]*N[i];
dxr += rt[i]*Nr[i];
dxs += rt[i]*Ns[i];
}
vec3d normal = dxr ^ dxs;
double q = normal*v;
Q += q*w[n];
}
}
return Q;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSISoluteBackflowStabilization.cpp | .cpp | 9,438 | 264 | /*This file 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 "FEMultiphasicFSISoluteBackflowStabilization.h"
#include "FEFluid.h"
#include "FEBioMultiphasicFSI.h"
#include <FECore/FENodeNodeList.h>
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEMultiphasicFSISoluteBackflowStabilization, FESurfaceLoad)
ADD_PARAMETER(m_sol , "sol");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEMultiphasicFSISoluteBackflowStabilization::FEMultiphasicFSISoluteBackflowStabilization(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_sol = -1;
m_dofC = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION), 0);
m_nnlist = FENodeNodeList();
}
//-----------------------------------------------------------------------------
//! initialize
bool FEMultiphasicFSISoluteBackflowStabilization::Init()
{
if (FESurfaceLoad::Init() == false) return false;
// determine the nr of concentration equations
FEModel& fem = *GetFEModel();
DOFS& fedofs = fem.GetDOFS();
m_dofW.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::RELATIVE_FLUID_VELOCITY));
int MAX_CDOFS = fedofs.GetVariableSize(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION));
if ((m_sol < 1) || (m_sol > MAX_CDOFS)) return false;
m_dof.AddDofs(m_dofW);
m_dof.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION));
FESurface* ps = &GetSurface();
m_backflow.assign(ps->Nodes(), false);
m_nnlist.Create(fem.GetMesh());
return true;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEMultiphasicFSISoluteBackflowStabilization::Activate()
{
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_sol - 1;
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
// mark node as having prescribed DOF
node.set_bc(dofc, DOF_OPEN);
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEMultiphasicFSISoluteBackflowStabilization::Update()
{
// determine backflow conditions
MarkBackFlow();
// prescribe solute backflow constraint at the nodes
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_sol - 1;
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
// set node as having prescribed DOF (concentration at previous time)
//Otherwise set node as having concentration of adjacent node
if (node.m_ID[dofc] < -1)
node.set(dofc, node.get_prev(dofc));
else
{
node.set_bc(dofc, DOF_PRESCRIBED);
node.m_ID[dofc] = -node.m_ID[dofc] - 2;
int nid = node.GetID()-1; //0 based
int val = m_nnlist.Valence(nid);
int* nlist = m_nnlist.NodeList(nid);
vector<int> connectnidarray;
int connectnid=0;
//check which connecting nodes are not on surface
for (int j = 0; j<val; ++j)
{
int cnid = *(nlist+j);
bool isSurf = false;
for (int k=0; k<ps->Nodes(); ++k)
{
if (cnid==ps->Node(k).GetID()-1)
isSurf = true;
}
if (!isSurf)
{
connectnidarray.push_back(cnid);
}
}
//find closest connecting node
if (connectnidarray.size()>0)
{
int cnodeIndex = 0;
FENode* cnodeArray = GetFEModel()->GetMesh().FindNodeFromID(connectnidarray[cnodeIndex]+1);
double smallDist = sqrt(pow((node.m_rt.x-cnodeArray->m_rt.x),2)+pow((node.m_rt.y-cnodeArray->m_rt.y),2)+pow((node.m_rt.z-cnodeArray->m_rt.z),2));
for (int j = 1; j<connectnidarray.size(); ++j)
{
FENode* tempNode = GetFEModel()->GetMesh().FindNodeFromID(connectnidarray[j]+1);
double temp = sqrt(pow((node.m_rt.x-tempNode->m_rt.x),2)+pow((node.m_rt.y-tempNode->m_rt.y),2)+pow((node.m_rt.z-tempNode->m_rt.z),2));
if(temp<smallDist)
{
cnodeIndex = j;
cnodeArray = tempNode;
smallDist = temp;
}
}
connectnid = connectnidarray[cnodeIndex];
FENode* cnode = GetFEModel()->GetMesh().FindNodeFromID(connectnid+1);
node.set(dofc, cnode->get(dofc));
}
else
node.set(dofc, 0);
}
}
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface
void FEMultiphasicFSISoluteBackflowStabilization::MarkBackFlow()
{
// Mark all nodes on this surface to have open concentration DOF
FESurface* ps = &GetSurface();
int dofc = m_dofC + m_sol - 1;
for (int i=0; i<ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
// mark node as having free DOF
if (node.m_ID[dofc] < -1) {
node.set_bc(dofc, DOF_OPEN);
node.m_ID[dofc] = -node.m_ID[dofc] - 2;
}
}
const FETimeInfo& tp = GetTimeInfo();
// Calculate normal flow velocity on each face to determine
// backflow condition
vec3d rt[FEElement::MAX_NODES];
vec3d vt[FEElement::MAX_NODES];
for (int iel=0; iel<m_psurf->Elements(); ++iel)
{
FESurfaceElement& el = m_psurf->Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i=0; i<neln; ++i) {
FENode& node = m_psurf->GetMesh()->Node(el.m_node[i]);
rt[i] = node.m_rt*tp.alpha + node.m_rp*(1-tp.alpha);
vt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*tp.alphaf + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1-tp.alphaf);
}
double* Nr, *Ns;
double* N;
double* w = el.GaussWeights();
vec3d dxr, dxs, v;
double vn = 0;
// repeat over integration points
for (int n=0; n<nint; ++n)
{
N = el.H(n);
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the velocity and tangent vectors at integration point
dxr = dxs = v = vec3d(0,0,0);
for (int i=0; i<neln; ++i)
{
v += vt[i]*N[i];
dxr += rt[i]*Nr[i];
dxs += rt[i]*Ns[i];
}
vec3d normal = dxr ^ dxs;
normal.unit();
vn += (normal*v)*w[n];
}
if (vn < 0) {
for (int i=0; i<neln; ++i) {
FENode& node = m_psurf->GetMesh()->Node(el.m_node[i]);
if (node.m_ID[dofc] > -1) {
node.set_bc(dofc, DOF_PRESCRIBED);
node.m_ID[dofc] = -node.m_ID[dofc] - 2;
}
}
}
}
}
//-----------------------------------------------------------------------------
//! calculate residual
void FEMultiphasicFSISoluteBackflowStabilization::LoadVector(FEGlobalVector& R)
{
}
//-----------------------------------------------------------------------------
//! serialization
void FEMultiphasicFSISoluteBackflowStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsLoading()) {
m_backflow.assign(GetSurface().Nodes(), false);
}
ar & m_backflow;
if (ar.IsShallow()) return;
ar & m_dofW & m_dofC;
//ar & m_nnlist;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidResistanceLoad.h | .h | 2,422 | 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 <FECore/FESurfaceLoad.h>
#include "FEFluidMaterial.h"
//-----------------------------------------------------------------------------
//! FEFluidResistanceBC is a fluid surface that has a normal
//! pressure proportional to the flow rate (resistance).
//!
class FEBIOFLUID_API FEFluidResistanceLoad : public FESurfaceLoad
{
public:
//! constructor
FEFluidResistanceLoad(FEModel* pfem);
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector
void LoadVector(FEGlobalVector& R) override {}
//! set the dilatation
void Update() override;
//! evaluate flow rate
double FlowRate();
//! initialize
bool Init() override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! activate
void Activate() override;
private:
double m_R; //!< flow resistance
double m_p0; //!< fluid pressure offset
private:
FEFluidMaterial* m_pfluid; //!< pointer to fluid
FEDofList m_dofW;
int m_dofEF;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSIDomain3D.cpp | .cpp | 32,931 | 969 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidFSIDomain3D.h"
#include <FECore/log.h>
#include <FECore/FEModel.h>
#include "FEBioFSI.h"
#include <FECore/FELinearSystem.h>
//-----------------------------------------------------------------------------
//! constructor
//! Some derived classes will pass 0 to the pmat, since the pmat variable will be
//! to initialize another material. These derived classes will set the m_pMat variable as well.
FEFluidFSIDomain3D::FEFluidFSIDomain3D(FEModel* pfem) : FESolidDomain(pfem), FEFluidFSIDomain(pfem), m_dofU(pfem), m_dofV(pfem), m_dofW(pfem), m_dofAW(pfem), m_dofSU(pfem), m_dofR(pfem), m_dof(pfem)
{
m_pMat = 0;
m_btrans = true;
m_sseps = 0;
if (pfem)
{
m_dofU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::DISPLACEMENT));
m_dofV.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::VELOCITY));
m_dofW.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RELATIVE_FLUID_ACCELERATION));
m_dofSU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::SHELL_DISPLACEMENT));
m_dofR.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RIGID_ROTATION));
m_dofEF = pfem->GetDOFIndex(FEBioFSI::GetVariableName(FEBioFSI::FLUID_DILATATION), 0);
m_dofAEF = pfem->GetDOFIndex(FEBioFSI::GetVariableName(FEBioFSI::FLUID_DILATATION_TDERIV), 0);
}
}
//-----------------------------------------------------------------------------
// \todo I don't think this is being used
FEFluidFSIDomain3D& FEFluidFSIDomain3D::operator = (FEFluidFSIDomain3D& d)
{
m_Elem = d.m_Elem;
m_pMesh = d.m_pMesh;
return (*this);
}
//-----------------------------------------------------------------------------
// get the total dof
const FEDofList& FEFluidFSIDomain3D::GetDOFList() const
{
return m_dof;
}
//-----------------------------------------------------------------------------
//! Assign material
void FEFluidFSIDomain3D::SetMaterial(FEMaterial* pmat)
{
FEDomain::SetMaterial(pmat);
if (pmat)
{
m_pMat = dynamic_cast<FEFluidFSI*>(pmat);
assert(m_pMat);
}
else m_pMat = 0;
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::Activate()
{
for (int i=0; i<Nodes(); ++i)
{
FENode& node = Node(i);
if (node.HasFlags(FENode::EXCLUDE) == false)
{
if (node.m_rid < 0)
{
node.set_active(m_dofU[0]);
node.set_active(m_dofU[1]);
node.set_active(m_dofU[2]);
}
node.set_active(m_dofW[0]);
node.set_active(m_dofW[1]);
node.set_active(m_dofW[2]);
node.set_active(m_dofEF);
}
}
}
//-----------------------------------------------------------------------------
//! Initialize element data
void FEFluidFSIDomain3D::PreSolveUpdate(const FETimeInfo& timeInfo)
{
const int NE = FEElement::MAX_NODES;
vec3d x0[NE], xt[NE], r0, rt, v;
FEMesh& m = *GetMesh();
for (size_t i=0; i<m_Elem.size(); ++i)
{
FESolidElement& el = m_Elem[i];
if (el.isActive())
{
int neln = el.Nodes();
for (int i=0; i<neln; ++i)
{
x0[i] = m.Node(el.m_node[i]).m_r0;
xt[i] = m.Node(el.m_node[i]).m_rt;
}
int n = el.GaussPoints();
for (int j=0; j<n; ++j)
{
r0 = el.Evaluate(x0, j);
rt = el.Evaluate(xt, j);
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>();
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
FEFSIMaterialPoint& ft = *mp.ExtractData<FEFSIMaterialPoint>();
et.m_Wp = et.m_Wt;
if ((pt.m_ef <= -1) || (et.m_J <= 0)) {
throw NegativeJacobianDetected();
}
mp.Update(timeInfo);
}
}
}
}
//-----------------------------------------------------------------------------
//! Unpack the element LM data.
void FEFluidFSIDomain3D::UnpackLM(FEElement& el, vector<int>& lm)
{
int N = el.Nodes();
lm.resize(N*10);
for (int i=0; i<N; ++i)
{
FENode& node = m_pMesh->Node(el.m_node[i]);
vector<int>& id = node.m_ID;
// first the displacement dofs
lm[7*i ] = id[m_dofU[0]];
lm[7*i+1] = id[m_dofU[1]];
lm[7*i+2] = id[m_dofU[2]];
lm[7*i+3] = id[m_dofW[0]];
lm[7*i+4] = id[m_dofW[1]];
lm[7*i+5] = id[m_dofW[2]];
lm[7*i+6] = id[m_dofEF];
// rigid rotational dofs
lm[7*N + 3*i ] = id[m_dofR[0]];
lm[7*N + 3*i+1] = id[m_dofR[1]];
lm[7*N + 3*i+2] = id[m_dofR[2]];
}
// substitute interface dofs for solid-shell interfaces
FESolidElement& sel = static_cast<FESolidElement&>(el);
for (int i = 0; i<sel.m_bitfc.size(); ++i)
{
if (sel.m_bitfc[i]) {
FENode& node = m_pMesh->Node(el.m_node[i]);
vector<int>& id = node.m_ID;
// first the displacement dofs
lm[7*i ] = id[m_dofSU[0]];
lm[7*i+1] = id[m_dofSU[1]];
lm[7*i+2] = id[m_dofSU[2]];
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::InternalForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int i=0; i<NE; ++i)
{
// element force vector
vector<double> fe;
vector<int> lm;
// get the element
FESolidElement& el = m_Elem[i];
if (el.isActive()) {
// get the element force vector and initialize it to zero
int ndof = 7*el.Nodes();
fe.assign(ndof, 0);
// calculate internal force vector
ElementInternalForce(el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
}
//-----------------------------------------------------------------------------
//! calculates the internal equivalent nodal forces for solid elements
void FEFluidFSIDomain3D::ElementInternalForce(FESolidElement& el, vector<double>& fe)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, n;
// jacobian matrix, inverse jacobian matrix and determinants
double Ji[3][3], detJ;
mat3ds sv, ss;
vec3d gradp;
const double *H, *Gr, *Gs, *Gt;
int nint = el.GaussPoints();
int neln = el.Nodes();
// gradient of shape functions
vector<vec3d> gradN(neln);
double* gw = el.GaussWeights();
double dtrans = m_btrans ? 1 : m_sseps;
// repeat for all integration points
for (n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEElasticMaterialPoint& et = *(mp.ExtractData<FEElasticMaterialPoint>());
FEFSIMaterialPoint& ft = *(mp.ExtractData<FEFSIMaterialPoint>());
double Jf = 1 + pt.m_ef;
// calculate the jacobian
detJ = invjact(el, Ji, n, tp.alphaf)*gw[n];
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
// get the viscous stress tensor for this integration point
sv = m_pMat->Fluid()->GetViscous()->Stress(mp);
// get the gradient of the elastic pressure
gradp = pt.m_gradef*m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
// get the solid stress tensor
ss = ft.m_ss;
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
{
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
}
// Jfdot/Jf
double dJfoJ = pt.m_efdot/Jf;
// Jsdot/Js
double dJsoJ = ft.m_Jdot/et.m_J;
for (i=0; i<neln; ++i)
{
vec3d fs = (ss*gradN[i])*detJ;
vec3d ff = (sv*gradN[i] + gradp*H[i])*detJ;
double fJ = (H[i]*(((dJfoJ - dJsoJ)*dtrans + (pt.m_gradef*ft.m_w)/Jf)) + gradN[i]*ft.m_w)*detJ;
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[7*i ] -= fs.x;
fe[7*i+1] -= fs.y;
fe[7*i+2] -= fs.z;
fe[7*i+3] -= ff.x;
fe[7*i+4] -= ff.y;
fe[7*i+5] -= ff.z;
fe[7*i+6] -= fJ;
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::BodyForce(FEGlobalVector& R, FEBodyForce& BF)
{
int NE = (int)m_Elem.size();
for (int i=0; i<NE; ++i)
{
// get the element
FESolidElement& el = m_Elem[i];
if (el.isActive()) {
vector<double> fe;
vector<int> lm;
// get the element force vector and initialize it to zero
int ndof = 7*el.Nodes();
fe.assign(ndof, 0);
// apply body forces
ElementBodyForce(BF, el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
}
//-----------------------------------------------------------------------------
//! calculates the body forces
void FEFluidFSIDomain3D::ElementBodyForce(FEBodyForce& BF, FESolidElement& el, vector<double>& fe)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
// jacobian
double detJ;
double *H;
double* gw = el.GaussWeights();
vec3d f;
// number of nodes
int neln = el.Nodes();
// loop over integration points
int nint = el.GaussPoints();
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
double dens = m_pMat->Fluid()->Density(mp);
detJ = detJt(el, n, tp.alphaf)*gw[n];
// get the force
f = BF.force(mp)*(dens*detJ);
H = el.H(n);
for (int i=0; i<neln; ++i)
{
fe[7*i+3] -= H[i]*f.x;
fe[7*i+4] -= H[i]*f.y;
fe[7*i+5] -= H[i]*f.z;
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the stiffness due to body forces
//! For now, we assume that the body force is constant
void FEFluidFSIDomain3D::ElementBodyForceStiffness(FEBodyForce& BF, FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int neln = el.Nodes();
int ndof = ke.columns()/neln;
// jacobian
double Ji[3][3], detJ;
double *H, *Gr, *Gs, *Gt;
double* gw = el.GaussWeights();
vec3d f, kwJ;
mat3d Kwu, Kww, K;
// gradient of shape functions
vector<vec3d> gradN(neln);
// loop over integration points
int nint = el.GaussPoints();
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
// calculate the jacobian
detJ = invjact(el, Ji, n, tp.alphaf)*gw[n]*tp.alphaf;
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
double dens = m_pMat->Fluid()->Density(mp);
// get the force
f = BF.force(mp);
K = BF.stiffness(mp);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// evaluate spatial gradient of shape functions
for (int i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
for (int i=0; i<neln; ++i) {
for (int j=0; j<neln; ++j)
{
kwJ = f*(-H[i]*H[j]*dens/(pt.m_ef+1)*detJ);
Kwu = (f & gradN[j])*(dens*H[i]*detJ);
Kww = K*(H[i]*H[j]*dens*detJ);
ke[ndof*i+3][ndof*j ] += Kwu(0,0); ke[ndof*i+3][ndof*j+1] += Kwu(0,1); ke[ndof*i+3][ndof*j+2] += Kwu(0,2);
ke[ndof*i+4][ndof*j ] += Kwu(1,0); ke[ndof*i+4][ndof*j+1] += Kwu(1,1); ke[ndof*i+4][ndof*j+2] += Kwu(1,2);
ke[ndof*i+5][ndof*j ] += Kwu(2,0); ke[ndof*i+5][ndof*j+1] += Kwu(2,1); ke[ndof*i+5][ndof*j+2] += Kwu(2,2);
ke[ndof*i+3][ndof*j+3] += Kww(0,0); ke[ndof*i+3][ndof*j+4] += Kwu(0,1); ke[ndof*i+3][ndof*j+5] += Kwu(0,2);
ke[ndof*i+4][ndof*j+3] += Kww(1,0); ke[ndof*i+4][ndof*j+4] += Kwu(1,1); ke[ndof*i+4][ndof*j+5] += Kwu(1,2);
ke[ndof*i+5][ndof*j+3] += Kww(2,0); ke[ndof*i+5][ndof*j+4] += Kwu(2,1); ke[ndof*i+5][ndof*j+5] += Kwu(2,2);
ke[ndof*i+3][ndof*j+6] += kwJ.x;
ke[ndof*i+4][ndof*j+6] += kwJ.y;
ke[ndof*i+5][ndof*j+6] += kwJ.z;
}
}
}
}
//-----------------------------------------------------------------------------
//! Calculates element material stiffness element matrix
void FEFluidFSIDomain3D::ElementStiffness(FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i7, j, j7, n;
// Get the current element's data
const int nint = el.GaussPoints();
const int neln = el.Nodes();
// gradient of shape functions
vector<vec3d> gradN(neln);
double dt = tp.timeIncrement;
double a = tp.gamma/(tp.beta*dt);
double b = tp.alpham/(tp.alphaf*tp.beta*dt*dt);
double c = tp.alpham/(tp.alphaf*tp.gamma*dt);
double dtrans = m_btrans ? 1 : m_sseps;
double *H, *Gr, *Gs, *Gt;
// jacobian
double Ji[3][3], detJ;
// weights at gauss points
const double *gw = el.GaussWeights();
// calculate element stiffness matrix
for (n=0; n<nint; ++n)
{
// calculate jacobian
detJ = invjact(el, Ji, n, tp.alphaf)*gw[n]*tp.alphaf;
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// setup the material point
// NOTE: deformation gradient and determinant have already been evaluated in the stress routine
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEElasticMaterialPoint& et = *(mp.ExtractData<FEElasticMaterialPoint>());
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFSIMaterialPoint& fpt = *(mp.ExtractData<FEFSIMaterialPoint>());
double Jf = 1 + pt.m_ef;
// get the tangents
mat3ds ss = m_pMat->Solid()->Stress(mp);
tens4ds cs = m_pMat->Solid()->Tangent(mp);
mat3ds sv = m_pMat->Fluid()->GetViscous()->Stress(mp);
mat3ds svJ = m_pMat->Fluid()->GetViscous()->Tangent_Strain(mp);
tens4ds cv = m_pMat->Fluid()->Tangent_RateOfDeformation(mp);
double dp = m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
double d2p = m_pMat->Fluid()->Tangent_Pressure_Strain_Strain(mp);
// Jfdot/Jf
double dJfoJ = pt.m_efdot/Jf;
vec3d gradp = pt.m_gradef*dp;
// Jsdot/Js = div(vs)
double dJsoJ = fpt.m_Jdot/et.m_J;
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
// evaluate stiffness matrix
for (i=0, i7=0; i<neln; ++i, i7 += 7)
{
for (j=0, j7 = 0; j<neln; ++j, j7 += 7)
{
mat3d M = mat3dd(a*dtrans) - et.m_L;
mat3d Kuu = (vdotTdotv(gradN[i], cs, gradN[j])
+ mat3dd(gradN[i]*(ss*gradN[j])))*detJ;
mat3d Kwu = (vdotTdotv(gradN[i], cv, gradN[j])*M
+ sv*((gradN[i] & gradN[j]) - (gradN[j] & gradN[i]))
+ ((gradp & gradN[j]) - (gradN[j] & gradp)*H[i]))*detJ;
mat3d Kww = vdotTdotv(gradN[i], cv, gradN[j])*detJ;
vec3d kwJ = ((svJ*gradN[i])*H[j]
+ (gradN[j]*dp+pt.m_gradef*(H[j]*d2p))*H[i])*detJ;
vec3d kJu = ((gradN[j]*(dJfoJ - dJsoJ - a)*dtrans
+ ((gradN[j] & pt.m_gradef) - (pt.m_gradef & gradN[j]))*fpt.m_w/Jf + et.m_L.transpose()*gradN[j])*H[i]
+ ((gradN[j] & gradN[i]) - (gradN[i] & gradN[j]))*fpt.m_w
)*detJ;
vec3d kJw = ((pt.m_gradef*(H[i]/Jf) + gradN[i])*H[j])*detJ;
double kJJ = (((c - dJfoJ)*dtrans - (pt.m_gradef*fpt.m_w)/Jf)*H[j]
+ gradN[j]*fpt.m_w)*H[i]/Jf*detJ;
ke[i7 ][j7 ] += Kuu(0,0); ke[i7 ][j7+1] += Kuu(0,1); ke[i7 ][j7+2] += Kuu(0,2);
ke[i7+1][j7 ] += Kuu(1,0); ke[i7+1][j7+1] += Kuu(1,1); ke[i7+1][j7+2] += Kuu(1,2);
ke[i7+2][j7 ] += Kuu(2,0); ke[i7+2][j7+1] += Kuu(2,1); ke[i7+2][j7+2] += Kuu(2,2);
ke[i7+3][j7 ] += Kwu(0,0); ke[i7+3][j7+1] += Kwu(0,1); ke[i7+3][j7+2] += Kwu(0,2);
ke[i7+4][j7 ] += Kwu(1,0); ke[i7+4][j7+1] += Kwu(1,1); ke[i7+4][j7+2] += Kwu(1,2);
ke[i7+5][j7 ] += Kwu(2,0); ke[i7+5][j7+1] += Kwu(2,1); ke[i7+5][j7+2] += Kwu(2,2);
ke[i7+3][j7+3] += Kww(0,0); ke[i7+3][j7+4] += Kww(0,1); ke[i7+3][j7+5] += Kww(0,2);
ke[i7+4][j7+3] += Kww(1,0); ke[i7+4][j7+4] += Kww(1,1); ke[i7+4][j7+5] += Kww(1,2);
ke[i7+5][j7+3] += Kww(2,0); ke[i7+5][j7+4] += Kww(2,1); ke[i7+5][j7+5] += Kww(2,2);
ke[i7+3][j7+6] += kwJ.x;
ke[i7+4][j7+6] += kwJ.y;
ke[i7+5][j7+6] += kwJ.z;
ke[i7+6][j7 ] += kJu.x;
ke[i7+6][j7+1] += kJu.y;
ke[i7+6][j7+2] += kJu.z;
ke[i7+6][j7+3] += kJw.x;
ke[i7+6][j7+4] += kJw.y;
ke[i7+6][j7+5] += kJw.z;
ke[i7+6][j7+6] += kJJ;
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::StiffnessMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
if (el.isActive()) {
// element stiffness matrix
FEElementMatrix ke(el);
// create the element's stiffness matrix
int ndof = 7*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate material stiffness
ElementStiffness(el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::MassMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
if (el.isActive()) {
FEElementMatrix ke(el);
// create the element's stiffness matrix
int ndof = 7*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate inertial stiffness
ElementMassMatrix(el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf)
{
FEFluidFSI* pme = dynamic_cast<FEFluidFSI*>(GetMaterial()); assert(pme);
// repeat over all solid elements
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
if (el.isActive()) {
// element stiffness matrix
FEElementMatrix ke(el);
// create the element's stiffness matrix
int ndof = 7*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate inertial stiffness
ElementBodyForceStiffness(bf, el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
}
//-----------------------------------------------------------------------------
//! calculates element inertial stiffness matrix
void FEFluidFSIDomain3D::ElementMassMatrix(FESolidElement& el, matrix& ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i7, j, j7, n;
// Get the current element's data
const int nint = el.GaussPoints();
const int neln = el.Nodes();
double dtrans = m_btrans ? 1 : m_sseps;
// gradient of shape functions
vector<vec3d> gradN(neln);
double *H;
double *Gr, *Gs, *Gt;
// jacobian
double Ji[3][3], detJ;
// weights at gauss points
const double *gw = el.GaussWeights();
double dt = tp.timeIncrement;
double a = tp.gamma/(tp.beta*dt);
double b = tp.alpham/(tp.alphaf*tp.beta*dt*dt);
double c = tp.alpham/(tp.alphaf*tp.gamma*dt);
// calculate element stiffness matrix
for (n=0; n<nint; ++n)
{
// calculate jacobian
detJ = invjact(el, Ji, n, tp.alphaf)*gw[n]*tp.alphaf;
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// setup the material point
// NOTE: deformation gradient and determinant have already been evaluated in the stress routine
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFSIMaterialPoint& fpt = *(mp.ExtractData<FEFSIMaterialPoint>());
double dens = m_pMat->Fluid()->Density(mp);
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
// evaluate stiffness matrix
for (i=0, i7=0; i<neln; ++i, i7 += 7)
{
for (j=0, j7 = 0; j<neln; ++j, j7 += 7)
{
mat3d Kwu = ((pt.m_aft & gradN[j]) - pt.m_Lf*(fpt.m_w*gradN[j])
+ mat3dd((gradN[j]*fpt.m_w)*a*dtrans)
+ mat3dd(b*H[j]*dtrans)
)*(H[i]*dens*detJ);
mat3d Kww = (mat3dd(c*dtrans*H[j] + gradN[j]*fpt.m_w) + pt.m_Lf*H[j])*(H[i]*dens*detJ);
vec3d kwJ = pt.m_aft*(-dens/(pt.m_ef+1)*H[i]*H[j]*detJ);
ke[i7+3][j7 ] += Kwu(0,0); ke[i7+3][j7+1] += Kwu(0,1); ke[i7+3][j7+2] += Kwu(0,2);
ke[i7+4][j7 ] += Kwu(1,0); ke[i7+4][j7+1] += Kwu(1,1); ke[i7+4][j7+2] += Kwu(1,2);
ke[i7+5][j7 ] += Kwu(2,0); ke[i7+5][j7+1] += Kwu(2,1); ke[i7+5][j7+2] += Kwu(2,2);
ke[i7+3][j7+3] += Kww(0,0); ke[i7+3][j7+4] += Kww(0,1); ke[i7+3][j7+5] += Kww(0,2);
ke[i7+4][j7+3] += Kww(1,0); ke[i7+4][j7+4] += Kww(1,1); ke[i7+4][j7+5] += Kww(1,2);
ke[i7+5][j7+3] += Kww(2,0); ke[i7+5][j7+4] += Kww(2,1); ke[i7+5][j7+5] += Kww(2,2);
ke[i7+3][j7+6] += kwJ.x;
ke[i7+4][j7+6] += kwJ.y;
ke[i7+5][j7+6] += kwJ.z;
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::Update(const FETimeInfo& tp)
{
bool berr = false;
int NE = (int) m_Elem.size();
#pragma omp parallel for shared(NE, berr)
for (int i=0; i<NE; ++i)
{
try
{
FESolidElement& el = Element(i);
if (el.isActive())
{
UpdateElementStress(i, tp);
}
}
catch (NegativeJacobian e)
{
#pragma omp critical
{
// reset the logfile mode
berr = true;
if (e.DoOutput()) feLogError(e.what());
}
}
}
if (berr) throw NegativeJacobianDetected();
}
//-----------------------------------------------------------------------------
//! Update element state data (mostly stresses, but some other stuff as well)
void FEFluidFSIDomain3D::UpdateElementStress(int iel, const FETimeInfo& tp)
{
double alphaf = tp.alphaf;
double alpham = tp.alpham;
double dt = GetFEModel()->GetTime().timeIncrement;
double dtrans = m_btrans ? 1 : m_sseps;
// get the solid element
FESolidElement& el = m_Elem[iel];
// get the number of integration points
int nint = el.GaussPoints();
// number of nodes
int neln = el.Nodes();
// nodal coordinates
const int NELN = FEElement::MAX_NODES;
vec3d r0[NELN], r[NELN];
vec3d vs[NELN];
vec3d a[NELN];
vec3d w[NELN];
vec3d aw[NELN];
double e[NELN];
double ae[NELN];
for (int j=0; j<neln; ++j) {
FENode& node = m_pMesh->Node(el.m_node[j]);
r0[j] = node.m_r0;
r[j] = node.m_rt*alphaf + node.m_rp*(1-alphaf);
vs[j] = node.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2])*alphaf + node.m_vp*(1-alphaf);
w[j] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*alphaf + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1-alphaf);
e[j] = node.get(m_dofEF)*alphaf + node.get_prev(m_dofEF)*(1-alphaf);
a[j] = node.m_at*alpham + node.m_ap*(1-alpham);
aw[j] = node.get_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2])*alpham + node.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2])*(1-alpham);
ae[j] = node.get(m_dofAEF)*alpham + node.get_prev(m_dofAEF)*(1-alpham);
}
// loop over the integration points and update
// velocity, velocity gradient, acceleration
// stress and pressure at the integration point
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>());
FEFSIMaterialPoint& ft = *(mp.ExtractData<FEFSIMaterialPoint>());
// elastic material point data
mp.m_r0 = el.Evaluate(r0, n);
mp.m_rt = el.Evaluate(r, n);
mat3d Ft, Fp;
double Jt, Jp;
Jt = defgrad(el, Ft, n);
Jp = defgradp(el, Fp, n);
ept.m_F = Ft*alphaf + Fp*(1 - alphaf);
ept.m_J = ept.m_F.det();
mat3d Fi = ept.m_F.inverse();
ept.m_L = (Ft - Fp)*Fi*(dtrans / dt);
ept.m_v = m_btrans ? el.Evaluate(vs, n) : vec3d(0, 0, 0);
ept.m_a = m_btrans ? el.Evaluate(a, n) : vec3d(0, 0, 0);
// FSI material point data
ft.m_w = el.Evaluate(w, n);
ft.m_Jdot = (Jt - Jp) / dt*dtrans;
ft.m_aw = el.Evaluate(aw, n)*dtrans;
// fluid material point data
pt.m_efdot = el.Evaluate(ae, n)*dtrans;
pt.m_vft = ept.m_v + ft.m_w;
mat3d Gradw = Gradient(el, w, n);
mat3d Lw = Gradw*Fi;
pt.m_Lf = ept.m_L + Lw;
pt.m_ef = el.Evaluate(e, n);
vec3d Gradef = Gradient(el, e, n);
pt.m_gradef = Fi.transpose()*Gradef;
// fluid acceleration
pt.m_aft = ept.m_a + ft.m_aw + pt.m_Lf*ft.m_w;
// update specialized material points
m_pMat->UpdateSpecializedMaterialPoints(mp, tp);
// calculate the stresses at this material point
pt.m_sf = m_pMat->Fluid()->Stress(mp);
ft.m_ss = m_pMat->Solid()->Stress(mp);
ept.m_s = pt.m_sf + ft.m_ss;
// calculate the fluid pressure
pt.m_pf = m_pMat->Fluid()->Pressure(pt.m_ef);
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::InertialForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int i=0; i<NE; ++i)
{
// get the element
FESolidElement& el = m_Elem[i];
if (el.isActive()) {
// element force vector
vector<double> fe;
vector<int> lm;
// get the element force vector and initialize it to zero
int ndof = 7*el.Nodes();
fe.assign(ndof, 0);
// calculate internal force vector
ElementInertialForce(el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::ElementInertialForce(FESolidElement& el, vector<double>& fe)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, n;
// jacobian determinant
double detJ;
const double* H;
int nint = el.GaussPoints();
int neln = el.Nodes();
double* gw = el.GaussWeights();
// repeat for all integration points
for (n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
double dens = m_pMat->Fluid()->Density(mp);
// calculate the jacobian
detJ = detJt(el, n, tp.alphaf)*gw[n];
H = el.H(n);
for (i=0; i<neln; ++i)
{
vec3d f = pt.m_aft*(dens*H[i]*detJ);
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[7*i+3] -= f.x;
fe[7*i+4] -= f.y;
fe[7*i+5] -= f.z;
}
}
}
//-----------------------------------------------------------------------------
void FEFluidFSIDomain3D::Serialize(DumpStream& ar)
{
FESolidDomain::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_sseps;
ar & m_dofU & m_dofV & m_dofW & m_dofAW;
ar & m_dofSU & m_dofR;
ar & m_dof;
ar & m_dofEF & m_dofAEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidMovingFrameLoad.cpp | .cpp | 4,539 | 153 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidMovingFrameLoad.h"
#include "FEFluidMaterialPoint.h"
#include <FECore/log.h>
BEGIN_FECORE_CLASS(FEFluidMovingFrameLoad, FEBodyForce)
ADD_PARAMETER(m_at.x, "ax");
ADD_PARAMETER(m_at.y, "ay");
ADD_PARAMETER(m_at.z, "az");
ADD_PARAMETER(m_wi.x, "wx");
ADD_PARAMETER(m_wi.y, "wy");
ADD_PARAMETER(m_wi.z, "wz");
ADD_PARAMETER(m_frame, "frame")->setEnums("fixed\0moving\0");
ADD_PARAMETER(m_wt, "wt")->setLongName("Angular velocity in fixed frame")->setUnits(UNIT_ANGULAR_VELOCITY)->SetFlags(FE_PARAM_HIDDEN);
ADD_PARAMETER(m_Wt, "Wt")->setLongName("Angular velocity in moving frame")->setUnits(UNIT_ANGULAR_VELOCITY)->SetFlags(FE_PARAM_HIDDEN);
ADD_PARAMETER(m_rt, "rt")->setLongName("Rotation vector in fixed frame")->setUnits(UNIT_RADIAN)->SetFlags(FE_PARAM_HIDDEN);
END_FECORE_CLASS();
FEFluidMovingFrameLoad::FEFluidMovingFrameLoad(FEModel* fem) : FEBodyForce(fem)
{
m_frame = 0; // assume angular velocity is input in fixed frame
}
void FEFluidMovingFrameLoad::Activate()
{
m_ap = m_at;
m_wp = m_wt;
m_Wp = m_Wt;
m_alp = m_alt;
m_Alp = m_Alt;
m_qp = m_qt;
FEBodyForce::Activate();
}
void FEFluidMovingFrameLoad::PrepStep()
{
const FETimeInfo& tp = GetTimeInfo();
double dt = tp.timeIncrement;
double alpha = tp.alpha;
if (m_frame == 0)
{
m_wt = m_wi; // input is ang vel in fixed frame
// current quantities
m_alp = m_alt;
m_alt = (m_wt - m_wp) / dt;
quatd wt(m_wt.x, m_wt.y, m_wt.z, 0.0);
m_qt = m_qp + (wt * m_qp) * (0.5 * dt); m_qt.MakeUnit();
// intermediate quantities
m_al = m_alt * alpha + m_alp * (1.0 - alpha);
m_w = m_wt * alpha + m_wp * (1.0 - alpha);
quatd wa(m_w.x, m_w.y, m_w.z, 0.0);
m_q = m_qp + (wa * m_qp) * (0.5 * dt * alpha); m_q.MakeUnit();
m_qp = m_qt;
m_wp = m_wt;
// quantities in body frame
quatd qti = m_qt.Inverse();
m_Wt = qti * m_wt;
m_rt = m_qt.GetRotationVector();
quatd qi = m_q.Inverse();
m_Al = qi * m_al;
m_W = qi * m_w;
}
else
{
m_Wt = m_wi; // input is ang vel in body frame
// current quantities
m_Alp = m_Alt;
m_Alt = (m_Wt - m_Wp) / dt;
quatd Wt(m_Wt.x, m_Wt.y, m_Wt.z, 0.0);
m_qt = m_qp + (m_qp * Wt) * (0.5 * dt); m_qt.MakeUnit();
// intermediate quantities
m_Al = m_Alt * alpha + m_Alp * (1.0 - alpha);
m_W = m_Wt * alpha + m_Wp * (1.0 - alpha);
quatd Wa(m_W.x, m_W.y, m_W.z, 0.0);
m_q = m_qp + (m_qp * Wa) * (0.5 * dt * alpha); m_q.MakeUnit();
m_qp = m_qt;
m_Wp = m_Wt;
// quantities in fixed frame
m_wt = m_qt * m_Wt;
m_rt = m_qt.GetRotationVector();
m_alp = m_alt;
m_alt = m_qt * m_Alt;
m_al = m_q * m_Al;
m_w = m_q * m_W;
}
// linear acceleration (always assumed to be given in the fixed frame)
m_a = m_at * alpha + m_ap * (1.0 - alpha);
m_ap = m_at;
quatd qi = m_q.Inverse();
m_A = qi * m_a;
FEBodyForce::PrepStep();
}
vec3d FEFluidMovingFrameLoad::force(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& fp = *pt.ExtractData<FEFluidMaterialPoint>();
vec3d r = pt.m_r0;
vec3d V = fp.m_vft;
vec3d f = m_A + (m_Al ^ r) + (m_W ^ (m_W ^ r)) + (m_W ^ V) * 2.0;
return f;
}
mat3d FEFluidMovingFrameLoad::stiffness(FEMaterialPoint& pt)
{
const FETimeInfo& tp = GetTimeInfo();
mat3da Sw(m_W);
mat3d K = Sw* (2.0 * tp.alphaf);
return K;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/stdafx.h | .h | 1,310 | 31 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <stdlib.h>
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FERealLiquid.cpp | .cpp | 15,662 | 415 | /*This file 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 "FERealLiquid.h"
#include "FEFluidMaterialPoint.h"
#include "FEThermoFluidMaterialPoint.h"
#include <FECore/log.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FERealLiquid, FEElasticFluid)
// material parameters
ADD_PARAMETER(m_nvc , FE_RANGE_GREATER(0), "nvc");
ADD_PROPERTY(m_psat, "psat")->SetLongName("saturation gauge pressure normalized");
ADD_PROPERTY(m_asat, "asat")->SetLongName("saturation free energy normalized");
ADD_PROPERTY(m_ssat, "ssat")->SetLongName("saturation entropy normalized");
ADD_PROPERTY(m_esat, "esat")->SetLongName("saturation dilatation");
ADD_PROPERTY(m_B[0], "B1" )->SetLongName("1st pressure virial coefficient");
ADD_PROPERTY(m_B[1], "B2", FEProperty::Optional)->SetLongName("2nd pressure virial coefficient");
ADD_PROPERTY(m_B[2], "B3", FEProperty::Optional)->SetLongName("3rd pressure virial coefficient");
ADD_PROPERTY(m_cvsat, "cvsat")->SetLongName("saturation isochoric heat capacity normalized");
ADD_PROPERTY(m_C[0], "C1" )->SetLongName("1st cv virial coefficient");
ADD_PROPERTY(m_C[1], "C2", FEProperty::Optional)->SetLongName("2nd cv virial coefficient");
ADD_PROPERTY(m_C[2], "C3", FEProperty::Optional)->SetLongName("3rd cv virial coefficient");
END_FECORE_CLASS();
FERealLiquid::FERealLiquid(FEModel* pfem) : FEElasticFluid(pfem)
{
m_nvc = 0;
m_R = m_Pr = m_Tr = 0;
m_psat = m_asat = m_ssat = m_esat = m_cvsat = nullptr;
m_B[0] = m_B[1] = m_B[2] = nullptr;
m_C[0] = m_C[1] = m_C[2] = nullptr;
}
//-----------------------------------------------------------------------------
//! initialization
bool FERealLiquid::Init()
{
m_R = GetGlobalConstant("R");
m_Tr = GetGlobalConstant("T");
m_Pr = GetGlobalConstant("P");
if (m_R <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; }
if (m_Tr <= 0) { feLogError("A positive referential absolute temperature T must be defined in Globals section"); return false; }
if (m_Pr <= 0) { feLogError("A positive referential absolute pressure P must be defined in Globals section"); return false; }
if (m_nvc == 0){ feLogError("At least one virial coefficient must be specified in this real liquid"); return false; }
m_pMat = dynamic_cast<FEThermoFluid*>(GetParent());
m_rhor = m_pMat->ReferentialDensity();
m_psat->Init();
m_asat->Init();
m_ssat->Init();
m_esat->Init();
m_cvsat->Init();
for (int k=0; k<m_nvc; ++k) {
if (m_B[k]) m_B[k]->Init();
if (m_C[k]) m_C[k]->Init();
}
return true;
}
//-----------------------------------------------------------------------------
void FERealLiquid::Serialize(DumpStream& ar)
{
FEElasticFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_R & m_Pr & m_Tr & m_rhor;
}
//-----------------------------------------------------------------------------
//! gauge pressure
double FERealLiquid::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double p = m_psat->value(That);
double x = fp.m_ef - m_esat->value(That);
for (int k=1; k<=m_nvc; ++k)
p += m_B[k-1]->value(That)*pow(x,k);
return p*m_Pr;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J
double FERealLiquid::Tangent_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double dpJ = m_B[0]->value(That);
double x = fp.m_ef - m_esat->value(That);
for (int k=2; k<=m_nvc; ++k)
dpJ += k*m_B[k-1]->value(That)*pow(x,k-1);
return dpJ*m_Pr;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to strain J
double FERealLiquid::Tangent_Strain_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double dpJ2 = (m_nvc > 1) ? 2*m_B[1]->value(That) : 0;
double x = fp.m_ef - m_esat->value(That);
for (int k=3; k<=m_nvc; ++k)
dpJ2 += k*(k-1)*m_B[k-1]->value(That)*pow(x,k-2);
return dpJ2*m_Pr;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to temperature T
double FERealLiquid::Tangent_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double dpT = m_psat->derive(That);
double dJsat = m_esat->derive(That);
double x = fp.m_ef - m_esat->value(That);
for (int k=1; k<=m_nvc; ++k)
dpT += m_B[k-1]->derive(That)*pow(x,k)
- k*dJsat*m_B[k-1]->value(That)*pow(x,k-1);
return dpT*m_Pr/m_Tr;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to temperature T
double FERealLiquid::Tangent_Temperature_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double dpT2 = m_psat->deriv2(That);
double dJsat = m_esat->derive(That);
double dJsa2 = m_esat->deriv2(That);
double x = fp.m_ef - m_esat->value(That);
vector<double> B(m_nvc,0);
for (int k=0; k<m_nvc; ++k) B[k] = m_B[k]->value(That);
for (int k=1; k<=m_nvc; ++k)
dpT2 += m_B[k-1]->deriv2(That)*pow(x,k)
- (2*dJsat*m_B[k-1]->derive(That) + dJsa2*B[k-1])*k*pow(x,k-1);
for (int k=2; k<=m_nvc; ++k)
dpT2 += k*(k-1)*pow(dJsat,2)*B[k-1]*pow(x,k-2);
return dpT2*m_Pr/pow(m_Tr,2);
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J and temperature T
double FERealLiquid::Tangent_Strain_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double dpJT = m_B[0]->derive(That);
double dJsat = m_esat->derive(That);
double x = fp.m_ef - m_esat->value(That);
for (int k=2; k<=m_nvc; ++k)
dpJT += k*m_B[k-1]->derive(That)*pow(x,k-1)
- k*(k-1)*dJsat*m_B[k-1]->value(That)*pow(x,k-2);
return dpJT*m_Pr/m_Tr;
}
//-----------------------------------------------------------------------------
//! specific free energy
double FERealLiquid::SpecificFreeEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double x = fp.m_ef - m_esat->value(That);
double a = m_asat->value(That) - x*m_psat->value(That);
for (int k=1; k<=m_nvc; ++k)
a -= m_B[k-1]->value(That)/(k+1)*pow(x,k+1);
return a*m_Pr/m_rhor;
}
//-----------------------------------------------------------------------------
//! specific entropy
double FERealLiquid::SpecificEntropy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double x = fp.m_ef - m_esat->value(That);
double dJsat = m_esat->derive(That);
double ssat = m_ssat->value(That);
double s = ssat + x*m_psat->derive(That);
for (int k=1; k<=m_nvc; ++k)
s += (m_B[k-1]->derive(That)*x/(k+1) - dJsat*m_B[k-1]->value(That))*pow(x,k);
return s*m_Pr/(m_rhor*m_Tr);
}
//-----------------------------------------------------------------------------
//! specific strain energy
double FERealLiquid::SpecificStrainEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
// get the specific free energy
double a = SpecificFreeEnergy(mp);
double That = (m_Tr+tf.m_T)/m_Tr;
double asat = m_asat->value(That)*m_Pr/m_rhor;
// the specific strain energy is the difference between these two values
return a - asat;
}
//-----------------------------------------------------------------------------
//! isochoric specific heat capacity
double FERealLiquid::IsochoricSpecificHeatCapacity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double x = fp.m_ef - m_esat->value(That);
double cv = 0;
for (int k=1; k<=m_nvc; ++k) cv += m_C[k-1]->value(That)*pow(x,k);
cv *= m_cvsat->value(1.0);
cv += m_cvsat->value(That);
return m_Pr/(m_rhor*m_Tr)*cv;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to strain J
double FERealLiquid::Tangent_cv_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double x = fp.m_ef - m_esat->value(That);
double dcvJ = 0;
for (int k=1; k<=m_nvc; ++k) dcvJ += k*m_C[k-1]->value(That)*pow(x,k-1);
dcvJ *= m_cvsat->value(1.0);
return m_Pr/(m_rhor*m_Tr)*dcvJ;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to temperature T
double FERealLiquid::Tangent_cv_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double That = (m_Tr+tf.m_T)/m_Tr;
double x = fp.m_ef - m_esat->value(That);
double dcvT = 0;
for (int k=1; k<=m_nvc; ++k) dcvT += (m_C[k-1]->derive(That)*x - k*m_esat->derive(That)*m_C[k-1]->value(That))*pow(x,k-1);
dcvT *= m_cvsat->value(1.0);
dcvT += m_cvsat->derive(That);
return m_Pr/(m_rhor*pow(m_Tr,2))*dcvT;
}
//-----------------------------------------------------------------------------
//! isobaric specific heat capacity
double FERealLiquid::IsobaricSpecificHeatCapacity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double cv = IsochoricSpecificHeatCapacity(mp);
double p = Pressure(mp); // current gauge pressure
double dpT = Tangent_Temperature(mp);
// evaluate dpT/dpJ in the reference configuration
double efsafe = fp.m_ef;
double Tsafe = tf.m_T;
fp.m_ef = 0;
tf.m_T = 0;
double r = Tangent_Temperature(mp)/Tangent_Strain(mp);
// restore values before continuing
fp.m_ef = efsafe;
tf.m_T = Tsafe;
// evaluate isobaric specific heat capacity
double cp = cv + r/m_rhor*(p - (m_Tr + tf.m_T)*dpT);
return cp;
}
//-----------------------------------------------------------------------------
//! dilatation from temperature and pressure
bool FERealLiquid::Dilatation(const double T, const double p, double& e)
{
double errrel = 1e-6;
double errabs = 1e-6;
int maxiter = 100;
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
FEThermoFluidMaterialPoint* ft = new FEThermoFluidMaterialPoint(fp);
double That = (T+m_Tr)/m_Tr;
double psat = m_psat->value(That);
double esat = m_esat->value(That);
double phat = p/m_Pr;
if (phat == psat) { e = esat; return true; }
switch (m_nvc) {
case 0:
delete ft;
return false;
break;
case 1:
{
double B0 = m_B[0]->value(That);
if (B0 == 0) { e = esat; return true; }
e = (phat - psat)/B0 + esat;
delete ft;
return true;
}
break;
case 2:
{
double B0 = m_B[0]->value(That);
double B1 = m_B[1]->value(That);
if ((B0 == 0) || (B1 == 0)) { e = esat; return true; }
double det = pow(B0,2) + 4*B1*(phat - psat);
if (det < 0) return false;
det = sqrt(det);
// only one root of this quadratic equation is valid.
e = esat - (B0+det)/(2*B1);
delete ft;
return true;
}
break;
default:
{
bool convgd = false;
bool done = false;
int iter = 0;
FEMaterialPoint mp(ft);
do {
++iter;
fp->m_ef = e;
double f = Pressure(mp) - p;
double df = Tangent_Strain(mp);
double de = (df != 0) ? -f/df : 0;
e += de;
if ((fabs(de) < errrel*fabs(e)) ||
(fabs(f/m_Pr) < errabs)) { convgd = true; done = true; }
if (iter > maxiter) done = true;
} while (!done);
delete ft;
return convgd;
}
break;
}
delete ft;
return false;
}
//-----------------------------------------------------------------------------
//! pressure from state variables
double FERealLiquid::Pressure(const double ef, const double T)
{
FEFluidMaterialPoint* fp = new FEFluidMaterialPoint();
FEThermoFluidMaterialPoint* ft = new FEThermoFluidMaterialPoint(fp);
fp->m_ef = ef;
ft->m_T = T;
FEMaterialPoint tmp(ft);
double p = Pressure(tmp);
delete ft;
return p;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidPressureTemperature.h | .h | 1,949 | 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) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEInitialCondition.h>
class FEInitialFluidPressureTemperature : public FENodalIC
{
public:
FEInitialFluidPressureTemperature(FEModel* fem);
bool Init() override;
void Activate() override;
void SetPDOF(int ndof);
bool SetPDOF(const char* szdof);
void SetTDOF(int ndof);
bool SetTDOF(const char* szdof);
void GetNodalValues(int inode, std::vector<double>& values) override;
void Serialize(DumpStream& ar) override;
protected:
int m_dofEF;
int m_dofT;
FEParamDouble m_Pdata;
FEParamDouble m_Tdata;
vector<double> m_e;
vector<double> m_T;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidAnalysis.cpp | .cpp | 1,688 | 38 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEPolarFluidAnalysis.h"
BEGIN_FECORE_CLASS(FEPolarFluidAnalysis, FEAnalysis)
// The analysis parameter is already defined in the FEAnalysis base class.
// Here, we just need to set the enum values for the analysis parameter.
FindParameterFromData(&m_nanalysis)->setEnums("STEADY-STATE\0DYNAMIC\0");
END_FECORE_CLASS()
FEPolarFluidAnalysis::FEPolarFluidAnalysis(FEModel* fem) : FEAnalysis(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidRCLoad.cpp | .cpp | 6,898 | 227 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidRCLoad.h"
#include "FEFluid.h"
#include "FEBioFluid.h"
#include <FECore/FEAnalysis.h>
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidRCLoad, FESurfaceLoad)
ADD_PARAMETER(m_R, "R");
ADD_PARAMETER(m_p0, "initial_pressure");
ADD_PARAMETER(m_C, "capacitance");
ADD_PARAMETER(m_Bern, "Bernoulli");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidRCLoad::FEFluidRCLoad(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_R = 0.0;
m_pfluid = nullptr;
m_p0 = 0;
m_C = 0.0;
m_Bern = false;
m_pt = m_dpt = 0;
m_qt = m_dqt = 0;
m_pp = m_dpp = 0;
m_qp = m_dqp = 0;
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dofEF = pfem->GetDOFIndex(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION), 0);
}
}
//-----------------------------------------------------------------------------
//! initialize
//! TODO: Generalize to include the initial conditions
bool FEFluidRCLoad::Init()
{
if (FESurfaceLoad::Init() == false) return false;
m_dof.Clear();
m_dof.AddDofs(m_dofW);
m_dof.AddDof(m_dofEF);
// get fluid from first surface element
// assuming the entire surface bounds the same fluid
FESurfaceElement& el = m_psurf->Element(0);
FEElement* pe = el.m_elem[0].pe;
if (pe == nullptr) return false;
// get the material
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
m_pfluid = pm->ExtractProperty<FEFluidMaterial>();
if (m_pfluid == nullptr) return false;
return true;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEFluidRCLoad::Activate()
{
FESurface* ps = &GetSurface();
for (int i = 0; i < ps->Nodes(); ++i)
{
FENode& node = ps->Node(i);
// mark node as having prescribed DOF
node.set_bc(m_dofEF, DOF_PRESCRIBED);
}
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEFluidRCLoad::Update()
{
const FETimeInfo& tp = GetTimeInfo();
double dt = tp.timeIncrement;
double gamma = tp.gamma;
double omoog = 1 - 1. / gamma;
int niter = GetFEModel()->GetCurrentStep()->GetFESolver()->m_niter;
// if this is the start of a new time step, update the flow/pressure parameters
if (niter == 0) {
m_qp = m_qt;
m_dqp = m_dqt * omoog;
m_pp = m_pt;
m_dpp = m_dpt * omoog;
}
// evaluate the flow rate
m_qt = FlowRate();
// evaluate the outflow pressure
double qt = m_Bern ? m_qt * fabs(m_qt) : m_qt;
double qp = m_Bern ? m_qp * fabs(m_qp) : m_qp;
m_dqt = m_dqp * omoog + (qt - qp) / gamma / dt;
m_dpt = m_dpp * omoog + (m_pt - m_pp) / gamma / dt;
m_pt = m_pp + (m_R * m_dqt + m_qt / m_C - m_dpp * omoog) * gamma * dt;
// calculate the dilatation
double e = 0;
bool good = m_pfluid->Dilatation(0, m_pt + m_p0, e);
assert(good);
// prescribe this dilatation at the nodes
FESurface* ps = &GetSurface();
for (int i = 0; i < ps->Nodes(); ++i)
{
if (ps->Node(i).m_ID[m_dofEF] < -1)
{
FENode& node = ps->Node(i);
// set node as having prescribed DOF
node.set(m_dofEF, e);
}
}
GetFEModel()->SetMeshUpdateFlag(true);
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface
double FEFluidRCLoad::FlowRate()
{
double Q = 0;
vec3d rt[FEElement::MAX_NODES];
vec3d vt[FEElement::MAX_NODES];
for (int iel = 0; iel < m_psurf->Elements(); ++iel)
{
FESurfaceElement& el = m_psurf->Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i = 0; i < neln; ++i) {
FENode& node = m_psurf->GetMesh()->Node(el.m_node[i]);
rt[i] = node.m_rt;
vt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
}
double* Nr, * Ns;
double* N;
double* w = el.GaussWeights();
vec3d dxr, dxs, v;
// repeat over integration points
for (int n = 0; n < nint; ++n)
{
N = el.H(n);
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the velocity and tangent vectors at integration point
dxr = dxs = v = vec3d(0, 0, 0);
for (int i = 0; i < neln; ++i)
{
v += vt[i] * N[i];
dxr += rt[i] * Nr[i];
dxs += rt[i] * Ns[i];
}
vec3d normal = dxr ^ dxs;
double q = normal * v;
Q += q * w[n];
}
}
return Q;
}
//-----------------------------------------------------------------------------
//! calculate residual
void FEFluidRCLoad::LoadVector(FEGlobalVector& R)
{
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidRCLoad::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
ar & m_pt & m_dpt & m_qt & m_dqt;
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofW & m_dofEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FENewtonianThermoFluid.h | .h | 2,897 | 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 "FEViscousFluid.h"
#include <FECore/FEFunction1D.h>
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Newtonian fluid
class FEBIOFLUID_API FENewtonianThermoFluid : public FEViscousFluid
{
public:
//! constructor
FENewtonianThermoFluid(FEModel* pfem);
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
//! viscous stress
mat3ds Stress(FEMaterialPoint& pt) override;
//! tangent of stress with respect to strain J
mat3ds Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of stress with respect to rate of deformation tensor D
tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) override;
//! tangent of stress with respect to temperature
mat3ds Tangent_Temperature(FEMaterialPoint& mp) override;
//! dynamic viscosity
double ShearViscosity(FEMaterialPoint& mp) override;
double TangentShearViscosityTemperature(FEMaterialPoint& mp);
//! bulk viscosity
double BulkViscosity(FEMaterialPoint& mp) override;
double TangentBulkViscosityTemperature(FEMaterialPoint& mp);
public:
double m_kappa; //!< bulk viscosity
double m_mu; //!< shear viscosity
double m_Tr; //!< referential temperature
FEFunction1D* m_kappahat; //!< normalized bulk viscosity vs normalized temperature
FEFunction1D* m_muhat; //!< normalized shear viscosity vs normalized temperature
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidSolver.h | .h | 6,048 | 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) 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/FENewtonSolver.h>
#include <FECore/FETimeInfo.h>
#include <FECore/FEGlobalVector.h>
#include <FECore/FEDofList.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
class FELinearSystem;
//-----------------------------------------------------------------------------
//! The FEPolarFluidSolver class solves polar fluid problems
//! It can deal with quasi-static and dynamic problems
//!
class FEBIOFLUID_API FEPolarFluidSolver : public FENewtonSolver
{
public:
//! constructor
FEPolarFluidSolver(FEModel* pfem);
//! destructor
~FEPolarFluidSolver();
//! serialize data to/from dump file
void Serialize(DumpStream& ar) override;
//! Initializes data structures
bool Init() override;
//! initialize the step
bool InitStep(double time) override;
//! Initialize linear equation system
bool InitEquations() override;
bool InitEquations2() override;
//! Generate warnings if needed
void SolverWarnings();
//! preferred matrix type should be unsymmetric.
Matrix_Type PreferredMatrixType() const override { return REAL_UNSYMMETRIC; };
public:
//{ --- evaluation and update ---
//! Perform an update
void Update(vector<double>& ui) override;
void Update2(const vector<double>& ui) override;
//! update nodal positions, velocities, accelerations, etc.
void UpdateKinematics(vector<double>& ui);
void UpdateConstraints();
//! update DOF increments
virtual void UpdateIncrements(vector<double>& Ui, vector<double>& ui, bool emap);
//}
//{ --- Solution functions ---
//! prepares the data for the first QN iteration
void PrepStep() override;
//! Performs a Newton-Raphson iteration
bool Quasin() override;
//{ --- Stiffness matrix routines ---
//! calculates the global stiffness matrix
bool StiffnessMatrix(FELinearSystem& LS) override;
//! contact stiffness
void ContactStiffness(FELinearSystem& LS);
//! calculates stiffness contributon of nonlinear constraints
void NonLinearConstraintStiffness(FELinearSystem& LS, const FETimeInfo& tp);
//{ --- Residual routines ---
//! Calculate the contact forces
void ContactForces(FEGlobalVector& R);
//! Calculates residual
bool Residual(vector<double>& R) override;
//! Calculate nonlinear constraint forces
void NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp);
protected:
void GetVelocityData(vector<double>& vi, vector<double>& ui);
void GetAngularVelocityData(vector<double>& xi, vector<double>& ui);
void GetDilatationData(vector<double>& ei, vector<double>& ui);
public:
// convergence tolerances
double m_Vtol; //!< velocity tolerance
double m_Gtol; //!< angular velocity tolerance
double m_Ftol; //!< dilatation tolerance
double m_minJf; //!< minimum allowable compression ratio
public:
// equation numbers
int m_nveq; //!< number of equations related to velocity dofs
int m_ngeq; //!< number of equations related to angular velocity dofs
int m_nfeq; //!< number of equations related to dilatation dofs
public:
vector<double> m_Fn; //!< concentrated nodal force vector
vector<double> m_Fr; //!< nodal reaction forces
vector<double> m_vi; //!< velocity increment vector
vector<double> m_Vi; //!< Total velocity vector for iteration
vector<double> m_gi; //!< angular velocity increment vector
vector<double> m_Gi; //!< Total angular velocity vector for iteration
vector<double> m_fi; //!< dilatation increment vector
vector<double> m_Fi; //!< Total dilatation vector for iteration
// generalized alpha method
double m_rhoi; //!< spectral radius (rho infinity)
double m_alphaf; //!< alpha step for Y={v,e}
double m_alpham; //!< alpha step for Ydot={∂v/∂t,∂e/∂t}
double m_beta; //!< beta
double m_gamma; //!< gamma
int m_pred; //!< predictor method
int m_order; //!< generalized-alpha integration order
protected:
FEDofList m_dofW; // fluid velocity
FEDofList m_dofAW; // material time derivative of fluid velocity
FEDofList m_dofG; // fluid angular velocity
FEDofList m_dofAG; // material time derivative of fluid angular velocity
FEDofList m_dofEF; // fluid dilatation
int m_dofAEF; // material time derivative of fluid dilatation
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidTemperatureBC.h | .h | 2,449 | 70 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "febiofluid_api.h"
#include <FECore/FEPrescribedBC.h>
#include <FECore/FESurface.h>
#include <FECore/FENodeNodeList.h>
//-----------------------------------------------------------------------------
//! FEThermoFluidTemperatureBC prescribes a temperature BC on an inflow/outflow boundary
//! by enforcing a simplified version of the energy balance as an essential BC
//!
class FEBIOFLUID_API FEThermoFluidTemperatureBC : public FEPrescribedSurface
{
public:
//! constructor
FEThermoFluidTemperatureBC(FEModel* pfem);
//! set the dilatation
void Update() override;
//! initialize
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
//! evaluate flow rate
void MarkBackFlow();
public:
// return the value for node i, dof j
void GetNodalValues(int nodelid, std::vector<double>& val) override;
// copy data from another class
void CopyFrom(FEBoundaryCondition* pbc) override;
private:
vector<double> m_T;
FESurface* m_surf;
FENodeNodeList m_nnlist;
vector<bool> m_backflow;
FEDofList m_dofW;
int m_dofT;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FENewtonianFluid.h | .h | 2,522 | 73 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEViscousFluid.h"
#include <FECore/FEFunction1D.h>
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Newtonian fluid
class FEBIOFLUID_API FENewtonianFluid : public FEViscousFluid
{
public:
//! constructor
FENewtonianFluid(FEModel* pfem);
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
//! viscous stress
mat3ds Stress(FEMaterialPoint& pt) override;
//! tangent of stress with respect to strain J
mat3ds Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of stress with respect to rate of deformation tensor D
tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) override;
//! tangent of stress with respect to temperature
mat3ds Tangent_Temperature(FEMaterialPoint& mp) override;
//! dynamic viscosity
double ShearViscosity(FEMaterialPoint& mp) override;
//! bulk viscosity
double BulkViscosity(FEMaterialPoint& mp) override;
public:
double m_kappa; //!< bulk viscosity
double m_mu; //!< shear viscosity
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidDomainFactory.h | .h | 1,613 | 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 <FECore/FECoreKernel.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
class FEBIOFLUID_API FEThermoFluidDomainFactory : public FEDomainFactory
{
public:
virtual FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSISoluteFlux.cpp | .cpp | 4,843 | 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) 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 "FEMultiphasicFSISoluteFlux.h"
#include "FEBioMultiphasicFSI.h"
#include <FECore/log.h>
#include <FECore/FEFacetSet.h>
#include "FECore/FEAnalysis.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEMultiphasicFSISoluteFlux, FESurfaceLoad)
ADD_PARAMETER(m_flux , "flux");
ADD_PARAMETER(m_isol , "sol");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEMultiphasicFSISoluteFlux::FEMultiphasicFSISoluteFlux(FEModel* pfem) : FESurfaceLoad(pfem), m_dofC(pfem), m_dofU(pfem)
{
m_flux = 1.0;
m_isol = -1;
}
//-----------------------------------------------------------------------------
//! allocate storage
void FEMultiphasicFSISoluteFlux::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
m_flux.SetItemList(ps->GetFacetSet());
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the prescribed normal component of velocity
void FEMultiphasicFSISoluteFlux::LoadVector(FEGlobalVector& R)
{
FEMultiphasicFSISoluteFlux* flux = this;
m_psurf->LoadVector(R, m_dofC, true, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
double wr = flux->m_flux(mp);
vec3d dxt = mp.dxr ^ mp.dxs;
// volumetric flow rate
double f = dxt.norm()*wr;
double H_i = dof_a.shape;
fa[0] = H_i * f;
});
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSISoluteFlux::StiffnessMatrix(FELinearSystem& LS)
{
const FETimeInfo& tp = GetTimeInfo();
// evaluate the stiffness contribution
FEMultiphasicFSISoluteFlux* flux = this;
m_psurf->LoadStiffness(LS, m_dofC, m_dofU, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) {
// shape functions and derivatives
double H_i = dof_a.shape;
double Gr_j = dof_b.shape_deriv_r;
double Gs_j = dof_b.shape_deriv_s;
double wr = flux->m_flux(mp);
// calculate surface normal
vec3d dxt = mp.dxr ^ mp.dxs;
double alpha = tp.alphaf;
// calculate stiffness component
vec3d t1 = dxt / dxt.norm()*wr;
vec3d t2 = - mp.dxs*Gr_j + mp.dxr*Gs_j;
mat3d A; A.skew(t2);
vec3d kab = -A*t1*(H_i)*alpha;
Kab.zero();
Kab[0][0] -= kab.x;
Kab[0][1] -= kab.y;
Kab[0][2] -= kab.z;
});
}
//-----------------------------------------------------------------------------
//! initialize
bool FEMultiphasicFSISoluteFlux::Init()
{
if (m_isol == -1) return false;
// set up the dof lists
FEModel* fem = GetFEModel();
m_dofC.Clear();
m_dofU.Clear();
m_dofC.AddDof(GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION), m_isol-1));
m_dofU.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::DISPLACEMENT));
m_dof.Clear();
m_dof.AddDofs(m_dofU);
m_dof.AddDofs(m_dofC);
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! serialization
void FEMultiphasicFSISoluteFlux::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_dofC & m_dofU;
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidTemperatureBC.cpp | .cpp | 7,652 | 217 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEThermoFluidTemperatureBC.h"
#include "FEBioThermoFluid.h"
#include "FEThermoFluid.h"
#include <FECore/FEModel.h>
//-----------------------------------------------------------------------------
//! constructor
FEThermoFluidTemperatureBC::FEThermoFluidTemperatureBC(FEModel* pfem) : FEPrescribedSurface(pfem), m_dofW(pfem)
{
m_dofT = -1;
m_surf = nullptr;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEThermoFluidTemperatureBC::Init()
{
FEModel& fem = *GetFEModel();
m_dofW.Clear();
m_dofW.AddVariable(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::RELATIVE_FLUID_VELOCITY));
m_dofT = fem.GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::TEMPERATURE), 0);
SetDOFList(m_dofW);
SetDOFList(m_dofT);
if (FEPrescribedSurface::Init() == false) return false;
m_surf = GetSurface();
m_T.assign(m_surf->Nodes(), 0.0);
m_backflow.assign(m_surf->Nodes(), false);
m_nnlist.Create(fem.GetMesh());
return FEPrescribedSurface::Init();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEThermoFluidTemperatureBC::Update()
{
// determine backflow conditions
MarkBackFlow();
int N = m_surf->Nodes();
std::vector<vector<double>> efNodes(N, vector<double>());
std::vector<vector<double>> vn(N, vector<double>());
for (int i=0; i<m_surf->Nodes(); ++i)
{
FENode& node = m_surf->Node(i);
if (m_backflow[i]) m_T[i] = node.get_prev(m_dofT);
else {
int nid = node.GetID()-1; //0 based
int val = m_nnlist.Valence(nid);
int* nlist = m_nnlist.NodeList(nid);
vector<int> connectnidarray;
int connectnid=0;
//check which connecting nodes are not on surface
for (int j = 0; j<val; ++j)
{
int cnid = *(nlist+j);
bool isSurf = false;
for (int k=0; k<m_surf->Nodes(); ++k)
{
if (cnid==m_surf->Node(k).GetID()-1)
isSurf = true;
}
if (!isSurf)
{
connectnidarray.push_back(cnid);
}
}
//find closest connecting node
if (connectnidarray.size()>0)
{
int cnodeIndex = 0;
FENode* cnodeArray = GetFEModel()->GetMesh().FindNodeFromID(connectnidarray[cnodeIndex]+1);
double smallDist = sqrt(pow((node.m_rt.x-cnodeArray->m_rt.x),2)+pow((node.m_rt.y-cnodeArray->m_rt.y),2)+pow((node.m_rt.z-cnodeArray->m_rt.z),2));
for (int j = 1; j<connectnidarray.size(); ++j)
{
FENode* tempNode = GetFEModel()->GetMesh().FindNodeFromID(connectnidarray[j]+1);
double temp = sqrt(pow((node.m_rt.x-tempNode->m_rt.x),2)+pow((node.m_rt.y-tempNode->m_rt.y),2)+pow((node.m_rt.z-tempNode->m_rt.z),2));
if(temp<smallDist)
{
cnodeIndex = j;
cnodeArray = tempNode;
smallDist = temp;
}
}
connectnid = connectnidarray[cnodeIndex];
FENode* cnode = GetFEModel()->GetMesh().FindNodeFromID(connectnid+1);
m_T[i] = cnode->get(m_dofT);
}
else
m_T[i] = node.get_prev(m_dofT);
}
}
FEPrescribedSurface::Update();
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface
void FEThermoFluidTemperatureBC::MarkBackFlow()
{
// Calculate normal flow velocity on each face to determine
// backflow condition
vec3d rt[FEElement::MAX_NODES];
vec3d vt[FEElement::MAX_NODES];
const FETimeInfo& tp = GetTimeInfo();
for (int iel=0; iel<m_surf->Elements(); ++iel)
{
FESurfaceElement& el = m_surf->Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i=0; i<neln; ++i) {
FENode& node = m_surf->GetMesh()->Node(el.m_node[i]);
rt[i] = node.m_rt*tp.alpha + node.m_rp*(1-tp.alpha);
vt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*tp.alpha + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1-tp.alpha);
}
double* Nr, *Ns;
double* N;
double* w = el.GaussWeights();
vec3d dxr, dxs, v;
double vn = 0;
// repeat over integration points
for (int n=0; n<nint; ++n)
{
N = el.H(n);
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the velocity and tangent vectors at integration point
dxr = dxs = v = vec3d(0,0,0);
for (int i=0; i<neln; ++i)
{
v += vt[i]*N[i];
dxr += rt[i]*Nr[i];
dxs += rt[i]*Ns[i];
}
vec3d normal = dxr ^ dxs;
normal.unit();
vn += (normal*v)*w[n];
}
if (vn < 0)
for (int i=0; i<neln; ++i) m_backflow[el.m_lnode[i]] = true;
else
for (int i=0; i<neln; ++i) m_backflow[el.m_lnode[i]] = false;
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidTemperatureBC::GetNodalValues(int nodelid, std::vector<double>& val)
{
val[0] = m_T[nodelid];
}
//-----------------------------------------------------------------------------
// copy data from another class
void FEThermoFluidTemperatureBC::CopyFrom(FEBoundaryCondition* pbc)
{
// TODO: implement this
assert(false);
}
//-----------------------------------------------------------------------------
//! serialization
void FEThermoFluidTemperatureBC::Serialize(DumpStream& ar)
{
FEPrescribedSurface::Serialize(ar);
ar & m_T;
if (ar.IsShallow()) return;
ar & m_dofT;
ar & m_surf;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPowellEyringFluid.h | .h | 2,497 | 67 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEViscousFluid.h"
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Powell-Eyring fluid
class FEBIOFLUID_API FEPowellEyringFluid : public FEViscousFluid
{
public:
//! constructor
FEPowellEyringFluid(FEModel* pfem);
//! viscous stress
mat3ds Stress(FEMaterialPoint& pt) override;
//! tangent of stress with respect to strain J
mat3ds Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of stress with respect to rate of deformation tensor D
tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) override;
//! tangent of stress with respect to temperature
mat3ds Tangent_Temperature(FEMaterialPoint& mp) override { return mat3ds(0); };
//! dynamic viscosity
double ShearViscosity(FEMaterialPoint& mp) override;
//! bulk viscosity
double BulkViscosity(FEMaterialPoint& mp) override;
public:
double m_mu0; //!< shear viscosity at zero shear rate
double m_mui; //!< shear viscosity at infinite shear rate
double m_lam; //!< time constant
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETiedFluidInterface.cpp | .cpp | 36,157 | 1,027 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FETiedFluidInterface.h"
#include <FECore/FENormalProjection.h>
#include <FECore/FEClosestPointProjection.h>
#include <FECore/log.h>
#include <FECore/DumpStream.h>
#include <FECore/FEGlobalMatrix.h>
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
#include "FEBioFluid.h"
//-----------------------------------------------------------------------------
// Define sliding interface parameters
BEGIN_FECORE_CLASS(FETiedFluidInterface, FEContactInterface)
ADD_PARAMETER(m_laugon , "laugon")->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0");
ADD_PARAMETER(m_atol , "tolerance" );
ADD_PARAMETER(m_gtol , "gaptol" );
ADD_PARAMETER(m_ptol , "ptol" );
ADD_PARAMETER(m_epst , "penalty" );
ADD_PARAMETER(m_bautopen , "auto_penalty" );
ADD_PARAMETER(m_btwo_pass, "two_pass" );
ADD_PARAMETER(m_stol , "search_tol" );
ADD_PARAMETER(m_epsn , "pressure_penalty" );
ADD_PARAMETER(m_srad , "search_radius" );
ADD_PARAMETER(m_naugmin , "minaug" );
ADD_PARAMETER(m_naugmax , "maxaug" );
ADD_PARAMETER(m_bfreedofs, "free_dofs" );
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FETiedFluidSurface::Data::Data()
{
m_Gap = vec3d(0,0,0);
m_vg = vec3d(0,0,0);
m_nu = vec3d(0,0,0);
m_rs = vec2d(0,0);
m_Lmd = vec3d(0,0,0);
m_tv = vec3d(0,0,0);
m_Lmp = 0.0;
m_epst= 1.0;
m_epsn= 1.0;
m_pg = 0.0;
m_vn = 0.0;
m_pme = (FESurfaceElement*)0;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::Data::Serialize(DumpStream& ar)
{
FEContactMaterialPoint::Serialize(ar);
ar & m_Gap;
ar & m_vg;
ar & m_nu;
ar & m_rs;
ar & m_Lmd;
ar & m_tv;
ar & m_Lmp;
ar & m_epst;
ar & m_epsn;
ar & m_pg;
ar & m_vn;
}
//-----------------------------------------------------------------------------
// FETiedFluidSurface
//-----------------------------------------------------------------------------
FETiedFluidSurface::FETiedFluidSurface(FEModel* pfem) : FEContactSurface(pfem), m_dofWE(pfem)
{
}
//-----------------------------------------------------------------------------
bool FETiedFluidSurface::Init()
{
// initialize surface data first
if (FEContactSurface::Init() == false) return false;
// set the dof list
if (m_dofWE.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY)) == false) return false;
if (m_dofWE.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION)) == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::UnpackLM(FEElement& el, vector<int>& lm)
{
int N = el.Nodes();
lm.resize(N*4);
for (int i=0; i<N; ++i)
{
int n = el.m_node[i];
FENode& node = m_pMesh->Node(n);
vector<int>& id = node.m_ID;
lm[4*i ] = id[m_dofWE[0]];
lm[4*i+1] = id[m_dofWE[1]];
lm[4*i+2] = id[m_dofWE[2]];
lm[4*i+3] = id[m_dofWE[3]];
}
}
//-----------------------------------------------------------------------------
//! create material point data
FEMaterialPoint* FETiedFluidSurface::CreateMaterialPoint()
{
return new FETiedFluidSurface::Data;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::GetVelocityGap(int nface, vec3d& vg)
{
FESurfaceElement& el = Element(nface);
int ni = el.GaussPoints();
vg = vec3d(0,0,0);
for (int k = 0; k < ni; ++k)
{
Data& d = static_cast<Data&>(*el.GetMaterialPoint(k));
vg += d.m_vg;
}
vg /= ni;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::GetPressureGap(int nface, double& pg)
{
FESurfaceElement& el = Element(nface);
int ni = el.GaussPoints();
pg = 0;
for (int k = 0; k < ni; ++k)
{
Data& d = static_cast<Data&>(*el.GetMaterialPoint(k));
pg += d.m_pg;
}
pg /= ni;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::GetViscousTraction(int nface, vec3d& tv)
{
FESurfaceElement& el = Element(nface);
int ni = el.GaussPoints();
tv = vec3d(0,0,0);
for (int k = 0; k < ni; ++k)
{
Data& d = static_cast<Data&>(*el.GetMaterialPoint(k));
tv += d.m_tv;
}
tv /= ni;
}
//-----------------------------------------------------------------------------
void FETiedFluidSurface::GetNormalVelocity(int nface, double& vn)
{
FESurfaceElement& el = Element(nface);
int ni = el.GaussPoints();
vn = 0;
for (int k = 0; k < ni; ++k)
{
Data& d = static_cast<Data&>(*el.GetMaterialPoint(k));
vn += d.m_vn;
}
vn /= ni;
}
//-----------------------------------------------------------------------------
// FETiedFluidInterface
//-----------------------------------------------------------------------------
FETiedFluidInterface::FETiedFluidInterface(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem), m_dofWE(pfem)
{
static int count = 1;
SetID(count++);
// initial values
m_atol = 0.1;
m_epst = 1;
m_epsn = 1;
m_btwo_pass = false;
m_stol = 0.01;
m_srad = 1.0;
m_gtol = -1; // we use augmentation tolerance by default
m_ptol = -1; // we use augmentation tolerance by default
m_bautopen = false;
m_bfreedofs = false;
m_naugmin = 0;
m_naugmax = 10;
// set parents
m_ss.SetContactInterface(this);
m_ms.SetContactInterface(this);
m_ss.SetSibling(&m_ms);
m_ms.SetSibling(&m_ss);
}
//-----------------------------------------------------------------------------
FETiedFluidInterface::~FETiedFluidInterface()
{
}
//-----------------------------------------------------------------------------
bool FETiedFluidInterface::Init()
{
// initialize surface data
if (m_ss.Init() == false) return false;
if (m_ms.Init() == false) return false;
// get the DOFS
m_dofWE.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dofWE.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION));
return true;
}
//-----------------------------------------------------------------------------
//! build the matrix profile for use in the stiffness matrix
void FETiedFluidInterface::BuildMatrixProfile(FEGlobalMatrix& K)
{
FEMesh& mesh = GetMesh();
vector<int> lm(4*FEElement::MAX_NODES*2);
int npass = (m_btwo_pass?2:1);
for (int np=0; np<npass; ++np)
{
FETiedFluidSurface& ss = (np == 0? m_ss : m_ms);
int ni = 0, k, l;
for (int j=0; j<ss.Elements(); ++j)
{
FESurfaceElement& se = ss.Element(j);
int nint = se.GaussPoints();
int* sn = &se.m_node[0];
for (k=0; k<nint; ++k, ++ni)
{
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*se.GetMaterialPoint(k));
FESurfaceElement* pe = pt.m_pme;
if (pe != 0)
{
FESurfaceElement& me = *pe;
int* mn = &me.m_node[0];
assign(lm, -1);
int nseln = se.Nodes();
int nmeln = me.Nodes();
for (l=0; l<nseln; ++l)
{
vector<int>& id = mesh.Node(sn[l]).m_ID;
lm[4*l ] = id[m_dofWE[0]];
lm[4*l+1] = id[m_dofWE[1]];
lm[4*l+2] = id[m_dofWE[2]];
lm[4*l+3] = id[m_dofWE[3]];
}
for (l=0; l<nmeln; ++l)
{
vector<int>& id = mesh.Node(mn[l]).m_ID;
lm[4*(l+nseln) ] = id[m_dofWE[0]];
lm[4*(l+nseln)+1] = id[m_dofWE[1]];
lm[4*(l+nseln)+2] = id[m_dofWE[2]];
lm[4*(l+nseln)+3] = id[m_dofWE[3]];
}
K.build_add(lm);
}
}
}
}
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::Activate()
{
// don't forget to call the base class
FEContactInterface::Activate();
// calculate the penalty
if (m_bautopen)
{
CalcAutoPressurePenalty(m_ss);
if (m_btwo_pass) CalcAutoPressurePenalty(m_ms);
}
// project the surfaces onto each other
// this will evaluate the gap functions in the reference configuration
InitialProjection(m_ss, m_ms);
if (m_btwo_pass) InitialProjection(m_ms, m_ss);
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::CalcAutoPressurePenalty(FETiedFluidSurface& s)
{
// loop over all surface elements
for (int i=0; i<s.Elements(); ++i)
{
// get the surface element
FESurfaceElement& el = s.Element(i);
// calculate a penalty
double eps = AutoPressurePenalty(el, s);
// assign to integration points of surface element
int nint = el.GaussPoints();
for (int j=0; j<nint; ++j)
{
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*el.GetMaterialPoint(j));
pt.m_epst = eps;
if (eps != 0) pt.m_epsn = 1./eps;
}
}
}
//-----------------------------------------------------------------------------
double FETiedFluidInterface::AutoPressurePenalty(FESurfaceElement& el, FETiedFluidSurface& s)
{
// get the mesh
FEMesh& m = GetMesh();
// evaluate element surface normal at parametric center
vec3d t[2];
s.CoBaseVectors0(el, 0, 0, t);
vec3d n = t[0] ^ t[1];
n.unit();
// get the element this surface element belongs to
FEElement* pe = el.m_elem[0].pe;
if (pe == 0) return 0.0;
// get the material
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
// check that it is a fluid material
FEFluidMaterial* fluid = dynamic_cast<FEFluidMaterial*> (pm);
if (fluid == 0) return 0.0;
m_pfluid = fluid;
// get a material point
FEMaterialPoint& mp = *pe->GetMaterialPoint(0);
// get the shear viscosity
double mu = fluid->GetViscous()->ShearViscosity(mp);
// get the area of the surface element
double A = s.FaceArea(el);
// get the volume of the volume element
double V = m.ElementVolume(*pe);
return mu*A/V;
}
//-----------------------------------------------------------------------------
// Perform initial projection between tied surfaces in reference configuration
void FETiedFluidInterface::InitialProjection(FETiedFluidSurface& ss, FETiedFluidSurface& ms)
{
FEMesh& mesh = GetMesh();
FESurfaceElement* pme;
vec3d r, nu;
double rs[2];
// initialize projection data
FENormalProjection np(ms);
np.SetTolerance(m_stol);
np.SetSearchRadius(m_srad);
np.Init();
FEClosestPointProjection cp(ss);
cp.SetTolerance(m_stol);
cp.SetSearchRadius(m_srad);
cp.Init();
vec3d sq;
vec2d srs;
// loop over all integration points
int n = 0;
for (int i=0; i<ss.Elements(); ++i)
{
FESurfaceElement& el = ss.Element(i);
int nint = el.GaussPoints();
for (int j=0; j<nint; ++j, ++n)
{
// calculate the global position of the integration point
r = ss.Local2Global(el, j);
// calculate the normal at this integration point
nu = ss.SurfaceNormal(el, j);
// find the intersection point with the secondary surface
pme = np.Project2(r, nu, rs);
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*el.GetMaterialPoint(j));
pt.m_pme = pme;
pt.m_nu = nu;
pt.m_rs[0] = rs[0];
pt.m_rs[1] = rs[1];
if (pme)
{
// the node could potentially be in contact
// find the global location of the intersection point
vec3d q = ms.Local2Global(*pme, rs[0], rs[1]);
// calculate the gap function
pt.m_Gap = q - r;
// free the nodal dofs of pme if requested
if (m_bfreedofs) {
for (int k=0; k<pme->Nodes(); ++k) {
FENode& node = mesh.Node(pme->m_node[k]);
FESurfaceElement* sme = cp.Project(node.m_rt, sq, srs);
if (sme) {
for (int l=0; l<m_dofWE.Size(); ++l)
if (node.get_bc(m_dofWE[l]) != DOF_OPEN) node.set_bc(m_dofWE[l], DOF_OPEN);
}
}
}
}
else
{
// the node is not in contact
pt.m_Gap = vec3d(0,0,0);
}
}
}
}
//-----------------------------------------------------------------------------
// Evaluate gap functions for fluid velocity and fluid pressure
void FETiedFluidInterface::ProjectSurface(FETiedFluidSurface& ss, FETiedFluidSurface& ms)
{
FEMesh& mesh = GetMesh();
FESurfaceElement* pme;
vec3d r;
vec3d vt[FEElement::MAX_NODES], v1;
double ps[FEElement::MAX_NODES], p1;
// loop over all integration points
for (int i=0; i<ss.Elements(); ++i)
{
FESurfaceElement& el = ss.Element(i);
int ne = el.Nodes();
int nint = el.GaussPoints();
// get the nodal velocities and pressures
for (int j=0; j<ne; ++j) {
vt[j] = mesh.Node(el.m_node[j]).get_vec3d(m_dofWE[0], m_dofWE[1], m_dofWE[2]);
ps[j] = m_pfluid->Pressure(mesh.Node(el.m_node[j]).get(m_dofWE[3]),0);
}
for (int j=0; j<nint; ++j)
{
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*el.GetMaterialPoint(j));
// calculate the global position of the integration point
r = ss.Local2Global(el, j);
// get the velocity and pressure at the integration point
v1 = el.eval(vt, j);
p1 = el.eval(ps, j);
// if this node is tied, evaluate gap functions
pme = pt.m_pme;
if (pme)
{
// calculate the tangential velocity gap function
vec3d vm[FEElement::MAX_NODES];
for (int k=0; k<pme->Nodes(); ++k) vm[k] = mesh.Node(pme->m_node[k]).get_vec3d(m_dofWE[0], m_dofWE[1], m_dofWE[2]);
vec3d v2 = pme->eval(vm, pt.m_rs[0], pt.m_rs[1]);
pt.m_vg = v2 - v1;
// calculate the pressure gap function
double pm[FEElement::MAX_NODES];
for (int k=0; k<pme->Nodes(); ++k) pm[k] = m_pfluid->Pressure(mesh.Node(pme->m_node[k]).get(m_dofWE[3]),0);
double p2 = pme->eval(pm, pt.m_rs[0], pt.m_rs[1]);
pt.m_pg = p1 - p2;
}
else
{
// the node is not tied
pt.m_vg = vec3d(0,0,0);
pt.m_pg = 0;
}
}
}
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::Update()
{
// project the surfaces onto each other
// this will update the gap functions as well
ProjectSurface(m_ss, m_ms);
if (m_btwo_pass) ProjectSurface(m_ms, m_ss);
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::LoadVector(FEGlobalVector& R, const FETimeInfo& tp)
{
int i, j, k;
vector<int> sLM, mLM, LM, en;
vector<double> fe;
const int MN = FEElement::MAX_NODES;
double detJ[MN], w[MN], *Hs, Hm[MN];
double N[8*MN];
// loop over the nr of passes
int npass = (m_btwo_pass?2:1);
for (int np=0; np<npass; ++np)
{
// get primary and secondary surfaces
FETiedFluidSurface& ss = (np == 0? m_ss : m_ms);
FETiedFluidSurface& ms = (np == 0? m_ms : m_ss);
// loop over all elements of primary surface
for (i=0; i<ss.Elements(); ++i)
{
// get the surface element
FESurfaceElement& se = ss.Element(i);
// get the nr of nodes and integration points
int nseln = se.Nodes();
int nint = se.GaussPoints();
// copy the LM vector; we'll need it later
ss.UnpackLM(se, sLM);
// we calculate all the metrics we need before we
// calculate the nodal forces
for (j=0; j<nint; ++j)
{
// get the base vectors
vec3d g[2];
ss.CoBaseVectors(se, j, g);
// jacobians: J = |g0xg1|
detJ[j] = (g[0] ^ g[1]).norm();
// integration weights
w[j] = se.GaussWeights()[j];
}
// loop over all integration points
// note that we are integrating over the current surface
for (j=0; j<nint; ++j)
{
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*se.GetMaterialPoint(j));
// get the secondary surface element
FESurfaceElement* pme = pt.m_pme;
if (pme)
{
// get the secondary surface element
FESurfaceElement& me = *pme;
// get the nr of secondary element nodes
int nmeln = me.Nodes();
// copy LM vector
ms.UnpackLM(me, mLM);
// calculate degrees of freedom
int ndof = 3*(nseln + nmeln);
// build the LM vector
LM.resize(ndof);
for (k=0; k<nseln; ++k)
{
LM[3*k ] = sLM[4*k ];
LM[3*k+1] = sLM[4*k+1];
LM[3*k+2] = sLM[4*k+2];
}
for (k=0; k<nmeln; ++k)
{
LM[3*(k+nseln) ] = mLM[4*k ];
LM[3*(k+nseln)+1] = mLM[4*k+1];
LM[3*(k+nseln)+2] = mLM[4*k+2];
}
// build the en vector
en.resize(nseln+nmeln);
for (k=0; k<nseln; ++k) en[k ] = se.m_node[k];
for (k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k];
// get primary element shape functions
Hs = se.H(j);
// get secondary element shape functions
double r = pt.m_rs[0];
double s = pt.m_rs[1];
me.shape_fnc(Hm, r, s);
// gap function
vec3d dg = pt.m_vg;
// lagrange multiplier
vec3d Lm = pt.m_Lmd;
// penalty
double eps = m_epst*pt.m_epst;
// viscous traction
vec3d tv = Lm + dg*eps;
pt.m_tv = tv;
// calculate the force vector
fe.resize(ndof);
zero(fe);
for (k=0; k<nseln; ++k)
{
N[3*k ] = Hs[k]*tv.x;
N[3*k+1] = Hs[k]*tv.y;
N[3*k+2] = Hs[k]*tv.z;
}
for (k=0; k<nmeln; ++k)
{
N[3*(k+nseln) ] = -Hm[k]*tv.x;
N[3*(k+nseln)+1] = -Hm[k]*tv.y;
N[3*(k+nseln)+2] = -Hm[k]*tv.z;
}
for (k=0; k<ndof; ++k) fe[k] += N[k]*detJ[j]*w[j];
// assemble the global residual
R.Assemble(en, LM, fe);
// do the pressure stuff
// calculate nr of pressure dofs
ndof = nseln + nmeln;
// calculate the flow rate
double epsn = m_epsn*pt.m_epsn;
double vn = pt.m_Lmp + epsn*pt.m_pg;
pt.m_vn = vn;
// fill the LM
LM.resize(ndof);
for (k=0; k<nseln; ++k) LM[k ] = sLM[4*k+3];
for (k=0; k<nmeln; ++k) LM[k + nseln] = mLM[4*k+3];
// fill the force array
fe.resize(ndof);
zero(fe);
for (k=0; k<nseln; ++k) N[k ] = -Hs[k];
for (k=0; k<nmeln; ++k) N[k+nseln] = Hm[k];
for (k=0; k<ndof; ++k) fe[k] += vn*N[k]*detJ[j]*w[j];
// assemble residual
R.Assemble(en, LM, fe);
}
}
}
}
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp)
{
int i, j, k, l;
vector<int> sLM, mLM, LM, en;
const int MN = FEElement::MAX_NODES;
double detJ[MN], w[MN], *Hs, Hm[MN], pt[MN], dpr[MN], dps[MN];
FEElementMatrix ke;
// do single- or two-pass
int npass = (m_btwo_pass?2:1);
for (int np=0; np < npass; ++np)
{
// get primary and secondary surfaces
FETiedFluidSurface& ss = (np == 0? m_ss : m_ms);
FETiedFluidSurface& ms = (np == 0? m_ms : m_ss);
// loop over all elements of primary surface
for (i=0; i<ss.Elements(); ++i)
{
// get the next element
FESurfaceElement& se = ss.Element(i);
FEElement* sse = se.m_elem[0].pe;
// get nr of nodes and integration points
int nseln = se.Nodes();
int nint = se.GaussPoints();
// nodal velocities and pressures
vec3d vt[FEElement::MAX_NODES];
double pn[FEElement::MAX_NODES];
for (j=0; j<nseln; ++j) {
vt[j] = ss.GetMesh()->Node(se.m_node[j]).get_vec3d(m_dofWE[0], m_dofWE[1], m_dofWE[2]);
pn[j] = m_pfluid->Pressure(ss.GetMesh()->Node(se.m_node[j]).get(m_dofWE[3]),0);
}
// copy the LM vector
ss.UnpackLM(se, sLM);
// we calculate all the metrics we need before we
// calculate the nodal forces
for (j=0; j<nint; ++j)
{
// get the base vectors
vec3d g[2];
ss.CoBaseVectors(se, j, g);
// jacobians: J = |g0xg1|
detJ[j] = (g[0] ^ g[1]).norm();
// integration weights
w[j] = se.GaussWeights()[j];
// pressure
pt[j] = se.eval(pn, j);
dpr[j] = se.eval_deriv1(pn, j);
dps[j] = se.eval_deriv2(pn, j);
}
// loop over all integration points
for (j=0; j<nint; ++j)
{
FETiedFluidSurface::Data& pt = static_cast<FETiedFluidSurface::Data&>(*se.GetMaterialPoint(j));
// get the secondary element
FESurfaceElement* pme = pt.m_pme;
if (pme)
{
FESurfaceElement& me = *pme;
// get the nr of secondary nodes
int nmeln = me.Nodes();
// nodal pressure
vec3d vm[FEElement::MAX_NODES];
double pm[FEElement::MAX_NODES];
for (k=0; k<nmeln; ++k) {
vm[k] = ms.GetMesh()->Node(me.m_node[k]).get_vec3d(m_dofWE[0], m_dofWE[1], m_dofWE[2]);
pm[k] = m_pfluid->Pressure(ms.GetMesh()->Node(me.m_node[k]).get(m_dofWE[3]),0);
}
// copy the LM vector
ms.UnpackLM(me, mLM);
int ndpn; // number of dofs per node
int ndof; // number of dofs in stiffness matrix
// calculate degrees of freedom for fluid-on-fluid contact
ndpn = 4;
ndof = ndpn*(nseln+nmeln);
// build the LM vector
LM.resize(ndof);
for (k=0; k<nseln; ++k)
{
LM[4*k ] = sLM[4*k ]; // wx-dof
LM[4*k+1] = sLM[4*k+1]; // wy-dof
LM[4*k+2] = sLM[4*k+2]; // wz-dof
LM[4*k+3] = sLM[4*k+3]; // ef-dof
}
for (k=0; k<nmeln; ++k)
{
LM[4*(k+nseln) ] = mLM[4*k ]; // wx-dof
LM[4*(k+nseln)+1] = mLM[4*k+1]; // wy-dof
LM[4*(k+nseln)+2] = mLM[4*k+2]; // wz-dof
LM[4*(k+nseln)+3] = mLM[4*k+3]; // ef-dof
}
// build the en vector
en.resize(nseln+nmeln);
for (k=0; k<nseln; ++k) en[k ] = se.m_node[k];
for (k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k];
// primary element shape functions
Hs = se.H(j);
// secondary element shape functions
double r = pt.m_rs[0];
double s = pt.m_rs[1];
me.shape_fnc(Hm, r, s);
// penalty
double eps = m_epst*pt.m_epst;
// create the stiffness matrix
ke.resize(ndof, ndof); ke.zero();
// a. K-term
//------------------------------------
for (k=0; k<nseln; ++k) {
for (l=0; l<nseln; ++l)
{
double K = eps*Hs[k]*Hs[l]*detJ[j]*w[j];
ke[ndpn*k ][ndpn*l ] += K;
ke[ndpn*k + 1][ndpn*l + 1] += K;
ke[ndpn*k + 2][ndpn*l + 2] += K;
}
for (l=0; l<nmeln; ++l)
{
double K = -eps*Hs[k]*Hm[l]*detJ[j]*w[j];
ke[ndpn*k ][ndpn*(nseln+l) ] += K;
ke[ndpn*k + 1][ndpn*(nseln+l) + 1] += K;
ke[ndpn*k + 2][ndpn*(nseln+l) + 2] += K;
}
}
for (k=0; k<nmeln; ++k) {
for (l=0; l<nseln; ++l)
{
double K = -eps*Hm[k]*Hs[l]*detJ[j]*w[j];
ke[ndpn*(nseln+k) ][ndpn*l ] += K;
ke[ndpn*(nseln+k) + 1][ndpn*l + 1] += K;
ke[ndpn*(nseln+k) + 2][ndpn*l + 2] += K;
}
for (l=0; l<nmeln; ++l)
{
double K = eps*Hm[k]*Hm[l]*detJ[j]*w[j];
ke[ndpn*(nseln+k) ][ndpn*(nseln+l) ] += K;
ke[ndpn*(nseln+k) + 1][ndpn*(nseln+l) + 1] += K;
ke[ndpn*(nseln+k) + 2][ndpn*(nseln+l) + 2] += K;
}
}
// --- D I L A T A T I O N S T I F F N E S S ---
{
double epsn = m_epsn*pt.m_epsn;
double K = m_pfluid->BulkModulus(*sse->GetMaterialPoint(0));
for (k=0; k<nseln; ++k) {
for (l=0; l<nseln; ++l)
ke[4*k + 3][4*l+3] += -K*epsn*w[j]*detJ[j]*Hs[k]*Hs[l];
for (l=0; l<nmeln; ++l)
ke[4*k + 3][4*(nseln+l)+3] += K*epsn*w[j]*detJ[j]*Hs[k]*Hm[l];
}
for (k=0; k<nmeln; ++k) {
for (l=0; l<nseln; ++l)
ke[4*(nseln+k)+3][4*l + 3] += K*epsn*w[j]*detJ[j]*Hm[k]*Hs[l];
for (l=0; l<nmeln; ++l)
ke[4*(nseln+k)+3][4*(nseln+l) + 3] += -K*epsn*w[j]*detJ[j]*Hm[k]*Hm[l];
}
}
// assemble the global stiffness
ke.SetNodes(en);
ke.SetIndices(LM);
LS.Assemble(ke);
}
}
}
}
}
//-----------------------------------------------------------------------------
bool FETiedFluidInterface::Augment(int naug, const FETimeInfo& tp)
{
// make sure we need to augment
if (m_laugon != FECore::AUGLAG_METHOD) return true;
int i;
vec3d Ln;
bool bconv = true;
int NS = m_ss.Elements();
int NM = m_ms.Elements();
// --- c a l c u l a t e i n i t i a l n o r m s ---
// a. normal component
double normL0 = 0, normP0 = 0;
for (int i=0; i<NS; ++i)
{
FESurfaceElement& se = m_ss.Element(i);
for (int j=0; j<se.GaussPoints(); ++j)
{
FETiedFluidSurface::Data& ds = static_cast<FETiedFluidSurface::Data&>(*se.GetMaterialPoint(j));
normL0 += ds.m_Lmd*ds.m_Lmd;
normP0 += ds.m_Lmp*ds.m_Lmp;
}
}
for (int i=0; i<NM; ++i)
{
FESurfaceElement& me = m_ms.Element(i);
for (int j=0; j<me.GaussPoints(); ++j)
{
FETiedFluidSurface::Data& dm = static_cast<FETiedFluidSurface::Data&>(*me.GetMaterialPoint(j));
normL0 += dm.m_Lmd*dm.m_Lmd;
normP0 += dm.m_Lmp*dm.m_Lmp;
}
}
// b. gap component
// (is calculated during update)
double maxgap = 0;
double maxpg = 0;
// update Lagrange multipliers
double normL1 = 0, normP1 = 0, eps, epsn;
for (i=0; i<NS; ++i)
{
FESurfaceElement& se = m_ss.Element(i);
for (int j = 0; j<se.GaussPoints(); ++j)
{
FETiedFluidSurface::Data& ds = static_cast<FETiedFluidSurface::Data&>(*se.GetMaterialPoint(j));
if (ds.m_pme) {
// update Lagrange multipliers on primary surface
eps = m_epst*ds.m_epst;
ds.m_Lmd = ds.m_Lmd + ds.m_vg*eps;
maxgap = max(maxgap,sqrt(ds.m_vg*ds.m_vg));
normL1 += ds.m_Lmd*ds.m_Lmd;
epsn = m_epsn*ds.m_epsn;
ds.m_Lmp = ds.m_Lmp + epsn*ds.m_pg;
maxpg = max(maxpg,fabs(ds.m_pg));
normP1 += ds.m_Lmp*ds.m_Lmp;
}
}
}
for (i=0; i<NM; ++i)
{
FESurfaceElement& me = m_ms.Element(i);
for (int j = 0; j<me.GaussPoints(); ++j)
{
FETiedFluidSurface::Data& dm = static_cast<FETiedFluidSurface::Data&>(*me.GetMaterialPoint(j));
if (dm.m_pme) {
// update Lagrange multipliers on secondary surface
eps = m_epst*dm.m_epst;
dm.m_Lmd = dm.m_Lmd + dm.m_vg*eps;
maxgap = max(maxgap,sqrt(dm.m_vg*dm.m_vg));
normL1 += dm.m_Lmd*dm.m_Lmd;
epsn = m_epsn*dm.m_epsn;
dm.m_Lmp = dm.m_Lmp + epsn*dm.m_pg;
maxpg = max(maxpg,fabs(dm.m_pg));
normP1 += dm.m_Lmp*dm.m_Lmp;
}
}
}
// calculate relative norms
double lnorm = (normL1 != 0 ? fabs((normL1 - normL0) / normL1) : fabs(normL1 - normL0));
double pnorm = (normP1 != 0 ? fabs((normP1 - normP0) / normP1) : fabs(normP1 - normP0));
// check convergence
if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false;
if ((m_ptol > 0) && (maxpg > m_ptol)) bconv = false;
if ((m_atol > 0) && (lnorm > m_atol)) bconv = false;
if ((m_atol > 0) && (pnorm > m_atol)) bconv = false;
if (naug < m_naugmin ) bconv = false;
if (naug >= m_naugmax) bconv = true;
feLog(" tied fluid interface # %d\n", GetID());
feLog(" CURRENT REQUIRED\n");
feLog(" V multiplier : %15le", lnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n");
feLog(" P multiplier : %15le", pnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n");
feLog(" maximum velocity gap : %15le", maxgap);
if (m_gtol > 0) feLog("%15le\n", m_gtol); else feLog(" ***\n");
feLog(" maximum pressure gap : %15le", maxpg);
if (m_ptol > 0) feLog("%15le\n", m_ptol); else feLog(" ***\n");
return bconv;
}
//-----------------------------------------------------------------------------
void FETiedFluidInterface::Serialize(DumpStream &ar)
{
// store contact data
FEContactInterface::Serialize(ar);
// store contact surface data
m_ms.Serialize(ar);
m_ss.Serialize(ar);
// serialize element pointers
SerializeElementPointers(m_ss, m_ms, ar);
SerializeElementPointers(m_ms, m_ss, ar);
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofWE;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEQuemadaFluid.h | .h | 2,546 | 70 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEViscousFluid.h"
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Quemada fluid
// see https://en.wikipedia.org/wiki/Hemorheology
class FEBIOFLUID_API FEQuemadaFluid : public FEViscousFluid
{
public:
//! constructor
FEQuemadaFluid(FEModel* pfem);
//! viscous stress
mat3ds Stress(FEMaterialPoint& pt) override;
//! tangent of stress with respect to strain J
mat3ds Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of stress with respect to rate of deformation tensor D
tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) override;
//! tangent of stress with respect to temperature
mat3ds Tangent_Temperature(FEMaterialPoint& mp) override { return mat3ds(0); };
//! dynamic viscosity
double ShearViscosity(FEMaterialPoint& mp) override;
//! bulk viscosity
double BulkViscosity(FEMaterialPoint& mp) override;
public:
double m_mu0; //!< shear viscosity at zero shear rate
double m_H; //!< volume fraction occupied by particles
double m_k0;
double m_ki;
double m_gc;
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioFluidSolutes.h | .h | 1,736 | 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 "febiofluid_api.h"
namespace FEBioFluidSolutes {
FEBIOFLUID_API void InitModule();
enum FLUID_SOLUTES_VARIABLE {
DISPLACEMENT,
RELATIVE_FLUID_VELOCITY,
RELATIVE_FLUID_ACCELERATION,
FLUID_DILATATION,
FLUID_DILATATION_TDERIV,
FLUID_CONCENTRATION,
FLUID_CONCENTRATION_TDERIV
};
FEBIOFLUID_API const char* GetVariableName(FLUID_SOLUTES_VARIABLE var);
}
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioFluid.cpp | .cpp | 17,024 | 314 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioFluid.h"
#include "FEFluid.h"
#include "FENewtonianFluid.h"
#include "FEBinghamFluid.h"
#include "FECarreauFluid.h"
#include "FECarreauYasudaFluid.h"
#include "FEPowellEyringFluid.h"
#include "FECrossFluid.h"
#include "FEQuemadaFluid.h"
#include "FEFluidFSI.h"
#include "FEBiphasicFSI.h"
#include "FEIdealGasIsentropic.h"
#include "FEIdealGasIsothermal.h"
#include "FELinearElasticFluid.h"
#include "FENonlinearElasticFluid.h"
#include "FELogNonlinearElasticFluid.h"
#include "FEFluidSolver.h"
#include "FEFluidDomain3D.h"
#include "FEFluidPressureLoad.h"
#include "FEFluidTractionLoad.h"
#include "FEFluidMixtureTractionLoad.h"
#include "FEFluidNormalTraction.h"
#include "FEFluidNormalVelocity.h"
#include "FEFluidVelocity.h"
#include "FEFluidRotationalVelocity.h"
#include "FEFluidResistanceBC.h"
#include "FEFluidResistanceLoad.h"
#include "FEFluidRCRBC.h"
#include "FEFluidRCRLoad.h"
#include "FETangentialDamping.h"
#include "FETangentialFlowStabilization.h"
#include "FEBackFlowStabilization.h"
#include "FEFluidRCBC.h"
#include "FEFluidRCLoad.h"
#include "FEPrescribedFluidPressure.h"
#include "FETiedFluidInterface.h"
#include "FEConstraintFrictionlessWall.h"
#include "FEConstraintNormalFlow.h"
#include "FEConstraintUniformFlow.h"
#include "FEBioFluidPlot.h"
#include "FEBioFluidData.h"
#include "FEFluidDomainFactory.h"
#include "FEFSIErosionVolumeRatio.h"
#include "FEFluidStressCriterion.h"
#include "FEFixedFluidVelocity.h"
#include "FEPrescribedFluidVelocity.h"
#include "FEFixedFluidDilatation.h"
#include "FEPrescribedFluidDilatation.h"
#include "FEInitialFluidDilatation.h"
#include "FEInitialFluidVelocity.h"
#include "FEInitialFluidPressure.h"
#include "FEConstFluidBodyForce.h"
#include "FECentrifugalFluidBodyForce.h"
#include "FEFluidMovingFrameLoad.h"
#include "FEFluidModule.h"
#include "FEFluidAnalysis.h"
#include <FECore/FETimeStepController.h>
//-----------------------------------------------------------------------------
const char* FEBioFluid::GetVariableName(FEBioFluid::FLUID_VARIABLE var)
{
switch (var)
{
case DISPLACEMENT : return "displacement" ; break;
case RELATIVE_FLUID_VELOCITY : return "relative fluid velocity" ; break;
case FLUID_DILATATION : return "fluid dilatation" ; break;
case RELATIVE_FLUID_ACCELERATION : return "relative fluid acceleration" ; break;
case FLUID_DILATATION_TDERIV : return "fluid dilatation tderiv" ; break;
}
assert(false);
return nullptr;
}
//-----------------------------------------------------------------------------
//! Initialization of the FEBioFluid module. This function registers all the classes
//! in this module with the FEBio framework.
void FEBioFluid::InitModule()
{
//-----------------------------------------------------------------------------
// Domain factory
FECoreKernel& febio = FECoreKernel::GetInstance();
febio.RegisterDomain(new FEFluidDomainFactory);
// define the fluid module
febio.CreateModule(new FEFluidModule, "fluid",
"{"
" \"title\" : \"Fluid Mechanics\","
" \"info\" : \"Steady-state or transient fluid dynamics analysis.\""
"}");
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEFluidAnalysis, "fluid");
//-----------------------------------------------------------------------------
// solver classes
REGISTER_FECORE_CLASS(FEFluidSolver, "fluid");
//-----------------------------------------------------------------------------
// Materials
REGISTER_FECORE_CLASS(FEFluid , "fluid" );
// viscous fluids
REGISTER_FECORE_CLASS(FENewtonianFluid , "Newtonian fluid");
REGISTER_FECORE_CLASS(FEBinghamFluid , "Bingham" )
REGISTER_FECORE_CLASS(FECarreauFluid , "Carreau" );
REGISTER_FECORE_CLASS(FECarreauYasudaFluid, "Carreau-Yasuda");
REGISTER_FECORE_CLASS(FEPowellEyringFluid , "Powell-Eyring" );
REGISTER_FECORE_CLASS(FECrossFluid , "Cross" );
REGISTER_FECORE_CLASS(FEQuemadaFluid , "Quemada" );
// elastic fluids
REGISTER_FECORE_CLASS(FEIdealGasIsentropic, "ideal gas isentropic");
//REGISTER_FECORE_CLASS(FEIdealGasIsothermal, "ideal gas isothermal");
REGISTER_FECORE_CLASS(FELinearElasticFluid, "linear" );
REGISTER_FECORE_CLASS(FENonlinearElasticFluid, "nonlinear" );
REGISTER_FECORE_CLASS(FELogNonlinearElasticFluid, "log-nonlinear");
//-----------------------------------------------------------------------------
// Domain classes
REGISTER_FECORE_CLASS(FEFluidDomain3D, "fluid-3D");
//-----------------------------------------------------------------------------
// Surface loads
REGISTER_FECORE_CLASS(FEFluidPressureLoad , "fluid pressure" , 0x0300); // Deprecated, use the BC version.
REGISTER_FECORE_CLASS(FEFluidTractionLoad , "fluid viscous traction" );
REGISTER_FECORE_CLASS(FEFluidMixtureTractionLoad , "fluid mixture viscous traction");
REGISTER_FECORE_CLASS(FEFluidNormalTraction , "fluid normal traction" );
REGISTER_FECORE_CLASS(FEFluidNormalVelocity , "fluid normal velocity" );
REGISTER_FECORE_CLASS(FEFluidVelocity , "fluid velocity" );
REGISTER_FECORE_CLASS(FEFluidResistanceLoad , "fluid resistance" , 0x0300); // Deprecated, use the BC version.
REGISTER_FECORE_CLASS(FEFluidRCRLoad , "fluid RCR" , 0x0300); // Deprecated, use the BC version.
REGISTER_FECORE_CLASS(FETangentialDamping , "fluid tangential damping" );
REGISTER_FECORE_CLASS(FETangentialFlowStabilization, "fluid tangential stabilization");
REGISTER_FECORE_CLASS(FEBackFlowStabilization , "fluid backflow stabilization" );
REGISTER_FECORE_CLASS(FEFluidRCLoad , "fluid RC" , 0x0300); // Deprecated, use the BC version.
//-----------------------------------------------------------------------------
// body loads
REGISTER_FECORE_CLASS(FEConstFluidBodyForce , "fluid body force");
REGISTER_FECORE_CLASS(FECentrifugalFluidBodyForce, "fluid centrifugal force");
REGISTER_FECORE_CLASS(FEFluidMovingFrameLoad , "fluid moving frame");
//-----------------------------------------------------------------------------
// boundary conditions
REGISTER_FECORE_CLASS(FEFixedFluidVelocity , "zero fluid velocity");
REGISTER_FECORE_CLASS(FEPrescribedFluidVelocity , "prescribed fluid velocity");
REGISTER_FECORE_CLASS(FEFixedFluidDilatation , "zero fluid dilatation");
REGISTER_FECORE_CLASS(FEPrescribedFluidDilatation, "prescribed fluid dilatation");
REGISTER_FECORE_CLASS(FEFluidRotationalVelocity , "fluid rotational velocity");
REGISTER_FECORE_CLASS(FEPrescribedFluidPressure , "fluid pressure");
REGISTER_FECORE_CLASS(FEFluidRCBC , "fluid RC");
REGISTER_FECORE_CLASS(FEFluidRCRBC , "fluid RCR");
REGISTER_FECORE_CLASS(FEFluidResistanceBC , "fluid resistance");
//-----------------------------------------------------------------------------
// initial conditions
REGISTER_FECORE_CLASS(FEInitialFluidDilatation, "initial fluid dilatation");
REGISTER_FECORE_CLASS(FEInitialFluidVelocity , "initial fluid velocity");
REGISTER_FECORE_CLASS(FEInitialFluidPressure , "initial fluid pressure");
//-----------------------------------------------------------------------------
// Contact interfaces
REGISTER_FECORE_CLASS(FETiedFluidInterface, "tied-fluid");
//-----------------------------------------------------------------------------
// constraint classes
REGISTER_FECORE_CLASS(FEConstraintFrictionlessWall, "frictionless fluid wall");
REGISTER_FECORE_CLASS(FEConstraintNormalFlow , "normal fluid flow" );
REGISTER_FECORE_CLASS(FEConstraintUniformFlow , "uniform fluid flow" );
//-----------------------------------------------------------------------------
// classes derived from FEPlotData
REGISTER_FECORE_CLASS(FEPlotDisplacement , "displacement" );
REGISTER_FECORE_CLASS(FEPlotNodalFluidVelocity , "nodal fluid velocity" );
REGISTER_FECORE_CLASS(FEPlotNodalRelativeFluidVelocity , "nodal fluid flux" );
REGISTER_FECORE_CLASS(FEPlotNodalFluidTemperature , "nodal fluid temperature" );
REGISTER_FECORE_CLASS(FEPlotFluidDilatation , "fluid dilatation" );
REGISTER_FECORE_CLASS(FEPlotFluidEffectivePressure , "effective fluid pressure" );
REGISTER_FECORE_CLASS(FEPlotElasticFluidPressure , "elastic fluid pressure" );
REGISTER_FECORE_CLASS(FEPlotFluidBodyForce , "fluid body force" );
REGISTER_FECORE_CLASS(FEPlotFluidVolumeRatio , "fluid volume ratio" );
REGISTER_FECORE_CLASS(FEPlotFluidDensity , "fluid density" );
REGISTER_FECORE_CLASS(FEPlotFluidDensityRate , "fluid density rate" );
REGISTER_FECORE_CLASS(FEPlotFluidVelocity , "fluid velocity" );
REGISTER_FECORE_CLASS(FEPlotBFSISolidVolumeFraction , "solid volume fraction" );
REGISTER_FECORE_CLASS(FEPlotFluidTemperature , "fluid temperature" );
REGISTER_FECORE_CLASS(FEPlotRelativeFluidVelocity , "relative fluid velocity" );
REGISTER_FECORE_CLASS(FEPlotFSIFluidFlux , "fluid flux" );
REGISTER_FECORE_CLASS(FEPlotPermeability , "permeability" );
REGISTER_FECORE_CLASS(FEPlotGradJ , "dilatation gradient" );
REGISTER_FECORE_CLASS(FEPlotGradPhiF , "fluid volume ratio gradient");
REGISTER_FECORE_CLASS(FEPlotFluidAcceleration , "fluid acceleration" );
REGISTER_FECORE_CLASS(FEPlotFluidVorticity , "fluid vorticity" );
REGISTER_FECORE_CLASS(FEPlotFluidStress , "fluid stress" );
REGISTER_FECORE_CLASS(FEPlotElementFluidRateOfDef , "fluid rate of deformation");
REGISTER_FECORE_CLASS(FEPlotFluidStressPowerDensity , "fluid stress power density");
REGISTER_FECORE_CLASS(FEPlotFluidHeatSupplyDensity , "fluid heat supply density");
REGISTER_FECORE_CLASS(FEPlotFluidSurfaceForce , "fluid surface force" );
REGISTER_FECORE_CLASS(FEPlotFluidSurfacePressure , "fluid surface pressure" );
REGISTER_FECORE_CLASS(FEPlotFluidSurfaceTractionPower , "fluid surface traction power");
REGISTER_FECORE_CLASS(FEPlotFluidSurfaceEnergyFlux , "fluid surface energy flux");
REGISTER_FECORE_CLASS(FEPlotFluidShearViscosity , "fluid shear viscosity" );
REGISTER_FECORE_CLASS(FEPlotFluidMassFlowRate , "fluid mass flow rate" );
REGISTER_FECORE_CLASS(FEPlotFluidStrainEnergyDensity , "fluid strain energy density");
REGISTER_FECORE_CLASS(FEPlotFluidKineticEnergyDensity , "fluid kinetic energy density");
REGISTER_FECORE_CLASS(FEPlotFluidEnergyDensity , "fluid energy density" );
REGISTER_FECORE_CLASS(FEPlotFluidBulkModulus , "fluid bulk modulus" );
REGISTER_FECORE_CLASS(FEPlotFluidElementStrainEnergy , "fluid element strain energy");
REGISTER_FECORE_CLASS(FEPlotFluidElementKineticEnergy , "fluid element kinetic energy");
REGISTER_FECORE_CLASS(FEPlotFluidElementLinearMomentum , "fluid element linear momentum");
REGISTER_FECORE_CLASS(FEPlotFluidElementAngularMomentum, "fluid element angular momentum");
REGISTER_FECORE_CLASS(FEPlotFluidElementCenterOfMass , "fluid element center of mass");
REGISTER_FECORE_CLASS(FEPlotFluidFlowRate , "fluid flow rate" );
REGISTER_FECORE_CLASS(FEPlotFluidPressure , "fluid pressure" );
REGISTER_FECORE_CLASS(FEPlotFluidPressureTangentTemperature, "fluid pressure tangent temperature");
REGISTER_FECORE_CLASS(FEPlotFluidPressureTangentStrain , "fluid pressure tangent strain" );
REGISTER_FECORE_CLASS(FEPlotFluidHeatFlux , "fluid heat flux" );
REGISTER_FECORE_CLASS(FEPlotFluidRelativeReynoldsNumber, "fluid relative Reynolds number");
REGISTER_FECORE_CLASS(FEPlotFluidSpecificFreeEnergy , "fluid specific free energy" );
REGISTER_FECORE_CLASS(FEPlotFluidSpecificEntropy , "fluid specific entropy" );
REGISTER_FECORE_CLASS(FEPlotFluidSpecificInternalEnergy, "fluid specific internal energy");
REGISTER_FECORE_CLASS(FEPlotFluidSpecificGaugeEnthalpy , "fluid specific gauge enthalpy" );
REGISTER_FECORE_CLASS(FEPlotFluidSpecificFreeEnthalpy , "fluid specific free enthalpy" );
REGISTER_FECORE_CLASS(FEPlotFluidSpecificStrainEnergy , "fluid specific strain energy" );
REGISTER_FECORE_CLASS(FEPlotFluidIsochoricSpecificHeatCapacity, "fluid isochoric specific heat capacity");
REGISTER_FECORE_CLASS(FEPlotFluidIsobaricSpecificHeatCapacity , "fluid isobaric specific heat capacity");
REGISTER_FECORE_CLASS(FEPlotFluidThermalConductivity , "fluid thermal conductivity" );
REGISTER_FECORE_CLASS(FEPlotBFSIPorosity , "porosity" );
REGISTER_FECORE_CLASS(FEPlotFSISolidStress , "solid stress" );
REGISTER_FECORE_CLASS(FEPlotFluidShearStressError , "fluid shear stress error");
//-----------------------------------------------------------------------------
REGISTER_FECORE_CLASS(FENodeFluidXVel , "nfvx");
REGISTER_FECORE_CLASS(FENodeFluidYVel , "nfvy");
REGISTER_FECORE_CLASS(FENodeFluidZVel , "nfvz");
REGISTER_FECORE_CLASS(FELogElemFluidPosX , "fx");
REGISTER_FECORE_CLASS(FELogElemFluidPosY , "fy");
REGISTER_FECORE_CLASS(FELogElemFluidPosZ , "fz");
REGISTER_FECORE_CLASS(FELogElasticFluidPressure, "fp");
REGISTER_FECORE_CLASS(FELogFluidVolumeRatio , "fJ");
REGISTER_FECORE_CLASS(FELogFluidDensity , "fd");
REGISTER_FECORE_CLASS(FELogFluidStressPower , "fsp");
REGISTER_FECORE_CLASS(FELogFluidVelocityX , "fvx");
REGISTER_FECORE_CLASS(FELogFluidVelocityY , "fvy");
REGISTER_FECORE_CLASS(FELogFluidVelocityZ , "fvz");
REGISTER_FECORE_CLASS(FELogFluidAccelerationX , "fax");
REGISTER_FECORE_CLASS(FELogFluidAccelerationY , "fay");
REGISTER_FECORE_CLASS(FELogFluidAccelerationZ , "faz");
REGISTER_FECORE_CLASS(FELogFluidVorticityX , "fwx");
REGISTER_FECORE_CLASS(FELogFluidVorticityY , "fwy");
REGISTER_FECORE_CLASS(FELogFluidVorticityZ , "fwz");
REGISTER_FECORE_CLASS(FELogFluidStressXX , "fsxx");
REGISTER_FECORE_CLASS(FELogFluidStressYY , "fsyy");
REGISTER_FECORE_CLASS(FELogFluidStressZZ , "fszz");
REGISTER_FECORE_CLASS(FELogFluidStressXY , "fsxy");
REGISTER_FECORE_CLASS(FELogFluidStressYZ , "fsyz");
REGISTER_FECORE_CLASS(FELogFluidStressXZ , "fsxz");
REGISTER_FECORE_CLASS(FELogFluidStress1 , "fs1" );
REGISTER_FECORE_CLASS(FELogFluidStress2 , "fs2" );
REGISTER_FECORE_CLASS(FELogFluidStress3 , "fs3" );
REGISTER_FECORE_CLASS(FELogFluidMaxShearStress , "fmxs");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefXX , "fdxx");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefYY , "fdyy");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefZZ , "fdzz");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefXY , "fdxy");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefYZ , "fdyz");
REGISTER_FECORE_CLASS(FELogFluidRateOfDefXZ , "fdxz");
//-----------------------------------------------------------------------------
// Derived from FEMeshAdaptor
REGISTER_FECORE_CLASS(FEFSIErosionVolumeRatio, "fsi-volume-erosion");
//-----------------------------------------------------------------------------
// Derived from FEMeshAdaptorCriterion
REGISTER_FECORE_CLASS(FEFluidStressCriterion , "fluid shear stress");
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FELinearElasticFluid.cpp | .cpp | 5,287 | 158 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FELinearElasticFluid.h"
#include <FECore/FEModel.h>
#include <FECore/log.h>
#include "FEFluidMaterialPoint.h"
//-----------------------------------------------------------------------------
FELinearElasticFluid::FELinearElasticFluid(FEModel* pfem) : FEElasticFluid(pfem)
{
m_k = 0;
m_rhor = 0;
}
//-----------------------------------------------------------------------------
//! initialization
bool FELinearElasticFluid::Init()
{
return true;
}
//-----------------------------------------------------------------------------
// serialization
void FELinearElasticFluid::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_k & m_rhor;
}
//-----------------------------------------------------------------------------
//! gauge pressure
double FELinearElasticFluid::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double p = -m_k*fp.m_ef;
return p;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J
double FELinearElasticFluid::Tangent_Strain(FEMaterialPoint& mp)
{
return -m_k;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to strain J
double FELinearElasticFluid::Tangent_Strain_Strain(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to temperature T
double FELinearElasticFluid::Tangent_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to temperature T
double FELinearElasticFluid::Tangent_Temperature_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J and temperature T
double FELinearElasticFluid::Tangent_Strain_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! specific free energy
double FELinearElasticFluid::SpecificFreeEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double a = m_k/(2*m_rhor)*pow(fp.m_ef,2);
return a;
}
//-----------------------------------------------------------------------------
//! specific entropy
double FELinearElasticFluid::SpecificEntropy(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! specific strain energy
double FELinearElasticFluid::SpecificStrainEnergy(FEMaterialPoint& mp)
{
return SpecificFreeEnergy(mp);
}
//-----------------------------------------------------------------------------
//! isobaric specific heat capacity
double FELinearElasticFluid::IsobaricSpecificHeatCapacity(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! isochoric specific heat capacity
double FELinearElasticFluid::IsochoricSpecificHeatCapacity(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to strain J
double FELinearElasticFluid::Tangent_cv_Strain(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to temperature T
double FELinearElasticFluid::Tangent_cv_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! dilatation from temperature and pressure
bool FELinearElasticFluid::Dilatation(const double T, const double p, double& e)
{
e = -p/m_k;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidStressCriterion.h | .h | 1,542 | 36 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMeshAdaptorCriterion.h>
class FEFluidStressCriterion : public FEMeshAdaptorCriterion
{
public:
FEFluidStressCriterion(FEModel* fem);
bool GetMaterialPointValue(FEMaterialPoint& mp, double& value) override;
DECLARE_FECORE_CLASS()
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEIdealGasIsothermal.cpp | .cpp | 4,867 | 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 "FEIdealGasIsothermal.h"
#include <FECore/log.h>
// define the material parameters
BEGIN_FECORE_CLASS(FEIdealGasIsothermal, FEFluid)
ADD_PARAMETER(m_M , FE_RANGE_GREATER(0.0), "M" )->setUnits(UNIT_MOLAR_MASS)->setLongName("molar mass");
END_FECORE_CLASS();
//============================================================================
// FEIdealGasIsothermal
//============================================================================
//-----------------------------------------------------------------------------
//! FEIdealGasIsothermal constructor
FEIdealGasIsothermal::FEIdealGasIsothermal(FEModel* pfem) : FEFluid(pfem)
{
m_rhor = 0;
m_k = 0;
m_M = 0;
}
//-----------------------------------------------------------------------------
//! initialization
bool FEIdealGasIsothermal::Init()
{
m_R = GetGlobalConstant("R");
m_Tr = GetGlobalConstant("T");
m_Pr = GetGlobalConstant("P");
if (m_R <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; }
if (m_Pr <= 0) { feLogError("A positive ambient absolute pressure P must be defined in Globals section"); return false; }
m_rhor = m_M*m_Pr/(m_R*m_Tr);
return true;
}
//-----------------------------------------------------------------------------
void FEIdealGasIsothermal::Serialize(DumpStream& ar)
{
FEFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_R & m_Pr & m_Tr & m_rhor;
}
//-----------------------------------------------------------------------------
//! elastic pressure
double FEIdealGasIsothermal::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
return Pressure(fp.m_ef,0);
}
//-----------------------------------------------------------------------------
//! elastic pressure from dilatation
double FEIdealGasIsothermal::Pressure(const double e, const double T)
{
double J = 1 + e;
return m_Pr*(1./J - 1);
}
//-----------------------------------------------------------------------------
//! tangent of elastic pressure with respect to strain J
double FEIdealGasIsothermal::Tangent_Pressure_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double dp = -m_Pr/J;
return dp;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of elastic pressure with respect to strain J
double FEIdealGasIsothermal::Tangent_Pressure_Strain_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double d2p = 2*m_Pr/(J*J);
return d2p;
}
//-----------------------------------------------------------------------------
//! evaluate temperature
double FEIdealGasIsothermal::Temperature(FEMaterialPoint& mp)
{
return m_Tr;
}
//-----------------------------------------------------------------------------
//! calculate free energy density (per reference volume)
double FEIdealGasIsothermal::StrainEnergyDensity(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1 + fp.m_ef;
double sed = m_Pr*(J-1-log(J));
return sed;
}
//-----------------------------------------------------------------------------
//! invert effective pressure-dilatation relation
bool FEIdealGasIsothermal::Dilatation(const double T, const double p, double& e)
{
double J = m_Pr/(p+m_Pr);
e = J - 1;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidMaterialPoint.cpp | .cpp | 2,427 | 61 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "FEThermoFluidMaterialPoint.h"
//============================================================================
FEThermoFluidMaterialPoint::FEThermoFluidMaterialPoint(FEMaterialPointData* pt) : FEMaterialPointData(pt) {}
//-----------------------------------------------------------------------------
FEMaterialPointData* FEThermoFluidMaterialPoint::Copy()
{
FEThermoFluidMaterialPoint* pt = new FEThermoFluidMaterialPoint(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
//-----------------------------------------------------------------------------
void FEThermoFluidMaterialPoint::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_T & m_Tdot & m_gradT & m_k & m_K & m_dKJ & m_dKT & m_cv & m_dcvJ & m_dcvT & m_cp & m_q;
}
//-----------------------------------------------------------------------------
void FEThermoFluidMaterialPoint::Init()
{
m_T = m_Tdot = 0;
m_gradT = vec3d(0);
m_k = 0;
m_K = m_dKJ = m_dKT = 0;
m_cv = m_dcvJ = m_dcvT = 0;
m_cp = 0;
m_q = vec3d(0);
// don't forget to initialize the base class
FEMaterialPointData::Init();
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFixedFluidAngularVelocity.h | .h | 1,550 | 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) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEFixedBC.h>
class FEFixedFluidAngularVelocity : public FEFixedBC
{
public:
FEFixedFluidAngularVelocity(FEModel* fem);
bool Init() override;
private:
bool m_dof[3];
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidSolutesPressure.h | .h | 1,919 | 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) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEInitialCondition.h>
class FEInitialFluidSolutesPressure : public FENodalIC
{
public:
FEInitialFluidSolutesPressure(FEModel* fem);
bool Init() override;
void Activate() override;
void SetPDOF(int ndof);
bool SetPDOF(const char* szdof);
void GetNodalValues(int inode, std::vector<double>& values) override;
void Serialize(DumpStream& ar) override;
protected:
int m_dofEF;
int m_dofC;
FEParamDouble m_Pdata;
vector<double> m_e;
double m_Rgas;
double m_Tabs;
double m_Fc;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPrescribedFluidVelocity.h | .h | 1,461 | 35 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedDOF.h>
class FEPrescribedFluidVelocity : public FEPrescribedDOF
{
public:
FEPrescribedFluidVelocity(FEModel* fem);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidMixtureTractionLoad.h | .h | 2,240 | 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 <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEFluidTractionLoad is a fluid surface that has a prescribed
//! viscous traction vector on it.
//!
class FEBIOFLUID_API FEFluidMixtureTractionLoad : public FESurfaceLoad
{
public:
//! constructor
FEFluidMixtureTractionLoad(FEModel* pfem);
//! initialization
bool Init() override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
private:
double m_scale; //!< magnitude of traction load
FEParamVec3 m_TC; //!< traction boundary cards
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesPressureBC.h | .h | 2,323 | 69 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedBC.h>
#include "FEFluidSolutes.h"
//-----------------------------------------------------------------------------
//! FEFluidResistanceBC is a fluid surface that has a normal
//! pressure proportional to the flow rate (resistance).
//!
class FEBIOFLUID_API FEFluidSolutesPressureBC : public FEPrescribedSurface
{
public:
//! constructor
FEFluidSolutesPressureBC(FEModel* pfem);
//! set the dilatation
void Update() override;
//! initialize
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
public:
// return the value for node i, dof j
void GetNodalValues(int nodelid, std::vector<double>& val) override;
// copy data from another class
void CopyFrom(FEBoundaryCondition* pbc) override;
private:
FEParamDouble m_p; //!< prescribed fluid pressure
vector<double> m_e;
private:
double m_Rgas;
double m_Tabs;
int m_dofEF;
int m_dofC;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidMovingFrameLoad.h | .h | 2,240 | 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 <FEBioMech/FEBodyForce.h>
#include <FECore/quatd.h>
#include <FECore/FEFunction1D.h>
//! This body load emulates the effect of a moving frame
class FEFluidMovingFrameLoad : public FEBodyForce
{
public:
FEFluidMovingFrameLoad(FEModel* fem);
void Activate() override;
void PrepStep() override;
vec3d force(FEMaterialPoint& pt) override;
mat3d stiffness(FEMaterialPoint& pt) override;
private:
vec3d m_at; // linear acceleration of moving frame in fixed frame
vec3d m_wi; // angular velocity input
int m_frame; // fixed (=0), or moving (=1) frame for input angular velocity
private:
vec3d m_ap, m_a, m_A;
vec3d m_wp, m_w, m_Wp, m_W;
vec3d m_alt, m_alp, m_al, m_Alt, m_Alp, m_Al;
quatd m_qt, m_qp, m_q;
// output parameters
vec3d m_wt; // angular velocity in fixed frame (output)
vec3d m_Wt; // angular velocity in moving frame (output)
vec3d m_rt; // rotational vector in fixed frame (output)
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FESolutesDomainFactory.h | .h | 1,606 | 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 <FECore/FECoreKernel.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
class FEBIOFLUID_API FESolutesDomainFactory : public FEDomainFactory
{
public:
virtual FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioMultiphasicFSI.h | .h | 1,958 | 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) 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 "febiofluid_api.h"
namespace FEBioMultiphasicFSI {
FEBIOFLUID_API void InitModule();
enum MULTIPHASIC_FSI_VARIABLE {
DISPLACEMENT,
VELOCITY,
ROTATION,
SHELL_DISPLACEMENT,
SHELL_VELOCITY,
SHELL_ACCELERATION,
RIGID_ROTATION,
RELATIVE_FLUID_VELOCITY,
RELATIVE_FLUID_ACCELERATION,
FLUID_VELOCITY,
FLUID_ACCELERATION,
FLUID_DILATATION,
FLUID_DILATATION_TDERIV,
FLUID_CONCENTRATION,
FLUID_CONCENTRATION_TDERIV
};
FEBIOFLUID_API const char* GetVariableName(MULTIPHASIC_FSI_VARIABLE var);
}
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETangentialFlowStabilization.h | .h | 2,428 | 69 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! Tangential flow stabilization prescribes a shear traction that opposes
//! tangential fluid velocity on a boundary surface, in the presence of normal
//! flow. This can help stabilize inflow/outflow conditions.
class FEBIOFLUID_API FETangentialFlowStabilization : public FESurfaceLoad
{
public:
//! constructor
FETangentialFlowStabilization(FEModel* pfem);
//! Initialization
bool Init() override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
//! calculate pressure stiffness
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! serialize data
void Serialize(DumpStream& ar) override;
protected:
vec3d FluidVelocity(FESurfaceMaterialPoint& mp, double alpha);
protected:
double m_beta; //!< damping coefficient
// degrees of freedom
FEDofList m_dofW;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPrescribedFluidPressure.cpp | .cpp | 5,583 | 168 | /*This file 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 "FEPrescribedFluidPressure.h"
#include "FEBioFluid.h"
#include <FECore/FESurface.h>
#include <FECore/FEModel.h>
#include "FEFluid.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEPrescribedFluidPressure, FEPrescribedSurface)
ADD_PARAMETER(m_p, "pressure")->setUnits(UNIT_PRESSURE)->setLongName("fluid pressure");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEPrescribedFluidPressure::FEPrescribedFluidPressure(FEModel* fem) : FEPrescribedSurface(fem)
{
m_p = 0.0;
m_psurf = nullptr;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEPrescribedFluidPressure::Init()
{
// get the dof index
m_dofEF = GetDOFIndex(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION), 0);
if (m_dofEF < 0) return false;
SetDOFList(m_dofEF);
if (FEPrescribedSurface::Init() == false) return false;
m_psurf = GetSurface();
m_e.assign(GetSurface()->Nodes(), 0.0);
// do an initial Update so that the dilatations are set properly at the very first time step
Update();
return true;
}
//-----------------------------------------------------------------------------
void FEPrescribedFluidPressure::UpdateDilatation()
{
int N = m_psurf->Nodes();
std::vector<vector<double>> efNodes(N, vector<double>());
//Project sum of all ca and osc values from int points to nodes on surface
//All values put into map, including duplicates
for (int i = 0; i < m_psurf->Elements(); ++i)
{
FESurfaceElement& el = m_psurf->Element(i);
// evaluate average prescribed pressure on this face
double p = 0;
for (int j = 0; j < el.GaussPoints(); ++j) {
FEMaterialPoint* pt = el.GetMaterialPoint(j);
p += m_p(*pt);
}
p /= el.GaussPoints();
FEElement* e = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(e->GetMatID());
FEFluid* pfl = pm->ExtractProperty<FEFluid>();
if (pfl == nullptr) break;
FESolidElement* se = dynamic_cast<FESolidElement*>(e);
if (se) {
double efi[FEElement::MAX_INTPOINTS] = { 0 };
double efo[FEElement::MAX_NODES] = { 0 };
for (int j = 0; j < se->GaussPoints(); ++j) {
FEMaterialPoint* pt = se->GetMaterialPoint(j);
bool good = pfl->Dilatation(0, p, efi[j]);
assert(good);
}
// project dilatations from integration points to nodes
se->project_to_nodes(efi, efo);
// only keep the dilatations at the nodes of the surface face
for (int j = 0; j < el.Nodes(); ++j)
efNodes[el.m_lnode[j]].push_back(efo[j]);
}
//If no solid element, insert all 0s
else {
for (int j = 0; j < el.Nodes(); ++j)
efNodes[el.m_lnode[j]].push_back(0);
}
}
//For each node, average the nodal ef
for (int i = 0; i < m_psurf->Nodes(); ++i)
{
double ef = 0;
for (int j = 0; j < efNodes[i].size(); ++j)
ef += efNodes[i][j];
ef /= efNodes[i].size();
// store value for now
m_e[i] = ef;
}
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEPrescribedFluidPressure::UpdateModel() { Update(); }
void FEPrescribedFluidPressure::Update()
{
UpdateDilatation();
FEPrescribedSurface::Update();
// TODO: Is this necessary?
GetFEModel()->SetMeshUpdateFlag(true);
}
//-----------------------------------------------------------------------------
void FEPrescribedFluidPressure::PrepStep(std::vector<double>& ui, bool brel)
{
UpdateDilatation();
FEPrescribedSurface::PrepStep(ui, brel);
}
//-----------------------------------------------------------------------------
void FEPrescribedFluidPressure::GetNodalValues(int nodelid, std::vector<double>& val)
{
val[0] = m_e[nodelid];
FENode& node = GetMesh().Node(m_nodeList[nodelid]);
node.set(m_dofEF, m_e[nodelid]);
}
void FEPrescribedFluidPressure::CopyFrom(FEBoundaryCondition* pbc)
{
// TODO: implement
assert(false);
}
//-----------------------------------------------------------------------------
//! serialization
void FEPrescribedFluidPressure::Serialize(DumpStream& ar)
{
FEPrescribedSurface::Serialize(ar);
ar & m_e;
if (ar.IsShallow()) return;
ar & m_dofEF;
ar & m_psurf;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FELinearElasticFluid.h | .h | 3,530 | 94 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElasticFluid.h"
#include <FECore/FEFunction1D.h>
//-----------------------------------------------------------------------------
//! Linear elastic fluid
//!
class FEBIOFLUID_API FELinearElasticFluid : public FEElasticFluid
{
public:
FELinearElasticFluid(FEModel* pfem);
~FELinearElasticFluid() {}
//! initialization
bool Init() override;
// serialization
void Serialize(DumpStream& ar) override;
//! gauge pressure
double Pressure(FEMaterialPoint& pt) override;
//! tangent of pressure with respect to strain J
double Tangent_Strain(FEMaterialPoint& mp) override;
//! 2nd tangent of pressure with respect to strain J
double Tangent_Strain_Strain(FEMaterialPoint& mp) override;
//! tangent of pressure with respect to temperature T
double Tangent_Temperature(FEMaterialPoint& mp) override;
//! 2nd tangent of pressure with respect to temperature T
double Tangent_Temperature_Temperature(FEMaterialPoint& mp) override;
//! tangent of pressure with respect to strain J and temperature T
double Tangent_Strain_Temperature(FEMaterialPoint& mp) override;
//! specific free energy
double SpecificFreeEnergy(FEMaterialPoint& mp) override;
//! specific entropy
double SpecificEntropy(FEMaterialPoint& mp) override;
//! specific strain energy
double SpecificStrainEnergy(FEMaterialPoint& mp) override;
//! isochoric specific heat capacity
double IsochoricSpecificHeatCapacity(FEMaterialPoint& mp) override;
//! tangent of isochoric specific heat capacity with respect to strain J
double Tangent_cv_Strain(FEMaterialPoint& mp) override;
//! tangent of isochoric specific heat capacity with respect to temperature T
double Tangent_cv_Temperature(FEMaterialPoint& mp) override;
//! isobaric specific heat capacity
double IsobaricSpecificHeatCapacity(FEMaterialPoint& mp) override;
//! dilatation from temperature and pressure
bool Dilatation(const double T, const double p, double& e) override;
public:
double m_k; //!< bulk modulus
double m_rhor; //!< true density
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSI.h | .h | 2,932 | 86 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FEBioMech/FEElasticMaterial.h>
#include "FEFluid.h"
//-----------------------------------------------------------------------------
//! FSI material point class.
//
class FEBIOFLUID_API FEFSIMaterialPoint : public FEMaterialPointData
{
public:
//! constructor
FEFSIMaterialPoint(FEMaterialPointData* pt);
//! create a shallow copy
FEMaterialPointData* Copy();
//! data serialization
void Serialize(DumpStream& ar);
//! Data initialization
void Init();
public:
// FSI material data
vec3d m_w; //!< fluid flux relative to solid
vec3d m_aw; //!< material time derivative of m_wt
double m_Jdot; //!< time derivative of solid volume ratio
mat3ds m_ss; //!< solid stress
};
//-----------------------------------------------------------------------------
//! Base class for FluidFSI materials.
class FEBIOFLUID_API FEFluidFSI : public FEMaterial
{
public:
FEFluidFSI(FEModel* pfem);
// returns a pointer to a new material point object
FEMaterialPointData* CreateMaterialPointData() override;
// Get the elastic component (overridden from FEMaterial)
FEElasticMaterial* GetElasticMaterial() { return m_pSolid; }
//! performs initialization
bool Init() override;
public:
FEFluid* Fluid() { return m_pFluid; }
FEElasticMaterial* Solid() { return m_pSolid; }
protected: // material properties
FEElasticMaterial* m_pSolid; //!< pointer to elastic solid material
FEFluid* m_pFluid; //!< pointer to fluid material
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSITraction.cpp | .cpp | 10,383 | 330 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidFSITraction.h"
#include "FECore/FEModel.h"
#include "FEFluid.h"
#include "FEFluidFSI.h"
#include "FEBioFSI.h"
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FEFluidFSITraction, FESurfaceLoad)
ADD_PARAMETER(m_bshellb , "shell_bottom");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FEFluidFSITraction::FEFluidFSITraction(FEModel* pfem) : FESurfaceLoad(pfem), m_dofU(pfem), m_dofSU(pfem), m_dofW(pfem)
{
m_bshellb = false;
// get the degrees of freedom
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::DISPLACEMENT));
m_dofSU.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::SHELL_DISPLACEMENT));
m_dofW.AddVariable(FEBioFSI::GetVariableName(FEBioFSI::RELATIVE_FLUID_VELOCITY));
m_dofEF = GetDOFIndex(FEBioFSI::GetVariableName(FEBioFSI::FLUID_DILATATION), 0);
m_dof.Clear();
m_dof.AddDofs(m_dofU);
m_dof.AddDofs(m_dofSU);
m_dof.AddDofs(m_dofW);
m_dof.AddDof(m_dofEF);
}
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidFSITraction::Init()
{
FESurface& surf = GetSurface();
surf.SetShellBottom(m_bshellb);
surf.SetInterfaceStatus(true);
if (FESurfaceLoad::Init() == false) return false;
// get the list of fluid-FSI elements connected to this interface
FEModel* fem = GetFEModel();
int NF = surf.Elements();
m_elem.resize(NF);
m_s.resize(NF, 1);
for (int j = 0; j<NF; ++j)
{
bool bself = false;
FESurfaceElement& el = surf.Element(j);
// extract the first of two elements on this interface
m_elem[j] = el.m_elem[0].pe;
if (el.m_elem[1].pe == nullptr) bself = true;
// get its material and check if FluidFSI
FEMaterial* pm = fem->GetMaterial(m_elem[j]->GetMatID());
FEFluidFSI* pfsi = dynamic_cast<FEFluidFSI*>(pm);
if (pfsi) {
double s = m_psurf->FacePointing(el, *m_elem[j]);
m_s[j] = bself ? -s : s;
if (m_s[j] == 0) return false;
}
else if (!bself) {
// extract the second of two elements on this interface
m_elem[j] = el.m_elem[1].pe;
pm = fem->GetMaterial(m_elem[j]->GetMatID());
pfsi = dynamic_cast<FEFluidFSI*>(pm);
if (pfsi == nullptr) return false;
m_s[j] = m_psurf->FacePointing(el, *m_elem[j]);
if (m_s[j] == 0) return false;
}
else
return false;
}
// TODO: Deal with the case when the surface is a shell domain separating two FSI domains
// that use different fluid bulk moduli
// (for now, users have to define two FEFluidFSITraction loads, one on front shell
// face and the other on back shell face)
return true;
}
//-----------------------------------------------------------------------------
double FEFluidFSITraction::GetFluidDilatation(FESurfaceMaterialPoint& mp, double alpha)
{
double ef = 0;
FESurfaceElement& el = *mp.SurfaceElement();
double* H = el.H(mp.m_index);
int neln = el.Nodes();
for (int j = 0; j < neln; ++j) {
FENode& node = m_psurf->Node(el.m_lnode[j]);
double ej = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1.0 - alpha);
ef += ej*H[j];
}
return ef;
}
//-----------------------------------------------------------------------------
mat3ds FEFluidFSITraction::GetFluidStress(FESurfaceMaterialPoint& pt)
{
FEModel* fem = GetFEModel();
FESurfaceElement& face = *pt.SurfaceElement();
int iel = face.m_lid;
// Get the fluid stress from the fluid-FSI element
mat3ds sv(mat3dd(0));
FEElement* pe = m_elem[iel];
int nint = pe->GaussPoints();
FEFluidFSI* pfsi = dynamic_cast<FEFluidFSI*>(fem->GetMaterial(pe->GetMatID()));
for (int n = 0; n<nint; ++n)
{
FEMaterialPoint& mp = *pe->GetMaterialPoint(n);
sv += pfsi->Fluid()->GetViscous()->Stress(mp);
}
sv /= nint;
return sv;
}
//-----------------------------------------------------------------------------
void FEFluidFSITraction::LoadVector(FEGlobalVector& R)
{
const FETimeInfo& tp = GetTimeInfo();
// If surface is bottom of shell, we should take shell displacement dofs (i.e. m_dofSU).
FEDofList dof = m_bshellb ? m_dofSU : m_dofU;
m_psurf->LoadVector(R, dof, false, [&](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
// get the surface element
FESurfaceElement& el = *mp.SurfaceElement();
int iel = el.m_lid;
FEFluidFSI* pfsi = dynamic_cast<FEFluidFSI*>(GetFEModel()->GetMaterial(m_elem[iel]->GetMatID()));
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
m_psurf->GetNodalCoordinates(el, tp.alphaf, rt);
// evaluate covariant basis vectors at integration point
vec3d gr = el.eval_deriv1(rt, mp.m_index)*m_s[iel];
vec3d gs = el.eval_deriv2(rt, mp.m_index);
vec3d gt = gr ^ gs;
// Get the fluid viscous stress at integration point
// necessarily using the attached solid element
mat3ds sv = GetFluidStress(mp);
// fluid dilatation at integration point
// only from surface element
double ef = GetFluidDilatation(mp, tp.alphaf);
double p = pfsi->Fluid()->Pressure(ef);
// evaluate traction
vec3d f = gt*p - sv*gt;
double H = dof_a.shape;
fa[0] = H * f.x;
fa[1] = H * f.y;
fa[2] = H * f.z;
});
}
//-----------------------------------------------------------------------------
void FEFluidFSITraction::StiffnessMatrix(FELinearSystem& LS)
{
FEModel* fem = GetFEModel();
FESurface* ps = &GetSurface();
const FETimeInfo& tp = GetTimeInfo();
// build dof list
// TODO: If surface is bottom of shell, we should take shell displacement dofs (i.e. m_dofSU).
FEDofList dofs(fem);
if (!m_bshellb) dofs.AddDofs(m_dofU); else dofs.AddDofs(m_dofSU);
dofs.AddDofs(m_dofW);
dofs.AddDof(m_dofEF);
// evaluate stiffness
m_psurf->LoadStiffness(LS, dofs, dofs, [&](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) {
FESurfaceElement& el = *mp.SurfaceElement();
int iel = el.m_lid;
int neln = el.Nodes();
double dt = tp.timeIncrement;
double alpha = tp.alphaf;
double a = tp.gamma / (tp.beta*dt);
vector<vec3d> gradN(neln);
// nodal coordinates
vec3d rt[FEElement::MAX_NODES];
ps->GetNodalCoordinates(el, tp.alphaf, rt);
// Get the fluid stress and its tangents from the fluid-FSI element
mat3ds sv(mat3dd(0)), svJ(mat3dd(0));
tens4ds cv; cv.zero();
mat3d Ls; Ls.zero();
FEElement* pe = m_elem[iel];
int pint = pe->GaussPoints();
FEFluidFSI* pfsi = dynamic_cast<FEFluidFSI*>(fem->GetMaterial(pe->GetMatID()));
for (int n = 0; n<pint; ++n)
{
FEMaterialPoint& mp = *pe->GetMaterialPoint(n);
FEElasticMaterialPoint& ep = *(mp.ExtractData<FEElasticMaterialPoint>());
sv += pfsi->Fluid()->GetViscous()->Stress(mp);
svJ += pfsi->Fluid()->GetViscous()->Tangent_Strain(mp);
cv += pfsi->Fluid()->Tangent_RateOfDeformation(mp);
Ls += ep.m_L;
}
sv /= pint;
svJ /= pint;
cv /= pint;
Ls /= pint;
mat3d M = mat3dd(a) - Ls;
double* N = el.H (mp.m_index);
double* Gr = el.Gr(mp.m_index);
double* Gs = el.Gs(mp.m_index);
// evaluate fluid dilatation
double ef = GetFluidDilatation(mp, tp.alphaf);
// covariant basis vectors
vec3d gr = el.eval_deriv1(rt, mp.m_index)*m_s[iel];
vec3d gs = el.eval_deriv2(rt, mp.m_index);
vec3d gt = gr ^ gs;
// evaluate fluid pressure
double p = pfsi->Fluid()->Pressure(ef);
vec3d f = gt*pfsi->Fluid()->GetElastic()->Tangent_Strain(ef,0);
vec3d gcnt[2], gcntp[2];
ps->ContraBaseVectors(el, mp.m_index, gcnt);
ps->ContraBaseVectorsP(el, mp.m_index, gcntp);
for (int i = 0; i<neln; ++i)
gradN[i] = (gcnt[0] * alpha + gcntp[0] * (1 - alpha))*(Gr[i]*m_s[iel]) +
(gcnt[1] * alpha + gcntp[1] * (1 - alpha))*Gs[i];
// calculate stiffness component
int i = dof_a.index;
int j = dof_b.index;
vec3d v = gr*Gs[j] - gs*Gr[j];
mat3d A; A.skew(v);
mat3d Kv = vdotTdotv(gt, cv, gradN[j]);
mat3d Kuu = (sv*A + Kv*M)*N[i] - A*(N[i] * p); Kuu *= -alpha;
mat3d Kuw = Kv*N[i]; Kuw *= -alpha;
vec3d kuJ = svJ*gt*(N[i] * N[j]) - f*(N[i] * N[j]); kuJ *= -alpha;
Kab.zero();
Kab.sub(0, 0, Kuu);
Kab.sub(0, 3, Kuw);
Kab[0][6] -= kuJ.x;
Kab[1][6] -= kuJ.y;
Kab[2][6] -= kuJ.z;
});
}
//-----------------------------------------------------------------------------
void FEFluidFSITraction::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_s;
if (ar.IsSaving())
{
int NE = (int)m_elem.size();
ar << NE;
for (int i = 0; i < NE; ++i)
{
FEElement* pe = m_elem[i];
int nid = (pe ? pe->GetID() : -1);
ar << nid;
}
}
else
{
FEMesh& mesh = ar.GetFEModel().GetMesh();
int NE, nid;
ar >> NE;
m_elem.resize(NE, nullptr);
for (int i = 0; i < NE; ++i)
{
ar >> nid;
if (nid != -1)
{
FEElement* pe = mesh.FindElementFromID(nid);
assert(pe);
m_elem[i] = pe;
}
}
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolver.h | .h | 5,058 | 154 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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/FENewtonSolver.h>
#include <FECore/FETimeInfo.h>
#include <FECore/FEGlobalVector.h>
#include <FECore/FEDofList.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
class FELinearSystem;
//-----------------------------------------------------------------------------
//! The FEFluidSolver class solves fluid mechanics problems
//! It can deal with quasi-static and dynamic problems
//!
class FEBIOFLUID_API FEFluidSolver : public FENewtonSolver
{
public:
//! constructor
FEFluidSolver(FEModel* pfem);
//! destructor
~FEFluidSolver();
//! Initializes data structures
bool Init() override;
//! initialize the step
bool InitStep(double time) override;
//! Initialize linear equation system
bool InitEquations() override;
bool InitEquations2() override;
//! preferred matrix type should be unsymmetric.
Matrix_Type PreferredMatrixType() const override { return REAL_UNSYMMETRIC; };
public:
//{ --- evaluation and update ---
//! Perform an update
void Update(vector<double>& ui) override;
//! update nodal positions, velocities, accelerations, etc.
void UpdateKinematics(vector<double>& ui);
//! used by JFNK
void Update2(const vector<double>& ui) override;
void UpdateConstraints();
//! update DOF increments
void UpdateIncrements(vector<double>& Ui, vector<double>& ui, bool emap);
//}
//{ --- Solution functions ---
//! prepares the data for the first QN iteration
void PrepStep() override;
//! Performs a Newton-Raphson iteration
bool Quasin() override;
//{ --- Stiffness matrix routines ---
//! calculates the global stiffness matrix
bool StiffnessMatrix(FELinearSystem& LS) override;
//! contact stiffness
void ContactStiffness(FELinearSystem& LS);
//! calculates stiffness contributon of nonlinear constraints
void NonLinearConstraintStiffness(FELinearSystem& LS, const FETimeInfo& tp);
//{ --- Residual routines ---
//! Calculate the contact forces
void ContactForces(FEGlobalVector& R);
//! Calculates residual
bool Residual(vector<double>& R) override;
//! Calculate nonlinear constraint forces
void NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp);
//! Serialization
void Serialize(DumpStream& ar) override;
protected:
void GetVelocityData(vector<double>& vi, vector<double>& ui);
void GetDilatationData(vector<double>& ei, vector<double>& ui);
public:
// convergence tolerances
double m_Vtol; //!< velocity tolerance
double m_Ftol; //!< dilatation tolerance
double m_minJf; //!< minimum allowable compression ratio
public:
// equation numbers
int m_nveq; //!< number of equations related to velocity dofs
int m_ndeq; //!< number of equations related to dilatation dofs
public:
vector<double> m_Fr; //!< nodal reaction forces
vector<double> m_vi; //!< velocity increment vector
vector<double> m_Vi; //!< Total velocity vector for iteration
vector<double> m_di; //!< dilatation increment vector
vector<double> m_Di; //!< Total dilatation vector for iteration
// generalized alpha method
double m_rhoi; //!< rho infinity
double m_alphaf; //!< alpha step for Y={v,e}
double m_alpham; //!< alpha step for Ydot={∂v/∂t,∂e/∂t}
double m_gammaf; //!< gamma
int m_pred; //!< predictor method
protected:
FEDofList m_dofW;
FEDofList m_dofAW;
FEDofList m_dofEF;
int m_dofAEF;
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidDomainFactory.cpp | .cpp | 2,067 | 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) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEPolarFluidDomainFactory.h"
#include "FEPolarFluid.h"
#include <FECore/FESolidDomain.h>
//-----------------------------------------------------------------------------
FEDomain* FEPolarFluidDomainFactory::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat)
{
FEModel* pfem = pmat->GetFEModel();
FE_Element_Class eclass = spec.eclass;
const char* sztype = 0;
if (dynamic_cast<FEPolarFluid*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) sztype = "polar-fluid-3D";
else return 0;
}
if (sztype)
{
FEDomain* pd = fecore_new<FESolidDomain>(sztype, pfem);
if (pd) pd->SetMaterial(pmat);
return pd;
}
else return 0;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesDomain3D.cpp | .cpp | 44,147 | 1,262 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidSolutesDomain3D.h"
#include "FEFluidSolver.h"
#include "FECore/log.h"
#include "FECore/DOFS.h"
#include <FECore/FEModel.h>
#include <FECore/FEAnalysis.h>
#include <FECore/sys.h>
#include "FEBioFluidSolutes.h"
#include <FECore/FELinearSystem.h>
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
//-----------------------------------------------------------------------------
//! constructor
//! Some derived classes will pass 0 to the pmat, since the pmat variable will be
//! to initialize another material. These derived classes will set the m_pMat variable as well.
FEFluidSolutesDomain3D::FEFluidSolutesDomain3D(FEModel* pfem) : FESolidDomain(pfem), FEFluidDomain(pfem), m_dofW(pfem), m_dofAW(pfem), m_dof(pfem)
{
m_pMat = 0;
m_btrans = true;
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_ACCELERATION));
m_dofEF = pfem->GetDOFIndex("ef");
m_dofAEF = pfem->GetDOFIndex("aef");
m_dofC = pfem->GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
m_dofAC = pfem->GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION_TDERIV), 0);
// list the degrees of freedom
// (This allows the FEDomain base class to handle several tasks such as UnpackLM)
m_dof.AddDof(m_dofW[0]);
m_dof.AddDof(m_dofW[1]);
m_dof.AddDof(m_dofW[2]);
m_dof.AddDof(m_dofEF);
}
}
//-----------------------------------------------------------------------------
// \todo I don't think this is being used
FEFluidSolutesDomain3D& FEFluidSolutesDomain3D::operator = (FEFluidSolutesDomain3D& d)
{
m_Elem = d.m_Elem;
m_pMesh = d.m_pMesh;
return (*this);
}
//-----------------------------------------------------------------------------
//! get the total dofs
const FEDofList& FEFluidSolutesDomain3D::GetDOFList() const
{
return m_dof;
}
//-----------------------------------------------------------------------------
//! Assign material
void FEFluidSolutesDomain3D::SetMaterial(FEMaterial* pmat)
{
FEDomain::SetMaterial(pmat);
if (pmat)
{
m_pMat = dynamic_cast<FEFluidSolutes*>(pmat);
assert(m_pMat);
}
else m_pMat = 0;
}
//-----------------------------------------------------------------------------
bool FEFluidSolutesDomain3D::Init()
{
// initialize base class
if (FESolidDomain::Init() == false) return false;
const int nsol = m_pMat->Solutes();
// set the active degrees of freedom list
FEDofList dofs = GetDOFList();
for (int i=0; i<nsol; ++i)
{
int m = m_pMat->GetSolute(i)->GetSoluteDOF();
dofs.AddDof(m_dofC + m);
}
m_dof = dofs;
return true;
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::Serialize(DumpStream& ar)
{
FESolidDomain::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_dofW & m_dofAW & m_dof;
ar & m_dofEF & m_dofAEF & m_dofC & m_dofAC;
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::Reset()
{
// reset base class
FESolidDomain::Reset();
const int nsol = m_pMat->Solutes();
for (int i=0; i<(int) m_Elem.size(); ++i)
{
// get the solid element
FESolidElement& el = m_Elem[i];
// get the number of integration points
int nint = el.GaussPoints();
// loop over the integration points
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidSolutesMaterialPoint& ps = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
// initialize solutes
ps.m_nsol = nsol;
ps.m_c.assign(nsol,0);
ps.m_ca.assign(nsol,0);
ps.m_cdot.assign(nsol,0);
ps.m_gradc.assign(nsol,vec3d(0,0,0));
ps.m_j.assign(nsol,vec3d(0,0,0));
ps.m_k.assign(nsol, 0);
ps.m_dkdJ.assign(nsol, 0);
ps.m_dkdc.resize(nsol, vector<double>(nsol,0));
for (int j=0; j<m_pMat->Reactions(); ++j)
m_pMat->GetReaction(j)->ResetElementData(mp);
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::Activate()
{
const int nsol = m_pMat->Solutes();
for (int i=0; i<Nodes(); ++i)
{
FENode& node = Node(i);
if (node.HasFlags(FENode::EXCLUDE) == false)
{
/* if (node.m_rid < 0)
{
node.set_active(m_dofU[0]);
node.set_active(m_dofU[1]);
node.set_active(m_dofU[2]);
}
*/ node.set_active(m_dofW[0]);
node.set_active(m_dofW[1]);
node.set_active(m_dofW[2]);
node.set_active(m_dofEF);
for (int isol=0; isol<nsol; ++isol)
node.set_active(m_dofC + m_pMat->GetSolute(isol)->GetSoluteDOF());
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::InitMaterialPoints()
{
const int nsol = m_pMat->Solutes();
FEMesh& m = *GetMesh();
const int NE = FEElement::MAX_NODES;
vector< vector<double> > c0(nsol, vector<double>(NE));
vector<int> sid(nsol);
for (int j = 0; j<nsol; ++j) sid[j] = m_pMat->GetSolute(j)->GetSoluteDOF();
for (int j = 0; j<(int)m_Elem.size(); ++j)
{
// get the solid element
FESolidElement& el = m_Elem[j];
// get the number of nodes
int neln = el.Nodes();
// get initial values of fluid pressure and solute concentrations
for (int i = 0; i<neln; ++i)
{
FENode& ni = m.Node(el.m_node[i]);
for (int isol = 0; isol<nsol; ++isol)
c0[isol][i] = ni.get(m_dofC + sid[isol]);
}
// get the number of integration points
int nint = el.GaussPoints();
// loop over the integration points
for (int n = 0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidSolutesMaterialPoint& ps = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
// initialize solutes
ps.m_nsol = nsol;
// initialize effective solute concentrations
for (int isol = 0; isol<nsol; ++isol) {
ps.m_c[isol] = el.Evaluate(c0[isol], n);
ps.m_ca[isol] = m_pMat->ConcentrationActual(mp, isol);
ps.m_gradc[isol] = gradient(el, c0[isol], n);
}
ps.m_psi = m_pMat->ElectricPotential(mp);
ps.m_Ie = m_pMat->CurrentDensity(mp);
for (int isol = 0; isol<nsol; ++isol)
ps.m_j[isol] = m_pMat->SoluteDiffusiveFlux(mp, isol);
}
}
}
//-----------------------------------------------------------------------------
//! Initialize element data
void FEFluidSolutesDomain3D::PreSolveUpdate(const FETimeInfo& timeInfo)
{
const int NE = FEElement::MAX_NODES;
vec3d x0[NE], r0, v;
FEMesh& m = *GetMesh();
for (size_t i=0; i<m_Elem.size(); ++i)
{
FESolidElement& el = m_Elem[i];
int neln = el.Nodes();
for (int i=0; i<neln; ++i)
{
x0[i] = m.Node(el.m_node[i]).m_r0;
}
int n = el.GaussPoints();
for (int j=0; j<n; ++j)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(j);
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
pt.m_r0 = el.Evaluate(x0, j);
mp.m_rt = mp.m_r0;
if (pt.m_ef <= -1) {
throw NegativeJacobianDetected();
}
// reset chemical reaction element data
for (int j=0; j<m_pMat->Reactions(); ++j)
m_pMat->GetReaction(j)->InitializeElementData(mp);
mp.Update(timeInfo);
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::InternalForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
#pragma omp parallel for shared (NE)
for (int i=0; i<NE; ++i)
{
// element force vector
vector<double> fe;
vector<int> lm;
// get the element
FESolidElement& el = m_Elem[i];
// get the element force vector and initialize it to zero
int ndof = ndpn*el.Nodes();
fe.assign(ndof, 0);
// calculate internal force vector
ElementInternalForce(el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
//-----------------------------------------------------------------------------
//! calculates the internal equivalent nodal forces for solid elements
void FEFluidSolutesDomain3D::ElementInternalForce(FESolidElement& el, vector<double>& fe)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, n;
// jacobian matrix, inverse jacobian matrix and determinants
double Ji[3][3], detJ;
mat3ds sv;
vec3d gradep;
const double *H, *Gr, *Gs, *Gt;
int nint = el.GaussPoints();
int neln = el.Nodes();
const int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
const int nreact = m_pMat->Reactions();
double dt = tp.timeIncrement;
// gradient of shape functions
vector<vec3d> gradN(neln);
double* gw = el.GaussWeights();
// repeat for all integration points
for (n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFluidSolutesMaterialPoint& spt = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
// calculate the jacobian
detJ = invjac0(el, Ji, n)*gw[n];
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
// get the viscous stress tensor for this integration point
sv = m_pMat->Fluid()->GetViscous()->Stress(mp);
// get the gradient of the elastic pressure
gradep = pt.m_gradef*m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
// Miscellaneous constants
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
double penalty = m_pMat->m_penalty;
// evaluate the chat
vector<double> chat(nsol,0);
double phiwhat = 0;
// chemical reactions
for (i=0; i<nreact; ++i) {
FEChemicalReaction* pri = m_pMat->GetReaction(i);
double zhat = pri->ReactionSupply(mp);
phiwhat += pri->m_Vbar*zhat;
for (int isol=0; isol<nsol; ++isol)
chat[isol] += zhat*pri->m_v[isol];
}
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
{
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
}
// Jdot/J
double dJoJ = pt.m_efdot/(pt.m_ef+1);
double dms = m_pMat->m_diffMtmSupp;
vector<int> z(nsol);
vector<vec3d> jd(nsol);
vec3d je(0,0,0);
double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp);
for (int isol=0; isol<nsol; ++isol) {
// get the charge number
z[isol] = m_pMat->GetSolute(isol)->ChargeNumber();
jd[isol] = m_pMat->SoluteDiffusiveFlux(mp,isol);
je += jd[isol]*z[isol];
}
vector<double> dkdt(nsol,0);
vector<vec3d> gradk(nsol,vec3d(0,0,0));
for (int isol=0; isol<nsol; ++isol)
{
dkdt[isol] = pt.m_efdot*spt.m_dkdJ[isol];
for (int jsol=0; jsol<nsol; ++jsol)
dkdt[isol] += spt.m_dkdc[isol][jsol]*spt.m_cdot[jsol];
}
for (i=0; i<neln; ++i)
{
vec3d fs = sv*gradN[i] + gradep*H[i];
for (int isol=0; isol<nsol; ++isol)
fs += spt.m_gradc[isol]*(R*T*spt.m_k[isol]*H[i]*dms); //fluid mtm bal only
double fJ = (dJoJ+phiwhat)*H[i] + gradN[i]*pt.m_vft;
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[ndpn*i ] -= fs.x*detJ;
fe[ndpn*i+1] -= fs.y*detJ;
fe[ndpn*i+2] -= fs.z*detJ;
fe[ndpn*i+3] -= fJ*detJ;
for (int isol=0; isol<nsol; ++isol)
{
double fc = (jd[isol]+je*penalty)*gradN[i] - H[i]*(spt.m_ca[isol]*dJoJ + spt.m_k[isol]*spt.m_cdot[isol] + spt.m_c[isol]*dkdt[isol] - chat[isol]);
fe[ndpn*i+4+isol] -= fc*detJ;
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::BodyForce(FEGlobalVector& R, FEBodyForce& BF)
{
int NE = (int)m_Elem.size();
int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
for (int i=0; i<NE; ++i)
{
vector<double> fe;
vector<int> lm;
// get the element
FESolidElement& el = m_Elem[i];
// get the element force vector and initialize it to zero
int ndof = ndpn*el.Nodes();
fe.assign(ndof, 0);
// apply body forces
ElementBodyForce(BF, el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
//-----------------------------------------------------------------------------
//! calculates the body forces
void FEFluidSolutesDomain3D::ElementBodyForce(FEBodyForce& BF, FESolidElement& el, vector<double>& fe)
{
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
// jacobian
double Ji[3][3], detJ;
const double *H, *Gr, *Gs, *Gt;
double* gw = el.GaussWeights();
vec3d f;
// number of nodes
int neln = el.Nodes();
int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
// gradient of shape functions
vector<vec3d> gradN(neln);
// nodal coordinates
vec3d r0[FEElement::MAX_NODES];
for (int i=0; i<neln; ++i)
r0[i] = m_pMesh->Node(el.m_node[i]).m_r0;
// loop over integration points
int nint = el.GaussPoints();
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
FEFluidSolutesMaterialPoint& spt = *mp.ExtractData<FEFluidSolutesMaterialPoint>();
double dens = m_pMat->Fluid()->Density(mp);
pt.m_r0 = el.Evaluate(r0, n);
detJ = invjac0(el, Ji, n)*gw[n];
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
// get the force
f = BF.force(mp);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
double dms = m_pMat->m_diffMtmSupp;
double penalty = m_pMat->m_penalty;
vector<vec3d> jb(nsol,vec3d(0,0,0));
vec3d je(0,0,0);
// evaluate sedimentation fluxes and effective flux contribution
for (int isol=0; isol<nsol; ++isol) {
double M = m_pMat->GetSolute(isol)->MolarMass();
// get the sedimentation coefficient
double s = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp)*M/(R*T);
// get the sedimentation flux
jb[isol] = f*(s*spt.m_ca[isol]);
// get the charge number
double z = m_pMat->GetSolute(isol)->ChargeNumber();
je += jb[isol]*z;
dens += M*spt.m_ca[isol]*dms;
}
// evaluate spatial gradient of shape functions
for (int i=0; i<neln; ++i)
{
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
}
for (int i=0; i<neln; ++i)
{
vec3d fs = f*H[i]*dens;
fe[ndpn*i ] -= fs.x*detJ;
fe[ndpn*i+1] -= fs.y*detJ;
fe[ndpn*i+2] -= fs.z*detJ;
for (int isol=0; isol<nsol; ++isol)
{
double fc = -gradN[i]*(jb[isol] + je*penalty);
fe[ndpn*i+4+isol] -= fc*detJ;
}
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the stiffness due to body forces
void FEFluidSolutesDomain3D::ElementBodyForceStiffness(FEBodyForce& BF, FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
// jacobian
double Ji[3][3], detJ;
const double *H, *Gr, *Gs, *Gt;
double* gw = el.GaussWeights();
// number of nodes
int neln = el.Nodes();
int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
vec3d f;
// gradient of shape functions
vector<vec3d> gradN(neln);
// loop over integration points
int nint = el.GaussPoints();
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
FEFluidSolutesMaterialPoint& spt = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
// calculate the jacobian
detJ = invjac0(el, Ji, n)*gw[n]*tp.alphaf;
H = el.H(n);
double dens = m_pMat->Fluid()->Density(mp);
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
double dms = m_pMat->m_diffMtmSupp;
double penalty = m_pMat->m_penalty;
vector<double> M(nsol);
vector<int> z(nsol);
vector<double> d0(nsol);
vector<double> s(nsol);
vector<vector<double>> d0p(nsol, vector<double>(nsol));
vector<vector<double>> wkcc(nsol, vector<double>(nsol));
vector<double> wkce(nsol,0);
vector<vec3d> wkvc(nsol);
vector<double> wkcJ(nsol,0);
// get the force
f = BF.force(mp);
vec3d wkvJ = f*(-dens/(1+pt.m_ef));
double wkcJe = 0;
for (int isol=0; isol<nsol; ++isol) {
// get the charge number
z[isol] = m_pMat->GetSolute(isol)->ChargeNumber();
M[isol] = m_pMat->GetSolute(isol)->MolarMass();
d0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp);
s[isol] = d0[isol]*M[isol]/(R*T);
wkvJ += f*(M[isol]*spt.m_dkdJ[isol]*spt.m_c[isol]*dms);
wkvc[isol] = f*(M[isol]*spt.m_k[isol]*dms);
wkcJ[isol] = s[isol]*spt.m_dkdJ[isol]*spt.m_c[isol];
wkcJe += z[isol]*wkcJ[isol];
for (int jsol=0; jsol<nsol; ++jsol)
{
d0p[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp, jsol);
wkcc[isol][jsol] = s[isol]*spt.m_dkdc[isol][jsol]*spt.m_c[isol];
wkce[jsol] += z[isol]*wkcc[isol][jsol];
wkvc[isol] += f*(M[jsol]*spt.m_dkdc[jsol][isol]*spt.m_c[jsol]*dms);
}
}
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// evaluate spatial gradient of shape functions
for (int i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
for (int i=0, i4=0; i<neln; ++i, i4 += ndpn) {
for (int j=0, j4 = 0; j<neln; ++j, j4 += ndpn)
{
vec3d kvJ = wkvJ*(H[i]*H[j]*detJ);
ke[i4 ][j4+3] += kvJ.x;
ke[i4+1][j4+3] += kvJ.y;
ke[i4+2][j4+3] += kvJ.z;
for (int isol = 0; isol<nsol; ++isol)
{
vec3d kvc = wkvc[isol]*(H[i]*H[j]*detJ);
ke[i4 ][j4+4+isol] += kvc.x;
ke[i4+1][j4+4+isol] += kvc.y;
ke[i4+2][j4+4+isol] += kvc.z;
double kcJ = -(gradN[i]*f)*H[j]*(wkcJ[isol] + wkcJe)*detJ;
ke[i4+4+isol][j4+3] += kcJ;
for(int jsol=0; jsol<nsol; ++jsol)
{
double kd = (isol == jsol) ? 1 : 0;
double kcc = -(gradN[i]*f)*H[j]*((kd + z[jsol])*s[jsol]*spt.m_k[jsol] + wkcc[isol][jsol] + wkce[jsol])*detJ;
ke[i4+4+isol][j4+4+jsol] += kcc;
}
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Calculates element material stiffness element matrix
void FEFluidSolutesDomain3D::ElementStiffness(FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i4, j, j4, n;
// Get the current element's data
const int nint = el.GaussPoints();
const int neln = el.Nodes();
const int nsol = m_pMat->Solutes();
const int ndpn = 4 + nsol;
const int nreact = m_pMat->Reactions();
// gradient of shape functions
vector<vec3d> gradN(neln);
double dt = tp.timeIncrement;
double ksi = tp.alpham/(tp.gamma*tp.alphaf);
double *H, *Gr, *Gs, *Gt;
// jacobian
double Ji[3][3], detJ;
// weights at gauss points
const double *gw = el.GaussWeights();
// calculate element stiffness matrix
for (n=0; n<nint; ++n)
{
// calculate jacobian
detJ = invjac0(el, Ji, n)*gw[n]*tp.alphaf;
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// setup the material point
// NOTE: deformation gradient and determinant have already been evaluated in the stress routine
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFluidSolutesMaterialPoint& spt = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
double Jf = 1 + pt.m_ef;
// get the tangents
mat3ds svJ = m_pMat->Fluid()->GetViscous()->Tangent_Strain(mp);
tens4ds cv = m_pMat->Fluid()->Tangent_RateOfDeformation(mp);
double dep = m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
double d2ep = m_pMat->Fluid()->Tangent_Pressure_Strain_Strain(mp);
// Jdot/J
double dJoJ = pt.m_efdot/Jf;
// Miscellaneous constants
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
double dms = m_pMat->m_diffMtmSupp;
double penalty = m_pMat->m_penalty;
double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp);
double dodJ = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Strain(mp);
vector<double> dodc(nsol);
vector<double> M(nsol);
vector<int> z(nsol);
vector<double> d0(nsol);
vector<vector<double>> d0c(nsol, vector<double>(nsol));
for (int isol=0; isol<nsol; ++isol) {
// get the charge number
dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp,isol);
z[isol] = m_pMat->GetSolute(isol)->ChargeNumber();
M[isol] = m_pMat->GetSolute(isol)->MolarMass();
d0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp);
for (int jsol=0; jsol<nsol; ++jsol)
d0c[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp, jsol);
}
//Get dk/dt (partial differential wrt time)
vector<double> dkdt(nsol,0);
vector<vec3d> gradk(nsol,vec3d(0,0,0));
vector<double> sum1(nsol,0);
vector<vec3d> sum2(nsol,vec3d(0,0,0));
vector<vec3d> sum3(nsol,vec3d(0,0,0));
vec3d ovJ(0,0,0);
vector<vec3d> ovc(nsol,vec3d(0,0,0));
for (int isol=0; isol<nsol; ++isol)
{
dkdt[isol] = pt.m_efdot*spt.m_dkdJ[isol];
gradk[isol] = pt.m_gradef*spt.m_dkdJ[isol];
sum1[isol] = (spt.m_k[isol]/Jf + spt.m_dkdJ[isol])*spt.m_cdot[isol];
sum2[isol] = spt.m_gradc[isol]*(d0[isol]*spt.m_dkdJ[isol]);
ovJ += spt.m_gradc[isol]*spt.m_dkdJ[isol];
for (int jsol=0; jsol<nsol; ++jsol)
{
dkdt[isol] += spt.m_dkdc[isol][jsol]*spt.m_cdot[jsol];
gradk[isol] += spt.m_gradc[jsol]*spt.m_dkdc[isol][jsol];
sum1[isol] += spt.m_c[isol]*(spt.m_dkdc[isol][jsol]/Jf)*spt.m_cdot[jsol];
sum2[isol] += spt.m_gradc[jsol]*(z[jsol]*d0[jsol]*spt.m_dkdJ[jsol]);
sum3[isol] += spt.m_gradc[jsol]*(z[jsol]*(spt.m_dkdc[jsol][isol]*d0[jsol] + spt.m_k[jsol]*d0c[jsol][isol]));
ovc[isol] += spt.m_gradc[jsol]*spt.m_dkdc[jsol][isol];
}
}
ovJ *= R*T*dms;
// evaluate the chat
vector<double> vbardzdc(nsol, 0.0);
vector<vector<double>> dchatdc(nsol, vector<double>(nsol, 0.0));
// chemical reactions
for (int isol = 0; isol < nsol; ++isol)
{
for (int jsol = 0; jsol < nsol; ++jsol) {
for (i=0; i<nreact; ++i) {
double v = m_pMat->GetReaction(i)->m_v[isol];
double dzdc = m_pMat->GetReaction(i)->Tangent_ReactionSupply_Concentration(mp,jsol);
dchatdc[isol][jsol] += v*dzdc;
}
}
}
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
// evaluate stiffness matrix
for (i=0, i4=0; i<neln; ++i, i4 += ndpn)
{
for (j=0, j4 = 0; j<neln; ++j, j4 += ndpn)
{
mat3d Kvv = vdotTdotv(gradN[i], cv, gradN[j]);
vec3d kJv = (pt.m_gradef*(H[i]/Jf) + gradN[i])*H[j];
vec3d kvJ = ((pt.m_gradef*d2ep + ovJ)*H[j] + gradN[j]*dep)*H[i] + svJ*gradN[i]*H[j];
double kJJ = (H[j]*(ksi/dt - dJoJ) + gradN[j]*pt.m_vft)*H[i]/Jf;
ke[i4 ][j4 ] += Kvv(0,0)*detJ;
ke[i4 ][j4+1] += Kvv(0,1)*detJ;
ke[i4 ][j4+2] += Kvv(0,2)*detJ;
ke[i4 ][j4+3] += kvJ.x*detJ;
ke[i4+1][j4 ] += Kvv(1,0)*detJ;
ke[i4+1][j4+1] += Kvv(1,1)*detJ;
ke[i4+1][j4+2] += Kvv(1,2)*detJ;
ke[i4+1][j4+3] += kvJ.y*detJ;
ke[i4+2][j4 ] += Kvv(2,0)*detJ;
ke[i4+2][j4+1] += Kvv(2,1)*detJ;
ke[i4+2][j4+2] += Kvv(2,2)*detJ;
ke[i4+2][j4+3] += kvJ.z*detJ;
ke[i4+3][j4 ] += kJv.x*detJ;
ke[i4+3][j4+1] += kJv.y*detJ;
ke[i4+3][j4+2] += kJv.z*detJ;
ke[i4+3][j4+3] += kJJ*detJ;
for (int isol=0; isol<nsol; ++isol) {
vec3d kcv = (pt.m_gradef*spt.m_ca[isol]/Jf + spt.m_gradc[isol]*spt.m_k[isol] + gradk[isol]*spt.m_c[isol])*(-H[i]*H[j]);
vec3d kvc = (gradN[j]*spt.m_k[isol] + ovc[isol]*H[j])*(H[i]*R*T*dms);
double kJc = 0;
double kcJ = (spt.m_ca[isol]*pt.m_efdot + spt.m_k[isol]*spt.m_cdot[isol] + spt.m_c[isol]*dkdt[isol])*H[i]*H[j]/Jf
- spt.m_c[isol]*(spt.m_k[isol]/Jf + spt.m_dkdJ[isol])*H[i]*(ksi/dt*H[j] + gradN[j]*pt.m_vft)
- spt.m_c[isol]*dJoJ*(2*spt.m_dkdJ[isol])*H[i]*H[j]
- sum1[isol]*H[i]*H[j] - (gradN[i]*sum2[isol])*H[j];
int irow = i4+4+isol;
int jrow = j4+4+isol;
ke[i4 ][jrow] += kvc.x*detJ;
ke[i4+1][jrow] += kvc.y*detJ;
ke[i4+2][jrow] += kvc.z*detJ;
ke[i4+3][jrow] += kJc*detJ;
ke[irow][j4 ] += kcv.x*detJ;
ke[irow][j4+1] += kcv.y*detJ;
ke[irow][j4+2] += kcv.z*detJ;
ke[irow][j4+3] += kcJ*detJ;
for(int jsol=0; jsol<nsol; ++jsol)
{
double kd = (jsol == isol) ? 1 : 0;
double kcc = -H[i]*(kd*spt.m_k[jsol] + spt.m_c[isol]*spt.m_dkdc[isol][jsol])*(H[j]*(ksi/dt + dJoJ) + gradN[j]*pt.m_vft)
+ H[i]*H[j]*dchatdc[isol][jsol]
- gradN[i]*(gradN[j]*(spt.m_k[jsol]*d0[jsol]*kd) + spt.m_gradc[isol]*(d0[isol]*spt.m_dkdc[isol][jsol] + spt.m_k[isol]*d0c[isol][jsol])*H[j])
- gradN[i]*(gradN[j]*(z[jsol]*spt.m_k[jsol]*d0[jsol]) + sum3[jsol]*H[j]);
ke[irow][j4+4+jsol] += kcc*detJ;
}
}
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::StiffnessMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
// element stiffness matrix
FEElementMatrix ke(el);
// create the element's stiffness matrix
int nsol = m_pMat->Solutes();
int ndpn = 4 + nsol;
int ndof = ndpn*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate material stiffness
ElementStiffness(el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::MassMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
// element stiffness matrix
FEElementMatrix ke(el);
// create the element's stiffness matrix
const int nsol = m_pMat->Solutes();
const int ndpn = 4 + nsol;
int ndof = ndpn*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate inertial stiffness
ElementMassMatrix(el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
for (int iel=0; iel<NE; ++iel)
{
FESolidElement& el = m_Elem[iel];
// element stiffness matrix
FEElementMatrix ke(el);
// create the element's stiffness matrix
const int nsol = m_pMat->Solutes();
const int ndpn = 4 + nsol;
int ndof = ndpn*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate element body force stiffness
ElementBodyForceStiffness(bf, el, ke);
// get the element's LM vector
vector<int> lm;
UnpackLM(el, lm);
ke.SetIndices(lm);
// assemble element matrix in global stiffness matrix
LS.Assemble(ke);
}
}
//-----------------------------------------------------------------------------
//! calculates element inertial stiffness matrix
void FEFluidSolutesDomain3D::ElementMassMatrix(FESolidElement& el, matrix& ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i4, j, j4, n;
// Get the current element's data
const int nint = el.GaussPoints();
const int neln = el.Nodes();
const int nsol = m_pMat->Solutes();
const int ndpn = 4 + nsol;
// gradient of shape functions
vector<vec3d> gradN(neln);
double *H;
double *Gr, *Gs, *Gt;
// jacobian
double Ji[3][3], detJ;
// weights at gauss points
const double *gw = el.GaussWeights();
double dt = tp.timeIncrement;
double ksi = tp.alpham/(tp.gamma*tp.alphaf)*m_btrans;
// calculate element stiffness matrix
for (n=0; n<nint; ++n)
{
// calculate jacobian
detJ = invjac0(el, Ji, n)*gw[n]*tp.alphaf;
vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]);
vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]);
vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
// setup the material point
// NOTE: deformation gradient and determinant have already been evaluated in the stress routine
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
double dens = m_pMat->Fluid()->Density(mp);
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
// evaluate stiffness matrix
for (i=0, i4=0; i<neln; ++i, i4 += ndpn)
{
for (j=0, j4 = 0; j<neln; ++j, j4 += ndpn)
{
mat3d Mv = ((mat3dd(ksi/dt) + pt.m_Lf)*H[j] + mat3dd(gradN[j]*pt.m_vft))*(H[i]*dens*detJ);
vec3d mJ = pt.m_aft*(-H[i]*H[j]*dens/(pt.m_ef+1)*detJ);
ke[i4 ][j4 ] += Mv(0,0);
ke[i4 ][j4+1] += Mv(0,1);
ke[i4 ][j4+2] += Mv(0,2);
ke[i4 ][j4+3] += mJ.x;
ke[i4+1][j4 ] += Mv(1,0);
ke[i4+1][j4+1] += Mv(1,1);
ke[i4+1][j4+2] += Mv(1,2);
ke[i4+1][j4+3] += mJ.y;
ke[i4+2][j4 ] += Mv(2,0);
ke[i4+2][j4+1] += Mv(2,1);
ke[i4+2][j4+2] += Mv(2,2);
ke[i4+2][j4+3] += mJ.z;
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::Update(const FETimeInfo& tp)
{
bool berr = false;
int NE = (int) m_Elem.size();
#pragma omp parallel for shared(NE, berr)
for (int i=0; i<NE; ++i)
{
try
{
UpdateElementStress(i, tp);
}
catch (NegativeJacobian e)
{
#pragma omp critical
{
// reset the logfile mode
berr = true;
if (NegativeJacobian::DoOutput()) feLogError(e.what());
}
}
}
if (berr) throw NegativeJacobianDetected();
}
//-----------------------------------------------------------------------------
//! Update element state data (mostly stresses, but some other stuff as well)
void FEFluidSolutesDomain3D::UpdateElementStress(int iel, const FETimeInfo& tp)
{
double alphaf = tp.alphaf;
double alpham = tp.alpham;
// get the solid element
FESolidElement& el = m_Elem[iel];
// get the number of integration points
int nint = el.GaussPoints();
// number of nodes
int neln = el.Nodes();
// number of solutes
const int nsol = m_pMat->Solutes();
// nodal coordinates
const int NELN = FEElement::MAX_NODES;
vec3d vt[NELN], vp[NELN];
vec3d at[NELN], ap[NELN];
double et[NELN], ep[NELN];
double aet[NELN], aep[NELN];
vector< vector<double> > ct(nsol, vector<double>(NELN));
vector< vector<double> > cp(nsol, vector<double>(NELN));
vector< vector<double> > act(nsol, vector<double>(NELN));
vector< vector<double> > acp(nsol, vector<double>(NELN));
vector<int> sid(nsol);
for (int j=0; j<nsol; ++j) sid[j] = m_pMat->GetSolute(j)->GetSoluteDOF();
for (int j=0; j<neln; ++j) {
FENode& node = m_pMesh->Node(el.m_node[j]);
vt[j] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
vp[j] = node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
at[j] = node.get_vec3d(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
ap[j] = node.get_vec3d_prev(m_dofAW[0], m_dofAW[1], m_dofAW[2]);
et[j] = node.get(m_dofEF);
ep[j] = node.get_prev(m_dofEF);
aet[j] = node.get(m_dofAEF);
aep[j] = node.get_prev(m_dofAEF);
for (int k=0; k<nsol; ++k) {
ct[k][j] = node.get(m_dofC + sid[k]);
cp[k][j] = node.get_prev(m_dofC + sid[k]);
act[k][j] = node.get(m_dofAC + sid[k]);
acp[k][j] = node.get_prev(m_dofAC + sid[k]);
}
}
// loop over the integration points and update
// velocity, velocity gradient, acceleration
// stress and pressure at the integration point
for (int n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFluidSolutesMaterialPoint& spt = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
// material point data
pt.m_vft = el.Evaluate(vt, n)*alphaf + el.Evaluate(vp, n)*(1-alphaf);
pt.m_Lf = gradient(el, vt, n)*alphaf + gradient(el, vp, n)*(1-alphaf);
pt.m_aft = pt.m_Lf*pt.m_vft;
if (m_btrans) pt.m_aft += el.Evaluate(at, n)*alpham + el.Evaluate(ap, n)*(1-alpham);
pt.m_ef = el.Evaluate(et, n)*alphaf + el.Evaluate(ep, n)*(1-alphaf);
pt.m_gradef = gradient(el, et, n)*alphaf + gradient(el, ep, n)*(1-alphaf);
pt.m_efdot = pt.m_gradef*pt.m_vft;
if (m_btrans) pt.m_efdot += el.Evaluate(aet, n)*alpham + el.Evaluate(aep, n)*(1-alpham);
for (int isol=0; isol < nsol; ++isol) {
spt.m_c[isol] = el.Evaluate(ct[isol], n)*alphaf + el.Evaluate(cp[isol], n)*(1-alphaf);
spt.m_gradc[isol] = gradient(el, ct[isol], n)*alphaf + gradient(el, cp[isol], n)*(1-alphaf);
spt.m_cdot[isol] = spt.m_gradc[isol]*pt.m_vft;
if (m_btrans) spt.m_cdot[isol] += el.Evaluate(act[isol], n)*alpham + el.Evaluate(acp[isol], n)*(1-alpham);
}
m_pMat->PartitionCoefficientFunctions(mp, spt.m_k, spt.m_dkdJ, spt.m_dkdc);
// calculate the stress at this material point
pt.m_sf = m_pMat->Fluid()->Stress(mp);
spt.m_pe = m_pMat->Fluid()->Pressure(mp);
// calculate the solute flux and actual concentration
for (int isol=0; isol < nsol; ++isol)
{
spt.m_j[isol] = m_pMat->SoluteDiffusiveFlux(mp, isol);
spt.m_ca[isol] = m_pMat->ConcentrationActual(mp, isol);
}
// calculate the fluid pressure
pt.m_pf = m_pMat->PressureActual(mp);
spt.m_psi = m_pMat->ElectricPotential(mp);
spt.m_Ie = m_pMat->CurrentDensity(mp);
// update chemical reaction element data
for (int j=0; j<m_pMat->Reactions(); ++j)
m_pMat->GetReaction(j)->UpdateElementData(mp);
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::InertialForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
#pragma omp parallel for shared (NE)
for (int i=0; i<NE; ++i)
{
// element force vector
vector<double> fe;
vector<int> lm;
// get the element
FESolidElement& el = m_Elem[i];
// get the element force vector and initialize it to zero
const int nsol = m_pMat->Solutes();
const int ndpn = 4+nsol;
int ndof = ndpn*el.Nodes();
fe.assign(ndof, 0);
// calculate internal force vector
ElementInertialForce(el, fe);
// get the element's LM vector
UnpackLM(el, lm);
// assemble element 'fe'-vector into global R vector
R.Assemble(el.m_node, lm, fe);
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesDomain3D::ElementInertialForce(FESolidElement& el, vector<double>& fe)
{
int i, n;
// jacobian determinant
double detJ;
const double* H;
int nint = el.GaussPoints();
int neln = el.Nodes();
int nsol = m_pMat->Solutes();
int ndpn = 4+nsol;
double* gw = el.GaussWeights();
// repeat for all integration points
for (n=0; n<nint; ++n)
{
FEMaterialPoint& mp = *el.GetMaterialPoint(n);
FEFluidMaterialPoint& pt = *(mp.ExtractData<FEFluidMaterialPoint>());
double dens = m_pMat->Fluid()->Density(mp);
// calculate the jacobian
detJ = detJ0(el, n)*gw[n];
H = el.H(n);
for (i=0; i<neln; ++i)
{
vec3d f = pt.m_aft*(dens*H[i]);
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[ndpn*i ] -= f.x*detJ;
fe[ndpn*i+1] -= f.y*detJ;
fe[ndpn*i+2] -= f.z*detJ;
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FERealVapor.h | .h | 4,372 | 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) 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 "FEElasticFluid.h"
#include "FEThermoFluid.h"
#include <FECore/FEFunction1D.h>
//-----------------------------------------------------------------------------
//! Elastic fluid model for real vapor
//!
class FEBIOFLUID_API FERealVapor : public FEElasticFluid
{
public:
enum { MAX_NVP = 7, MAX_NVC = 4 };
public:
FERealVapor(FEModel* pfem);
~FERealVapor() {}
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
//! gauge pressure
double Pressure(FEMaterialPoint& pt) override;
//! specific free energy
double SpecificFreeEnergy(FEMaterialPoint& mp) override;
//! specific entropy
double SpecificEntropy(FEMaterialPoint& mp) override;
//! specific strain energy
double SpecificStrainEnergy(FEMaterialPoint& mp) override;
//! isochoric specific heat capacity
double IsochoricSpecificHeatCapacity(FEMaterialPoint& mp) override;
//! isobaric specific heat capacity
double IsobaricSpecificHeatCapacity(FEMaterialPoint& mp) override;
//! dilatation from temperature and pressure
bool Dilatation(const double T, const double p, double& e) override;
//! tangent of pressure with respect to strain J
double Tangent_Strain(FEMaterialPoint& mp) override;
//! tangent of pressure with respect to temperature T
double Tangent_Temperature(FEMaterialPoint& mp) override;
public:
double m_Pr; //!< referential absolute pressure
double m_Tr; //!< referential absolute temperature
double m_Tc; //!< normalized critical temperature (Tc/Tr)
double m_alpha; //!< exponent alpha used for calculating temperature map
double m_rhor; //!< referential mass density
int m_nvp; //!< number of virial coefficients for pressure
int m_nvc; //!< number of virial coefficients for isochoric specific heat capacity
FEFunction1D* m_D[MAX_NVP]; //!< non-dimensional pressure coefficient (multiply by m_Pr to get actual value)
FEFunction1D* m_psat; //!< normalized gauge pressure on saturation curve (multiply by m_Pr to get actual value)
FEFunction1D* m_asat; //!< normalized specific free energy on saturation curve (multiply by m_Pr/m_rhor to get actual value)
FEFunction1D* m_ssat; //!< normalized specific entropy on saturation curve (multiply by m_Pr/m_rhor*m_Tr to get actual value)
FEFunction1D* m_esat; //!< dilatation on saturation curve
FEFunction1D* m_cvsat; //!< non-dimensional isochoric specific heat capacity on saturation curve (multiply by m_Pr/m_rhor*m_Tr to get actual value)
FEFunction1D* m_C[MAX_NVC]; //!< non-dimensional virial coefficients for isochoric specific heat capacity
FEThermoFluid* m_pMat; //!< parent thermo-fluid material
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETemperatureBackFlowStabilization.h | .h | 2,480 | 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 "febiofluid_api.h"
#include <FECore/FESurfaceLoad.h>
#include <FECore/FENodeNodeList.h>
//-----------------------------------------------------------------------------
//! FETemperatureBackflowStabilization is a fluid surface where temperature
//! is maintained constant when the fluid velocity normal to the surface is
//! inward.
//!
class FEBIOFLUID_API FETemperatureBackFlowStabilization : public FESurfaceLoad
{
public:
//! constructor
FETemperatureBackFlowStabilization(FEModel* pfem);
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! set the dilatation
void Update() override;
//! evaluate flow rate
void MarkBackFlow();
//! initialize
bool Init() override;
//! activate
void Activate() override;
//! serialization
void Serialize(DumpStream& ar) override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
private:
FEDofList m_dofW;
int m_dofT;
FENodeNodeList m_nnlist;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIDomainFactory.cpp | .cpp | 2,525 | 70 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEMultiphasicFSIDomainFactory.h"
#include "FEMultiphasicFSI.h"
#include "FEBiphasicFSI.h"
#include "FEFluidFSI.h"
#include <FECore/FESolidDomain.h>
//-----------------------------------------------------------------------------
FEDomain* FEMultiphasicFSIDomainFactory::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat)
{
FEModel* pfem = pmat->GetFEModel();
FE_Element_Class eclass = spec.eclass;
FE_Element_Shape eshape = spec.eshape;
const char* sztype = 0;
if (dynamic_cast<FEMultiphasicFSI*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) sztype = "multiphasic-FSI-3D";
else return 0;
}
else if (dynamic_cast<FEBiphasicFSI*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) sztype = "biphasic-FSI-3D";
else return 0;
}
else if (dynamic_cast<FEFluidFSI*>(pmat))
{
// fluid elements
if (eclass == FE_ELEM_SOLID) sztype = "fluid-FSI-3D";
else return 0;
}
if (sztype)
{
FEDomain* pd = fecore_new<FESolidDomain>(sztype, pfem);
if (pd) pd->SetMaterial(pmat);
return pd;
}
else return 0;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBioPolarFluid.cpp | .cpp | 5,900 | 126 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2022 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioPolarFluid.h"
#include <FECore/FECoreKernel.h>
#include "FEPolarFluidSolver.h"
#include "FEPolarFluid.h"
#include "FEViscousPolarLinear.h"
#include "FEPolarFluidDomain3D.h"
#include "FEPolarFluidDomainFactory.h"
#include "FEPolarFluidAnalysis.h"
#include "FETangentialFlowPFStabilization.h"
#include "FEFluidModule.h"
#include "FEInitialFluidAngularVelocity.h"
#include "FEFixedFluidAngularVelocity.h"
#include "FEPrescribedFluidAngularVelocity.h"
#include "FEBioFluidPlot.h"
#include "FEConstFluidBodyMoment.h"
#include <FECore/FETimeStepController.h>
//-----------------------------------------------------------------------------
const char* FEBioPolarFluid::GetVariableName(FEBioPolarFluid::POLAR_FLUID_VARIABLE var)
{
switch (var)
{
case DISPLACEMENT : return "displacement" ; break;
case RELATIVE_FLUID_VELOCITY : return "relative fluid velocity" ; break;
case RELATIVE_FLUID_ACCELERATION : return "relative fluid acceleration"; break;
case FLUID_ANGULAR_VELOCITY : return "fluid angular velocity" ; break;
case FLUID_ANGULAR_ACCELERATION : return "fluid angular acceleration" ; break;
case FLUID_DILATATION : return "fluid dilatation" ; break;
case FLUID_DILATATION_TDERIV : return "fluid dilatation tderiv" ; break;
}
assert(false);
return nullptr;
}
void FEBioPolarFluid::InitModule()
{
FECoreKernel& febio = FECoreKernel::GetInstance();
// register domain
febio.RegisterDomain(new FEPolarFluidDomainFactory);
// define the polar fluid module
febio.CreateModule(new FEPolarFluidModule, "polar fluid",
"{"
" \"title\" : \"Polar Fluid\","
" \"info\" : \"Polar fluid analysis.\""
"}");
febio.AddModuleDependency("fluid");
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEPolarFluidAnalysis, "polar fluid");
//-----------------------------------------------------------------------------
// solver classes
REGISTER_FECORE_CLASS(FEPolarFluidSolver , "polar fluid");
//-----------------------------------------------------------------------------
// Materials
REGISTER_FECORE_CLASS(FEPolarFluid , "polar fluid");
REGISTER_FECORE_CLASS(FEViscousPolarLinear, "polar linear");
//-----------------------------------------------------------------------------
// Domain classes
REGISTER_FECORE_CLASS(FEPolarFluidDomain3D, "polar-fluid-3D");
//-----------------------------------------------------------------------------
// initial conditions
REGISTER_FECORE_CLASS(FEInitialFluidAngularVelocity , "initial fluid angular velocity");
//-----------------------------------------------------------------------------
// boundary conditions
REGISTER_FECORE_CLASS(FEFixedFluidAngularVelocity , "zero fluid angular velocity" );
REGISTER_FECORE_CLASS(FEPrescribedFluidAngularVelocity , "prescribed fluid angular velocity");
//-----------------------------------------------------------------------------
// Surface loads
REGISTER_FECORE_CLASS(FETangentialFlowPFStabilization , "fluid tangential stabilization" );
//-----------------------------------------------------------------------------
// Body loads
REGISTER_FECORE_CLASS(FEConstFluidBodyMoment , "polar fluid body moment");
//-----------------------------------------------------------------------------
// classes derived from FEPlotData
REGISTER_FECORE_CLASS(FEPlotNodalPolarFluidAngularVelocity , "nodal polar fluid angular velocity" );
REGISTER_FECORE_CLASS(FEPlotPolarFluidAngularVelocity , "polar fluid angular velocity" );
REGISTER_FECORE_CLASS(FEPlotPolarFluidRelativeAngularVelocity, "polar fluid relative angular velocity");
REGISTER_FECORE_CLASS(FEPlotPolarFluidRegionalAngularVelocity, "polar fluid regional angular velocity");
REGISTER_FECORE_CLASS(FEPlotPolarFluidStress , "polar fluid stress" );
REGISTER_FECORE_CLASS(FEPlotPolarFluidCoupleStress , "polar fluid couple stress" );
REGISTER_FECORE_CLASS(FEPlotFluidSurfaceMoment , "fluid surface moment" );
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidAnalysis.h | .h | 1,555 | 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 "febiofluid_api.h"
class FEBIOFLUID_API FEPolarFluidAnalysis : public FEAnalysis
{
public:
enum PolarFluidAnalysisType {
STEADY_STATE,
DYNAMIC
};
public:
FEPolarFluidAnalysis(FEModel* fem);
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FESoluteBackflowStabilization.h | .h | 2,606 | 81 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "FEFluidSolutes.h"
#include <FECore/FENodeNodeList.h>
//-----------------------------------------------------------------------------
//! FESoluteBackflowStabilization is a fluid surface where solute concentration
//! is maintained constant when the fluid velocity normal to the surface is
//! inward.
//!
class FEBIOFLUID_API FESoluteBackflowStabilization : public FESurfaceLoad
{
public:
//! constructor
FESoluteBackflowStabilization(FEModel* pfem);
//! calculate traction stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! set the dilatation
void Update() override;
//! evaluate flow rate
void MarkBackFlow();
//! initialize
bool Init() override;
//! activate
void Activate() override;
//! serialization
void Serialize(DumpStream& ar) override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
void SetSolute(int isol) { m_isol = isol; }
protected:
int m_isol; //!< solute id
private:
FEDofList m_dofW;
int m_dofC;
vector<int> m_ndof;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidDomain.h | .h | 3,418 | 85 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "febiofluid_api.h"
class FEModel;
class FELinearSystem;
class FEBodyForce;
class FEBodyMoment;
class FEGlobalVector;
class FETimeInfo;
//! Abstract interface class for polar fluid domains.
//! A polar fluid domain is used by the polar fluid mechanics solver.
//! This interface defines the functions that have to be implemented by a
//! polar fluid domain. There are basically two categories: residual functions
//! that contribute to the global residual vector. And stiffness matrix
//! function that calculate contributions to the global stiffness matrix.
class FEBIOFLUID_API FEPolarFluidDomain
{
public:
FEPolarFluidDomain(FEModel* pfem);
virtual ~FEPolarFluidDomain(){}
// --- R E S I D U A L ---
//! calculate the internal forces
virtual void InternalForces(FEGlobalVector& R) = 0;
//! Calculate the body force vector
virtual void BodyForce(FEGlobalVector& R, FEBodyForce& bf) = 0;
//! Calculate the body moment vector
virtual void BodyMoment(FEGlobalVector& R, FEBodyMoment& bm) = 0;
//! calculate the interial forces (for dynamic problems)
virtual void InertialForces(FEGlobalVector& R) = 0;
// --- S T I F F N E S S M A T R I X ---
//! Calculate global stiffness matrix (only contribution from internal force derivative)
//! \todo maybe I should rename this the InternalStiffness matrix?
virtual void StiffnessMatrix (FELinearSystem& LS) = 0;
//! Calculate stiffness contribution of body forces
virtual void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) = 0;
//! Calculate stiffness contribution of body moments
virtual void BodyMomentStiffness(FELinearSystem& LS, FEBodyMoment& bm) = 0;
//! calculate the mass matrix (for dynamic problems)
virtual void MassMatrix(FELinearSystem& LS) = 0;
//! transient analysis
void SetTransientAnalysis() { m_btrans = true; }
void SetSteadyStateAnalysis() { m_btrans = false; }
protected:
bool m_btrans; // flag for transient (true) or steady-state (false) analysis
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSupply.cpp | .cpp | 1,653 | 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) 2023 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidSupply.h"
//-----------------------------------------------------------------------------
// Derivative of supply w.r.t. solute concentration at material point
// Set this to zero by default because biphasic problems do not require it
double FEFluidSupply::Tangent_Supply_Concentration(FEMaterialPoint& pt, const int isol)
{
return 0;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidRCRBC.cpp | .cpp | 6,978 | 227 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidRCRBC.h"
#include "FEFluid.h"
#include "FEBioFluid.h"
#include <FECore/FEAnalysis.h>
#include <FECore/log.h>
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidRCRBC, FEPrescribedSurface)
ADD_PARAMETER(m_R , "R")->setUnits("F.t/L^5");
ADD_PARAMETER(m_Rd, "Rd")->setUnits("F.t/L^5");
ADD_PARAMETER(m_p0, "initial_pressure")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_pd, "pressure_offset")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_C , "capacitance")->setUnits("L^5/F");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidRCRBC::FEFluidRCRBC(FEModel* pfem) : FEPrescribedSurface(pfem), m_dofW(pfem)
{
m_R = 0.0;
m_pfluid = nullptr;
m_psurf = nullptr;
m_p0 = 0;
m_Rd = 0.0;
m_pd = 0.0;
m_C = 0.0;
m_e = 0.0;
}
//-----------------------------------------------------------------------------
//! initialize
//! TODO: Generalize to include the initial conditions
bool FEFluidRCRBC::Init()
{
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dofEF = GetDOFIndex(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION), 0);
SetDOFList(m_dofEF);
if (FEPrescribedSurface::Init() == false) return false;
m_psurf = GetSurface();
// get fluid from first surface element
// assuming the entire surface bounds the same fluid
FESurfaceElement& el = m_psurf->Element(0);
FEElement* pe = el.m_elem[0].pe;
if (pe == nullptr) return false;
// get the material
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
m_pfluid = pm->ExtractProperty<FEFluidMaterial>();
if (m_pfluid == nullptr) return false;
m_pn = m_pp = m_p0;
m_pdn = m_pdp = m_pd;
m_qn = m_qp = 0;
m_tp = 0;
return true;
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEFluidRCRBC::UpdateDilatation()
{
// Check if we started a new time, if so, update variables
FETimeInfo& timeInfo = GetFEModel()->GetTime();
double time = timeInfo.currentTime;
int iter = timeInfo.currentIteration;
double dt = timeInfo.timeIncrement;
if ((time > m_tp) && (iter == 0)) {
m_pp = m_pn;
m_qp = m_qn;
m_pdp = m_pdn;
m_tp = time;
}
// evaluate the flow rate at the current time
m_qn = FlowRate();
m_pdn = m_pd;
double tau = m_Rd * m_C;
// calculate the RCR pressure
m_pn = m_pdn + (m_Rd / (1 + tau / dt) + m_R) * m_qn + tau / (dt + tau) * (m_pp - m_pdp - m_R * m_qp);
// calculate the dilatation
m_e = 0.0;
bool good = m_pfluid->Dilatation(0, m_pn, m_e);
assert(good);
}
void FEFluidRCRBC::UpdateModel() { Update(); }
void FEFluidRCRBC::Update()
{
UpdateDilatation();
// the base class handles mapping the values to the nodal dofs
FEPrescribedSurface::Update();
// TODO: Is this necessary?
GetFEModel()->SetMeshUpdateFlag(true);
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface at current time
double FEFluidRCRBC::FlowRate()
{
double Q = 0;
const FETimeInfo& tp = GetTimeInfo();
vec3d rt[FEElement::MAX_NODES];
vec3d vt[FEElement::MAX_NODES];
for (int iel=0; iel<m_psurf->Elements(); ++iel)
{
FESurfaceElement& el = m_psurf->Element(iel);
// nr integration points
int nint = el.GaussPoints();
// nr of element nodes
int neln = el.Nodes();
// nodal coordinates
for (int i=0; i<neln; ++i) {
FENode& node = m_psurf->Node(el.m_lnode[i]);
rt[i] = node.m_rt;
vt[i] = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
}
double* Nr, *Ns;
double* N;
double* w = el.GaussWeights();
vec3d dxr, dxs, v;
// repeat over integration points
for (int n=0; n<nint; ++n)
{
N = el.H(n);
Nr = el.Gr(n);
Ns = el.Gs(n);
// calculate the velocity and tangent vectors at integration point
dxr = dxs = v = vec3d(0,0,0);
for (int i=0; i<neln; ++i)
{
v += vt[i]*N[i];
dxr += rt[i]*Nr[i];
dxs += rt[i]*Ns[i];
}
vec3d normal = dxr ^ dxs;
double q = normal*v;
Q += q*w[n];
}
}
return Q;
}
//-----------------------------------------------------------------------------
void FEFluidRCRBC::PrepStep(std::vector<double>& ui, bool brel)
{
UpdateDilatation();
FEPrescribedSurface::PrepStep(ui, brel);
}
//-----------------------------------------------------------------------------
void FEFluidRCRBC::GetNodalValues(int nodelid, std::vector<double>& val)
{
val[0] = m_e;
FENode& node = GetMesh().Node(m_nodeList[nodelid]);
node.set(m_dofEF, m_e);
}
//-----------------------------------------------------------------------------
// copy data from another class
void FEFluidRCRBC::CopyFrom(FEBoundaryCondition* pbc)
{
// TODO: implement this
assert(false);
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidRCRBC::Serialize(DumpStream& ar)
{
FEPrescribedSurface::Serialize(ar);
ar & m_pn & m_pp & m_qn & m_qp & m_pdn & m_pdp & m_tp & m_e;
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofW & m_dofEF;
ar & m_psurf;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidResistanceBC.h | .h | 2,624 | 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 "FEFluidMaterial.h"
//-----------------------------------------------------------------------------
//! FEFluidResistanceBC is a fluid surface that has a normal
//! pressure proportional to the flow rate (resistance).
//!
class FEBIOFLUID_API FEFluidResistanceBC : public FEPrescribedSurface
{
public:
//! constructor
FEFluidResistanceBC(FEModel* pfem);
//! evaluate flow rate
double FlowRate();
//! initialize
bool Init() override;
//! serialize data to archive
void Serialize(DumpStream& ar) override;
void Update() override;
void UpdateModel() override;
public:
void PrepStep(std::vector<double>& ui, bool brel) override;
// return the value for node i, dof j
void GetNodalValues(int nodelid, std::vector<double>& val) override;
// copy data from another class
void CopyFrom(FEBoundaryCondition* pbc) override;
private:
//! set the dilatation
void UpdateDilatation();
private:
double m_R; //!< flow resistance
double m_p0; //!< fluid pressure offset
private:
FEFluidMaterial* m_pfluid; //!< pointer to fluid
double m_e; //!< fluid dilatation
FESurface* m_psurf;
FEDofList m_dofW;
int m_dofEF;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesNaturalFlux.cpp | .cpp | 11,679 | 311 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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.*/
//For now only allows for one solute at a time, jn=-d0*gradc+c*vf
//Stiffness does not include effect from different solutes
#include "stdafx.h"
#include "FEFluidSolutesNaturalFlux.h"
#include "FEFluidMaterial.h"
#include "FEFluidSolutes.h"
#include "FEBioFluidSolutes.h"
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
#include <FECore/FEAnalysis.h>
#include "FEFluidSolutesDomain3D.h"
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FEFluidSolutesNaturalFlux, FESurfaceLoad)
ADD_PARAMETER(m_isol , "solute_id")->setEnums("$(solutes)");
ADD_PARAMETER(m_bup , "update");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FEFluidSolutesNaturalFlux::FEFluidSolutesNaturalFlux(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem), m_dofEF(pfem), m_dofC(pfem)
{
m_isol = -1;
m_bup = false;
}
//-----------------------------------------------------------------------------
//! allocate storage
void FEFluidSolutesNaturalFlux::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidSolutesNaturalFlux::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow() == false)
{
ar & m_dofC & m_dofW & m_dofEF;
}
}
//-----------------------------------------------------------------------------
bool FEFluidSolutesNaturalFlux::Init()
{
if (m_isol <= 0) return false;
// set up the dof lists
FEModel* fem = GetFEModel();
m_dofC.Clear();
m_dofW.Clear();
m_dofEF.Clear();
m_dofC.AddDof(fem->GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), m_isol - 1));
m_dofW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_VELOCITY));
m_dofEF.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_DILATATION));
m_dof.AddDofs(m_dofW);
m_dof.AddDofs(m_dofC);
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
void FEFluidSolutesNaturalFlux::Update()
{
if (m_bup) {
for (int is=0; is<m_psurf->Elements(); ++is)
{
// get surface element
FESurfaceElement& el = m_psurf->Element(is);
// get underlying solid element
FESolidElement* pe = dynamic_cast<FESolidElement*>(el.m_elem[0].pe);
if (pe == nullptr) break;
// get element data
int neln = pe->Nodes();
int nint = pe->GaussPoints();
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
// get the local solute id
FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm);
if (psi == nullptr) break;
int sid = psi->FindLocalSoluteID(m_isol);
if (sid == -1) break;
// identify nodes on the surface
vector<bool> nsrf(neln,false);
for (int j=0; j<neln; ++j) {
for (int k=0; k < el.Nodes(); ++k) {
if (el.m_node[k] == pe->m_node[j]) nsrf[j] = true;
}
}
// get average effective concentration of nodes not on surface
double cavg = 0;
int m = 0;
for (int i=0; i<neln; ++i) {
if (!nsrf[i]) {
int n = pe->m_node[i];
FENode& node = GetMesh().Node(n);
int dof = m_dofC[m_isol-1];
if (dof != -1) {
cavg += node.get(dof);
++m;
}
}
}
// assign this average value to surface nodes as initial guess
if (m) {
cavg /= m;
for (int i=0; i<neln; ++i) {
if (nsrf[i]) {
int n = pe->m_node[i];
FENode& node = GetMesh().Node(n);
int dof = m_dofC[m_isol-1];
if (dof != -1) node.set(dof, cavg);
}
}
}
}
}
}
//-----------------------------------------------------------------------------
void FEFluidSolutesNaturalFlux::LoadVector(FEGlobalVector& R)
{
FEFluidSolutesNaturalFlux* flux = this;
m_psurf->LoadVector(R, m_dofC, true, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, std::vector<double>& fa) {
const FETimeInfo& tp = GetTimeInfo();
// get surface element
FESurfaceElement& el = *mp.SurfaceElement();
// get underlying solid element
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
// get the local solute id
FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm);
if (psi == nullptr) {
fa[0] = 0;
return;
}
FEFluidSolutes* pmat = dynamic_cast<FEFluidSolutes*>(pm);
int sid = psi->FindLocalSoluteID(flux->m_isol);
vec3d dxt = mp.dxr ^ mp.dxs;
// get element-averaged diffusive flux
vec3d jd(0,0,0);
int nint = pe->GaussPoints();
for (int n=0; n<nint; ++n) {
FEMaterialPoint& pt = *pe->GetMaterialPoint(n);
jd += pmat->SoluteDiffusiveFlux(pt, m_isol-1);
}
jd /= nint;
// evaluate desired natural solute flux = normal convective flux * area
double jn = jd*dxt*tp.alphaf;
double H_i = dof_a.shape;
fa[0] = H_i * jn;
});
}
/*{
FEFluidSolutesNaturalFlux* flux = this;
m_psurf->LoadVector(R, m_dofC, true, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, std::vector<double>& fa) {
const FETimeInfo& tp = GetTimeInfo();
// get surface element
FESurfaceElement& el = *mp.SurfaceElement();
// get underlying solid element
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
// get the local solute id
FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm);
if (psi == nullptr) {
fa[0] = 0;
return;
}
int sid = psi->FindLocalSoluteID(flux->m_isol);
vec3d dxt = mp.dxr ^ mp.dxs;
// get element-averaged partition coefficient
double kappa = 0;
int nint = pe->GaussPoints();
for (int n=0; n<nint; ++n) {
FEMaterialPoint& pt = *pe->GetMaterialPoint(n);
FEFluidSolutesMaterialPoint& ps = *(pt.ExtractData<FEFluidSolutesMaterialPoint>());
kappa += ps.m_k[sid];
}
kappa /= nint;
// evaluate average effective solute concentration and fluid velocity at nodes
vec3d w(0,0,0);
double ce = 0, cp = 0;
for (int i=0; i<el.Nodes(); ++i) {
FENode& node = m_psurf->Node(el.m_lnode[i]);
w += node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*tp.alphaf + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1-tp.alphaf);
ce += node.get(m_dofC[m_isol-1])*tp.alphaf + node.get_prev(m_dofC[m_isol-1])*(1-tp.alphaf);
cp += node.get_prev(m_dofC[m_isol-1]);
}
w /= el.Nodes();
ce /= el.Nodes();
cp /= el.Nodes();
// evaluate desired natural solute flux = normal convective flux * area
double wn = w*dxt;
double jn = kappa*ce*wn;
// molar flow rate (if negative, use previous value of concentration)
double f = (wn >= 0) ? jn : kappa*cp*wn;
// double f = (jn > 0) ? jn : 0;
double H_i = dof_a.shape;
fa[0] = H_i * f;
});
}*/
//-----------------------------------------------------------------------------
void FEFluidSolutesNaturalFlux::StiffnessMatrix(FELinearSystem& LS)
{}
/*{
FEFluidSolutesNaturalFlux* flux = this;
m_psurf->LoadStiffness(LS, m_dofC, m_dof, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) {
const FETimeInfo& tp = GetTimeInfo();
// get surface element
FESurfaceElement& el = *mp.SurfaceElement();
// get underlying solid element
FEElement* pe = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID());
// get the local solute id
FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm);
if (psi == nullptr) return;
int sid = psi->FindLocalSoluteID(flux->m_isol);
// get element-averaged solute partition coefficient
double kappa = 0, d0 = 0;
int nint = pe->GaussPoints();
for (int n=0; n<nint; ++n) {
FEMaterialPoint& pt = *pe->GetMaterialPoint(n);
FEFluidSolutesMaterialPoint& ps = *(pt.ExtractData<FEFluidSolutesMaterialPoint>());
kappa += ps.m_k[sid];
d0 += psi->GetSolute(sid)->m_pDiff->Free_Diffusivity(pt);
}
kappa /= nint;
d0 /= nint;
// evaluate average effective solute concentration and fluid velocity
vec3d w(0,0,0);
double ce = 0;
for (int i=0; i<el.Nodes(); ++i) {
FENode& node = m_psurf->Node(el.m_lnode[i]);
w += node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2])*tp.alphaf + node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2])*(1-tp.alphaf);
ce += node.get(m_dofC[m_isol-1])*tp.alphaf + node.get_prev(m_dofC[m_isol-1])*(1-tp.alphaf);
}
w /= el.Nodes();
ce /= el.Nodes();
// shape functions and derivatives
double H_i = dof_a.shape;
double H_j = dof_b.shape;
// calculate surface normal
vec3d dxt = mp.dxr ^ mp.dxs;
// calculate stiffness component
vec3d kcv = dxt*(H_i*H_j*kappa*ce*tp.alphaf);
double kcc = (dxt*w)*(H_i*H_j*kappa)*tp.alphaf;
Kab[0][0] = -kcv.x;
Kab[0][1] = -kcv.y;
Kab[0][2] = -kcv.z;
Kab[0][3] = -kcc;
});
}*/
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutes.cpp | .cpp | 18,599 | 530 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidSolutes.h"
#include "FECore/FEModel.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
#include <FECore/log.h>
#include <FECore/tools.h>
#include <complex>
using namespace std;
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEFluidSolutes, FEMaterial)
// material properties
// ADD_PARAMETER(m_penalty, FE_RANGE_GREATER_OR_EQUAL(0.0), "penalty" );
ADD_PARAMETER(m_diffMtmSupp , "dms")->setLongName("include osmosis");
ADD_PROPERTY(m_pFluid, "fluid");
ADD_PROPERTY(m_pOsmC , "osmotic_coefficient");
ADD_PROPERTY(m_pSolute, "solute" , FEProperty::Optional);
ADD_PROPERTY(m_pReact , "reaction" , FEProperty::Optional);
END_FECORE_CLASS();
//============================================================================
// FEFluidSolutesMaterialPoint
//============================================================================
FEFluidSolutesMaterialPoint::FEFluidSolutesMaterialPoint(FEMaterialPointData* pt) : FEMaterialPointData(pt) {}
//-----------------------------------------------------------------------------
FEMaterialPointData* FEFluidSolutesMaterialPoint::Copy()
{
FEFluidSolutesMaterialPoint* pt = new FEFluidSolutesMaterialPoint(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
//-----------------------------------------------------------------------------
void FEFluidSolutesMaterialPoint::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_nsol & m_psi & m_Ie & m_pe;
ar & m_c & m_ca & m_gradc & m_j & m_cdot & m_k & m_dkdJ;
ar & m_dkdc;
}
//-----------------------------------------------------------------------------
void FEFluidSolutesMaterialPoint::Init()
{
m_nsol = 0;
m_psi = 0;
m_pe = 0;
m_Ie = vec3d(0,0,0);
m_c.clear();
m_ca.clear();
m_gradc.clear();
m_j.clear();
m_cdot.clear();
m_k.clear();
m_dkdJ.clear();
m_dkdJJ.clear();
m_dkdc.clear();
m_dkdJc.clear();
m_dkdcc.clear();
FEMaterialPointData::Init();
}
//-----------------------------------------------------------------------------
double FEFluidSolutesMaterialPoint::Osmolarity() const
{
double ew = 0.0;
for (int isol = 0; isol < (int)m_ca.size(); ++isol)
{
ew += m_ca[isol];
}
return ew;
}
//============================================================================
// FEFluidSolutes
//============================================================================
//-----------------------------------------------------------------------------
//! FEFluidSolutes constructor
FEFluidSolutes::FEFluidSolutes(FEModel* pfem) : FEMaterial(pfem)
{
m_pFluid = 0;
m_Rgas = 0; m_Tabs = 0; m_Fc = 0;
m_diffMtmSupp = false;
m_penalty = 1;
m_pOsmC = 0;
}
//-----------------------------------------------------------------------------
// returns a pointer to a new material point object
FEMaterialPointData* FEFluidSolutes::CreateMaterialPointData()
{
FEFluidMaterialPoint* fpt = new FEFluidMaterialPoint();
return new FEFluidSolutesMaterialPoint(fpt);
}
//-----------------------------------------------------------------------------
void FEFluidSolutes::AddChemicalReaction(FEChemicalReaction* pcr)
{
m_pReact.push_back(pcr);
}
//-----------------------------------------------------------------------------
// initialize
bool FEFluidSolutes::Init()
{
// set the solute IDs first, since they are referenced in FESolute::Init()
for (int i = 0; i<Solutes(); ++i) {
m_pSolute[i]->SetSoluteLocalID(i);
}
// call the base class.
// This also initializes all properties
if (FEMaterial::Init() == false) return false;
// Determine how to solve for the electric potential psi
int isol;
int zmin = 0, zmax = 0, z;
for (isol=0; isol<(int)m_pSolute.size(); ++isol) {
z = m_pSolute[isol]->ChargeNumber();
if (z < zmin) zmin = z;
if (z > zmax) zmax = z;
}
m_zmin = zmin;
m_ndeg = zmax - zmin; // polynomial degree
m_Rgas = GetFEModel()->GetGlobalConstant("R");
m_Tabs = GetFEModel()->GetGlobalConstant("T");
m_Fc = GetFEModel()->GetGlobalConstant("Fc");
if (m_Rgas <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; }
if (m_Tabs <= 0) { feLogError("A positive absolute temperature T must be defined in Globals section"); return false; }
if ((zmin || zmax) && (m_Fc <= 0)) {
feLogError("A positive Faraday constant Fc must be defined in Globals section");
return false;
}
return true;
}
//-----------------------------------------------------------------------------
void FEFluidSolutes::Serialize(DumpStream& ar)
{
FEMaterial::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Rgas & m_Tabs & m_Fc;
ar & m_zmin & m_ndeg;
}
//-----------------------------------------------------------------------------
//! Electric potential
double FEFluidSolutes::ElectricPotential(const FEMaterialPoint& pt, const bool eform)
{
// check if solution is neutral
if (m_ndeg == 0) {
if (eform) return 1.0;
else return 0.0;
}
int i, j;
// if not neutral, solve electroneutrality polynomial for zeta
const FEFluidSolutesMaterialPoint& set = *pt.ExtractData<FEFluidSolutesMaterialPoint>();
const int nsol = (int)m_pSolute.size();
double cF = 0.0;
FEMaterialPoint& mp = const_cast<FEMaterialPoint&>(pt);
vector<double> c(nsol); // effective concentration
vector<double> khat(nsol); // solubility
vector<int> z(nsol); // charge number
for (i=0; i<nsol; ++i) {
c[i] = set.m_c[i];
khat[i] = m_pSolute[i]->m_pSolub->Solubility(mp);
z[i] = m_pSolute[i]->ChargeNumber();
}
// evaluate polynomial coefficients
const int n = m_ndeg;
vector<double> a(n+1,0);
if (m_zmin < 0) {
for (i=0; i<nsol; ++i) {
j = z[i] - m_zmin;
a[j] += z[i]*khat[i]*c[i];
}
a[-m_zmin] = cF;
} else {
for (i=0; i<nsol; ++i) {
j = z[i];
a[j] += z[i]*khat[i]*c[i];
}
a[0] = cF;
}
// solve polynomial
double psi = set.m_psi; // use previous solution as initial guess
double zeta = exp(-m_Fc*psi/m_Rgas/m_Tabs);
if (!solvepoly(n, a, zeta)) {
zeta = 1.0;
}
// Return exponential (non-dimensional) form if desired
if (eform) return zeta;
// Otherwise return dimensional value of electric potential
psi = -m_Rgas*m_Tabs/m_Fc*log(zeta);
return psi;
}
//-----------------------------------------------------------------------------
//! partition coefficient
double FEFluidSolutes::PartitionCoefficient(const FEMaterialPoint& pt, const int sol)
{
FEMaterialPoint& mp = const_cast<FEMaterialPoint&>(pt);
// solubility
double khat = m_pSolute[sol]->m_pSolub->Solubility(mp);
// charge number
int z = m_pSolute[sol]->ChargeNumber();
// electric potential
double zeta = ElectricPotential(pt, true);
double zz = pow(zeta, z);
// partition coefficient
double kappa = zz*khat;
return kappa;
}
//-----------------------------------------------------------------------------
//! partition coefficients and their derivatives
void FEFluidSolutes::PartitionCoefficientFunctions(const FEMaterialPoint& mp, vector<double>& kappa,
vector<double>& dkdJ,
vector< vector<double> >& dkdc)
{
//TODO: Include dkdcc and dkdJc
int isol, jsol, ksol;
const FEFluidMaterialPoint& fpt = *(mp.ExtractData<FEFluidMaterialPoint>());
const FEFluidSolutesMaterialPoint& spt = *(mp.ExtractData<FEFluidSolutesMaterialPoint>());
FEMaterialPoint& pt = const_cast<FEMaterialPoint&>(mp);
const int nsol = (int)m_pSolute.size();
vector<double> c(nsol);
vector<int> z(nsol);
vector<double> khat(nsol);
vector<double> dkhdJ(nsol);
vector<double> dkhdJJ(nsol);
vector< vector<double> > dkhdc(nsol, vector<double>(nsol));
vector< vector<double> > dkhdJc(nsol, vector<double>(nsol));
vector< vector< vector<double> > > dkhdcc(nsol, dkhdc); // use dkhdc to initialize only
vector<double> zz(nsol);
kappa.resize(nsol);
double den = 0;
double num = 0;
double zeta = ElectricPotential(mp, true);
for (isol=0; isol<nsol; ++isol) {
// get the effective concentration, its gradient and its time derivative
c[isol] = spt.m_c[isol];
// get the charge number
z[isol] = m_pSolute[isol]->ChargeNumber();
// evaluate the solubility and its derivatives w.r.t. J and c
khat[isol] = m_pSolute[isol]->m_pSolub->Solubility(pt);
dkhdJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain(pt);
dkhdJJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Strain(pt);
for (jsol=0; jsol<nsol; ++jsol) {
dkhdc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration(pt,jsol);
dkhdJc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Concentration(pt,jsol);
for (ksol=0; ksol<nsol; ++ksol) {
dkhdcc[isol][jsol][ksol] =
m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration_Concentration(pt,jsol,ksol);
}
}
zz[isol] = pow(zeta, z[isol]);
kappa[isol] = zz[isol]*khat[isol];
den += SQR(z[isol])*kappa[isol]*c[isol];
num += pow((double)z[isol],3)*kappa[isol]*c[isol];
}
// evaluate electric potential (nondimensional exponential form) and its derivatives
// also evaluate partition coefficients and their derivatives
double zidzdJ = 0;
double zidzdJJ = 0, zidzdJJ1 = 0, zidzdJJ2 = 0;
vector<double> zidzdc(nsol,0);
vector<double> zidzdJc(nsol,0), zidzdJc1(nsol,0), zidzdJc2(nsol,0);
vector< vector<double> > zidzdcc(nsol, vector<double>(nsol,0));
vector< vector<double> > zidzdcc1(nsol, vector<double>(nsol,0));
vector<double> zidzdcc2(nsol,0);
double zidzdcc3 = 0;
if (den > 0) {
for (isol=0; isol<nsol; ++isol)
zidzdJ += z[isol]*zz[isol]*dkhdJ[isol]*c[isol];
zidzdJ = -(zidzdJ)/den;
for (isol=0; isol<nsol; ++isol) {
for (jsol=0; jsol<nsol; ++jsol) {
zidzdJJ1 += SQR(z[jsol])*c[jsol]*(z[jsol]*zidzdJ*kappa[jsol]+zz[jsol]*dkhdJ[jsol]);
zidzdJJ2 += z[jsol]*zz[jsol]*c[jsol]*(zidzdJ*z[jsol]*dkhdJ[jsol]+dkhdJJ[jsol]);
zidzdc[isol] += z[jsol]*zz[jsol]*dkhdc[jsol][isol]*c[jsol];
}
zidzdc[isol] = -(z[isol]*kappa[isol]+zidzdc[isol])/den;
zidzdcc3 += pow(double(z[isol]),3)*kappa[isol]*c[isol];
}
zidzdJJ = zidzdJ*(zidzdJ-zidzdJJ1/den)-(zidzdJJ2)/den;
for (isol=0; isol<nsol; ++isol) {
for (jsol=0; jsol<nsol; ++jsol) {
zidzdJc1[isol] += SQR(z[jsol])*c[jsol]*(zidzdc[isol]*z[jsol]*kappa[jsol]+zz[jsol]*dkhdc[jsol][isol]);
zidzdJc2[isol] += z[jsol]*zz[jsol]*c[jsol]*(zidzdc[isol]*z[jsol]*dkhdJ[jsol]+dkhdJc[jsol][isol]);
zidzdcc2[isol] += SQR(z[jsol])*zz[jsol]*c[jsol]*dkhdc[jsol][isol];
for (ksol=0; ksol<nsol; ++ksol)
zidzdcc1[isol][jsol] += z[ksol]*zz[ksol]*c[ksol]*dkhdcc[ksol][isol][jsol];
}
zidzdJc[isol] = zidzdJ*(zidzdc[isol]-(SQR(z[isol])*kappa[isol] + zidzdJc1[isol])/den)
-(z[isol]*zz[isol]*dkhdJ[isol] + zidzdJc2[isol])/den;
}
for (isol=0; isol<nsol; ++isol) {
for (jsol=0; jsol<nsol; ++jsol) {
zidzdcc[isol][jsol] = zidzdc[isol]*zidzdc[jsol]*(1 - zidzdcc3/den)
- zidzdcc1[isol][jsol]/den
- z[isol]*(z[isol]*kappa[isol]*zidzdc[jsol]+zz[isol]*dkhdc[isol][jsol])/den
- z[jsol]*(z[jsol]*kappa[jsol]*zidzdc[isol]+zz[jsol]*dkhdc[jsol][isol])/den
- zidzdc[jsol]*zidzdcc2[isol]/den
- zidzdc[isol]*zidzdcc2[jsol]/den;
}
}
}
dkdJ.resize(nsol);
dkdc.resize(nsol, vector<double>(nsol,0));
for (isol=0; isol<nsol; ++isol) {
dkdJ[isol] = zz[isol]*dkhdJ[isol]+z[isol]*kappa[isol]*zidzdJ;
for (jsol=0; jsol<nsol; ++jsol) {
dkdc[isol][jsol] = zz[isol]*dkhdc[isol][jsol]+z[isol]*kappa[isol]*zidzdc[jsol];
}
}
}
//-----------------------------------------------------------------------------
//! Current density
vec3d FEFluidSolutes::CurrentDensity(const FEMaterialPoint& pt)
{
int i;
const int nsol = (int)m_pSolute.size();
vector<vec3d> j(nsol);
vector<int> z(nsol);
vec3d Ie(0,0,0);
for (i=0; i<nsol; ++i) {
j[i] = SoluteFlux(pt, i);
z[i] = m_pSolute[i]->ChargeNumber();
Ie += j[i]*z[i];
}
Ie *= m_Fc;
return Ie;
}
//-----------------------------------------------------------------------------
//! actual concentration
double FEFluidSolutes::ConcentrationActual(const FEMaterialPoint& pt, const int sol)
{
const FEFluidSolutesMaterialPoint& spt = *pt.ExtractData<FEFluidSolutesMaterialPoint>();
// effective concentration
double c = spt.m_c[sol];
// partition coefficient
double kappa = PartitionCoefficient(pt, sol);
double ca = kappa*c;
return ca;
}
//-----------------------------------------------------------------------------
//! actual fluid pressure
double FEFluidSolutes::PressureActual(const FEMaterialPoint& pt)
{
int i;
const FEFluidMaterialPoint& fpt = *pt.ExtractData<FEFluidMaterialPoint>();
const FEFluidSolutesMaterialPoint& spt = *(pt.ExtractData<FEFluidSolutesMaterialPoint>());
const int nsol = (int)m_pSolute.size();
// effective pressure
double p = spt.m_pe;
// actual concentration
vector<double> c(nsol);
for (i=0; i<nsol; ++i)
c[i] = ConcentrationActual(pt, i);
// osmotic coefficient
FEMaterialPoint& mp = const_cast<FEMaterialPoint&>(pt);
double osmc = m_pOsmC->OsmoticCoefficient(mp);
// actual pressure
double pa = 0;
for (i=0; i<nsol; ++i) pa += c[i];
pa = p + m_Rgas*m_Tabs*osmc*pa;
return pa;
}
//-----------------------------------------------------------------------------
//! Calculate solute molar flux
vec3d FEFluidSolutes::SoluteFlux(const FEMaterialPoint& pt, const int sol)
{
const FEFluidSolutesMaterialPoint& spt = *pt.ExtractData<FEFluidSolutesMaterialPoint>();
const FEFluidMaterialPoint& fpt = *pt.ExtractData<FEFluidMaterialPoint>();
// concentration gradient
vec3d gradc = spt.m_gradc[sol];
// solute free diffusivity
FEMaterialPoint& mp = const_cast<FEMaterialPoint&>(pt);
double D0 = m_pSolute[sol]->m_pDiff->Free_Diffusivity(mp);
double kappa = PartitionCoefficient(pt, sol);
double c = spt.m_c[sol];
vec3d v = fpt.m_vft;
// solute flux j
vec3d j = -gradc*D0*kappa + v*c*kappa;
return j;
}
//-----------------------------------------------------------------------------
//! Calculate diffusive solute molar flux
vec3d FEFluidSolutes::SoluteDiffusiveFlux(const FEMaterialPoint& pt, const int sol)
{
const FEFluidSolutesMaterialPoint& spt = *pt.ExtractData<FEFluidSolutesMaterialPoint>();
const FEFluidMaterialPoint& fpt = *pt.ExtractData<FEFluidMaterialPoint>();
// concentration gradient
vec3d gradc = spt.m_gradc[sol];
// solute free diffusivity
FEMaterialPoint& mp = const_cast<FEMaterialPoint&>(pt);
double D0 = m_pSolute[sol]->m_pDiff->Free_Diffusivity(mp);
double kappa = PartitionCoefficient(pt, sol);
// diffusive solute flux j
vec3d jd = -gradc*D0*kappa;
return jd;
}
//-----------------------------------------------------------------------------
// solute interface functions
double FEFluidSolutes::GetEffectiveSoluteConcentration(FEMaterialPoint& mp, int soluteIndex)
{
FEFluidSolutesMaterialPoint& spt = *mp.ExtractData<FEFluidSolutesMaterialPoint>();
return spt.m_c[soluteIndex];
}
double FEFluidSolutes::GetFreeDiffusivity(FEMaterialPoint& mp, int soluteIndex)
{
return m_pSolute[soluteIndex]->m_pDiff->Free_Diffusivity(mp);
}
double FEFluidSolutes::GetPartitionCoefficient(FEMaterialPoint& mp, int soluteIndex)
{
FEFluidSolutesMaterialPoint& spt = *mp.ExtractData<FEFluidSolutesMaterialPoint>();
return spt.m_k[soluteIndex];
}
double FEFluidSolutes::GetOsmolarity(const FEMaterialPoint& mp)
{
double osm = 0;
const FEFluidSolutesMaterialPoint& spt = *mp.ExtractData<FEFluidSolutesMaterialPoint>();
const int nsol = (int)m_pSolute.size();
for (int i=0; i<nsol; ++i) osm += spt.m_ca[i];
return osm;
}
double FEFluidSolutes::dkdc(const FEMaterialPoint& mp, int i, int j)
{
const FEFluidSolutesMaterialPoint& spt = *mp.ExtractData<FEFluidSolutesMaterialPoint>();
return spt.m_dkdc[i][j];
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBioThermoFluid.cpp | .cpp | 6,789 | 154 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioThermoFluid.h"
#include <FECore/FECoreKernel.h>
#include "FEThermoFluidSolver.h"
#include "FEThermoFluid.h"
#include "FEThermoFluidDomain3D.h"
#include "FEThermoFluidDomainFactory.h"
#include "FEFixedFluidTemperature.h"
#include "FEInitialFluidTemperature.h"
#include "FEInitialFluidPressureTemperature.h"
#include "FEPrescribedFluidTemperature.h"
#include "FEFluidHeatSupplyConst.h"
#include "FEFluidNormalHeatFlux.h"
#include "FEFluidNaturalHeatFlux.h"
#include "FENewtonianThermoFluid.h"
#include "FENewtonianRealVapor.h"
#include "FEIdealGas.h"
#include "FERealGas.h"
#include "FERealVapor.h"
#include "FERealLiquid.h"
#include "FEFluidConstantConductivity.h"
#include "FETempDependentConductivity.h"
#include "FEConductivityRealVapor.h"
#include "FEThermoFluidPressureLoad.h"
#include "FETemperatureBackFlowStabilization.h"
#include "FEThermoFluidPressureBC.h"
#include "FEThermoFluidTemperatureBC.h"
#include "FEFluidModule.h"
#include "FEThermoFluidAnalysis.h"
#include "FEBioFluidPlot.h"
#include <FECore/FETimeStepController.h>
//-----------------------------------------------------------------------------
const char* FEBioThermoFluid::GetVariableName(FEBioThermoFluid::THERMOFLUID_VARIABLE var)
{
switch (var)
{
case DISPLACEMENT : return "displacement" ; break;
case RELATIVE_FLUID_VELOCITY : return "relative fluid velocity" ; break;
case RELATIVE_FLUID_ACCELERATION : return "relative fluid acceleration"; break;
case FLUID_DILATATION : return "fluid dilatation" ; break;
case FLUID_DILATATION_TDERIV : return "fluid dilatation tderiv" ; break;
case TEMPERATURE : return "temperature" ; break;
case TEMPERATURE_TDERIV : return "temperature tderiv" ; break;
}
assert(false);
return nullptr;
}
void FEBioThermoFluid::InitModule()
{
FECoreKernel& febio = FECoreKernel::GetInstance();
// register domain
febio.RegisterDomain(new FEThermoFluidDomainFactory);
// define the thermo-fluid module
febio.CreateModule(new FEThermoFluidModule, "thermo-fluid",
"{"
" \"title\" : \"Thermofluid\","
" \"info\" : \"Fluid analysis with heat transfer and thermodynamics.\""
"}");
febio.AddModuleDependency("fluid");
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEThermoFluidAnalysis, "thermo-fluid");
//-----------------------------------------------------------------------------
REGISTER_FECORE_CLASS(FEThermoFluidSolver, "thermo-fluid");
REGISTER_FECORE_CLASS(FEThermoFluid, "thermo-fluid");
REGISTER_FECORE_CLASS(FEThermoFluidDomain3D, "thermo-fluid-3D");
//-----------------------------------------------------------------------------
// initial conditions
REGISTER_FECORE_CLASS(FEInitialFluidTemperature , "initial fluid temperature");
REGISTER_FECORE_CLASS(FEInitialFluidPressureTemperature , "initial fluid pressure and temperature");
//-----------------------------------------------------------------------------
// boundary conditions
REGISTER_FECORE_CLASS(FEFixedFluidTemperature , "zero fluid temperature" );
REGISTER_FECORE_CLASS(FEPrescribedFluidTemperature , "prescribed fluid temperature");
REGISTER_FECORE_CLASS(FEThermoFluidPressureBC , "fluid pressure");
REGISTER_FECORE_CLASS(FEThermoFluidTemperatureBC , "natural temperature");
//-----------------------------------------------------------------------------
// Surface loads
REGISTER_FECORE_CLASS(FEFluidNormalHeatFlux, "fluid heat flux");
REGISTER_FECORE_CLASS(FEFluidNaturalHeatFlux, "fluid natural heat flux");
REGISTER_FECORE_CLASS(FETemperatureBackFlowStabilization, "temperature backflow stabilization");
//-----------------------------------------------------------------------------
// Body loads
REGISTER_FECORE_CLASS(FEFluidHeatSupplyConst , "constant fluid heat supply");
//-----------------------------------------------------------------------------
// Materials
// viscous thermofluids
REGISTER_FECORE_CLASS(FENewtonianThermoFluid, "Newtonian fluid");
REGISTER_FECORE_CLASS(FENewtonianRealVapor, "Newtonian real vapor");
// elastic fluids
REGISTER_FECORE_CLASS(FEIdealGas , "ideal gas" );
REGISTER_FECORE_CLASS(FERealGas , "real gas" );
REGISTER_FECORE_CLASS(FERealVapor , "real vapor" );
REGISTER_FECORE_CLASS(FERealLiquid , "real liquid" );
// thermal conductivity
REGISTER_FECORE_CLASS(FEFluidConstantConductivity, "constant thermal conductivity");
REGISTER_FECORE_CLASS(FETempDependentConductivity, "temp-dependent thermal conductivity");
REGISTER_FECORE_CLASS(FEConductivityRealVapor , "real vapor thermal conductivity");
//-----------------------------------------------------------------------------
// loads
REGISTER_FECORE_CLASS(FEThermoFluidPressureLoad, "fluid pressure constraint");
//-----------------------------------------------------------------------------
// classes derived from FEPlotData
REGISTER_FECORE_CLASS(FEPlotFluidRelativeThermalPecletNumber, "fluid relative thermal Peclet number");
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FECentrifugalFluidBodyForce.cpp | .cpp | 2,051 | 60 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FECentrifugalFluidBodyForce.h"
BEGIN_FECORE_CLASS(FECentrifugalFluidBodyForce, FEBodyForce);
ADD_PARAMETER(w, "angular_speed")->setUnits(UNIT_ANGULAR_VELOCITY);
ADD_PARAMETER(n, "rotation_axis");
ADD_PARAMETER(c, "rotation_center")->setUnits(UNIT_LENGTH);
END_FECORE_CLASS();
FECentrifugalFluidBodyForce::FECentrifugalFluidBodyForce(FEModel* pfem) : FEBodyForce(pfem)
{
w = 0.0;
n = vec3d(0,0,1);
c = vec3d(0,0,0);
}
vec3d FECentrifugalFluidBodyForce::force(FEMaterialPoint& mp)
{
mat3d K = stiffness(mp);
return K*(mp.m_rt - c);
}
double FECentrifugalFluidBodyForce::divforce(FEMaterialPoint& mp)
{
return -2*w*w;
}
mat3d FECentrifugalFluidBodyForce::stiffness(FEMaterialPoint& mp)
{
return (mat3dd(1) - dyad(n))*(-w*w);
}
| C++ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.