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/FEFluidSolutesPressureBC.cpp | .cpp | 6,929 | 179 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidSolutesPressureBC.h"
#include "FEBioFluidSolutes.h"
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidSolutesPressureBC, FEPrescribedSurface)
ADD_PARAMETER(m_p, "pressure")->setUnits("P")->setLongName("fluid pressure");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidSolutesPressureBC::FEFluidSolutesPressureBC(FEModel* pfem) : FEPrescribedSurface(pfem)
{
m_p = 0;
m_dofEF = -1;
m_dofC = -1;
m_Rgas = 0;
m_Tabs = 0;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidSolutesPressureBC::Init()
{
m_dofEF = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_DILATATION), 0);
m_dofC = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
SetDOFList(m_dofEF);
if (FEPrescribedSurface::Init() == false) return false;
m_Rgas = GetFEModel()->GetGlobalConstant("R");
m_Tabs = GetFEModel()->GetGlobalConstant("T");
m_e.assign(GetSurface()->Nodes(), 0.0);
return true;
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the resistance pressure
void FEFluidSolutesPressureBC::Update()
{
// prescribe this dilatation at the nodes
FESurface* ps = GetSurface();
int N = ps->Nodes();
std::vector<vector<double>> efNodes(N, vector<double>());
std::vector<vector<double>> caNodes(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<ps->Elements(); ++i)
{
FESurfaceElement& el = ps->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>();
FESoluteInterface* psi = pm->ExtractProperty<FESoluteInterface>();
FESolidElement* se = dynamic_cast<FESolidElement*>(e);
if (se) {
double efo[FEElement::MAX_NODES] = {0};
if (psi) {
const int nsol = psi->Solutes();
std::vector<double> kappa(nsol,0);
double osc = 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);
for (int k=0; k<nsol; ++k)
kappa[k] += psi->GetPartitionCoefficient(*pt, k);
}
osc /= nint;
for (int k=0; k<nsol; ++k) kappa[k] /= nint;
// loop over face nodes
for (int j=0; j<el.Nodes(); ++j) {
double osm = 0;
FENode& node = ps->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];
// evaluate dilatation at this node
bool good = pfl->Dilatation(0, p - m_Rgas*m_Tabs*osc*osm, efo[j]);
assert(good);
}
}
else {
// loop over face nodes
for (int j=0; j<el.Nodes(); ++j) {
FENode& node = ps->Node(el.m_lnode[j]);
// evaluate dilatation at this node
bool good = pfl->Dilatation(0, p, efo[j]);
assert(good);
}
}
// 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<ps->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;
}
FEPrescribedSurface::Update();
}
//-----------------------------------------------------------------------------
void FEFluidSolutesPressureBC::GetNodalValues(int nodelid, std::vector<double>& val)
{
val[0] = m_e[nodelid];
}
//-----------------------------------------------------------------------------
// copy data from another class
void FEFluidSolutesPressureBC::CopyFrom(FEBoundaryCondition* pbc)
{
// TODO: implement this
assert(false);
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidSolutesPressureBC::Serialize(DumpStream& ar)
{
FEPrescribedSurface::Serialize(ar);
ar & m_e;
if (ar.IsShallow()) return;
ar & m_dofC & m_dofEF;
ar & m_Rgas & m_Tabs;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidNormalHeatFlux.cpp | .cpp | 2,877 | 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.*/
#include "stdafx.h"
#include "FEFluidNormalHeatFlux.h"
#include <FECore/FEElemElemList.h>
#include <FECore/FEGlobalMatrix.h>
#include <FECore/FEGlobalVector.h>
#include <FECore/log.h>
#include <FECore/LinearSolver.h>
#include "FEBioThermoFluid.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidNormalHeatFlux, FESurfaceLoad)
ADD_PARAMETER(m_flux , "flux");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidNormalHeatFlux::FEFluidNormalHeatFlux(FEModel* pfem) : FESurfaceLoad(pfem)
{
m_flux = 0.0;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidNormalHeatFlux::Init()
{
// get the degrees of freedom
m_dof.Clear();
m_dof.AddVariable(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::TEMPERATURE));
if (m_dof.IsEmpty()) return false;
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the prescribed normal velocity
void FEFluidNormalHeatFlux::LoadVector(FEGlobalVector& R)
{
FESurface& surf = GetSurface();
// evaluate the integral
surf.LoadVector(R, m_dof, false, [&](FESurfaceMaterialPoint& pt, const FESurfaceDofShape& dof_a, std::vector<double>& val) {
// evaluate pressure at this material point
double q = m_flux(pt);
double J = (pt.dxr ^ pt.dxs).norm();
double H = dof_a.shape;
val[0] = H*q*J;
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEViscousPolarFluid.cpp | .cpp | 1,354 | 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) 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 "FEViscousPolarFluid.h"
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEElasticFluid.h | .h | 4,281 | 106 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 <FECore/tens4d.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! Base class for the viscous part of the fluid response.
//! These materials provide the viscous stress and its tangents.
//!
class FEBIOFLUID_API FEElasticFluid : public FEMaterialProperty
{
public:
FEElasticFluid(FEModel* pfem) : FEMaterialProperty(pfem) {}
virtual ~FEElasticFluid() {}
//! gauge pressure
virtual double Pressure(FEMaterialPoint& pt) = 0;
//! tangent of pressure with respect to strain J
virtual double Tangent_Strain(FEMaterialPoint& mp);
//! 2nd tangent of pressure with respect to strain J
virtual double Tangent_Strain_Strain(FEMaterialPoint& mp);
//! tangent of pressure with respect to temperature T
virtual double Tangent_Temperature(FEMaterialPoint& mp);
//! 2nd tangent of pressure with respect to temperature T
virtual double Tangent_Temperature_Temperature(FEMaterialPoint& mp);
//! tangent of pressure with respect to strain J and temperature T
virtual double Tangent_Strain_Temperature(FEMaterialPoint& mp);
//! specific free energy
virtual double SpecificFreeEnergy(FEMaterialPoint& mp) = 0;
//! specific entropy
virtual double SpecificEntropy(FEMaterialPoint& mp) = 0;
//! specific strain energy
virtual double SpecificStrainEnergy(FEMaterialPoint& mp) = 0;
//! isochoric specific heat capacity
virtual double IsochoricSpecificHeatCapacity(FEMaterialPoint& mp) = 0;
//! tangent of isochoric specific heat capacity with respect to strain J
virtual double Tangent_cv_Strain(FEMaterialPoint& mp);
//! tangent of isochoric specific heat capacity with respect to temperature T
virtual double Tangent_cv_Temperature(FEMaterialPoint& mp);
//! isobaric specific heat capacity
virtual double IsobaricSpecificHeatCapacity(FEMaterialPoint& mp) = 0;
//! calculate dilatation for given (effective) pressure and temperature
virtual bool Dilatation(const double T, const double p, double& e) = 0;
//! calculate fluid pressure and its derivatives from state variables
double Pressure(const double ef, const double T);
double Tangent_Strain(const double ef, const double T);
double Tangent_Temperature(const double ef, const double T);
double Tangent_Strain_Strain(const double ef, const double T);
double Tangent_Strain_Temperature(const double ef, const double T);
double Tangent_Temperature_Temperature(const double ef, const double T);
public:
//! specific internal energy
double SpecificInternalEnergy(FEMaterialPoint& mp);
//! specific gauge enthalpy
double SpecificGaugeEnthalpy(FEMaterialPoint& mp);
//! specific free enthalpy
double SpecificFreeEnthalpy(FEMaterialPoint& mp);
FECORE_BASE_CLASS(FEElasticFluid)
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioFSI.cpp | .cpp | 4,604 | 114 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioFSI.h"
#include <FECore/FECoreKernel.h>
#include "FEFluidFSISolver.h"
#include "FEFluidFSI.h"
#include "FEFluidFSIDomain3D.h"
#include "FEFluidFSITraction.h"
#include "FEFluidFSIDomainFactory.h"
#include "FEBackFlowFSIStabilization.h"
#include "FETangentialFlowFSIStabilization.h"
#include "FEBiphasicFSITraction.h"
#include "FEBiphasicFSI.h"
#include "FEBiphasicFSIDomain3D.h"
#include "FEFluidModule.h"
#include "FEFluidFSIAnalysis.h"
#include "FEFluidSupplyStarling.h"
#include <FECore/FETimeStepController.h>
//-----------------------------------------------------------------------------
const char* FEBioFSI::GetVariableName(FEBioFSI::FSI_VARIABLE var)
{
switch (var)
{
case DISPLACEMENT : return "displacement" ; break;
case VELOCITY : return "velocity" ; break;
case ROTATION : return "rotation" ; break;
case SHELL_DISPLACEMENT : return "shell displacement" ; break;
case SHELL_VELOCITY : return "shell velocity" ; break;
case SHELL_ACCELERATION : return "shell acceleration" ; break;
case RIGID_ROTATION : return "rigid rotation" ; break;
case RELATIVE_FLUID_VELOCITY : return "relative fluid velocity" ; break;
case RELATIVE_FLUID_ACCELERATION : return "relative fluid acceleration"; break;
case FLUID_VELOCITY : return "fluid velocity" ; break;
case FLUID_ACCELERATION : return "fluid acceleration" ; break;
case FLUID_DILATATION : return "fluid dilatation" ; break;
case FLUID_DILATATION_TDERIV : return "fluid dilatation tderiv" ; break;
}
assert(false);
return nullptr;
}
void FEBioFSI::InitModule()
{
FECoreKernel& febio = FECoreKernel::GetInstance();
// register domain
febio.RegisterDomain(new FEFluidFSIDomainFactory);
// define the fsi module
febio.CreateModule(new FEFluidFSIModule, "fluid-FSI",
"{"
" \"title\" : \"Fluid-Structure Interaction\","
" \"info\" : \"FSI analysis where a fluid interacts with a rigid, solid or biphasic structure.\""
"}");
febio.AddModuleDependency("fluid");
febio.AddModuleDependency("biphasic"); // also pulls in "solid"
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEFluidFSIAnalysis, "fluid-FSI");
//-----------------------------------------------------------------------------
REGISTER_FECORE_CLASS(FEFluidFSISolver, "fluid-FSI");
REGISTER_FECORE_CLASS(FEFluidFSI, "fluid-FSI");
REGISTER_FECORE_CLASS(FEFluidFSIDomain3D, "fluid-FSI-3D");
REGISTER_FECORE_CLASS(FEFluidFSITraction, "fluid-FSI traction");
REGISTER_FECORE_CLASS(FEBiphasicFSITraction, "biphasic-FSI traction");
REGISTER_FECORE_CLASS(FEBackFlowFSIStabilization, "fluid backflow stabilization");
REGISTER_FECORE_CLASS(FETangentialFlowFSIStabilization, "fluid tangential stabilization");
REGISTER_FECORE_CLASS(FEBiphasicFSI, "biphasic-FSI");
REGISTER_FECORE_CLASS(FEBiphasicFSIDomain3D, "biphasic-FSI-3D");
REGISTER_FECORE_CLASS(FEFluidSupplyStarling, "Starling");
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidDomain3D.h | .h | 4,767 | 137 | /*This file 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/FESolidDomain.h>
#include "FEPolarFluidDomain.h"
#include "FEPolarFluid.h"
//-----------------------------------------------------------------------------
//! domain described by 3D volumetric elements
//!
class FEBIOFLUID_API FEPolarFluidDomain3D : public virtual FESolidDomain, public FEPolarFluidDomain
{
public:
//! constructor
FEPolarFluidDomain3D(FEModel* pfem);
~FEPolarFluidDomain3D() {}
//! assignment operator
FEPolarFluidDomain3D& operator = (FEPolarFluidDomain3D& d);
//! serialize data to archive
void Serialize(DumpStream& ar) override;
//! 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 total dof list
const FEDofList& GetDOFList() const override;
public: // overrides from FEElasticDomain
// 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;
//! body moments
void BodyMoment(FEGlobalVector& R, FEBodyMoment& bm) 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;
//! body momdent stiffness
void BodyMomentStiffness(FELinearSystem& LS, FEBodyMoment& bm) 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);
//! calculates the stiffness matrix due to body moments
void ElementBodyMomentStiffness(FEBodyMoment& bm, 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 external body moments for solid elements
void ElementBodyMoment(FEBodyMoment& bm, FESolidElement& elem, vector<double>& fe);
//! Calculates the inertial force vector for solid elements
void ElementInertialForce(FESolidElement& el, vector<double>& fe);
protected:
FEPolarFluid* m_pMat;
protected:
FEDofList m_dofW;
FEDofList m_dofAW;
FEDofList m_dofG;
FEDofList m_dofAG;
FEDofList m_dof;
int m_dofEF;
int m_dofAEF;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FELogNonlinearElasticFluid.cpp | .cpp | 6,257 | 176 | /*This file 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 "FELogNonlinearElasticFluid.h"
#include "FEFluidMaterialPoint.h"
//-----------------------------------------------------------------------------
FELogNonlinearElasticFluid::FELogNonlinearElasticFluid(FEModel* pfem) : FEElasticFluid(pfem)
{
m_k = 0;
m_rhor = 0;
}
//-----------------------------------------------------------------------------
//! initialization
bool FELogNonlinearElasticFluid::Init()
{
return true;
}
//-----------------------------------------------------------------------------
// serialization
void FELogNonlinearElasticFluid::Serialize(DumpStream& ar)
{
if (ar.IsLoading()) return;
ar & m_k & m_rhor;
}
//-----------------------------------------------------------------------------
//! gauge pressure
double FELogNonlinearElasticFluid::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1+fp.m_ef;
return -m_k*log(J)/J;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J
double FELogNonlinearElasticFluid::Tangent_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1+fp.m_ef;
return m_k*(log(J)-1)/pow(J,2);
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to strain J
double FELogNonlinearElasticFluid::Tangent_Strain_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1+fp.m_ef;
return m_k*(3-2*log(J))/pow(J,3);
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to temperature T
double FELogNonlinearElasticFluid::Tangent_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! 2nd tangent of pressure with respect to temperature T
double FELogNonlinearElasticFluid::Tangent_Temperature_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J and temperature T
double FELogNonlinearElasticFluid::Tangent_Strain_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! specific free energy
double FELogNonlinearElasticFluid::SpecificFreeEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
double J = 1+fp.m_ef;
return m_k/2*pow(log(J),2)/m_rhor;
}
//-----------------------------------------------------------------------------
//! specific entropy
double FELogNonlinearElasticFluid::SpecificEntropy(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! specific strain energy
double FELogNonlinearElasticFluid::SpecificStrainEnergy(FEMaterialPoint& mp)
{
return SpecificFreeEnergy(mp);
}
//-----------------------------------------------------------------------------
//! isobaric specific heat capacity
double FELogNonlinearElasticFluid::IsobaricSpecificHeatCapacity(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! isochoric specific heat capacity
double FELogNonlinearElasticFluid::IsochoricSpecificHeatCapacity(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to strain J
double FELogNonlinearElasticFluid::Tangent_cv_Strain(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! tangent of isochoric specific heat capacity with respect to temperature T
double FELogNonlinearElasticFluid::Tangent_cv_Temperature(FEMaterialPoint& mp)
{
return 0;
}
//-----------------------------------------------------------------------------
//! dilatation from temperature and pressure
bool FELogNonlinearElasticFluid::Dilatation(const double T, const double p, double& e)
{
double errabs = 1e-3;
double errrel = 1e-3;
int maxiter = 50;
bool cnvgd = false;
// initializations
e = -p/(m_k+p); // initial guess
double f = log(1+e)+p*(1+e)/m_k; // function
double de = 0;
int iter = 0;
while (!cnvgd) {
double df = p/m_k+1.0/(1+e); // derivative
double de = -f/df; // solution increment
e += de; // update solution
f = log(1+e)+p*(1+e)/m_k; // function
// check convergence
if ((fabs(f) < errabs) || (fabs(de) < errrel*fabs(e))) cnvgd = true;
else if (++iter > maxiter) return false;
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidDomainFactory.h | .h | 1,604 | 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 FEFluidDomainFactory : public FEDomainFactory
{
public:
virtual FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat);
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEConstraintUniformFlow.cpp | .cpp | 6,120 | 163 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEConstraintUniformFlow.h"
#include "FECore/FECoreKernel.h"
#include <FECore/FEMesh.h>
BEGIN_FECORE_CLASS(FEConstraintUniformFlow, FESurfaceConstraint)
ADD_PARAMETER(m_lc.m_laugon, "laugon");
ADD_PARAMETER(m_lc.m_tol, "tol");
ADD_PARAMETER(m_lc.m_eps, "penalty");
ADD_PARAMETER(m_lc.m_naugmin, "minaug");
ADD_PARAMETER(m_lc.m_naugmax, "maxaug");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEConstraintUniformFlow::FEConstraintUniformFlow(FEModel* pfem) : FESurfaceConstraint(pfem), m_surf(pfem), m_lc(pfem)
{
m_vbar = 0;
m_binit = false;
}
//-----------------------------------------------------------------------------
//! Initializes data structures.
void FEConstraintUniformFlow::Activate()
{
// don't forget to call base class
FESurfaceConstraint::Activate();
if (m_binit == false)
{
// evaluate the nodal normals
m_surf.UpdateNodeNormals();
// get the dof indices
int dof_wx = GetDOFIndex("wx");
int dof_wy = GetDOFIndex("wy");
int dof_wz = GetDOFIndex("wz");
// create linear constraint
// for a surface with prescribed velocity the constraint
// on (vx, vy, vz) is
// nx*vx + ny*vy + nz*vz = vbar
for (int i=0; i<m_surf.Nodes(); ++i) {
// (1-nx^2)*vx - nx*ny*vy - nx*nz*vz = 0
FEAugLagLinearConstraint* pLC = fecore_alloc(FEAugLagLinearConstraint, GetFEModel());
for (int j=0; j<3; ++j) {
FENode& node = m_surf.Node(i);
vec3d nn = m_surf.NodeNormal(i);
switch (j) {
case 0: pLC->AddDOF(node.GetID(), dof_wx, nn.x); break;
case 1: pLC->AddDOF(node.GetID(), dof_wy, nn.y); break;
case 2: pLC->AddDOF(node.GetID(), dof_wz, nn.z); break;
}
}
// add the linear constraint to the system
m_lc.add(pLC);
}
m_lc.Init();
m_lc.Activate();
m_binit = true;
}
}
//-----------------------------------------------------------------------------
bool FEConstraintUniformFlow::Init()
{
// initialize surface
return m_surf.Init();
}
//-----------------------------------------------------------------------------
void FEConstraintUniformFlow::Update()
{
// evaluate the mean normal velocity on this surface
// get the dof indices
int dof_wx = GetDOFIndex("wx");
int dof_wy = GetDOFIndex("wy");
int dof_wz = GetDOFIndex("wz");
/*
m_vbar = 0;
// loop over all elements
for (int i=0; i<m_surf.Nodes(); ++i)
{
FENode& node = m_surf.Node(i);
vec3d w = node.get_vec3d(dof_wx, dof_wy, dof_wz);
double wn = w*m_nn[i];
m_vbar += wn;
}
m_vbar /= m_surf.Nodes(); */
m_vbar = 0;
double area = 0;
// loop over all elements
for (int i=0; i<m_surf.Elements(); ++i)
{
FESurfaceElement& el = m_surf.Element(i);
int ne = el.Nodes();
vector<vec3d> w(ne,vec3d(0,0,0));
// get the nodal fluid velocities
for (int j=0; j<ne; ++j) w[j] = m_surf.Node(el.m_lnode[j]).get_vec3d(dof_wx, dof_wy, dof_wz);
int nint = el.GaussPoints();
double* gw = el.GaussWeights();
vec3d t[2];
for (int n=0; n<nint; ++n) {
double* H = el.H(n);
vec3d wn(0,0,0);
for (int ie=0; ie<ne; ++ie) wn += w[ie]*H[ie];
m_surf.CoBaseVectors(el, n, t);
vec3d nu = t[0] ^ t[1];
m_vbar += (wn*nu)*gw[n];
area += nu.norm()*gw[n];
}
}
m_vbar /= area;
// assign mean velocity as rhs of constraint
m_lc.m_rhs = m_vbar;
}
//-----------------------------------------------------------------------------
void FEConstraintUniformFlow::Serialize(DumpStream& ar) { m_lc.Serialize(ar); }
void FEConstraintUniformFlow::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { m_lc.LoadVector(R, tp); }
void FEConstraintUniformFlow::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { m_lc.StiffnessMatrix(LS, tp); }
bool FEConstraintUniformFlow::Augment(int naug, const FETimeInfo& tp) { return m_lc.Augment(naug, tp); }
void FEConstraintUniformFlow::BuildMatrixProfile(FEGlobalMatrix& M) { m_lc.BuildMatrixProfile(M); }
int FEConstraintUniformFlow::InitEquations(int neq) { return m_lc.InitEquations(neq); }
void FEConstraintUniformFlow::Update(const std::vector<double>& Ui, const std::vector<double>& ui) { m_lc.Update(Ui, ui); }
void FEConstraintUniformFlow::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) { m_lc.UpdateIncrements(Ui, ui); }
void FEConstraintUniformFlow::PrepStep() { m_lc.PrepStep(); }
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesResistanceBC.cpp | .cpp | 8,771 | 248 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidSolutesResistanceBC.h"
#include "FEBioFluidSolutes.h"
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidSolutesResistanceBC, FEPrescribedSurface)
ADD_PARAMETER(m_R , "R")->setUnits("F.t/L^5");
ADD_PARAMETER(m_p0, "pressure_offset")->setUnits(UNIT_PRESSURE);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidSolutesResistanceBC::FEFluidSolutesResistanceBC(FEModel* pfem) : FEPrescribedSurface(pfem), m_dofW(pfem)
{
m_R = 0.0;
m_p0 = 0;
m_dofEF = -1;
m_dofC = -1;
m_Rgas = 0;
m_Tabs = 0;
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidSolutesResistanceBC::Init()
{
m_dofW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_VELOCITY));
m_dofEF = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_DILATATION), 0);
m_dofC = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
SetDOFList(m_dofEF);
if (FEPrescribedSurface::Init() == false) return false;
m_Rgas = GetFEModel()->GetGlobalConstant("R");
m_Tabs = GetFEModel()->GetGlobalConstant("T");
m_e.assign(GetSurface()->Nodes(), 0.0);
return true;
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidSolutesResistanceBC::Serialize(DumpStream& ar)
{
FEPrescribedSurface::Serialize(ar);
ar & m_e;
if (ar.IsShallow()) return;
ar & m_dofW & m_dofEF & m_dofC;
ar & m_Rgas & m_Tabs;
}
//-----------------------------------------------------------------------------
void FEFluidSolutesResistanceBC::Update()
{
// prescribe this dilatation at the nodes
FESurface* ps = GetSurface();
int N = ps->Nodes();
std::vector<vector<double>> efNodes(N, vector<double>());
std::vector<vector<double>> caNodes(N, vector<double>());
// evaluate the flow rate
double Q = FlowRate();
// calculate the resistance pressure
double p = m_R*Q;
// Project mean of osmotic coefficient and partition coefficient from int points to nodes on surface
// Use these to evaluate osmolarity at each node on surface
for (int i=0; i<ps->Elements(); ++i)
{
FESurfaceElement& el = ps->Element(i);
FEElement* e = el.m_elem[0].pe;
FEMaterial* pm = GetFEModel()->GetMaterial(e->GetMatID());
FEFluid* pfl = pm->ExtractProperty<FEFluid>();
FESoluteInterface* psi = pm->ExtractProperty<FESoluteInterface>();
FESolidElement* se = dynamic_cast<FESolidElement*>(e);
if (se) {
double efo[FEElement::MAX_NODES] = {0};
if (psi) {
const int nsol = psi->Solutes();
std::vector<double> kappa(nsol,0);
double osc = 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);
for (int k=0; k<nsol; ++k)
kappa[k] += psi->GetPartitionCoefficient(*pt, k);
}
osc /= nint;
for (int k=0; k<nsol; ++k) kappa[k] /= nint;
// loop over face nodes
for (int j=0; j<el.Nodes(); ++j) {
double osm = 0;
FENode& node = ps->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];
// evaluate dilatation at this node
double c = m_Rgas*osc*osm;
bool good = pfl->Dilatation(0, p+m_p0 - m_Rgas*m_Tabs*osc*osm, efo[j]);
assert(good);
}
}
else {
// loop over face nodes
for (int j=0; j<el.Nodes(); ++j) {
FENode& node = ps->Node(el.m_lnode[j]);
// evaluate dilatation at this node
bool good = pfl->Dilatation(0, p+m_p0, efo[j]);
assert(good);
}
}
// 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<ps->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;
}
FEPrescribedSurface::Update();
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface at the current time
double FEFluidSolutesResistanceBC::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;
// prescribe this dilatation at the nodes
FESurface* ps = GetSurface();
for (int iel=0; iel<ps->Elements(); ++iel)
{
FESurfaceElement& el = ps->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 = ps->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 FEFluidSolutesResistanceBC::GetNodalValues(int nodelid, std::vector<double>& val)
{
val[0] = m_e[nodelid];
}
//-----------------------------------------------------------------------------
// copy data from another class
void FEFluidSolutesResistanceBC::CopyFrom(FEBoundaryCondition* pbc)
{
// TODO: implement this
assert(false);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSolutesFlux.h | .h | 2,425 | 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.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! The flux surface is a surface domain that sustains a solute flux boundary
//! condition for FluidSolutesDomain
class FEBIOFLUID_API FEFluidSolutesFlux : public FESurfaceLoad
{
public:
//! constructor
FEFluidSolutesFlux(FEModel* pfem);
//! 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;
void SetSolute(int isol) { m_isol = isol; }
//! initialization
bool Init() override;
//! serialization
void Serialize(DumpStream& ar) override;
private:
FEParamDouble m_flux; //!< flux scale factor magnitude
int m_isol; //!< solute index
private:
FEDofList m_dofC;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidDomain.cpp | .cpp | 1,453 | 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 "FEFluidDomain.h"
//-----------------------------------------------------------------------------
FEFluidDomain::FEFluidDomain(FEModel* pfem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FELogNonlinearElasticFluid.h | .h | 3,548 | 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 FELogNonlinearElasticFluid : public FEElasticFluid
{
public:
FELogNonlinearElasticFluid(FEModel* pfem);
~FELogNonlinearElasticFluid() {}
//! 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/FETangentialDamping.h | .h | 2,373 | 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 damping prescribes a shear traction that opposes tangential
//! fluid velocity on a boundary surface. This can help stabilize inflow
//! conditions.
class FEBIOFLUID_API FETangentialDamping : public FESurfaceLoad
{
public:
//! constructor
FETangentialDamping(FEModel* pfem);
//! Initialization
bool Init() override;
//! data serialization
void Serialize(DumpStream& ar) 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;
protected:
vec3d FluidVelocity(FESurfaceMaterialPoint& mp, double alpha);
protected:
double m_eps; //!< damping coefficient (penalty)
// degrees of freedom
FEDofList m_dofW;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioMultiphasicFSI.cpp | .cpp | 5,187 | 112 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEBioMultiphasicFSI.h"
#include <FECore/FECoreKernel.h>
#include "FEMultiphasicFSISolver.h"
#include "FEMultiphasicFSI.h"
#include "FEMultiphasicFSIDomain3D.h"
#include "FEBiphasicFSITraction.h"
#include "FEMultiphasicFSIDomainFactory.h"
#include "FEBackFlowFSIStabilization.h"
#include "FETangentialFlowFSIStabilization.h"
#include "FEMultiphasicFSISoluteFlux.h"
#include "FEMultiphasicFSIPressure.h"
#include "FEMultiphasicFSIPressureBC.h"
#include "FESoluteConvectiveFlow.h"
#include "FEMultiphasicFSISoluteBackflowStabilization.h"
#include "FEFluidModule.h"
#include "FEMultiphasicFSIAnalysis.h"
#include <FECore/FETimeStepController.h>
//-----------------------------------------------------------------------------
const char* FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::MULTIPHASIC_FSI_VARIABLE var)
{
switch (var)
{
case DISPLACEMENT : return "displacement" ; break;
case VELOCITY : return "velocity" ; break;
case ROTATION : return "rotation" ; break;
case SHELL_DISPLACEMENT : return "shell displacement" ; break;
case SHELL_VELOCITY : return "shell velocity" ; break;
case SHELL_ACCELERATION : return "shell acceleration" ; break;
case RIGID_ROTATION : return "rigid rotation" ; break;
case RELATIVE_FLUID_VELOCITY : return "relative fluid velocity" ; break;
case RELATIVE_FLUID_ACCELERATION : return "relative fluid acceleration"; break;
case FLUID_VELOCITY : return "fluid velocity" ; break;
case FLUID_ACCELERATION : return "fluid acceleration" ; break;
case FLUID_DILATATION : return "fluid dilatation" ; break;
case FLUID_DILATATION_TDERIV : return "fluid dilatation tderiv" ; break;
case FLUID_CONCENTRATION : return "concentration" ; break;
case FLUID_CONCENTRATION_TDERIV : return "concentration tderiv" ; break;
}
assert(false);
return nullptr;
}
void FEBioMultiphasicFSI::InitModule()
{
FECoreKernel& febio = FECoreKernel::GetInstance();
// register domain
febio.RegisterDomain(new FEMultiphasicFSIDomainFactory);
// define the fsi module
febio.CreateModule(new FEMultiphasicFSIModule, "multiphasic-FSI");
febio.AddModuleDependency("fluid");
febio.AddModuleDependency("multiphasic"); // also pulls in solid, biphasic, solutes
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEMultiphasicFSIAnalysis, "multiphasic-FSI");
//-----------------------------------------------------------------------------
REGISTER_FECORE_CLASS(FEMultiphasicFSISolver, "multiphasic-FSI");
REGISTER_FECORE_CLASS(FEMultiphasicFSI, "multiphasic-FSI");
REGISTER_FECORE_CLASS(FEMultiphasicFSIDomain3D, "multiphasic-FSI-3D");
REGISTER_FECORE_CLASS(FEBiphasicFSITraction, "multiphasic-FSI traction");
REGISTER_FECORE_CLASS(FEBackFlowFSIStabilization, "fluid backflow stabilization");
REGISTER_FECORE_CLASS(FETangentialFlowFSIStabilization, "fluid tangential stabilization");
// loads
REGISTER_FECORE_CLASS(FEMultiphasicFSISoluteFlux, "solute flux");
REGISTER_FECORE_CLASS(FEMultiphasicFSISoluteBackflowStabilization, "solute backflow stabilization");
REGISTER_FECORE_CLASS(FEMultiphasicFSIPressure, "fluid pressure", 0x0300); // deprecated, use BC version
// bcs
REGISTER_FECORE_CLASS(FEMultiphasicFSIPressureBC, "fluid pressure");
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEConstFluidBodyMoment.h | .h | 2,022 | 54 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMaterialPoint.h>
#include <FECore/FEModelParam.h>
#include "FEBodyMoment.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 FEConstFluidBodyMoment : public FEBodyMoment
{
public:
//! constructor
FEConstFluidBodyMoment(FEModel* pfem);
public:
//! calculate the body force at a material point
vec3d moment(FEMaterialPoint& pt) override;
//! calculate constribution to stiffness matrix
mat3ds stiffness(FEMaterialPoint& pt) override;
protected:
FEParamVec3 m_moment;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETangentialFlowFSIStabilization.cpp | .cpp | 6,964 | 200 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FETangentialFlowFSIStabilization.h"
#include "FEFluidMaterial.h"
#include "FEBioFluid.h"
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FETangentialFlowFSIStabilization, FESurfaceLoad)
ADD_PARAMETER(m_beta, "beta");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FETangentialFlowFSIStabilization::FETangentialFlowFSIStabilization(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.Clear();
m_dofU.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::DISPLACEMENT));
m_dofW.Clear();
m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY));
m_dof.Clear();
m_dof.AddDofs(m_dofU);
m_dof.AddDofs(m_dofW);
}
}
//-----------------------------------------------------------------------------
//! allocate storage
void FETangentialFlowFSIStabilization::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
}
//-----------------------------------------------------------------------------
//! initialize
bool FETangentialFlowFSIStabilization::Init()
{
if (FESurfaceLoad::Init() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FETangentialFlowFSIStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofU & m_dofW;
}
//-----------------------------------------------------------------------------
vec3d FETangentialFlowFSIStabilization::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 FETangentialFlowFSIStabilization::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);
// 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 FETangentialFlowFSIStabilization::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();
// fluid velocity
vec3d v = FluidVelocity(mp, tp.alphaf);
// 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();
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);
// force vector (change sign for inflow vs outflow)
vec3d ttt = vtau*(-m_beta*rho*vmag);
// 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;
// calculate stiffness component
mat3d Kww = K*(H_i*H_j*tp.alphaf);
vec3d g = (dxr*Gs_j - dxs*Gr_j)*(H_i*tp.alphaf);
mat3d Kwu; Kwu.skew(g);
Kwu = (ttt & n)*Kwu;
Kab.zero();
// dw/du
Kab.sub(3, 0, Kwu);
// dw/dw
Kab.sub(3, 3, Kww);
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEIdealGasIsothermal.h | .h | 2,697 | 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 "FEFluid.h"
//-----------------------------------------------------------------------------
//! Ideal gas under isothermal conditions.
class FEBIOFLUID_API FEIdealGasIsothermal : public FEFluid
{
public:
FEIdealGasIsothermal(FEModel* pfem);
public:
//! initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
//! elastic pressure
double Pressure(FEMaterialPoint& mp) override;
double Pressure(const double e, const double T = 0) override;
//! tangent of elastic pressure with respect to strain J
double Tangent_Pressure_Strain(FEMaterialPoint& mp) override;
//! 2nd tangent of elastic pressure with respect to strain J
double Tangent_Pressure_Strain_Strain(FEMaterialPoint& mp) override;
//! strain energy density
double StrainEnergyDensity(FEMaterialPoint& mp) override;
//! invert effective pressure-dilatation relation
bool Dilatation(const double T, const double p, double& e) override;
//! evaluate temperature
double Temperature(FEMaterialPoint& mp) override;
public:
double m_M; //!< moral mass
double m_Pr; //!< ambient pressure
double m_Tr; //!< ambient temperature
double m_R; //!< universal gas constant
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEBioFluidSolutes.cpp | .cpp | 5,295 | 122 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidModule.h"
#include "FEBioFluidSolutes.h"
#include "FEFluidSolutesSolver.h"
#include "FEFluidSolutes.h"
#include "FEFluidSolutesDomain3D.h"
#include "FEFluidSolutesDomainFactory.h"
#include "FESoluteBackflowStabilization.h"
#include "FEInitialFluidSolutesPressure.h"
#include "FEFluidSolutesFlux.h"
#include "FEFluidSolutesNaturalFlux.h"
#include "FEFluidSolutesPressureBC.h"
#include "FEFluidSolutesResistanceBC.h"
#include "FEFluidSolutesRCRBC.h"
#include "FESoluteConvectiveFlow.h"
#include "FESolutesSolver.h"
#include "FESolutesMaterial.h"
#include "FESolutesDomain.h"
#include "FESolutesDomainFactory.h"
#include "FEBioFluidPlot.h"
#include <FEBioMix/FESoluteFlux.h>
#include <FECore/FECoreKernel.h>
#include <FECore/FETimeStepController.h>
#include "FEFluidSolutesAnalysis.h"
//-----------------------------------------------------------------------------
const char* FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_SOLUTES_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 FLUID_CONCENTRATION : return "concentration" ; break;
case FLUID_CONCENTRATION_TDERIV : return "concentration tderiv" ; break;
}
assert(false);
return nullptr;
}
void FEBioFluidSolutes::InitModule()
{
FECoreKernel& febio = FECoreKernel::GetInstance();
// register domain
febio.RegisterDomain(new FEFluidSolutesDomainFactory);
// define the fsi module
febio.CreateModule(new FEFluidSolutesModule, "fluid-solutes",
"{"
" \"title\" : \"Fluid-Solutes\","
" \"info\" : \"Fluid analysis with solute transport and reactive processes.\""
"}");
febio.AddModuleDependency("fluid");
febio.AddModuleDependency("multiphasic"); // also pulls in solid, biphasic, solutes
//-----------------------------------------------------------------------------
// analysis classes (default type must match module name!)
REGISTER_FECORE_CLASS(FEFluidSolutesAnalysis, "fluid-solutes");
// monolithic fluid-solutes solver
REGISTER_FECORE_CLASS(FEFluidSolutesSolver, "fluid-solutes");
REGISTER_FECORE_CLASS(FEFluidSolutes, "fluid-solutes");
REGISTER_FECORE_CLASS(FEFluidSolutesDomain3D, "fluid-solutes-3D");
// loads
REGISTER_FECORE_CLASS(FEFluidSolutesFlux , "solute flux" );
REGISTER_FECORE_CLASS(FESoluteBackflowStabilization, "solute backflow stabilization");
REGISTER_FECORE_CLASS(FEFluidSolutesNaturalFlux , "solute natural flux" , FECORE_EXPERIMENTAL);
REGISTER_FECORE_CLASS(FESoluteConvectiveFlow , "solute convective flow" , FECORE_EXPERIMENTAL);
// bcs
REGISTER_FECORE_CLASS(FEFluidSolutesPressureBC , "fluid pressure" );
REGISTER_FECORE_CLASS(FEFluidSolutesResistanceBC , "fluid resistance");
REGISTER_FECORE_CLASS(FEFluidSolutesRCRBC , "fluid RCR" );
// ics
// REGISTER_FECORE_CLASS(FEInitialFluidSolutesPressure, "initial fluid pressure");
//-----------------------------------------------------------------------------
// classes derived from FEPlotData
REGISTER_FECORE_CLASS(FEPlotFluidRelativePecletNumber, "solute relative Peclet number");
// solutes solver classes
febio.RegisterDomain(new FESolutesDomainFactory);
REGISTER_FECORE_CLASS(FESolutesSolver, "solutes");
REGISTER_FECORE_CLASS(FESolutesMaterial, "solutes");
REGISTER_FECORE_CLASS(FESolutesDomain, "solutes-3D");
febio.SetActiveModule(0);
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidSupplyStarling.h | .h | 2,368 | 61 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEFluidSupply.h"
//-----------------------------------------------------------------------------
// This class implements a material that has a fluid supply following
// Starling's equation
class FEBIOFLUID_API FEFluidSupplyStarling : public FEFluidSupply
{
public:
//! constructor
FEFluidSupplyStarling(FEModel* pfem);
//! Solute supply
double Supply(FEMaterialPoint& pt) override;
//! Tangent of supply with respect to solid strain
mat3d Tangent_Supply_Strain(FEMaterialPoint& mp) override;
//! Tangent of supply with respect to pressure
double Tangent_Supply_Dilatation(FEMaterialPoint& mp) override;
//! tangent of fluid supply with respect to rate of deformation
mat3ds Tangent_Supply_RateOfDeformation(FEMaterialPoint& mp) override { return mat3ds(0); }
//! Initialization
bool Init() override { return FEFluidSupply::Init(); }
public:
FEParamDouble m_kp; //!< coefficient of pressure drop
FEParamDouble m_pv; //!< prescribed (e.g., vascular) pressure
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidRCBC.h | .h | 3,324 | 91 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEPrescribedBC.h>
#include "FEFluidMaterial.h"
//-----------------------------------------------------------------------------
//! FEFluidRCBC is a fluid surface that has an RC-equivalent circuit for outflow conditions
//!
class FEBIOFLUID_API FEFluidRCBC : public FEPrescribedSurface
{
public:
//! constructor
FEFluidRCBC(FEModel* pfem);
//! evaluate flow rate
double FlowRate();
//! initialize
bool Init() override;
//! Update
void Update() override;
void UpdateModel() override;
//! serialization
void Serialize(DumpStream& ar) 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; //!< initial fluid pressure
double m_C; //!< capacitance
bool m_Bern; //!< Use Bernoulli's Relation (Q*|Q|)
double m_qt; //!< flow rate at current time step
double m_dqt; //!< flow rate time derivative at current time step
double m_pt; //!< pressure at current time step
double m_dpt; //!< pressure derivative at current time step
double m_qp; //!< flow rate at previous time step
double m_dqp; //!< flow rate time derivative at previous time step
double m_pp; //!< pressure at previoust time step
double m_dpp; //!< pressure derivative at previoust time step
double m_e;
private:
FEFluidMaterial* m_pfluid; //!< pointer to fluid
FESurface* m_psurf; //!< pointer to surface
FEDofList m_dofW;
int m_dofEF;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidFSIAnalysis.cpp | .cpp | 1,680 | 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 "FEFluidFSIAnalysis.h"
BEGIN_FECORE_CLASS(FEFluidFSIAnalysis, 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()
FEFluidFSIAnalysis::FEFluidFSIAnalysis(FEModel* fem) : FEAnalysis(fem)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FESolutesSolver.cpp | .cpp | 26,417 | 814 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FESolutesSolver.h"
#include "FESolutesDomain.h"
#include <FECore/log.h>
#include <FECore/DOFS.h>
#include <FECore/FEGlobalMatrix.h>
#include <FECore/sys.h>
#include <FEBioMech/FEBodyForce.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/FELinearSystem.h>
#include <FECore/FEModel.h>
#include <FECore/FENLConstraint.h>
#include "FEBioFluidSolutes.h"
#include <assert.h>
#include "FEFluidSolutesAnalysis.h"
//-----------------------------------------------------------------------------
// define the parameter list
BEGIN_FECORE_CLASS(FESolutesSolver, FENewtonSolver)
ADD_PARAMETER(m_Ctol , "ctol" );
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_forcePositive, "force_positive_concentrations");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! FEFluidSolutesSolver Construction
//
FESolutesSolver::FESolutesSolver(FEModel* pfem) : FENewtonSolver(pfem), m_dofC(pfem), m_dofAC(pfem)
{
// default values
m_Rtol = 0.001;
m_Etol = 0.01;
m_Ctol = 0.01;
m_Rmin = 1.0e-20;
m_Rmax = 0; // not used if zero
m_niter = 0;
// assume non-symmetric stiffness
m_msymm = REAL_UNSYMMETRIC;
m_forcePositive = true; // force all concentrations to remain positive
m_rhoi = 0;
m_pred = 0;
// Preferred strategy is Broyden's method
SetDefaultStrategy(QN_BROYDEN);
// turn off checking for a zero diagonal
CheckZeroDiagonal(false);
// Allocate degrees of freedom
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
DOFS& dofs = pfem->GetDOFS();
int varC = dofs.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), VAR_ARRAY);
int varAC = dofs.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION_TDERIV), VAR_ARRAY);
}
}
//-----------------------------------------------------------------------------
FESolutesSolver::~FESolutesSolver()
{
}
//-----------------------------------------------------------------------------
//! Allocates and initializes the data structures used by the FEFluidSolutesSolver
//
bool FESolutesSolver::Init()
{
// initialize base class
if (FENewtonSolver::Init() == false) return false;
// check parameters
if (m_Ctol < 0.0) { feLogError("ctol 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_gammaf = 1.0;
}
else if ((m_rhoi >= 0) && (m_rhoi <= 1)) {
m_alphaf = 1.0/(1+m_rhoi);
m_alpham = (3-m_rhoi)/(1+m_rhoi)/2;
m_gammaf = 0.5 + m_alpham - m_alphaf;
}
else { feLogError("rhoi must be -1 or between 0 and 1."); return false; }
// allocate vectors
int neq = m_neq;
m_Fr.assign(neq, 0);
m_Ui.assign(neq, 0);
m_Ut.assign(neq, 0);
// get number of DOFS
FEModel& fem = *GetFEModel();
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
// allocate concentration-vectors
m_ci.assign(MAX_CDOFS,vector<double>(0,0));
m_Ci.assign(MAX_CDOFS,vector<double>(0,0));
for (int i=0; i<MAX_CDOFS; ++i) {
m_ci[i].assign(m_nceq[i], 0);
m_Ci[i].assign(m_nceq[i], 0);
}
vector<int> dofs;
for (int j=0; j<(int)m_nceq.size(); ++j) {
if (m_nceq[j]) {
dofs.push_back(m_dofC[j]);
}
}
// we need to fill the total DOF vector m_Ut
// TODO: I need to find an easier way to do this
FEMesh& mesh = fem.GetMesh();
gather(m_Ut, mesh, dofs);
// set flag for transient or steady-state analyses
for (int i = 0; i<mesh.Domains(); ++i)
{
FESolutesDomain& dom = dynamic_cast<FESolutesDomain&>(mesh.Domain(i));
if (fem.GetCurrentStep()->m_nanalysis == FEFluidSolutesAnalysis::STEADY_STATE)
dom.SetSteadyStateAnalysis();
else
dom.SetTransientAnalysis();
}
return true;
}
//-----------------------------------------------------------------------------
//! Initialize equations
bool FESolutesSolver::InitEquations()
{
m_dofC.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
m_dofAC.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION_TDERIV));
AddSolutionVariable(&m_dofC, 1, "concentration", m_Ctol);
// base class initialization
FENewtonSolver::InitEquations();
// determined the nr of velocity and dilatation equations
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// determine the nr of concentration equations
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
m_nceq.assign(MAX_CDOFS, 0);
// get number of DOFS
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& n = mesh.Node(i);
for (int j=0; j<MAX_CDOFS; ++j) {
if (n.m_ID[m_dofC[j]] != -1) m_nceq[j]++;
}
}
// add up all equation
m_nCeq = 0;
for (int i = 0; i < m_nceq.size(); ++i) m_nCeq += m_nceq[i];
return true;
}
//-----------------------------------------------------------------------------
//! Initialize equations
bool FESolutesSolver::InitEquations2()
{
m_dofC.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
m_dofAC.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION_TDERIV));
AddSolutionVariable(&m_dofC, -1, "concentration", m_Ctol);
// base class initialization
FENewtonSolver::InitEquations2();
// determined the nr of velocity and dilatation equations
FEModel& fem = *GetFEModel();
FEMesh& mesh = fem.GetMesh();
// determine the nr of concentration equations
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
m_nceq.assign(MAX_CDOFS, 0);
// get number of DOFS
for (int i = 0; i<mesh.Nodes(); ++i)
{
FENode& n = mesh.Node(i);
for (int j = 0; j<MAX_CDOFS; ++j) {
if (n.m_ID[m_dofC[j]] != -1) m_nceq[j]++;
}
}
// add up all equation
m_nCeq = 0;
for (int i = 0; i < m_nceq.size(); ++i) m_nCeq += m_nceq[i];
return true;
}
//-----------------------------------------------------------------------------
void FESolutesSolver::GetConcentrationData(vector<double> &ci, vector<double> &ui, const int sol)
{
FEModel& fem = *GetFEModel();
int N = fem.GetMesh().Nodes(), nid, m = 0;
zero(ci);
for (int i=0; i<N; ++i)
{
FENode& n = fem.GetMesh().Node(i);
nid = n.m_ID[m_dofC[sol]];
if (nid != -1)
{
nid = (nid < -1 ? -nid-2 : nid);
ci[m++] = ui[nid];
assert(m <= (int) ci.size());
}
}
}
//-----------------------------------------------------------------------------
//! Update the kinematics of the model, such as nodal positions, velocities,
//! accelerations, etc.
void FESolutesSolver::UpdateKinematics(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];
// get number of DOFS
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
// update solute data
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
// update nodal concentration
for (int j=0; j<MAX_CDOFS; ++j) {
int n = node.m_ID[m_dofC[j]];
// Force the concentrations to remain positive
if (n >= 0) {
double ct = 0 + m_Ut[n] + m_Ui[n] + ui[n];
if ((ct < 0.0) && m_forcePositive) ct = 0.0;
node.set(m_dofC[j], ct);
}
}
}
// make sure the prescribed dofs are fulfilled
int nbc = fem.BoundaryConditions();
for (int i=0; i<nbc; ++i)
{
FEBoundaryCondition& bc = *fem.BoundaryCondition(i);
if (bc.IsActive() && HasActiveDofs(bc.GetDofList())) bc.Update();
}
// prescribe DOFs for specialized surface loads
int nsl = fem.ModelLoads();
for (int i=0; i<nsl; ++i)
{
FEModelLoad& psl = *fem.ModelLoad(i);
// if (psl.IsActive() && HasActiveDofs(psl.GetDofList())) psl.Update();
if (psl.IsActive()) psl.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 == FEFluidSolutesAnalysis::DYNAMIC)
{
int N = mesh.Nodes();
double dt = fem.GetTime().timeIncrement;
double cgi = 1 - 1.0/m_gammaf;
for (int i=0; i<N; ++i)
{
FENode& n = mesh.Node(i);
// concentration time derivative
// update nodal concentration
for (int j=0; j<MAX_CDOFS; ++j) {
int k = n.m_ID[m_dofC[j]];
// Force the concentrations to remain positive
if (k >= 0) {
double ct = n.get(m_dofC[j]);
double cp = n.get_prev(m_dofC[j]);
double acp = n.get_prev(m_dofAC[j]);
double act = acp*cgi + (ct - cp)/(m_gammaf*dt);
n.set(m_dofC[j], ct);
n.set(m_dofAC[j], act);
}
}
}
}
}
//-----------------------------------------------------------------------------
void FESolutesSolver::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];
// get number of DOFS
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
// update solute data
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
// update nodal concentration
for (int j=0; j<MAX_CDOFS; ++j) {
int n = node.m_ID[m_dofC[j]];
// Force the concentrations to remain positive
if (n >= 0) {
double ct = 0 + m_Ut[n] + m_Ui[n] + ui[n];
if ((ct < 0.0) && m_forcePositive) ct = 0.0;
node.set(m_dofC[j], ct);
}
}
}
// 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
GetFEModel()->Update();
}
//-----------------------------------------------------------------------------
//! Updates the current state of the model
void FESolutesSolver::Update(vector<double>& ui)
{
FEModel& fem = *GetFEModel();
FETimeInfo& tp = fem.GetTime();
tp.currentIteration = m_niter;
// update kinematics
UpdateKinematics(ui);
// update model state
UpdateModel();
}
//-----------------------------------------------------------------------------
bool FESolutesSolver::InitStep(double time)
{
FEModel& fem = *GetFEModel();
// set time integration parameters
FETimeInfo& tp = fem.GetTime();
tp.alphaf = m_alphaf;
tp.alpham = m_alpham;
tp.gamma = m_gammaf;
// evaluate load curve values at current (or intermediate) time
double t = tp.currentTime;
double dt = tp.timeIncrement;
double ta = (t > 0) ? t - (1-m_alphaf)*dt : m_alphaf*dt;
return FESolver::InitStep(ta);
}
//-----------------------------------------------------------------------------
//! Prepares the data for the first BFGS-iteration.
void FESolutesSolver::PrepStep()
{
FEModel& fem = *GetFEModel();
// get number of DOFS
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
FETimeInfo& tp = fem.GetTime();
double dt = tp.timeIncrement;
tp.currentIteration = m_niter;
// zero total DOFs
zero(m_Ui);
for (int j=0; j<(int)m_nceq.size(); ++j) if (m_nceq[j]) zero(m_Ci[j]);
// 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_r0;
ni.m_dp = ni.m_dt = ni.m_d0;
ni.UpdateValues();
switch (m_pred) {
case 0:
{
// update nodal concentration
for (int j=0; j<MAX_CDOFS; ++j)
ni.set(m_dofAC[j], ni.get_prev(m_dofAC[j])*(m_gammaf-1)/m_gammaf);
}
break;
case 1:
{
for (int j=0; j<MAX_CDOFS; ++j)
ni.set(m_dofC[j], ni.get_prev(m_dofC[j]) + ni.get_prev(m_dofAC[j])*dt*(1-m_gammaf)*m_alphaf);
}
break;
case 2:
{
for (int j=0; j<MAX_CDOFS; ++j)
ni.set(m_dofC[j], ni.get_prev(m_dofC[j]) + ni.get_prev(m_dofAC[j])*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() && HasActiveDofs(bc.GetDofList())) 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) mesh.Domain(i).PreSolveUpdate(tp);
// update stresses
fem.Update();
// 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() && HasActiveDofs(pml.GetDofList())) pml.PrepStep();
}
// see if we need to do contact augmentations
m_baugment = false;
// see if we have to do nonlinear constraint augmentations
if (fem.NonlinearConstraints() != 0) m_baugment = true;
}
//-----------------------------------------------------------------------------
bool FESolutesSolver::Quasin()
{
FEModel& fem = *GetFEModel();
// convergence norms
double normR1; // residual norm
double normE1; // energy norm
double normRi = 0; // initial residual norm
double normEi = 0; // initial energy norm
double normEm = 0; // max energy norm
// get number of DOFS
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
// solute convergence data
vector<double> normCi(MAX_CDOFS); // initial concentration norm
vector<double> normC(MAX_CDOFS); // current concentration norm
vector<double> normc(MAX_CDOFS); // incremement concentration norm
// Get the current step
FEAnalysis* pstep = fem.GetCurrentStep();
// 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();
// set initial convergence norms
if (m_niter == 0)
{
normRi = fabs(m_R0*m_R0);
normEi = fabs(m_ui*m_R0);
normEm = normEi;
}
// calculate norms
// update all degrees of freedom
for (int i=0; i<m_neq; ++i) m_Ui[i] += s*m_ui[i];
// calculate the norms
normR1 = m_R1*m_R1;
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 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;
// check solute convergence
// extract the concentration increments
for (int j = 0; j<(int)m_nceq.size(); ++j) {
if (m_nceq[j]) {
GetConcentrationData(m_ci[j], m_ui,j);
// set initial norm
if (m_niter == 0)
normCi[j] = fabs(m_ci[j]*m_ci[j]);
// update total concentration
for (int i = 0; i<m_nceq[j]; ++i) m_Ci[j][i] += s*m_ci[j][i];
// calculate norms
normC[j] = m_Ci[j]*m_Ci[j];
normc[j] = (m_ci[j]*m_ci[j])*(s*s);
}
}
// check convergence
if (m_Ctol > 0) {
for (int j = 0; j<(int)m_nceq.size(); ++j)
if (m_nceq[j]) bconv = bconv && (normc[j] <= (m_Ctol*m_Ctol)*normC[j]);
}
// 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);
for (int j = 0; j<(int)m_nceq.size(); ++j) {
if (m_nceq[j])
feLog("\t solute %d concentration %15le %15le %15le\n", j+1, normCi[j], normc[j] ,(m_Ctol*m_Ctol)*normC[j] );
}
// 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;
for (int j = 0; j<(int)m_nceq.size(); ++j)
if (m_nceq[j]) normCi[j] = normc[j];
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 FESolutesSolver::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)
{
FESolutesDomain& dom = dynamic_cast<FESolutesDomain&>(mesh.Domain(i));
dom.StiffnessMatrix(LS);
}
// calculate stiffness matrix due to model loads
const int nml = fem.ModelLoads();
for (int i=0; i<nml; ++i)
{
FEModelLoad* pml = fem.ModelLoad(i);
// if (pml->IsActive() && HasActiveDofs(pml->GetDofList())) pml->StiffnessMatrix(LS);
if (pml->IsActive()) pml->StiffnessMatrix(LS);
}
return true;
}
//-----------------------------------------------------------------------------
//! 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 FESolutesSolver::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
FEGlobalVector 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)
{
FESolutesDomain& dom = dynamic_cast<FESolutesDomain&>(mesh.Domain(i));
dom.InternalForces(RHS);
}
// 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);
}
// increase RHS counter
m_nrhs++;
return true;
}
//-----------------------------------------------------------------------------
//! Serialization
void FESolutesSolver::Serialize(DumpStream& ar)
{
FENewtonSolver::Serialize(ar);
ar & m_neq & m_nceq;
ar & m_nrhs & m_niter & m_nref & m_ntotref;
ar & m_Fr & m_Ui & m_Ut;
ar & m_Ci;
if (ar.IsLoading())
{
m_Fr.assign(m_neq, 0);
for (int i=0; i<m_nceq.size(); ++i) {
m_ci[i].assign(m_nceq[i], 0);
m_Ci[i].assign(m_nceq[i], 0);
}
}
if (ar.IsShallow()) return;
ar & m_alphaf & m_alpham;
ar & m_gammaf;
ar & m_pred;
ar & m_dofC & m_dofAC;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBackFlowStabilization.cpp | .cpp | 5,640 | 183 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBackFlowStabilization.h"
#include "FEFluidMaterial.h"
#include "FEBioFluid.h"
#include <FECore/FELinearSystem.h>
#include <FECore/FEModel.h>
//-----------------------------------------------------------------------------
// Parameter block for pressure loads
BEGIN_FECORE_CLASS(FEBackFlowStabilization, FESurfaceLoad)
ADD_PARAMETER(m_beta, "beta");
END_FECORE_CLASS()
//-----------------------------------------------------------------------------
//! constructor
FEBackFlowStabilization::FEBackFlowStabilization(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);
}
}
//-----------------------------------------------------------------------------
//! initialize
bool FEBackFlowStabilization::Init()
{
if (FESurfaceLoad::Init() == false) return false;
return true;
}
//-----------------------------------------------------------------------------
void FEBackFlowStabilization::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofW;
}
//-----------------------------------------------------------------------------
void FEBackFlowStabilization::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();
// 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();
// 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;
mat3d K = dyad(n)*(m_beta*rho * 2 * vn*da);
// calculate stiffness component
mat3d Kww = K*(H_i * H_j)*tp.alphaf;
Kab.sub(0, 0, Kww);
}
});
}
//-----------------------------------------------------------------------------
vec3d FEBackFlowStabilization::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 FEBackFlowStabilization::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);
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/FEFluidRCRLoad.cpp | .cpp | 6,950 | 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 "FEFluidRCRLoad.h"
#include "FEFluid.h"
#include "FEBioFluid.h"
#include <FECore/FEAnalysis.h>
#include <FECore/log.h>
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidRCRLoad, FESurfaceLoad)
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
FEFluidRCRLoad::FEFluidRCRLoad(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_R = 0.0;
m_pfluid = nullptr;
m_p0 = 0;
m_Rd = 0.0;
m_pd = 0.0;
m_C = 0.0;
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 FEFluidRCRLoad::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;
m_pn = m_pp = m_p0;
m_pdn = m_pdp = m_pd;
m_qn = m_qp = 0;
m_tp = 0;
return true;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEFluidRCRLoad::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 FEFluidRCRLoad::Update()
{
// 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
double e = 0;
bool good = m_pfluid->Dilatation(0, m_pn, 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);
}
}
// Force a mesh update after loads have been updated
ForceMeshUpdate();
}
//-----------------------------------------------------------------------------
//! evaluate the flow rate across this surface at current time
double FEFluidRCRLoad::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->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 FEFluidRCRLoad::LoadVector(FEGlobalVector& R)
{
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidRCRLoad::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
ar & m_pn& m_pp& m_qn& m_qp& m_pdn& m_pdp& m_tp;
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofW & m_dofEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FERealVapor.cpp | .cpp | 14,233 | 383 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FERealVapor.h"
#include <FECore/log.h>
#include <FECore/FEFunction1D.h>
#include <FECore/sys.h>
#include <FECore/tools.h>
#include "FEFluidMaterialPoint.h"
#include "FEThermoFluidMaterialPoint.h"
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FERealVapor, FEElasticFluid)
// material parameters
ADD_PARAMETER(m_Tc , FE_RANGE_GREATER(1.0), "Tc")->setLongName("normalized critical temperature");
ADD_PROPERTY(m_esat , "esat" )->SetLongName("ln(Jsat)");
ADD_PROPERTY(m_psat , "psat" )->SetLongName("ln(Psat/Pr)");
ADD_PROPERTY(m_asat , "asat" )->SetLongName("normalized saturation free energy");
ADD_PROPERTY(m_ssat , "ssat" )->SetLongName("ln(normalized saturation entropy");
ADD_PROPERTY(m_cvsat, "cvsat")->SetLongName("ln(normalized saturation cv");
ADD_PROPERTY(m_D[0] , "D0" )->SetLongName("1st normalized pressure coefficient");
ADD_PROPERTY(m_D[1] , "D1" , FEProperty::Optional)->SetLongName("2nd normalized pressure coefficient");
ADD_PROPERTY(m_D[2] , "D2" , FEProperty::Optional)->SetLongName("3rd normalized pressure coefficient");
ADD_PROPERTY(m_D[3] , "D3" , FEProperty::Optional)->SetLongName("4th normalized pressure coefficient");
ADD_PROPERTY(m_D[4] , "D4" , FEProperty::Optional)->SetLongName("5th normalized pressure coefficient");
ADD_PROPERTY(m_D[5] , "D5" , FEProperty::Optional)->SetLongName("6th normalized pressure coefficient");
ADD_PROPERTY(m_D[6] , "D6" , FEProperty::Optional)->SetLongName("7th normalized pressure coefficient");
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();
FERealVapor::FERealVapor(FEModel* pfem) : FEElasticFluid(pfem)
{
m_nvp = 0;
m_nvc = 0;
m_Pr = m_Tr = 0;
m_Tc = 1;
for (int k=0; k<MAX_NVP; ++k) m_D[k] = nullptr;
for (int k=0; k<MAX_NVC; ++k) m_C[k] = nullptr;
m_psat = m_asat = m_ssat = m_esat = m_cvsat = nullptr;
m_alpha = 0.35; // hard-coded for now
}
//-----------------------------------------------------------------------------
//! initialization
bool FERealVapor::Init()
{
m_Tr = GetGlobalConstant("T");
m_Pr = GetGlobalConstant("P");
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();
m_esat->Init();
m_psat->Init();
m_asat->Init();
m_ssat->Init();
m_cvsat->Init();
m_nvp = 0;
for (int k=0; k<MAX_NVP; ++k) {
if (m_D[k]) {
m_D[k]->Init();
++m_nvp;
}
}
m_nvc = 0;
for (int k=0; k<MAX_NVC; ++k) {
if (m_C[k]) {
m_C[k]->Init();
++m_nvc;
}
}
if (m_nvp < 1) { feLogError("At least one virial coefficient should be provided for the pressure"); return false; }
if (m_nvc < 1) { feLogError("At least one virial coefficient should be provided for cv"); return false; }
return true;
}
//-----------------------------------------------------------------------------
void FERealVapor::Serialize(DumpStream& ar)
{
FEElasticFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_Pr & m_Tr & m_rhor;
ar & m_nvp & m_nvc;
}
//-----------------------------------------------------------------------------
//! gauge pressure
double FERealVapor::Pressure(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double J = 1 + fp.m_ef;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Jsat = exp(m_esat->value(q));
double Psat = exp(m_psat->value(q));
double D[MAX_NVP];
for (int k=0; k<m_nvp; ++k) D[k] = m_D[k]->value(q);
double x = Jsat/J;
double sum = 0;
for (int k=0; k<m_nvp; ++k) sum += D[k]*pow(x,k+1);
double p = Psat*(x + (1-x)*sum) - 1;
return p*m_Pr;
}
//-----------------------------------------------------------------------------
//! specific free energy
double FERealVapor::SpecificFreeEnergy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double asat = m_asat->value(q);
double J = 1 + fp.m_ef;
double Jsat = exp(m_esat->value(q));
double Psat = exp(m_psat->value(q));
double D[MAX_NVP];
for (int k=0; k<m_nvp; ++k) D[k] = m_D[k]->value(q);
double x = Jsat/J;
double sum = 0;
for (int k=1; k<m_nvp; ++k) {
double xk = pow(x,k);
double xkp = xk*x;
sum += D[k]*((1-xkp)/(k+1) - (1-xk)/k);
}
double a = asat - Jsat*(1-1/x) + Psat*Jsat*(log(x) + D[0]*(log(x)+1-x) + sum);
return a*m_Pr/m_rhor;
}
//-----------------------------------------------------------------------------
//! specific entropy
double FERealVapor::SpecificEntropy(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double ssat = exp(m_ssat->value(q));
double J = 1 + fp.m_ef;
double Jsat = exp(m_esat->value(q));
double Psat = exp(m_psat->value(q));
double coef = -m_alpha*(1-exp(-q))/(m_Tc-That);
double dJsat = coef*Jsat*m_esat->derive(q);
double dPsat = coef*Psat*m_psat->derive(q);
double D[MAX_NVP], dD[MAX_NVP];
for (int k=0; k<m_nvp; ++k) {
D[k] = m_D[k]->value(q);
dD[k] = coef*m_D[k]->derive(q);
}
double x = Jsat/J;
double dx = dJsat/J;
double sum1 = 0, sum2 = 0, sum3 = 0;
for (int k=1; k<m_nvp; ++k) {
double xk = pow(x,k);
double xkp = xk*x;
double y = (1-xkp)/(k+1) - (1-xk)/k;
sum1 += D[k]*y;
sum2 += D[k]*xk;
sum3 += dD[k]*y;
}
double z = log(x)+1-x;
double s = ssat - (dPsat*Jsat + Psat*dJsat)*(log(x) + D[0]*z + sum1)
- Psat*(1-x)*dJsat*(D[0] + sum2) - Psat*Jsat*(dD[0]*z + sum3);
return s*m_Pr/(m_Tr*m_rhor);
}
//-----------------------------------------------------------------------------
//! specific strain energy
double FERealVapor::SpecificStrainEnergy(FEMaterialPoint& mp)
{
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
// get the specific free energy
double a = SpecificFreeEnergy(mp);
double That = (m_Tr+tf.m_T)/m_Tr;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Jsat = exp(m_esat->value(q));
double asat = m_asat->value(q)*m_Pr/m_rhor;
// the specific strain energy is the difference between these two values
return a - asat;
}
//-----------------------------------------------------------------------------
//! isochoric specific heat capacity
double FERealVapor::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 < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Jsat = exp(m_esat->value(q));
double x = 1 - Jsat/J;
double cv = exp(m_cvsat->value(q));
for (int k=0; k<m_nvc; ++k) cv += m_C[k]->value(q)*pow(x,k+1);
return cv*m_Pr/(m_Tr*m_rhor);
}
//-----------------------------------------------------------------------------
//! isobaric specific heat capacity
double FERealVapor::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 FERealVapor::Dilatation(const double T, const double p, double& e)
{
// check that the prescribed gauge pressure is valid (positive)
if (p < 0) return false;
// if valid, continue
double Phat = 1 + p/m_Pr;
double That = (T+m_Tr)/m_Tr;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Psat = exp(m_psat->value(q));
// check to make sure that we are in the vapor phase
if (Phat > Psat) return false;
// then continue
double Jsat = exp(m_esat->value(q));
double D[MAX_NVP];
vector <double> B(m_nvp+2,0);
for (int k=0; k<m_nvp; ++k) D[k] = m_D[k]->value(q);
B[0] = -Phat/Psat;
B[1] = 1 + D[0];
B[m_nvp+1] = -D[m_nvp-1];
for (int k=0; k<m_nvp-1; ++k) B[k+2] = D[k+1] - D[k];
double x = (-B[1]+sqrt(B[1]*B[1]-4*B[0]*B[2]))/(2*B[2]);
// check to see if we are infinitesimally close to the saturation curve
if (Psat - Phat < 1e-3) {
// if nearly on saturation curve, use saturation curve dilatation
e = Jsat/x - 1;
return true;
}
// initial guess for J depends if e = 0 or not
double J = (e == 0) ? Jsat/x : 1 + e;
// if one virial coefficient only, we're done
if (m_nvp == 1) { e = J - 1; return true; }
// solve iteratively for J using Newton's method
bool convgd = solvepoly(m_nvp, B, x, true);
J = Jsat/x;
e = J - 1;
return convgd;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to strain J
double FERealVapor::Tangent_Strain(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double J = 1 + fp.m_ef;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Jsat = exp(m_esat->value(q));
double Psat = exp(m_psat->value(q));
double D[MAX_NVP];
for (int k=0; k<m_nvp; ++k) D[k] = m_D[k]->value(q);
double x = Jsat/J;
double sum = 1;
for (int k=0; k<m_nvp; ++k) sum += D[k]*(pow(x,k)*(k+1-x*(k+2)));
double dx = -Jsat/pow(J,2);
double dpJ = Psat*dx*sum;
return dpJ*m_Pr;
}
//-----------------------------------------------------------------------------
//! tangent of pressure with respect to temperature T
double FERealVapor::Tangent_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& fp = *mp.ExtractData<FEFluidMaterialPoint>();
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
double T = tf.m_T + m_Tr;
double That = T/m_Tr;
double J = 1 + fp.m_ef;
double y = (That < m_Tc) ? (m_Tc-That)/(m_Tc-1) : 0;
double q = log(1+pow(y,m_alpha));
double Jsat = exp(m_esat->value(q));
double Psat = exp(m_psat->value(q));
double coef = -m_alpha*(1-exp(-q))/(m_Tc-That);
double dJsat = coef*Jsat*m_esat->derive(q);
double dPsat = coef*Psat*m_psat->derive(q);
double D[MAX_NVP], dD[MAX_NVP];
for (int k=0; k<m_nvp; ++k) {
D[k] = m_D[k]->value(q);
dD[k] = coef*m_D[k]->derive(q);
}
double x = Jsat/J;
double sum1 = 0;
double sum2 = 1;
for (int k=0; k<m_nvp; ++k) {
sum1 += (dPsat*D[k]+Psat*dD[k])*pow(x,k+1);
sum2 += D[k]*(pow(x,k)*(k+1-x*(k+2)));
}
double dx = dJsat/J;
double dpT = x*dPsat + (1-x)*sum1 + Psat*dx*sum2;
return dpT*m_Pr/m_Tr;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEBackFlowStabilization.h | .h | 2,232 | 65 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! Backflow stabilization prescribes a normal traction that opposes
//! backflow on a boundary surface.
class FEBIOFLUID_API FEBackFlowStabilization : public FESurfaceLoad
{
public:
//! constructor
FEBackFlowStabilization(FEModel* pfem);
//! calculate pressure stiffness
void StiffnessMatrix(FELinearSystem& LS) override;
//! calculate residual
void LoadVector(FEGlobalVector& R) override;
//! serialize data
void Serialize(DumpStream& ar) override;
//! initialization
bool Init() override;
protected:
vec3d FluidVelocity(FESurfaceMaterialPoint& mp, double alpha);
protected:
double m_beta; //!< backflow stabilization coefficient
// degrees of freedom
FEDofList m_dofW;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidHeatSupply.cpp | .cpp | 2,416 | 62 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidHeatSupply.h"
#include "FEThermoFluid.h"
#include "FEThermoFluidDomain3D.h"
//-----------------------------------------------------------------------------
FEFluidHeatSupply::FEFluidHeatSupply(FEModel* pfem) : FEBodyLoad(pfem)
{
}
//-----------------------------------------------------------------------------
// NOTE: Work in progress! Working on integrating body loads as model loads
void FEFluidHeatSupply::LoadVector(FEGlobalVector& R)
{
for (int i = 0; i<Domains(); ++i)
{
FEDomain* dom = Domain(i);
FEThermoFluidDomain3D* fdom = dynamic_cast<FEThermoFluidDomain3D*>(dom);
if (fdom) fdom->HeatSupply(R, *this);
}
}
//-----------------------------------------------------------------------------
// NOTE: Work in progress! Working on integrating body loads as model loads
void FEFluidHeatSupply::StiffnessMatrix(FELinearSystem& LS)
{
for (int i = 0; i<Domains(); ++i)
{
FEDomain* dom = Domain(i);
FEThermoFluidDomain3D* fdom = dynamic_cast<FEThermoFluidDomain3D*>(dom);
if (fdom) fdom->HeatSupplyStiffness(LS, *this);
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidTractionLoad.cpp | .cpp | 3,088 | 89 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidTractionLoad.h"
#include <FECore/FESurface.h>
#include <FECore/FEFacetSet.h>
#include <FECore/FEMesh.h>
#include "FEBioFluid.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidTractionLoad, FESurfaceLoad)
ADD_PARAMETER(m_scale, "scale" );
ADD_PARAMETER(m_TC , "traction");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidTractionLoad::FEFluidTractionLoad(FEModel* pfem) : FESurfaceLoad(pfem)
{
m_scale = 1.0;
m_TC = vec3d(0,0,0);
}
//-----------------------------------------------------------------------------
//! allocate storage
void FEFluidTractionLoad::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
m_TC.SetItemList(ps->GetFacetSet());
}
//-----------------------------------------------------------------------------
bool FEFluidTractionLoad::Init()
{
m_dof.Clear();
if (m_dof.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY)) == false) return false;
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the traction load
void FEFluidTractionLoad::LoadVector(FEGlobalVector& R)
{
m_psurf->LoadVector(R, m_dof, true, [&](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
// fluid traction
vec3d t = m_TC(mp)*m_scale;
vec3d f = t*((mp.dxr ^ mp.dxs).norm());
double H = dof_a.shape;
fa[0] = H * f.x;
fa[1] = H * f.y;
fa[2] = H * f.z;
});
}
//-----------------------------------------------------------------------------
//! calculate traction stiffness (there is none)
void FEFluidTractionLoad::StiffnessMatrix(FELinearSystem& LS)
{
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidConstantConductivity.h | .h | 2,267 | 58 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEFluidThermalConductivity.h"
//-----------------------------------------------------------------------------
//! Base class for fluid thermal conductivity materials.
class FEBIOFLUID_API FEFluidConstantConductivity : public FEFluidThermalConductivity
{
public:
FEFluidConstantConductivity(FEModel* pfem) : FEFluidThermalConductivity(pfem) {}
virtual ~FEFluidConstantConductivity() {}
public:
//! calculate thermal conductivity at material point
double ThermalConductivity(FEMaterialPoint& pt) override { return m_K(pt); }
//! tangent of thermal conductivity with respect to strain J
double Tangent_Strain(FEMaterialPoint& mp) override { return 0; }
//! tangent of thermal conductivity with respect to temperature T
double Tangent_Temperature(FEMaterialPoint& mp) override { return 0; };
public:
FEParamDouble m_K; //!< thermal conductivity
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FECrossFluid.h | .h | 2,513 | 68 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEViscousFluid.h"
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Cross fluid
class FEBIOFLUID_API FECrossFluid : public FEViscousFluid
{
public:
//! constructor
FECrossFluid(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
double m_m; //!< exponent
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidNormalTraction.cpp | .cpp | 3,409 | 100 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidNormalTraction.h"
#include "FEBioFluid.h"
#include <FECore/FESurface.h>
#include <FECore/FEFacetSet.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidNormalTraction, FESurfaceLoad)
ADD_PARAMETER(m_traction, "traction");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidNormalTraction::FEFluidNormalTraction(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_traction = 1.0;
}
//-----------------------------------------------------------------------------
//! allocate storage
void FEFluidNormalTraction::SetSurface(FESurface* ps)
{
FESurfaceLoad::SetSurface(ps);
m_traction.SetItemList(ps->GetFacetSet());
}
//-----------------------------------------------------------------------------
//! initialization
bool FEFluidNormalTraction::Init()
{
m_dofW.Clear();
if (m_dofW.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::RELATIVE_FLUID_VELOCITY))) return false;
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
void FEFluidNormalTraction::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofW;
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the traction load
void FEFluidNormalTraction::LoadVector(FEGlobalVector& R)
{
const FETimeInfo& tp = GetTimeInfo();
// evaluate integral over surface
m_psurf->LoadVector(R, m_dofW, false, [&](FESurfaceMaterialPoint& mp, const FESurfaceDofShape &dof_a, vector<double>& fa) {
FESurfaceElement& el = *mp.SurfaceElement();
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);
vec3d normal = dxr ^ dxs;
double tn = m_traction(mp);
vec3d f = normal*tn;
double H = dof_a.shape;
fa[0] = H * f.x;
fa[1] = H * f.y;
fa[2] = H * f.z;
});
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEInitialFluidTemperature.h | .h | 1,488 | 37 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEInitialCondition.h>
class FEInitialFluidTemperature : public FEInitialDOF
{
public:
FEInitialFluidTemperature(FEModel* fem);
bool Init() override;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidPressureLoad.cpp | .cpp | 12,586 | 353 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEThermoFluidPressureLoad.h"
#include "FEBioThermoFluid.h"
#include "FEThermoFluidSolver.h"
#include <FECore/log.h>
#include <FECore/FEModel.h>
#include <FECore/FELinearSystem.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEThermoFluidPressureLoad, FESurfaceConstraint)
ADD_PARAMETER(m_p, "pressure")->setUnits("P")->setLongName("fluid pressure");
ADD_PARAMETER(m_laugon, "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0LAGMULT\0");
BEGIN_PARAM_GROUP("Augmentation");
ADD_PARAMETER(m_tol, "tol")->setLongName("tolerance");
ADD_PARAMETER(m_eps, "penalty");
ADD_PARAMETER(m_naugmin, "minaug");
ADD_PARAMETER(m_naugmax, "maxaug");
END_PARAM_GROUP();
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEThermoFluidPressureLoad::FEThermoFluidPressureLoad(FEModel* pfem) : FESurfaceConstraint(pfem), m_surf(pfem)
{
m_pfluid = nullptr;
m_p = 0;
m_tol = 0.1;
m_laugon = FECore::PENALTY_METHOD;
m_eps = 1.0;
m_naugmin = 0;
m_naugmax = 10;
m_dofEF = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::FLUID_DILATATION), 0);
m_dofT = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::TEMPERATURE), 0);
}
//-----------------------------------------------------------------------------
bool FEThermoFluidPressureLoad::Init()
{
if (FESurfaceConstraint::Init() == false) return false;
m_surf.Init();
// get fluid from first surface element
// assuming the entire surface bounds the same fluid
FESurfaceElement& el = m_surf.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<FEThermoFluid>();
if (m_pfluid == nullptr) return false;
switch (m_laugon) {
case 0:
case 1:
m_Lm.resize(m_surf.Nodes(), 0.0);
m_Lmp.resize(m_surf.Nodes(), 0.0);
break;
case 2:
{
m_EQ.resize(m_surf.Nodes(), -1);
m_Lm.resize(m_surf.Nodes(), 0.0);
m_Lmp.resize(m_surf.Nodes(), 0.0);
}
break;
default:
break;
}
// project the prescribed pressure to the nodes
m_surf.ProjectToNodes(m_p, m_pn);
return true;
}
//-----------------------------------------------------------------------------
// allocate equations
int FEThermoFluidPressureLoad::InitEquations(int neq)
{
if (m_laugon < FECore::LAGMULT_METHOD) return 0;
int n = neq;
for (int i = 0; i < m_surf.Nodes(); ++i) m_EQ[i] = n++;
return n - neq;
}
//-----------------------------------------------------------------------------
void FEThermoFluidPressureLoad::UnpackLM(vector<int>& lm, int n)
{
int ndof;
if (m_laugon < FECore::LAGMULT_METHOD) ndof = 2;
else ndof = 3;
lm.reserve(ndof);
FENode& node = m_surf.Node(n);
lm.push_back(node.m_ID[m_dofEF]);
lm.push_back(node.m_ID[m_dofT]);
if (m_laugon == FECore::LAGMULT_METHOD) lm.push_back(m_EQ[n]);
}
//-----------------------------------------------------------------------------
// Build the matrix profile
void FEThermoFluidPressureLoad::BuildMatrixProfile(FEGlobalMatrix& M)
{
for (int i=0; i<m_surf.Nodes(); ++i) {
vector<int> lm;
UnpackLM(lm, i);
// add it to the pile
M.build_add(lm);
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidPressureLoad::Update(const std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < m_surf.Nodes(); ++i)
{
if (m_EQ[i] != -1) m_Lm[i] = m_Lmp[i] + Ui[m_EQ[i]] + ui[m_EQ[i]];
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidPressureLoad::PrepStep()
{
m_surf.ProjectToNodes(m_p, m_pn);
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < m_surf.Nodes(); ++i)
{
m_Lmp[i] = m_Lm[i];
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidPressureLoad::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui)
{
if (m_laugon < FECore::LAGMULT_METHOD) return;
for (int i = 0; i < m_surf.Nodes(); ++i)
{
if (m_EQ[i] != -1) Ui[m_EQ[i]] += ui[m_EQ[i]];
}
}
//-----------------------------------------------------------------------------
//! serialization
void FEThermoFluidPressureLoad::Serialize(DumpStream& ar)
{
FESurfaceConstraint::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pfluid;
ar & m_dofT & m_dofEF;
if (m_laugon == FECore::AUGLAG_METHOD) ar & m_Lm;
else if (m_laugon > FECore::AUGLAG_METHOD)
ar & m_Lm & m_Lmp;
}
//-----------------------------------------------------------------------------
//! \todo Why is this class not using the FESolver for assembly?
void FEThermoFluidPressureLoad::LoadVector(FEGlobalVector& R, const FETimeInfo& tp)
{
double alpha = tp.alphaf;
if (m_laugon == FECore::LAGMULT_METHOD) {
int ndof = 3;
vector<double> fe(ndof, 0.0);
for (int i=0; i<m_surf.Nodes(); ++i) {
FENode& node = m_surf.Node(i);
double e = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1-alpha);
double T = node.get(m_dofT)*alpha + node.get_prev(m_dofT)*(1-alpha);
double p = m_pfluid->GetElastic()->Pressure(e, T);
double dpJ = m_pfluid->GetElastic()->Tangent_Strain(e, T);
double dpT = m_pfluid->GetElastic()->Tangent_Temperature(e, T);
double lam = m_Lm[i]*alpha + m_Lmp[i]*(1-alpha);
double f = p - m_pn[i];
fe[0] = -lam*dpJ;
fe[1] = -lam*dpT;
fe[2] = -f;
vector<int> lm;
UnpackLM(lm,i);
R.Assemble(lm, fe);
}
}
else {
int ndof = 2;
vector<double> fe(ndof, 0.0);
for (int i=0; i<m_surf.Nodes(); ++i) {
FENode& node = m_surf.Node(i);
double e = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1-alpha);
double T = node.get(m_dofT)*alpha + node.get_prev(m_dofT)*(1-alpha);
double p = m_pfluid->GetElastic()->Pressure(e, T);
double dpJ = m_pfluid->GetElastic()->Tangent_Strain(e, T);
double dpT = m_pfluid->GetElastic()->Tangent_Temperature(e, T);
double p0 = m_pn[i];
double c = m_Lm[i] + m_eps*(p - p0);
fe[0] = -c*dpJ;
fe[1] = -c*dpT;
vector<int> lm;
UnpackLM(lm,i);
R.Assemble(lm, fe);
}
}
}
//-----------------------------------------------------------------------------
//! \todo Why is this class not using the FESolver for assembly?
void FEThermoFluidPressureLoad::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp)
{
double alpha = tp.alphaf;
if (m_laugon == FECore::LAGMULT_METHOD) {
int ndof = 3;
FEElementMatrix ke;
ke.resize(ndof, ndof);
for (int i=0; i<m_surf.Nodes(); ++i) {
ke.zero();
FENode& node = m_surf.Node(i);
double e = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1-alpha);
double T = node.get(m_dofT)*alpha + node.get_prev(m_dofT)*(1-alpha);
double p = m_pfluid->GetElastic()->Pressure(e, T);
double dpJ = m_pfluid->GetElastic()->Tangent_Strain(e, T);
double dpT = m_pfluid->GetElastic()->Tangent_Temperature(e, T);
double lam = m_Lm[i]*alpha + m_Lmp[i]*(1-alpha);
double f = p - m_pn[i];
double dpJ2 = m_pfluid->GetElastic()->Tangent_Strain_Strain(e, T);
double dpJT = m_pfluid->GetElastic()->Tangent_Strain_Temperature(e, T);
double dpT2 = m_pfluid->GetElastic()->Tangent_Temperature_Temperature(e, T);
mat3d Kab(lam*dpJ2, lam*dpJT, dpJ,
lam*dpJT, lam*dpT2, dpT,
dpJ, dpT, 0);
ke.add(0, 0, Kab);
// unpack LM
vector<int> lm;
UnpackLM(lm, i);
ke.SetIndices(lm);
// assemle into global stiffness matrix
LS.Assemble(ke);
}
}
else {
int ndof = 2;
FEElementMatrix ke;
ke.resize(ndof, ndof);
for (int i=0; i<m_surf.Nodes(); ++i) {
ke.zero();
FENode& node = m_surf.Node(i);
double e = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1-alpha);
double T = node.get(m_dofT)*alpha + node.get_prev(m_dofT)*(1-alpha);
double p = m_pfluid->GetElastic()->Pressure(e, T);
double p0 = m_pn[i];
double dpJ = m_pfluid->GetElastic()->Tangent_Strain(e, T);
double dpT = m_pfluid->GetElastic()->Tangent_Temperature(e, T);
double c = m_Lm[i] + m_eps*(p - p0);
double dpJ2 = m_pfluid->GetElastic()->Tangent_Strain_Strain(e, T);
double dpJT = m_pfluid->GetElastic()->Tangent_Strain_Temperature(e, T);
double dpT2 = m_pfluid->GetElastic()->Tangent_Temperature_Temperature(e, T);
ke(0, 0) += m_eps*dpJ*dpJ + c*dpJ2;
ke(0, 1) += m_eps*dpJ*dpT + c*dpJT;
ke(1, 0) += m_eps*dpJ*dpT + c*dpJT;
ke(1, 1) += m_eps*dpT*dpT + c*dpT2;
// unpack LM
vector<int> lm;
UnpackLM(lm, i);
ke.SetIndices(lm);
// assemle into global stiffness matrix
LS.Assemble(ke);
}
}
}
//-----------------------------------------------------------------------------
bool FEThermoFluidPressureLoad::Augment(int naug, const FETimeInfo& tp)
{
if (m_laugon != FECore::AUGLAG_METHOD) return true;
double alpha = tp.alphaf;
// calculate lag multipliers
double L0 = 0, L1 = 0;
for (int i=0; i<m_surf.Nodes(); ++i) {
FENode& node = m_surf.Node(i);
double e = node.get(m_dofEF)*alpha + node.get_prev(m_dofEF)*(1-alpha);
double T = node.get(m_dofT)*alpha + node.get_prev(m_dofT)*(1-alpha);
double p = m_pfluid->GetElastic()->Pressure(e, T);
double lam = m_Lm[i] + m_eps*(p - m_pn[i]);
L0 += m_Lm[i]*m_Lm[i];
L1 += lam*lam;
m_Lmp[i] = lam;
}
L0 = sqrt(L0);
L1 = sqrt(L1);
double d;
if (L1 != 0)
d = fabs((L1 - L0)/L1);
else d = fabs(L1 - L0);
const std::string name = GetName();
feLog("constraint %s: %15.7lg %15.7lg %15.7lg\n", name.c_str(), L0, fabs(L1 - L0), fabs(m_tol*L1));
bool bconv = false;
if (d <= m_tol) bconv = true;
if ((m_naugmax >= 0) && (naug >= m_naugmax)) bconv = true;
if (naug < m_naugmin) bconv = false;
if (bconv == false)
{
for (int i=0; i<m_surf.Nodes(); ++i) m_Lm[i] = m_Lmp[i];
}
return bconv;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidPressureLoad.h | .h | 2,467 | 74 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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 "FEFluid.h"
#include <FECore/FESurfaceLoad.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! The FEConstraintNormalFlow class implements a fluid surface with zero
//! tangential velocity as a linear constraint.
class FEBIOFLUID_API FEFluidPressureLoad : public FESurfaceLoad
{
public:
//! constructor
FEFluidPressureLoad(FEModel* pfem);
//! destructor
~FEFluidPressureLoad() {}
//! calculate traction stiffness (there is none for this load)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! calculate load vector (there is none for this load)
void LoadVector(FEGlobalVector& R) override {}
//! set the dilatation
void Update() override;
//! initialize
bool Init() override;
//! activate
void Activate() override;
//! serialization
void Serialize(DumpStream& ar) override;
protected:
int m_dofEF;
FEFluidMaterial* m_pfluid; //!< pointer to fluid
public:
double m_p0; // prescribed pressure
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIPressure.cpp | .cpp | 6,740 | 215 | //
// FEFluidSolutesPressure.cpp
// FEBioFluid
//
// Created by Jay Shim on 12/10/20.
// Copyright © 2020 febio.org. All rights reserved.
//
#include "stdafx.h"
#include "FEMultiphasicFSIPressure.h"
#include "FEMultiphasicFSI.h"
#include "FEBioMultiphasicFSI.h"
#include <FECore/FEModel.h>
//=============================================================================
BEGIN_FECORE_CLASS(FEMultiphasicFSIPressure, FESurfaceLoad)
ADD_PARAMETER(m_p, "pressure");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEMultiphasicFSIPressure::FEMultiphasicFSIPressure(FEModel* pfem) : FESurfaceLoad(pfem)
{
m_pfs = nullptr;
m_p = 0;
m_dofEF = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_DILATATION), 0);
m_dofC = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION), 0);
m_dof.Clear();
m_dof.AddDof(m_dofEF);
}
//-----------------------------------------------------------------------------
//! initialize
bool FEMultiphasicFSIPressure::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_pfs = dynamic_cast<FEMultiphasicFSI*>(pm);
if (m_pfs == nullptr) return false;
return true;
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEMultiphasicFSIPressure::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 FEMultiphasicFSIPressure::Update()
{
// prescribe this dilatation at the nodes
FESurface* ps = &GetSurface();
int nsol = 0;
double T = 0;
double R = 0;
nsol = m_pfs->Solutes();
T = m_pfs->m_Tabs;
R = m_pfs->m_Rgas;
std::map<int,vector<double>> oscNodes;
std::map<int,vector<double>> caNodes;
//initialize maps based on surface nodal IDs
for (int i=0; i<ps->Nodes(); ++i)
{
oscNodes.insert(pair<int,vector<double> >(ps->Node(i).GetID(), vector<double>()));
caNodes.insert(pair<int,vector<double> >(ps->Node(i).GetID(), 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<ps->Elements(); ++i)
{
FESurfaceElement& el = ps->Element(i);
FEElement* e = el.m_elem[0].pe;
FESolidElement* se = dynamic_cast<FESolidElement*>(e);
if (se) {
double osci[FEElement::MAX_INTPOINTS];
double osco[FEElement::MAX_NODES];
double cai[FEElement::MAX_INTPOINTS];
double cao[FEElement::MAX_NODES];
for (int j=0; j<se->GaussPoints(); ++j) {
FEMaterialPoint* pt = se->GetMaterialPoint(j);
FEMultiphasicFSIMaterialPoint* fsp = pt->ExtractData<FEMultiphasicFSIMaterialPoint>();
if (fsp)
{
osci[j] = m_pfs->GetOsmoticCoefficient()->OsmoticCoefficient(*pt);
cai[j] = fsp->m_ca[0];
for (int isol = 1; isol < nsol; ++isol)
cai[j] += fsp->m_ca[isol];
}
else
{
osci[j] = 0;
cai[j] = 0;
}
}
// project stresses from integration points to nodes
se->project_to_nodes(osci, osco);
se->project_to_nodes(cai, cao);
// only keep the stresses at the nodes of the contact face
for (int j=0; j<el.Nodes(); ++j)
{
oscNodes[el.m_node[j]+1].push_back(osco[se->FindNode(el.m_node[j])]);
caNodes[el.m_node[j]+1].push_back(cao[se->FindNode(el.m_node[j])]);
}
}
//If no solid element, insert all 0s
else{
for (int j=0; j<el.Nodes(); ++j)
{
oscNodes[el.m_node[j]+1].push_back(0);
caNodes[el.m_node[j]+1].push_back(0);
}
}
}
//For each node average the nodal ca and osc and then calculate ef based on desired p
for (int i=0; i<ps->Nodes(); ++i)
{
if (ps->Node(i).m_ID[m_dofEF] < -1)
{
FENode& node = ps->Node(i);
//get osmotic component of pressure
double ca = 0;
double osc = 0;
for (int j = 0; j < caNodes[node.GetID()].size(); ++j)
{
ca += caNodes[node.GetID()][j];
osc += oscNodes[node.GetID()][j];
}
ca /= caNodes[node.GetID()].size();
osc /= caNodes[node.GetID()].size();
double pc = R*T*osc*ca;
//get correct ef for desired pressure
double e = 0;
bool good = false;
good = m_pfs->Fluid()->Dilatation(0, m_p - pc, e);
assert(good);
// set node as having prescribed DOF
node.set(m_dofEF, e);
}
}
/*
for (int i=0; i<ps->Nodes(); ++i)
{
if (ps->Node(i).m_ID[m_dofEF] < -1)
{
FENode& node = ps->Node(i);
//get osmotic component of pressure
double c = 0;
for (int isol = 0; isol < nsol; ++isol)
{
c += node.get(m_dofC + isol);
}
//get correct ef for desired pressure
double e = -1/K*(m_p - R*T*m_osc*c);
// set node as having prescribed DOF
node.set(m_dofEF, e);
}
}
*/
GetFEModel()->SetMeshUpdateFlag(true);
}
//-----------------------------------------------------------------------------
//! calculate residual
void FEMultiphasicFSIPressure::LoadVector(FEGlobalVector& R)
{
}
//-----------------------------------------------------------------------------
//! serialization
void FEMultiphasicFSIPressure::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pfs;
ar & m_dofC;
ar & m_dofEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluid.cpp | .cpp | 6,278 | 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) 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 "FEPolarFluid.h"
#include "FELinearElasticFluid.h"
#include "FENonlinearElasticFluid.h"
#include "FELogNonlinearElasticFluid.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEPolarFluid, FEPolarFluidMaterial)
// material properties
ADD_PARAMETER(m_k , FE_RANGE_GREATER_OR_EQUAL(0.0), "k")->setUnits(UNIT_PRESSURE);
ADD_PARAMETER(m_kg , FE_RANGE_GREATER_OR_EQUAL(0.0), "kg");
ADD_PROPERTY(m_pElastic, "elastic", FEProperty::Optional);
END_FECORE_CLASS();
//============================================================================
// FEPolarFluid
//============================================================================
//-----------------------------------------------------------------------------
//! FEFluidFSI constructor
FEPolarFluid::FEPolarFluid(FEModel* pfem) : FEPolarFluidMaterial(pfem)
{
m_kg = 0;
m_k = 0;
m_pElastic = nullptr;
}
//-----------------------------------------------------------------------------
// returns a pointer to a new material point object
FEMaterialPointData* FEPolarFluid::CreateMaterialPointData()
{
return new FEPolarFluidMaterialPoint(new FEFluidMaterialPoint());
}
//-----------------------------------------------------------------------------
// initialize
bool FEPolarFluid::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);
if (pLN) {
pLN->m_k = m_k;
pLN->m_rhor = m_rhor;
}
else if (pNL) {
pNL->m_k = m_k;
pNL->m_rhor = m_rhor;
}
else if (pLNL) {
pLNL->m_k = m_k;
pLNL->m_rhor = m_rhor;
}
return true;
}
//-----------------------------------------------------------------------------
void FEPolarFluid::Serialize(DumpStream& ar)
{
FEPolarFluidMaterial::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Tr;
}
//-----------------------------------------------------------------------------
//! bulk modulus
double FEPolarFluid::BulkModulus(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& vt = *mp.ExtractData<FEFluidMaterialPoint>();
return -(vt.m_ef+1)*Tangent_Pressure_Strain(mp);
}
//-----------------------------------------------------------------------------
//! elastic pressure
double FEPolarFluid::Pressure(FEMaterialPoint& mp)
{
return m_pElastic->Pressure(mp);
}
//-----------------------------------------------------------------------------
//! elastic pressure from dilatation
double FEPolarFluid::Pressure(const double e, const double T)
{
return m_pElastic->Pressure(e, T);
}
//-----------------------------------------------------------------------------
double FEPolarFluid::Tangent_Pressure_Strain(FEMaterialPoint& mp)
{
return m_pElastic->Tangent_Strain(mp);
}
//-----------------------------------------------------------------------------
double FEPolarFluid::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 FEPolarFluid::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 FEPolarFluid::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 FEPolarFluid::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 FEPolarFluid::Dilatation(const double T, const double p, double& e)
{
e = -p/m_k;
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEConductivityRealVapor.cpp | .cpp | 6,772 | 184 | /*This file 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 "FEConductivityRealVapor.h"
#include "FEThermoFluid.h"
#include "FERealVapor.h"
#include "FEThermoFluidMaterialPoint.h"
#include <FECore/log.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEConductivityRealVapor, FEFluidThermalConductivity)
// parameters
ADD_PARAMETER(m_Kr, "Kr")->setLongName("referential thermal conductivity")->setUnits(UNIT_THERMAL_CONDUCTIVITY);
// properties
ADD_PROPERTY(m_esat , "esat", FEProperty::Optional)->SetLongName("saturation dilatation");
ADD_PROPERTY(m_Ksat , "Ksat", FEProperty::Optional)->SetLongName("normalized saturation thermal conductivity");
ADD_PROPERTY(m_C[0] , "C0" , FEProperty::Optional)->SetLongName("1st K virial coeff");
ADD_PROPERTY(m_C[1] , "C1" , FEProperty::Optional)->SetLongName("2nd K virial coeff");
ADD_PROPERTY(m_C[2] , "C2" , FEProperty::Optional)->SetLongName("3rd K virial coeff");
ADD_PROPERTY(m_C[3] , "C3" , FEProperty::Optional)->SetLongName("4th K virial coeff");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEConductivityRealVapor::FEConductivityRealVapor(FEModel* pfem) : FEFluidThermalConductivity(pfem)
{
m_Ksat = nullptr;
m_esat = nullptr;
for (int k=0; k<MAX_NVC; ++k) m_C[k] = nullptr;
m_Kr = 0;
m_Tr = 0;
}
//-----------------------------------------------------------------------------
//! initialization
bool FEConductivityRealVapor::Init()
{
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_Ksat) m_Ksat->Init();
m_nvc = 0;
for (int k=0; k<MAX_NVC; ++k) {
if (m_C[k]) {
m_C[k]->Init();
++m_nvc;
}
}
return FEFluidThermalConductivity::Init();
}
//-----------------------------------------------------------------------------
void FEConductivityRealVapor::Serialize(DumpStream& ar)
{
FEFluidThermalConductivity::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Kr & m_Tr & m_nvc;
ar & m_Ksat;
for (int i=0; i<MAX_NVC; ++i)
ar & m_C[i];
if (ar.IsLoading()) {
if (m_Ksat) m_Ksat->Init();
for (int i=0; i<MAX_NVC; ++i)
if (m_C[i]) m_C[i]->Init();
}
}
//-----------------------------------------------------------------------------
//! calculate thermal conductivity at material point
double FEConductivityRealVapor::ThermalConductivity(FEMaterialPoint& mp)
{
double K = 1.0;
if (m_Ksat) {
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));
K = m_Ksat->value(q);
double Jsat = exp(m_esat->value(q));
double x = 1 - Jsat/J;
for (int k=0; k<m_nvc; ++k) K += m_C[k]->value(q)*pow(x,k+1);
}
return K*m_Kr;
}
//-----------------------------------------------------------------------------
//! tangent of thermal conductivity with respect to strain J
double FEConductivityRealVapor::Tangent_Strain(FEMaterialPoint& mp)
{
double d = 1e-6;
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
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 Kp = ThermalConductivity(tmp);
fp->m_ef = pf.m_ef-d;
double Km = ThermalConductivity(tmp);
delete ft;
double dKJ = (Kp - Km)/(2*d);
return dKJ;
}
//-----------------------------------------------------------------------------
//! tangent of thermal conductivity with respect to temperature T
double FEConductivityRealVapor::Tangent_Temperature(FEMaterialPoint& mp)
{
double Tr = GetGlobalConstant("T");
double d = 1e-6*Tr;
FEThermoFluidMaterialPoint& tf = *mp.ExtractData<FEThermoFluidMaterialPoint>();
FEFluidMaterialPoint& pf = *mp.ExtractData<FEFluidMaterialPoint>();
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 Kp = ThermalConductivity(tmp);
ft->m_T = tf.m_T-d;
double Km = ThermalConductivity(tmp);
delete ft;
double dKT = (Kp - Km)/(2*d);
return dKT;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEQuemadaFluid.cpp | .cpp | 4,120 | 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 "FEQuemadaFluid.h"
#include "FEFluid.h"
// define the material parameters
BEGIN_FECORE_CLASS(FEQuemadaFluid, FEViscousFluid)
ADD_PARAMETER(m_mu0, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu0")->setUnits("P.t")->setLongName("zero shear rate viscosity");
ADD_PARAMETER(m_H , FE_RANGE_GREATER_OR_EQUAL(0.0), "H")->setLongName("suspension volume fraction");
ADD_PARAMETER(m_k0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "k0");
ADD_PARAMETER(m_ki , FE_RANGE_GREATER_OR_EQUAL(0.0), "kinf");
ADD_PARAMETER(m_gc , FE_RANGE_GREATER(0.0) , "gc")->setUnits("1/t")->setLongName("criticial shear rate");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FEQuemadaFluid::FEQuemadaFluid(FEModel* pfem) : FEViscousFluid(pfem)
{
m_mu0 = 0;
m_H = 0;
m_k0 = 0;
m_ki = 0;
m_gc = 1;
}
//-----------------------------------------------------------------------------
//! viscous stress
mat3ds FEQuemadaFluid::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 FEQuemadaFluid::Tangent_Strain(FEMaterialPoint& mp)
{
return mat3ds(0,0,0,0,0,0);
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to rate of deformation tensor D
tens4ds FEQuemadaFluid::Tangent_RateOfDeformation(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
double grsqrt = sqrt(gdot/m_gc);
double k = (m_k0 + m_ki*grsqrt)/(1+grsqrt);
double mu = m_mu0*pow(1-0.5*k*m_H,-2);
double dmu = (gdot > 0) ? 4*m_mu0*m_H/m_gc*(m_k0 - m_ki)*(1+grsqrt)/grsqrt/pow(-2*(1+grsqrt)+m_H*(m_k0+m_ki*grsqrt),3) : 0.0;
mat3dd I(1.0);
tens4ds c = dyad1s(D)*(2*dmu) + dyad4s(I)*(2*mu);
return c;
}
//-----------------------------------------------------------------------------
//! dynamic viscosity
double FEQuemadaFluid::ShearViscosity(FEMaterialPoint& pt)
{
FEFluidMaterialPoint& vt = *pt.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double gdot = sqrt(2*(D.sqr()).tr());
double grsqrt = sqrt(gdot/m_gc);
double k = (m_k0 + m_ki*grsqrt)/(1+grsqrt);
double mu = m_mu0*pow(1-0.5*k*m_H,-2);
return mu;
}
//-----------------------------------------------------------------------------
//! bulk viscosity
double FEQuemadaFluid::BulkViscosity(FEMaterialPoint& pt)
{
return 2*ShearViscosity(pt)/3.;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidDomain3D.cpp | .cpp | 33,088 | 1,028 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEThermoFluidDomain3D.h"
#include "FEThermoFluidSolver.h"
#include "FEFluidHeatSupply.h"
#include "FECore/log.h"
#include "FECore/DOFS.h"
#include <FECore/FEModel.h>
#include <FECore/FEAnalysis.h>
#include <FECore/sys.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.
FEThermoFluidDomain3D::FEThermoFluidDomain3D(FEModel* pfem) : FESolidDomain(pfem), FEFluidDomain(pfem), m_dofW(pfem), m_dofAW(pfem), m_dof(pfem)
{
m_pMat = 0;
m_btrans = true;
if (pfem)
{
// set the active degrees of freedom list
m_dofW.AddVariable(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::RELATIVE_FLUID_ACCELERATION));
m_dofEF = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::FLUID_DILATATION), 0);
m_dofAEF = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::FLUID_DILATATION_TDERIV), 0);
m_dofT = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::TEMPERATURE), 0);
m_dofAT = pfem->GetDOFIndex(FEBioThermoFluid::GetVariableName(FEBioThermoFluid::TEMPERATURE_TDERIV), 0);
FEDofList dofs(pfem);
dofs.AddDofs(m_dofW);
dofs.AddDof(m_dofEF);
dofs.AddDof(m_dofT);
m_dof = dofs;
}
}
//-----------------------------------------------------------------------------
// \todo I don't think this is being used
FEThermoFluidDomain3D& FEThermoFluidDomain3D::operator = (FEThermoFluidDomain3D& d)
{
m_Elem = d.m_Elem;
m_pMesh = d.m_pMesh;
return (*this);
}
//-----------------------------------------------------------------------------
// get total dof list
const FEDofList& FEThermoFluidDomain3D::GetDOFList() const
{
return m_dof;
}
//-----------------------------------------------------------------------------
//! Assign material
void FEThermoFluidDomain3D::SetMaterial(FEMaterial* pmat)
{
FEDomain::SetMaterial(pmat);
if (pmat)
{
m_pMat = dynamic_cast<FEThermoFluid*>(pmat);
assert(m_pMat);
}
else m_pMat = 0;
}
//-----------------------------------------------------------------------------
bool FEThermoFluidDomain3D::Init()
{
// initialize base class
if (FESolidDomain::Init() == false) return false;
FEModel* pfem = GetFEModel();
m_Tr = GetFEModel()->GetGlobalConstant("T");
return true;
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::Serialize(DumpStream& ar)
{
FESolidDomain::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_pMat;
ar & m_Tr;
ar & m_dof;
ar & m_dofW & m_dofAW;
ar & m_dofEF & m_dofAEF;
ar & m_dofT & m_dofAT;
}
//-----------------------------------------------------------------------------
//! Initialize element data
void FEThermoFluidDomain3D::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();
}
mp.Update(timeInfo);
}
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::InternalForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
int ndpn = 5;
#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 FEThermoFluidDomain3D::ElementInternalForce(FESolidElement& el, vector<double>& fe)
{
int i, n;
// jacobian matrix, inverse jacobian matrix and determinants
double Ji[3][3], detJ;
mat3ds sv;
vec3d gradp, q;
double dpT, dpJ, rho, cv;
const double *H, *Gr, *Gs, *Gt;
int nint = el.GaussPoints();
int neln = el.Nodes();
int ndpn = 5;
// 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>());
FEThermoFluidMaterialPoint& tf = *(mp.ExtractData<FEThermoFluidMaterialPoint>());
// 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->GetViscous()->Stress(mp);
// get the derivative of the elastic pressure with respect to temperature
dpT = m_pMat->GetElastic()->Tangent_Temperature(mp);
// get the derivative of the elastic pressure with respect to strain
dpJ = m_pMat->GetElastic()->Tangent_Strain(mp);
// get the gradient of the elastic pressure
gradp = tf.m_gradT*dpT + pt.m_gradef*dpJ;
// get the heat flux
q = m_pMat->HeatFlux(mp);
// get fluid mass density
rho = m_pMat->Density(mp);
// get the isochoric specific heat capacity
cv = m_pMat->GetElastic()->IsochoricSpecificHeatCapacity(mp);
// get absolute temperature
double T = m_Tr + tf.m_T;
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);
for (i=0; i<neln; ++i)
{
vec3d fs = sv*gradN[i] + gradp*H[i];
double fJ = dJoJ*H[i] + gradN[i]*pt.m_vft;
double fT = q*gradN[i] + H[i]*(((sv - mat3dd(T*dpT))*pt.m_Lf).trace() - rho*cv*tf.m_Tdot);
// 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;
fe[ndpn*i+4] -= fT*detJ;
}
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::BodyForce(FEGlobalVector& R, FEBodyForce& BF)
{
int NE = (int)m_Elem.size();
int ndpn = 5;
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 FEThermoFluidDomain3D::ElementBodyForce(FEBodyForce& BF, FESolidElement& el, vector<double>& fe)
{
// jacobian
double detJ;
double *H;
double* gw = el.GaussWeights();
vec3d f;
// number of nodes
int neln = el.Nodes();
int ndpn = 5;
// 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>();
double dens = m_pMat->Density(mp);
pt.m_r0 = el.Evaluate(r0, n);
detJ = detJ0(el, n)*gw[n];
// get the force
f = BF.force(mp);
H = el.H(n);
for (int i=0; i<neln; ++i)
{
fe[ndpn*i ] -= H[i]*dens*f.x*detJ;
fe[ndpn*i+1] -= H[i]*dens*f.y*detJ;
fe[ndpn*i+2] -= H[i]*dens*f.z*detJ;
}
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::HeatSupply(FEGlobalVector& R, FEFluidHeatSupply& BF)
{
int NE = (int)m_Elem.size();
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 = 5*el.Nodes();
fe.assign(ndof, 0);
// apply body forces
ElementHeatSupply(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 FEThermoFluidDomain3D::ElementHeatSupply(FEFluidHeatSupply& BF, FESolidElement& el, vector<double>& fe)
{
// jacobian
double detJ;
double *H;
double* gw = el.GaussWeights();
double r;
// number of nodes
int neln = el.Nodes();
int ndpn = 5;
// 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>();
double dens = m_pMat->Density(mp);
pt.m_r0 = el.Evaluate(r0, n);
detJ = detJ0(el, n)*gw[n];
// get the force
r = BF.heat(mp);
H = el.H(n);
for (int i=0; i<neln; ++i)
{
fe[ndpn*i+4] += H[i]*dens*r*detJ;
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the stiffness due to body forces
void FEThermoFluidDomain3D::ElementBodyForceStiffness(FEBodyForce& BF, FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int neln = el.Nodes();
int ndof = ke.columns()/neln;
// jacobian
double detJ;
double *H;
double* gw = el.GaussWeights();
vec3d f, k;
// gradient of shape functions
vec3d gradN;
// 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 = detJ0(el, n)*gw[n]*tp.alphaf;
H = el.H(n);
double dens = m_pMat->Density(mp);
// get the force
f = BF.force(mp);
H = el.H(n);
for (int i=0; i<neln; ++i) {
for (int j=0; j<neln; ++j)
{
k = f*(-H[i]*H[j]*dens/(pt.m_ef+1)*detJ);
ke[ndof*i ][ndof*j+3] += k.x;
ke[ndof*i+1][ndof*j+3] += k.y;
ke[ndof*i+2][ndof*j+3] += k.z;
}
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the stiffness due to body forces
void FEThermoFluidDomain3D::ElementHeatSupplyStiffness(FEFluidHeatSupply& BF, FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int neln = el.Nodes();
int ndof = ke.columns()/neln;
// jacobian
double detJ;
double *H;
double* gw = el.GaussWeights();
double r, drT;
// gradient of shape functions
vec3d gradN;
// 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>();
double Jf = 1 + pt.m_ef;
// calculate the jacobian
detJ = detJ0(el, n)*gw[n]*tp.alphaf;
H = el.H(n);
double dens = m_pMat->Density(mp);
// get the heat supply and its temperature derivative
r = BF.heat(mp);
drT = BF.stiffness(mp);
H = el.H(n);
for (int i=0; i<neln; ++i) {
for (int j=0; j<neln; ++j)
{
ke[ndof*i+4][ndof*j+3] -= H[i]*H[j]*dens*r/Jf*detJ;
ke[ndof*i+4][ndof*j+4] += H[i]*H[j]*dens*drT/Jf*detJ;
}
}
}
}
//-----------------------------------------------------------------------------
//! Calculates element material stiffness element matrix
void FEThermoFluidDomain3D::ElementStiffness(FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i5, j, j5, 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 ksi = tp.alpham/(tp.gamma*tp.alphaf)*m_btrans;
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>());
FEThermoFluidMaterialPoint& tf = *(mp.ExtractData<FEThermoFluidMaterialPoint>());
double Jf = 1 + pt.m_ef;
// get the tangents
mat3ds sv = m_pMat->GetViscous()->Stress(mp);
mat3ds svJ = m_pMat->GetViscous()->Tangent_Strain(mp);
mat3ds svT = m_pMat->GetViscous()->Tangent_Temperature(mp);
tens4ds Cv = m_pMat->Tangent_RateOfDeformation(mp);
double dpJ = m_pMat->GetElastic()->Tangent_Strain(mp);
double dpJJ = m_pMat->GetElastic()->Tangent_Strain_Strain(mp);
double dpT = m_pMat->GetElastic()->Tangent_Temperature(mp);
double dpTT = m_pMat->GetElastic()->Tangent_Temperature_Temperature(mp);
double dpJT = m_pMat->GetElastic()->Tangent_Strain_Temperature(mp);
// Jdot/J
double dJoJ = pt.m_efdot/Jf;
double rho = m_pMat->Density(mp);
double cv = m_pMat->GetElastic()->IsochoricSpecificHeatCapacity(mp);
double dcvT = m_pMat->GetElastic()->Tangent_cv_Temperature(mp);
double dcvJ = m_pMat->GetElastic()->Tangent_cv_Strain(mp);
double k = m_pMat->GetConduct()->ThermalConductivity(mp);
double dkJ = m_pMat->GetConduct()->Tangent_Strain(mp);
double dkT = m_pMat->GetConduct()->Tangent_Temperature(mp);
double T = m_Tr + tf.m_T;
// 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, i5=0; i<neln; ++i, i5 += 5)
{
for (j=0, j5 = 0; j<neln; ++j, j5 += 5)
{
mat3d Kvv = vdotTdotv(gradN[i], Cv, gradN[j]);
vec3d kvJ = (svJ*gradN[i])*H[j] + (gradN[j]*dpJ+(tf.m_gradT*dpJT+pt.m_gradef*dpJJ)*H[j])*H[i];
vec3d kvT = (svT*gradN[i])*H[j] + (gradN[j]*dpT+(tf.m_gradT*dpTT+pt.m_gradef*dpJT)*H[j])*H[i];
vec3d kJv = (pt.m_gradef*(H[i]/Jf) + gradN[i])*H[j];
double kJJ = (H[j]*(ksi/dt - dJoJ) + gradN[j]*pt.m_vft)*H[i]/Jf;
double kJT = 0;
vec3d kTv = ((Cv.dot(pt.m_Lf) + sv - mat3dd(T*dpT))*gradN[j] - tf.m_gradT*(rho*cv*H[j]))*H[i];
double kTJ = -dkJ*H[j]*(gradN[i]*tf.m_gradT)
+ H[i]*H[j]*((svJ - mat3dd(T*dpJT))*pt.m_Lf).trace()
+ H[i]*H[j]*rho*(cv/Jf - dcvJ)*tf.m_Tdot;
double kTT = -(tf.m_gradT*(dkT*H[j]) + gradN[j]*k)*gradN[i]
+ H[i]*H[j]*((svT - mat3dd(dpT+T*dpTT))*pt.m_Lf).trace()
- H[i]*H[j]*rho*(dcvT*tf.m_Tdot+ksi*cv/dt)
- H[i]*rho*cv*(gradN[j]*pt.m_vft);
ke[i5 ][j5 ] += Kvv(0,0)*detJ;
ke[i5 ][j5+1] += Kvv(0,1)*detJ;
ke[i5 ][j5+2] += Kvv(0,2)*detJ;
ke[i5 ][j5+3] += kvJ.x*detJ;
ke[i5 ][j5+4] += kvT.x*detJ;
ke[i5+1][j5 ] += Kvv(1,0)*detJ;
ke[i5+1][j5+1] += Kvv(1,1)*detJ;
ke[i5+1][j5+2] += Kvv(1,2)*detJ;
ke[i5+1][j5+3] += kvJ.y*detJ;
ke[i5+1][j5+4] += kvT.y*detJ;
ke[i5+2][j5 ] += Kvv(2,0)*detJ;
ke[i5+2][j5+1] += Kvv(2,1)*detJ;
ke[i5+2][j5+2] += Kvv(2,2)*detJ;
ke[i5+2][j5+3] += kvJ.z*detJ;
ke[i5+2][j5+4] += kvT.z*detJ;
ke[i5+3][j5 ] += kJv.x*detJ;
ke[i5+3][j5+1] += kJv.y*detJ;
ke[i5+3][j5+2] += kJv.z*detJ;
ke[i5+3][j5+3] += kJJ*detJ;
ke[i5+3][j5+4] += kJT*detJ;
ke[i5+4][j5 ] += kTv.x*detJ;
ke[i5+4][j5+1] += kTv.y*detJ;
ke[i5+4][j5+2] += kTv.z*detJ;
ke[i5+4][j5+3] += kTJ*detJ;
ke[i5+4][j5+4] += kTT*detJ;
}
}
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::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 ndof = 5*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 FEThermoFluidDomain3D::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
int ndof = 5*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 FEThermoFluidDomain3D::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf)
{
// 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 ndof = 5*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);
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::HeatSupplyStiffness(FELinearSystem& LS, FEFluidHeatSupply& 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
int ndof = 5*el.Nodes();
ke.resize(ndof, ndof);
ke.zero();
// calculate inertial stiffness
ElementHeatSupplyStiffness(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 FEThermoFluidDomain3D::ElementMassMatrix(FESolidElement& el, matrix& ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int i, i5, j, j5, 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 *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->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, i5=0; i<neln; ++i, i5 += 5)
{
for (j=0, j5 = 0; j<neln; ++j, j5 += 5)
{
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[i5 ][j5 ] += Mv(0,0);
ke[i5 ][j5+1] += Mv(0,1);
ke[i5 ][j5+2] += Mv(0,2);
ke[i5 ][j5+3] += mJ.x;
ke[i5+1][j5 ] += Mv(1,0);
ke[i5+1][j5+1] += Mv(1,1);
ke[i5+1][j5+2] += Mv(1,2);
ke[i5+1][j5+3] += mJ.y;
ke[i5+2][j5 ] += Mv(2,0);
ke[i5+2][j5+1] += Mv(2,1);
ke[i5+2][j5+2] += Mv(2,2);
ke[i5+2][j5+3] += mJ.z;
}
}
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::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 FEThermoFluidDomain3D::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();
// nodal coordinates
const int NELN = FEElement::MAX_NODES;
vec3d v[NELN];
vec3d a[NELN];
double e[NELN];
double ae[NELN];
double T[NELN];
double aT[NELN];
for (int j=0; j<neln; ++j) {
FENode& node = m_pMesh->Node(el.m_node[j]);
v[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);
a[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);
e[j] = node.get(m_dofEF)*alphaf + node.get_prev(m_dofEF)*(1-alphaf);
ae[j] = node.get(m_dofAEF)*alpham + node.get_prev(m_dofAEF)*(1-alpham);
T[j] = node.get(m_dofT)*alphaf + node.get_prev(m_dofT)*(1-alphaf);
aT[j] = node.get(m_dofAT)*alpham + node.get_prev(m_dofAT)*(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>());
FEThermoFluidMaterialPoint& tf = *(mp.ExtractData<FEThermoFluidMaterialPoint>());
// material point data
pt.m_vft = el.Evaluate(v, n);
pt.m_Lf = gradient(el, v, n);
pt.m_aft = pt.m_Lf*pt.m_vft;
if (m_btrans) pt.m_aft += el.Evaluate(a, n);
pt.m_ef = el.Evaluate(e, n);
pt.m_gradef = gradient(el, e, n);
pt.m_efdot = pt.m_gradef*pt.m_vft;
if (m_btrans) pt.m_efdot += el.Evaluate(ae, n);
tf.m_T = el.Evaluate(T, n);
tf.m_gradT = gradient(el, T, n);
tf.m_Tdot = tf.m_gradT*pt.m_vft;
if (m_btrans) tf.m_Tdot += el.Evaluate(aT, n);
// calculate the stress at this material point
pt.m_sf = m_pMat->Stress(mp);
// calculate the fluid pressure
pt.m_pf = m_pMat->Pressure(mp);
// calculate the heat flux
tf.m_q = m_pMat->HeatFlux(mp);
// calculate remaining entries of thermofluid material point
// TODO: Not sure that we need any of these (consider taking them out)
tf.m_k = m_pMat->BulkModulus(mp);
tf.m_K = m_pMat->GetConduct()->ThermalConductivity(mp);
tf.m_dKJ = m_pMat->GetConduct()->Tangent_Strain(mp);
tf.m_dKT = m_pMat->GetConduct()->Tangent_Temperature(mp);
tf.m_cv = m_pMat->GetElastic()->IsochoricSpecificHeatCapacity(mp);
tf.m_dcvJ = m_pMat->GetElastic()->Tangent_cv_Strain(mp);
tf.m_dcvT = m_pMat->GetElastic()->Tangent_cv_Temperature(mp);
tf.m_cp = m_pMat->GetElastic()->IsobaricSpecificHeatCapacity(mp);
}
}
//-----------------------------------------------------------------------------
void FEThermoFluidDomain3D::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
int ndof = 5*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 FEThermoFluidDomain3D::ElementInertialForce(FESolidElement& el, vector<double>& fe)
{
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->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[5*i ] -= f.x*detJ;
fe[5*i+1] -= f.y*detJ;
fe[5*i+2] -= f.z*detJ;
}
}
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidMaterialPoint.h | .h | 2,517 | 66 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! Fluid material point class.
//
class FEBIOFLUID_API FEFluidMaterialPoint : public FEMaterialPointData
{
public:
//! constructor
FEFluidMaterialPoint(FEMaterialPointData* pt = 0);
//! create a shallow copy
FEMaterialPointData* Copy();
//! data serialization
void Serialize(DumpStream& ar);
//! Data initialization
void Init();
public:
mat3ds RateOfDeformation() const { return m_Lf.sym(); }
mat3da Spin() { return m_Lf.skew(); }
vec3d Vorticity() const { return vec3d(m_Lf(2,1)-m_Lf(1,2), m_Lf(0,2)-m_Lf(2,0), m_Lf(1,0)-m_Lf(0,1)); }
public:
// fluid data
vec3d m_r0; //!< material position
vec3d m_vft; //!< fluid velocity
vec3d m_aft; //!< fluid acceleration
mat3d m_Lf; //!< fluid velocity gradient
double m_ef; //!< fluid dilatation
double m_efdot; //!< material time derivative of ef
vec3d m_gradef; //!< gradient of ef
double m_pf; //!< elastic fluid pressure
mat3ds m_sf; //!< fluid stress
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFixedFluidDilatation.h | .h | 1,467 | 37 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2020 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEFixedBC.h>
class FEFixedFluidDilatation : public FEFixedBC
{
public:
FEFixedFluidDilatation(FEModel* fem);
bool Init() override;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidVelocity.cpp | .cpp | 4,884 | 148 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEFluidVelocity.h"
#include <FECore/log.h>
#include "FEBioFluid.h"
//=============================================================================
BEGIN_FECORE_CLASS(FEFluidVelocity, FESurfaceLoad)
ADD_PARAMETER(m_scale , "scale");
ADD_PARAMETER(m_velocity, "velocity");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FEFluidVelocity::FEFluidVelocity(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem), m_dofEF(pfem)
{
m_scale = 1.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.AddVariable(FEBioFluid::GetVariableName(FEBioFluid::FLUID_DILATATION));
}
}
//-----------------------------------------------------------------------------
//! Calculate the residual for the prescribed normal component of velocity
void FEFluidVelocity::LoadVector(FEGlobalVector& R)
{
m_psurf->LoadVector(R, m_dofEF, true, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) {
// calculate the tangent vectors
vec3d v = m_velocity(mp);
vec3d nu = mp.dxr ^ mp.dxs;
double da = nu.unit();
double vn = (v*nu)*m_scale;
double H = dof_a.shape;
fa[0] = H * vn * da;
});
}
//-----------------------------------------------------------------------------
//! initialize
bool FEFluidVelocity::Init()
{
m_dof.Clear();
m_dof.AddDofs(m_dofW);
m_dof.AddDofs(m_dofEF);
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FEFluidVelocity::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_dofW[0], DOF_PRESCRIBED);
node.set_bc(m_dofW[1], DOF_PRESCRIBED);
node.set_bc(m_dofW[2], DOF_PRESCRIBED);
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
//! Evaluate and prescribe the nodal velocities
void FEFluidVelocity::Update()
{
// evaluate nodal velocities from boundary cards
FESurface* ps = &GetSurface();
vector<vec3d> VN(ps->Nodes(), vec3d(0, 0, 0));
vector<int> nf(ps->Nodes(), 0);
for (int iel = 0; iel < ps->Elements(); ++iel)
{
FESurfaceElement& el = m_psurf->Element(iel);
// nr of element nodes
int neln = el.Nodes();
for (int i = 0; i < neln; ++i)
{
FESurfaceMaterialPoint mp;
mp.m_elem = ⪙
mp.m_index = i; // this is a node index, but we really need a gauss-point index
VN[el.m_lnode[i]] += m_velocity(mp);
++nf[el.m_lnode[i]];
}
}
for (int i = 0; i < ps->Nodes(); ++i) VN[i] /= nf[i];
for (int i=0; i<ps->Nodes(); ++i)
{
// evaluate the nodal velocity
vec3d v = VN[i]*m_scale;
FENode& node = ps->Node(i);
if (node.m_ID[m_dofW[0]] < -1) node.set(m_dofW[0], v.x);
if (node.m_ID[m_dofW[1]] < -1) node.set(m_dofW[1], v.y);
if (node.m_ID[m_dofW[2]] < -1) node.set(m_dofW[2], v.z);
}
}
//-----------------------------------------------------------------------------
//! serialization
void FEFluidVelocity::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_bpv & m_dofW & m_dofEF;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidHeatSupplyConst.h | .h | 2,051 | 56 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEFluidHeatSupply.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 FEFluidHeatSupplyConst : public FEFluidHeatSupply
{
public:
//! constructor
FEFluidHeatSupplyConst(FEModel* pfem);
public:
//! calculate the body force at a material point
double heat(FEMaterialPoint& pt) override;
//! calculate constribution to stiffness matrix
double stiffness(FEMaterialPoint& pt) override { return 0; }
public:
double m_r; //!< specific heat supply
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEViscousFluid.h | .h | 2,444 | 64 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FEMaterial.h>
#include <FECore/tens4d.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! Base class for the viscous part of the fluid response.
//! These materials provide the viscous stress and its tangents.
//!
class FEBIOFLUID_API FEViscousFluid : public FEMaterialProperty
{
public:
FEViscousFluid(FEModel* pfem) : FEMaterialProperty(pfem) {}
virtual ~FEViscousFluid() {}
//! viscous stress
virtual mat3ds Stress(FEMaterialPoint& pt) = 0;
//! tangent of stress with respect to strain J
virtual mat3ds Tangent_Strain(FEMaterialPoint& mp) = 0;
//! tangent of stress with respect to rate of deformation tensor D
virtual tens4ds Tangent_RateOfDeformation(FEMaterialPoint& mp) = 0;
//! tangent of stress with respect to temperature
virtual mat3ds Tangent_Temperature(FEMaterialPoint& mp) = 0;
//! dynamic viscosity
virtual double ShearViscosity(FEMaterialPoint& mp) = 0;
//! bulk viscosity
virtual double BulkViscosity(FEMaterialPoint& mp) = 0;
FECORE_BASE_CLASS(FEViscousFluid)
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEThermoFluidSolver.h | .h | 6,174 | 175 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 FEThermoFluidSolver class solves thermo-fluid mechanics problems
//! It can deal with quasi-static and dynamic problems
//!
class FEBIOFLUID_API FEThermoFluidSolver : public FENewtonSolver
{
public:
enum SOLVE_STRATEGY {
SOLVE_COUPLED, // monolithic solution approach
SOLVE_SEQUENTIAL // first solve velocity+dilatation, then temperature
};
//! constructor
FEThermoFluidSolver(FEModel* pfem);
//! destructor
~FEThermoFluidSolver();
//! 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);
void GetTemperatureData(vector<double>& ti, vector<double>& ui);
public:
// convergence tolerances
double m_Vtol; //!< velocity tolerance
double m_Ftol; //!< dilatation tolerance
double m_Ttol; //!< temperature tolerance
double m_minJf; //!< minimum allowable compression ratio
double m_minT; //!< minimum allowable absolute temperature
double m_Tmin; //!< threshold for detecting sudden drop in concentration
double m_Tmax; //!< threshold for detecting sudden increase in concentration
int m_Tnum; //!< minimum number of points at which C drops suddenly
public:
// equation numbers
int m_nveq; //!< number of equations related to velocity dofs
int m_ndeq; //!< number of equations related to dilatation dofs
int m_nteq; //!< number of equations related to temperature 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
vector<double> m_ti; //!< temperature increment vector
vector<double> m_Ti; //!< Total temperature 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;
FEDofList m_dofT;
int m_dofAEF;
int m_dofAT;
int m_solve_strategy;
private:
bool m_sudden_T_change;
// declare the parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FETempDependentConductivity.h | .h | 2,520 | 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) 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 FETempDependentConductivity : public FEFluidThermalConductivity
{
public:
FETempDependentConductivity(FEModel* pfem);
virtual ~FETempDependentConductivity() {}
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:
FEFunction1D* m_Khat; //!< normalized thermal conductivity
double m_Kr; //!< thermal conductivity at reference temperature
double m_Tr; //!< reference temperature
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FERealGas.h | .h | 4,473 | 112 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 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>
//-----------------------------------------------------------------------------
//! Base class for the viscous part of the fluid response.
//! These materials provide the viscous stress and its tangents.
//!
class FEBIOFLUID_API FERealGas : public FEElasticFluid
{
public:
enum { MAX_NVA = 7, MAX_NVC = 4 };
public:
FERealGas(FEModel* pfem);
~FERealGas() {}
//! 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_R; //!< universal gas constant
double m_Pr; //!< referential absolute pressure
double m_Tr; //!< referential absolute temperature
double m_rhor; //!< referential mass density
int m_nva; //!< number of virial coefficients for pressure constitutive relation
int m_nvc; //!< number of virial coefficients for isochoric specific heat capacity
FEFunction1D* m_a0; //!< specific free energy at zero pressure
FEFunction1D* m_A[MAX_NVA]; //!< non-dimensional virial coefficients for pressure constitutive relation
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/FEFluidFSI.cpp | .cpp | 3,635 | 103 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEFluidFSI.h"
#include <FECore/FECoreKernel.h>
#include <FECore/DumpStream.h>
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEFluidFSI, FEMaterial)
// material properties
ADD_PROPERTY(m_pSolid, "solid", FEProperty::Required | FEProperty::TopLevel);
ADD_PROPERTY(m_pFluid, "fluid");
END_FECORE_CLASS();
//============================================================================
// FEFSIMaterialPoint
//============================================================================
FEFSIMaterialPoint::FEFSIMaterialPoint(FEMaterialPointData* pt) : FEMaterialPointData(pt) {}
//-----------------------------------------------------------------------------
FEMaterialPointData* FEFSIMaterialPoint::Copy()
{
FEFSIMaterialPoint* pt = new FEFSIMaterialPoint(*this);
if (m_pNext) pt->m_pNext = m_pNext->Copy();
return pt;
}
//-----------------------------------------------------------------------------
void FEFSIMaterialPoint::Serialize(DumpStream& ar)
{
FEMaterialPointData::Serialize(ar);
ar & m_w & m_aw & m_Jdot & m_ss;
}
//-----------------------------------------------------------------------------
void FEFSIMaterialPoint::Init()
{
m_w = m_aw = vec3d(0,0,0);
m_Jdot = 0;
m_ss.zero();
FEMaterialPointData::Init();
}
//============================================================================
// FEFluidFSI
//============================================================================
//-----------------------------------------------------------------------------
//! FEFluidFSI constructor
FEFluidFSI::FEFluidFSI(FEModel* pfem) : FEMaterial(pfem)
{
m_pSolid = 0;
m_pFluid = 0;
}
//-----------------------------------------------------------------------------
// returns a pointer to a new material point object
FEMaterialPointData* FEFluidFSI::CreateMaterialPointData()
{
FEFluidMaterialPoint* fpt = new FEFluidMaterialPoint(m_pSolid->CreateMaterialPointData());
return new FEFSIMaterialPoint(fpt);
}
//-----------------------------------------------------------------------------
// initialize
bool FEFluidFSI::Init()
{
m_pFluid->Init();
m_pSolid->Init();
// set the solid density to zero (required for the solid of a FSI domain)
m_pSolid->SetDensity(0.0);
return FEMaterial::Init();
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEFluidNaturalHeatFlux.h | .h | 2,174 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FECore/FESurfaceLoad.h>
#include <FECore/FEModelParam.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! FEFluidNormalHeatFlux is a thermo-fluid surface that has a normal
//! heat flux prescribed on it, equal to what's coming underneath it
class FEBIOFLUID_API FEFluidNaturalHeatFlux : public FESurfaceLoad
{
public:
//! constructor
FEFluidNaturalHeatFlux(FEModel* pfem);
//! initialization
bool Init() override;
//! Set the surface to apply the load to
void SetSurface(FESurface* ps) override;
//! calculate load vector
void LoadVector(FEGlobalVector& R) override;
//! calculate heat flux stiffness (there is none)
void StiffnessMatrix(FELinearSystem& LS) override {}
//! serialization
void Serialize(DumpStream& ar) override;
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEPolarFluidMaterial.h | .h | 3,224 | 85 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEFluidMaterial.h"
#include <FEBioMech/FEBodyForce.h>
#include "FEFluidMaterialPoint.h"
#include "FEViscousFluid.h"
#include "FEViscousPolarFluid.h"
//-----------------------------------------------------------------------------
//! Base class for fluid materials.
class FEBIOFLUID_API FEPolarFluidMaterial : public FEFluidMaterial
{
public:
FEPolarFluidMaterial(FEModel* pfem);
virtual ~FEPolarFluidMaterial() {}
public:
//! calculate stress at material point
virtual mat3ds Stress(FEMaterialPoint& pt) override = 0;
//! tangent of stress with respect to strain J
virtual mat3ds Tangent_Strain(FEMaterialPoint& mp) override = 0;
//! elastic fluid pressure
virtual double Pressure(FEMaterialPoint& mp) override = 0;
//! tangent of elastic pressure with respect to strain J
virtual double Tangent_Pressure_Strain(FEMaterialPoint& mp) override = 0;
//! 2nd tangent of elastic pressure with respect to strain J
virtual double Tangent_Pressure_Strain_Strain(FEMaterialPoint& mp) override = 0;
//! bulk modulus
virtual double BulkModulus(FEMaterialPoint& mp) override = 0;
//! strain energy density
virtual double StrainEnergyDensity(FEMaterialPoint& mp) override = 0;
//! invert effective pressure-dilatation relation
virtual bool Dilatation(const double T, const double p, double& e) override = 0;
//! evaluate temperature
virtual double Temperature(FEMaterialPoint& mp) override = 0;
//! return viscous part
FEViscousPolarFluid* GetViscousPolar() { return m_pViscpol; }
//! fluid pressure from state variables
virtual double Pressure(const double ef, const double T) override = 0;
private: // material properties
FEViscousPolarFluid* m_pViscpol; //!< pointer to viscous polar part of fluid material
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEConstraintUniformFlow.h | .h | 3,178 | 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 <FECore/FEAugLagLinearConstraint.h>
#include <FECore/FESurface.h>
#include "febiofluid_api.h"
//-----------------------------------------------------------------------------
//! The FEConstraintUniformFlow class implements a fluid surface with zero
//! tangential velocity as a linear constraint.
class FEBIOFLUID_API FEConstraintUniformFlow : public FESurfaceConstraint
{
public:
//! constructor
FEConstraintUniformFlow(FEModel* pfem);
//! destructor
~FEConstraintUniformFlow() {}
//! Activation
void Activate() override;
//! initialization
bool Init() override;
//! Get the surface
FESurface* GetSurface() override { return &m_surf; }
//! update
void Update() 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;
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;
double m_vbar; //! mean normal velocity
vector<vec3d> m_nn; //! nodal normals at initialization
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FEViscousPolarLinear.cpp | .cpp | 3,787 | 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) 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 "FEViscousPolarLinear.h"
#include "FEFluidMaterialPoint.h"
#include "FEPolarFluidMaterialPoint.h"
// define the material parameters
BEGIN_FECORE_CLASS(FEViscousPolarLinear, FEViscousPolarFluid)
ADD_PARAMETER(m_tau, FE_RANGE_GREATER_OR_EQUAL(0.0), "tau");
ADD_PARAMETER(m_alpha, "alpha");
ADD_PARAMETER(m_beta , FE_RANGE_GREATER_OR_EQUAL(0.0), "beta");
ADD_PARAMETER(m_gamma, FE_RANGE_GREATER_OR_EQUAL(0.0), "gamma");
END_FECORE_CLASS();
//! constructor
FEViscousPolarLinear::FEViscousPolarLinear(FEModel* pfem) : FEViscousPolarFluid(pfem)
{
m_tau = m_alpha = m_beta = m_gamma = 0;
}
//! dual vector of non-symmetric part of viscous stress in polar fluid
vec3d FEViscousPolarLinear::SkewStressDualVector(FEMaterialPoint& mp)
{
FEFluidMaterialPoint* pt = (mp.ExtractData<FEFluidMaterialPoint>());
FEPolarFluidMaterialPoint* pf = (mp.ExtractData<FEPolarFluidMaterialPoint>());
vec3d h = pf ? pf->m_gf - pt->Vorticity()/2 : - pt->Vorticity()/2;
return h*(-2*m_tau);
}
//! non-symmetric part of viscous stress in polar fluid
mat3da FEViscousPolarLinear::SkewStress(FEMaterialPoint& mp)
{
return mat3da(SkewStressDualVector(mp));
}
//! tangent of stress with respect to strain J
mat3da FEViscousPolarLinear::SkewTangent_Strain(FEMaterialPoint& mp)
{
return mat3da(0,0,0);
}
//! tangent of stress with respect to relative rate of rotation tensor H
mat3d FEViscousPolarLinear::SkewTangent_RateOfRotation(FEMaterialPoint& mp)
{
return mat3dd(-2*m_tau);
}
//! viscous couple stress in polar fluid
mat3d FEViscousPolarLinear::CoupleStress(FEMaterialPoint& mp)
{
FEPolarFluidMaterialPoint* pf = (mp.ExtractData<FEPolarFluidMaterialPoint>());
mat3d Psi = pf->m_Psi;
mat3d M = mat3dd(Psi.trace()*m_alpha) + Psi*(m_beta+m_gamma) + Psi.transpose()*(m_beta - m_gamma);
return M;
}
//! tangent of viscous couple stress with respect to strain J
mat3d FEViscousPolarLinear::CoupleTangent_Strain(FEMaterialPoint& mp)
{
return mat3d(0.);
}
//! tangent of viscous couple stress with respect to rate of rotation tensor g (left-minor transpose of...)
tens4d FEViscousPolarLinear::CoupleTangent_RateOfRotation(FEMaterialPoint& mp)
{
mat3dd I(1);
tens4d m = dyad1(I,I)*m_alpha + dyad2(I,I)*(m_beta-m_gamma) + dyad3(I,I)*(m_beta+m_gamma);
return m;
}
//! dynamic viscosity
double FEViscousPolarLinear::RelativeRotationalViscosity(FEMaterialPoint& mp)
{
return m_tau;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FENewtonianThermoFluid.cpp | .cpp | 6,549 | 193 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FENewtonianThermoFluid.h"
#include "FEFluid.h"
#include "FEBiphasicFSI.h"
#include "FEThermoFluid.h"
#include <FECore/log.h>
// define the material parameters
BEGIN_FECORE_CLASS(FENewtonianThermoFluid, FEViscousFluid)
ADD_PARAMETER(m_kappa, FE_RANGE_GREATER_OR_EQUAL(0.0), "kappa")->setUnits(UNIT_VISCOSITY)->setLongName("bulk viscosity");
ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu" )->setUnits(UNIT_VISCOSITY)->setLongName("shear viscosity");
// properties
ADD_PROPERTY(m_kappahat, "khat" ,FEProperty::Optional)->SetLongName("normalized bulk viscosity");
ADD_PROPERTY(m_muhat , "muhat",FEProperty::Optional)->SetLongName("normalized shear viscosity");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! Constructor.
FENewtonianThermoFluid::FENewtonianThermoFluid(FEModel* pfem) : FEViscousFluid(pfem)
{
m_kappa = 0;
m_mu = 0;
m_Tr = 0;
m_kappahat = nullptr;
m_muhat = nullptr;
}
//-----------------------------------------------------------------------------
//! initialization
bool FENewtonianThermoFluid::Init()
{
if (m_kappahat || m_muhat) {
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_kappahat) m_kappahat->Init();
if (m_muhat) m_muhat->Init();
return FEViscousFluid::Init();
}
//-----------------------------------------------------------------------------
void FENewtonianThermoFluid::Serialize(DumpStream& ar)
{
FEViscousFluid::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_Tr;
}
//-----------------------------------------------------------------------------
//! viscous stress
mat3ds FENewtonianThermoFluid::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 FENewtonianThermoFluid::Tangent_Strain(FEMaterialPoint& mp)
{
return mat3ds(0,0,0,0,0,0);
}
//-----------------------------------------------------------------------------
//! tangent of stress with respect to rate of deformation tensor D
tens4ds FENewtonianThermoFluid::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 FENewtonianThermoFluid::Tangent_Temperature(FEMaterialPoint& mp)
{
FEFluidMaterialPoint& vt = *mp.ExtractData<FEFluidMaterialPoint>();
mat3ds D = vt.RateOfDeformation();
double dmu = TangentShearViscosityTemperature(mp);
double dkappa = TangentBulkViscosityTemperature(mp);
mat3ds ds = mat3dd(1.0)*(D.tr()*(dkappa - 2.*dmu/3.)) + D*(2*dmu);
return ds;
}
//-----------------------------------------------------------------------------
//! dynamic shear viscosity
double FENewtonianThermoFluid::ShearViscosity(FEMaterialPoint& mp)
{
double mu = m_mu;
if (m_muhat) {
FEThermoFluidMaterialPoint* tf = mp.ExtractData<FEThermoFluidMaterialPoint>();
if (tf) {
double That = (tf->m_T+m_Tr)/m_Tr;
mu *= m_muhat->value(That);
}
}
return mu;
}
//-----------------------------------------------------------------------------
//! dynamic shear viscosity tangent w.r.t. temperature
double FENewtonianThermoFluid::TangentShearViscosityTemperature(FEMaterialPoint& mp)
{
double dmu = 0;
if (m_muhat) {
FEThermoFluidMaterialPoint* tf = mp.ExtractData<FEThermoFluidMaterialPoint>();
if (tf) {
double That = (tf->m_T+m_Tr)/m_Tr;
dmu = m_muhat->derive(That)*m_mu/m_Tr;
}
}
return dmu;
}
//-----------------------------------------------------------------------------
//! bulk viscosity
double FENewtonianThermoFluid::BulkViscosity(FEMaterialPoint& mp)
{
double kappa = m_kappa;
if (m_kappa) {
FEThermoFluidMaterialPoint* tf = mp.ExtractData<FEThermoFluidMaterialPoint>();
if (tf) {
double That = (tf->m_T+m_Tr)/m_Tr;
kappa *= m_kappahat->value(That);
}
}
return kappa;
}
//-----------------------------------------------------------------------------
//! bulk viscosity tangent w.r.t. temperature
double FENewtonianThermoFluid::TangentBulkViscosityTemperature(FEMaterialPoint& mp)
{
double dkappa = 0;
if (m_kappa) {
FEThermoFluidMaterialPoint* tf = mp.ExtractData<FEThermoFluidMaterialPoint>();
if (tf) {
double That = (tf->m_T+m_Tr)/m_Tr;
dkappa = m_kappahat->derive(That)*m_kappa/m_Tr;
}
}
return dkappa;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSI.h | .h | 8,323 | 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) 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 <FEBioMech/FEElasticMaterial.h>
#include "FEFluidFSI.h"
#include "FEBiphasicFSI.h"
#include "FEMultiphasicFSI.h"
#include <FEBioMix/FEHydraulicPermeability.h>
#include <FEBioMech/FEBodyForce.h>
#include "FEFluid.h"
#include <FEBioMix/FESolute.h>
#include <FEBioMix/FESoluteInterface.h>
#include <FEBioMix/FEOsmoticCoefficient.h>
#include <FEBioMix/FEChemicalReaction.h>
#include <FECore/FEModelParam.h>
//-----------------------------------------------------------------------------
//! FSI material point class.
//
class FEBIOFLUID_API FEMultiphasicFSIMaterialPoint : public FEMaterialPointData
{
public:
//! constructor
FEMultiphasicFSIMaterialPoint(FEMaterialPointData* pt);
//! create a shallow copy
FEMaterialPointData* Copy();
//! data serialization
void Serialize(DumpStream& ar);
//! Data initialization
void Init();
public:
double Osmolarity() const;
public:
// Multiphasic FSI material data
int m_nsol; //!< number of solutes
vector<double> m_c; //!< effective solute concentration
vector<double> m_ca; //!< effective solute concentration
vector<vec3d> m_gradc; //!< spatial gradient of solute concentration
vector<vec3d> m_j; //!< solute molar flux
vector<double> m_cdot; //!< material time derivative of solute concentration following fluid
double m_psi; //!< electric potential
vec3d m_Ie; //!< current density
double m_pe; //!< effective fluid pressure
double m_cF; //!< fixed charge density in current configuration
vector<double> m_k; //!< solute partition coefficient
vector<double> m_dkdJ; //!< 1st deriv of m_k with strain (J)
vector<double> m_dkdJJ; //!< 2nd deriv of m_k with strain (J)
vector< vector<double> > m_dkdc; //!< 1st deriv of m_k with effective concentration
vector< vector<double> > m_dkdJc; //!< cross deriv of m_k with J and c
vector< vector< vector<double> > > m_dkdcc; // 2nd deriv of m_k with c
};
//-----------------------------------------------------------------------------
//! Base class for FluidFSI materials.
class FEBIOFLUID_API FEMultiphasicFSI : public FEBiphasicFSI, public FESoluteInterface_T<FEMultiphasicFSIMaterialPoint>
{
public:
FEMultiphasicFSI(FEModel* pfem);
// returns a pointer to a new material point object
FEMaterialPointData* CreateMaterialPointData() override;
//! performs initialization
bool Init() override;
//! Serialization
void Serialize(DumpStream& ar) override;
public:
//! calculate inner stress at material point
mat3ds Stress(FEMaterialPoint& pt);
//! return the diffusivity tensor as a matrix
void Diffusivity(double k[3][3], FEMaterialPoint& pt, int sol);
//! return the diffusivity as a tensor
mat3ds Diffusivity(FEMaterialPoint& pt, int sol);
//! return the inverse diffusivity as a tensor
mat3ds InvDiffusivity(FEMaterialPoint& pt, int sol);
//! return the tangent diffusivity tensor
tens4dmm Diffusivity_Tangent_Strain(FEMaterialPoint& pt, int isol);
//! return the tangent diffusivity tensor
mat3ds Diffusivity_Tangent_Concentration(FEMaterialPoint& pt, int isol, int jsol);
//! return the diffusivity property
FESoluteDiffusivity* GetDiffusivity(int sol) { return m_pSolute[sol]->m_pDiff; }
//! calculate solute molar flux
vec3d SoluteFlux(FEMaterialPoint& pt, const int sol);
//! actual concentration (as opposed to effective concentration)
double ConcentrationActual(FEMaterialPoint& pt, const int sol);
//! actual fluid pressure (as opposed to effective pressure)
double PressureActual(FEMaterialPoint& pt);
//! fixed charge density
virtual double FixedChargeDensity(FEMaterialPoint& pt);
//! partition coefficient
double PartitionCoefficient(FEMaterialPoint& pt, const int sol);
//! partition coefficients and their derivatives
void PartitionCoefficientFunctions(FEMaterialPoint& mp, vector<double>& kappa,
vector<double>& dkdJ,
vector< vector<double> >& dkdc);
//! electric potential
double ElectricPotential(FEMaterialPoint& pt, const bool eform=false);
//! current density
vec3d CurrentDensity(FEMaterialPoint& pt);
//! solute density
double SoluteDensity(const int sol) { return m_pSolute[sol]->Density(); }
//! solute molar mass
double SoluteMolarMass(const int sol) { return m_pSolute[sol]->MolarMass(); }
//! solute charge number
int SoluteChargeNumber(const int sol) { return m_pSolute[sol]->ChargeNumber(); }
//! Add a chemical reaction
void AddChemicalReaction(FEChemicalReaction* pcr);
// solute interface
public:
int Solutes() override { return (int)m_pSolute.size(); }
FESolute* GetSolute(int i) override { return m_pSolute[i]; }
double GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) override;
FEOsmoticCoefficient* GetOsmoticCoefficient() override { return m_pOsmC; }
double GetFixedChargeDensity(const FEMaterialPoint& mp) override {
const FEMultiphasicFSIMaterialPoint* spt = (mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
return spt->m_cF;
}
public: // from FEBiphasicInterface
double GetActualFluidPressure(const FEMaterialPoint& mp) override {
const FEMultiphasicFSIMaterialPoint* pt = (mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
return pt->m_pe;
}
public:
FEChemicalReaction* GetReaction (int i) { return m_pReact[i]; }
int Reactions () { return (int) m_pReact.size(); }
public: // material parameters
FEParamDouble m_cFr; //!< fixed charge density in reference configurations TODO: gradphisr
vector<FEBodyForce*> m_mbf; //!< body forces acting on this multiphasic material solutes
double m_Rgas; //!< universal gas constant
double m_Tabs; //!< absolute temperature
double m_Fc; //!< Faraday's constant
bool m_diffMtmSupp; //!< Toggle on or off diffusive mtm supply for fluid
int m_zmin; //!< minimum charge number in mixture
int m_ndeg; //!< polynomial degree of zeta in electroneutrality
double m_penalty; //!< penalty for enforcing electroneutrality
protected: // material properties
std::vector<FESolute*> m_pSolute; //!< pointer to solute materials
FEOsmoticCoefficient* m_pOsmC; //!< pointer to osmotic coefficient material
std::vector<FEChemicalReaction*> m_pReact; //!< pointer to chemical reactions
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBioFluid/FESoluteConvectiveFlow.cpp | .cpp | 6,560 | 180 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FESoluteConvectiveFlow.h"
#include "FECore/FEElemElemList.h"
#include "FECore/FEGlobalMatrix.h"
#include "FECore/FEGlobalVector.h"
#include "FECore/LinearSolver.h"
#include <FECore/FEModel.h>
#include "FEBioFluidSolutes.h"
//=============================================================================
BEGIN_FECORE_CLASS(FESoluteConvectiveFlow, FESurfaceLoad)
ADD_PARAMETER(m_sol , "solute_id")->setEnums("$(solutes)");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
//! constructor
FESoluteConvectiveFlow::FESoluteConvectiveFlow(FEModel* pfem) : FESurfaceLoad(pfem), m_dofW(pfem)
{
m_sol = -1;
m_dofW.AddVariable(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::RELATIVE_FLUID_VELOCITY));
m_dofEF = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_DILATATION), 0);
m_dofC = GetDOFIndex(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION), 0);
}
//-----------------------------------------------------------------------------
//! initialize
bool FESoluteConvectiveFlow::Init()
{
// determine the nr of concentration equations
FEModel& fem = *GetFEModel();
DOFS& fedofs = fem.GetDOFS();
int MAX_CDOFS = fedofs.GetVariableSize(FEBioFluidSolutes::GetVariableName(FEBioFluidSolutes::FLUID_CONCENTRATION));
if ((m_sol < 1) || (m_sol > MAX_CDOFS)) return false;
FEMesh& mesh = GetMesh();
m_octree = new FEOctreeSearch(&mesh);
m_octree->Init();
FESurface* ps = &GetSurface();
m_np = new FENormalProjection(*ps);
m_np->SetTolerance(0.01);
m_np->SetSearchRadius(1.0);
m_np->Init();
int NN = mesh.Nodes();
m_bexclude.assign(NN, false);
return FESurfaceLoad::Init();
}
//-----------------------------------------------------------------------------
//! Activate the degrees of freedom for this BC
void FESoluteConvectiveFlow::Activate()
{
int dofc = m_dofC + m_sol - 1;
FEModel& fem = *GetFEModel();
FEMesh& mesh = GetMesh();
for (int i=0; i<mesh.Nodes(); ++i)
{
FENode& node = mesh.Node(i);
if (node.get_bc(dofc) == DOF_PRESCRIBED) {
m_bexclude[i] = true;
}
else if (node.get_bc(dofc) == DOF_OPEN) {
// mark node as having prescribed DOF
node.set_bc(dofc, DOF_PRESCRIBED);
}
}
FESurfaceLoad::Activate();
}
//-----------------------------------------------------------------------------
// return nodal value
void FESoluteConvectiveFlow::Update()
{
FEMesh& mesh = GetMesh();
const FETimeInfo& tp = GetTimeInfo();
double gamma = tp.gamma;
double dt = tp.timeIncrement;
for (int i=0; i<mesh.Nodes(); ++i)
{
if (!m_bexclude[i]) {
FENode& node = mesh.Node(i);
vec3d x = node.m_rt;
vec3d vt = node.get_vec3d(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d vp = node.get_vec3d_prev(m_dofW[0], m_dofW[1], m_dofW[2]);
vec3d X = x - (vt*gamma + vp*(1-gamma))*dt;
int dofc = m_dofC + m_sol - 1;
double r[3] = { 0 };
double c = 0;
// search for the solid element in which X lies
FESolidElement* el = (FESolidElement*)m_octree->FindElement(X, r);
if (el) {
const int NELN = FESolidElement::MAX_NODES;
double ep[NELN], cp[NELN];
int neln = el->Nodes();
for (int j=0; j<neln; ++j) {
FENode& node = mesh.Node(el->m_node[j]);
ep[j] = node.get_prev(m_dofEF);
cp[j] = node.get_prev(dofc);
}
double Jt = 1 + node.get(m_dofEF);
double Jp = 1 + el->evaluate(ep, r[0], r[1], r[2]);
c = Jp*el->evaluate(cp, r[0], r[1], r[2])/Jt;
}
// if solid element is not found, project x onto the solute inlet surface
else {
FESurfaceElement* pme;
vec3d n = x - X;
n.unit();
pme = m_np->Project(x, n, r);
if (pme) {
const int NELN = FEShellElement::MAX_NODES;
double ep[NELN], cp[NELN];
int neln = pme->Nodes();
for (int j=0; j<neln; ++j) {
FENode& mode = mesh.Node(pme->m_node[j]);
ep[j] = mode.get_prev(m_dofEF);
cp[j] = mode.get_prev(dofc);
}
double Jt = 1 + node.get(m_dofEF);
double Jp = 1 + pme->eval(ep, r[0], r[1]);
c = Jp*pme->eval(cp, r[0], r[1])/Jt;
}
else
c = node.get_prev(dofc);
}
if (node.m_ID[dofc] < -1)
node.set(dofc, c);
}
}
}
//-----------------------------------------------------------------------------
//! serialization
void FESoluteConvectiveFlow::Serialize(DumpStream& ar)
{
FESurfaceLoad::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_dofW & m_dofEF & m_dofC;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FEMultiphasicFSIDomain3D.cpp | .cpp | 85,168 | 1,765 | /*This file 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 "FEMultiphasicFSIDomain3D.h"
#include <FECore/log.h>
#include "FECore/DOFS.h"
#include <FECore/FEModel.h>
#include <FECore/FEAnalysis.h>
#include <FECore/sys.h>
#include "FEBioMultiphasicFSI.h"
#include "FEFluidFSI.h"
#include "FEBiphasicFSI.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.
FEMultiphasicFSIDomain3D::FEMultiphasicFSIDomain3D(FEModel* pfem) : FESolidDomain(pfem), FEMultiphasicFSIDomain(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;
// TODO: Can this be done in Init, since there is no error checking
if (pfem)
{
m_dofU.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::DISPLACEMENT));
m_dofV.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::VELOCITY));
m_dofW.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::RELATIVE_FLUID_VELOCITY));
m_dofAW.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::RELATIVE_FLUID_ACCELERATION));
m_dofSU.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::SHELL_DISPLACEMENT));
m_dofR.AddVariable(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::RIGID_ROTATION));
m_dofEF = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_DILATATION), 0);
m_dofAEF = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_DILATATION_TDERIV), 0);
m_dofC = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION), 0);
m_dofAC = pfem->GetDOFIndex(FEBioMultiphasicFSI::GetVariableName(FEBioMultiphasicFSI::FLUID_CONCENTRATION_TDERIV), 0);
}
}
//-----------------------------------------------------------------------------
// \todo I don't think this is being used
FEMultiphasicFSIDomain3D& FEMultiphasicFSIDomain3D::operator = (FEMultiphasicFSIDomain3D& d)
{
m_Elem = d.m_Elem;
m_pMesh = d.m_pMesh;
return (*this);
}
//-----------------------------------------------------------------------------
// get the total dof
const FEDofList& FEMultiphasicFSIDomain3D::GetDOFList() const
{
return m_dof;
}
//-----------------------------------------------------------------------------
//! Assign material
void FEMultiphasicFSIDomain3D::SetMaterial(FEMaterial* pmat)
{
FEDomain::SetMaterial(pmat);
if (pmat)
{
m_pMat = dynamic_cast<FEMultiphasicFSI*>(pmat);
assert(m_pMat);
}
else m_pMat = 0;
}
//-----------------------------------------------------------------------------
bool FEMultiphasicFSIDomain3D::Init()
{
// initialize base class
if (FESolidDomain::Init() == false) return false;
//TODO Initialize body force like biphasic solver? maybe not necessary.
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);
FEBiphasicFSIMaterialPoint& pb = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& ps = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
pb.m_phi0 = m_pMat->SolidReferentialVolumeFraction(mp);
ps.m_cF = m_pMat->FixedChargeDensity(mp);
}
}
// set the active degrees of freedom list
FEDofList dofs(GetFEModel());
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 FEMultiphasicFSIDomain3D::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 FEMultiphasicFSIDomain3D::InitMaterialPoints()
{
const int nsol = m_pMat->Solutes();
FEMesh& m = *GetMesh();
const int NE = FEElement::MAX_NODES;
double ef[NE];
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]);
ef[i] = ni.get(m_dofEF);
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);
FEFluidMaterialPoint& ft = *(mp.ExtractData<FEFluidMaterialPoint>());
FEFSIMaterialPoint& fs = *(mp.ExtractData<FEFSIMaterialPoint>());
FEBiphasicFSIMaterialPoint& pt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& ps = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
// initialize effective fluid pressure, its gradient, and fluid flux
ft.m_ef = el.Evaluate(ef, n);
ft.m_gradef = gradient(el, ef, n);
ps.m_pe = m_pMat->Fluid()->Pressure(mp);
// 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_gradc[isol] = gradient(el, c0[isol], n);
}
ps.m_psi = m_pMat->ElectricPotential(mp);
for (int isol = 0; isol<nsol; ++isol) {
ps.m_ca[isol] = m_pMat->ConcentrationActual(mp, isol);
ps.m_j[isol] = m_pMat->SoluteFlux(mp, isol);
}
ft.m_pf = m_pMat->PressureActual(mp);
// initialize referential solid volume fraction
pt.m_phi0 = m_pMat->SolidReferentialVolumeFraction(mp);
// calculate FCD, current and stress
ps.m_cF = m_pMat->FixedChargeDensity(mp);
ps.m_Ie = m_pMat->CurrentDensity(mp);
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::Reset()
{
// reset base class data
FESolidDomain::Reset();
const int nsol = m_pMat->Solutes();
// initialize all element data
ForEachMaterialPoint([=](FEMaterialPoint& mp) {
FEBiphasicFSIMaterialPoint& pt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& ps = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
// initialize referential solid volume fraction
pt.m_phi0 = m_pMat->m_phi0(mp);
// 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 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);
for (int j=0; j<m_pMat->Reactions(); ++j)
m_pMat->GetReaction(j)->ResetElementData(mp);
}
}
}
//-----------------------------------------------------------------------------
//! Initialize element data
void FEMultiphasicFSIDomain3D::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>();
mp.m_r0 = r0;
mp.m_rt = rt;
et.m_Wp = et.m_Wt;
if ((pt.m_ef <= -1) || (et.m_J <= 0)) {
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);
}
}
}
}
//-----------------------------------------------------------------------------
//! Unpack the element LM data.
void FEMultiphasicFSIDomain3D::UnpackLM(FEElement& el, vector<int>& lm)
{
int N = el.Nodes();
int nsol = m_pMat->Solutes();
int ndpn = 7+nsol;
lm.resize(N*(3+ndpn));
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[ndpn*i ] = id[m_dofU[0]];
lm[ndpn*i+1] = id[m_dofU[1]];
lm[ndpn*i+2] = id[m_dofU[2]];
lm[ndpn*i+3] = id[m_dofW[0]];
lm[ndpn*i+4] = id[m_dofW[1]];
lm[ndpn*i+5] = id[m_dofW[2]];
lm[ndpn*i+6] = id[m_dofEF];
for (int isol = 0; isol < nsol; ++isol)
{
//int m = m_pMat->GetSolute(i)->GetSoluteDOF();
lm[ndpn*i+7+isol] = id[m_dofC + m_pMat->GetSolute(isol)->GetSoluteDOF()];
}
// rigid rotational dofs
lm[ndpn*N + 3*i ] = id[m_dofR[0]];
lm[ndpn*N + 3*i+1] = id[m_dofR[1]];
lm[ndpn*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[ndpn*i ] = id[m_dofSU[0]];
lm[ndpn*i+1] = id[m_dofSU[1]];
lm[ndpn*i+2] = id[m_dofSU[2]];
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::InternalForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
int nsol = m_pMat->Solutes();
int ndpn = 7+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];
if (el.isActive()) {
// 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 FEMultiphasicFSIDomain3D::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, se, pi;
vec3d gradp, divTe;
mat3ds km1;
const double *H, *Gr, *Gs, *Gt;
int nint = el.GaussPoints();
int neln = el.Nodes();
const int nsol = m_pMat->Solutes();
int ndpn = 7+nsol;
const int nreact = m_pMat->Reactions();
// 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>());
FEElasticMaterialPoint& et = *(mp.ExtractData<FEElasticMaterialPoint>());
FEFSIMaterialPoint& ft = *(mp.ExtractData<FEFSIMaterialPoint>());
FEBiphasicFSIMaterialPoint& bt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& mt = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
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);
se = m_pMat->Solid()->Stress(mp);
double pa = m_pMat->PressureActual(mp);
// get the gradient of the elastic pressure
gradp = pt.m_gradef*m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
// get inverse of permeability tensor
km1 = m_pMat->InvPermeability(mp);
//get pI
pi = mat3dd(m_pMat->Fluid()->Pressure(mp));
// Miscellaneous constants
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
double penalty = m_pMat->m_penalty;
double dms = m_pMat->m_diffMtmSupp;
// 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];
}
}
vector<double> M(nsol);
vector<int> z(nsol);
vec3d je(0,0,0);
vector<double> d0(nsol);
vector<mat3ds> dm1(nsol);
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();
M[isol] = m_pMat->GetSolute(isol)->MolarMass();
d0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp);
dm1[isol] = m_pMat->InvDiffusivity(mp, isol);
je += mt.m_j[isol]*z[isol];
}
vector<double> dkdt(nsol,0);
for (int isol=0; isol<nsol; ++isol)
{
dkdt[isol] = mt.m_dkdJ[isol]*ft.m_Jdot;
for (int jsol=0; jsol<nsol; ++jsol)
{
dkdt[isol] += mt.m_dkdc[isol][jsol]*mt.m_cdot[jsol];
}
}
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 wrt fluid
double phif = m_pMat->Porosity(mp);
double phis = m_pMat->SolidVolumeFrac(mp);
vec3d gradphif = m_pMat->gradPorosity(mp);
vec3d gradphifphis = m_pMat->gradPhifPhis(mp);
double dJfdotf = pt.m_efdot + pt.m_gradef*ft.m_w/phif;
// Jsdot/Js
double dJsoJ = ft.m_Jdot/et.m_J;
double phifdot = dJsoJ*phis;
mat3dd I = mat3dd(1.0);
//Old Nat BC
mat3ds Tmix = se - sv*phis;
for (int isol = 0; isol < nsol; ++isol)
{
Tmix += -mat3dd(1.0)*R*T*osmc*mt.m_ca[isol];
}
//New Nat BC
//mat3ds Tmix = -mat3dd(1.0)*pa + se - sv*phis;
for (i=0; i<neln; ++i)
{
vec3d fs = (Tmix*gradN[i] + (sv*gradphifphis*phis*phis/phif - km1*ft.m_w)*H[i])*detJ; //Old Nat BC
//vec3d fs = (Tmix*gradN[i] + (-gradp + sv*gradphifphis*phis*phis/phif - km1*ft.m_w)*H[i])*detJ; //New Nat BC
vec3d ff = (sv*gradN[i] + (gradp + km1*ft.m_w - sv*gradphif/phif)*H[i])*detJ;
double fJ = (H[i]*(dJfdotf*phif/Jf - dJsoJ + phif*phiwhat) + gradN[i]*ft.m_w)*detJ;
for (int isol=0; isol<nsol; ++isol)
{
fs += (-mt.m_gradc[isol]*mt.m_k[isol]*phif*R*T - (dm1[isol] - I/phif/d0[isol])*mt.m_j[isol]*R*T - ft.m_w*R*T*phis/phif*mt.m_k[isol]*mt.m_c[isol]/d0[isol])*H[i]*detJ*dms;
ff += (ft.m_w*R*T/phif*mt.m_k[isol]*mt.m_c[isol]/d0[isol] - mt.m_j[isol]*R*T/phif/d0[isol])*H[i]*dms*detJ;
}
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[ndpn*i ] -= fs.x;
fe[ndpn*i+1] -= fs.y;
fe[ndpn*i+2] -= fs.z;
fe[ndpn*i+3] -= ff.x;
fe[ndpn*i+4] -= ff.y;
fe[ndpn*i+5] -= ff.z;
fe[ndpn*i+6] -= fJ;
for (int isol=0; isol<nsol; ++isol)
{
double fc = ((mt.m_j[isol]+je*penalty)*gradN[i] + H[i]*(phif*chat[isol] - (ft.m_Jdot*phif*mt.m_k[isol]*mt.m_c[isol] + phifdot*et.m_J*mt.m_k[isol]*mt.m_c[isol] + dkdt[isol]*et.m_J*phif*mt.m_c[isol] + mt.m_cdot[isol]*et.m_J*phif*mt.m_k[isol])/et.m_J))*detJ;
fe[ndpn*i+7+isol] -= fc;
}
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::BodyForce(FEGlobalVector& R, FEBodyForce& BF)
{
int NE = (int)m_Elem.size();
int nsol = m_pMat->Solutes();
int ndpn = 7+nsol;
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 = 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 FEMultiphasicFSIDomain3D::ElementBodyForce(FEBodyForce& BF, FESolidElement& el, vector<double>& fe)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
// jacobian
double Ji[3][3], detJ;
double *H, *Gr, *Gs, *Gt;
double* gw = el.GaussWeights();
vec3d ff, f;
int neln = el.Nodes();
int nsol = m_pMat->Solutes();
int ndpn = 7+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>();
FEMultiphasicFSIMaterialPoint& mt = *mp.ExtractData<FEMultiphasicFSIMaterialPoint>();
double densTs = m_pMat->TrueSolidDensity(mp);
double densTf = m_pMat->TrueFluidDensity(mp);
pt.m_r0 = el.Evaluate(r0, n);
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]);
H = el.H(n);
Gr = el.Gr(n);
Gs = el.Gs(n);
Gt = el.Gt(n);
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<mat3ds> D(nsol);
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);
D[isol] = m_pMat->Diffusivity(mp, isol);
}
// evaluate spatial gradient of shape functions
for (int i=0; i<neln; ++i)
{
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
}
// get the force
double phis = m_pMat->SolidVolumeFrac(mp);
double phif = m_pMat->Porosity(mp);
mat3dd I = mat3dd(1.0);
for (int i=0; i<neln; ++i)
{
f = BF.force(mp)*((-densTf+densTs)*phis*detJ*H[i]);
ff = BF.force(mp)*(densTf*detJ*H[i]);
for (int isol = 0; isol < nsol; ++isol)
{
f += (I*phif-D[isol]/d0[isol])*BF.force(mp)*M[isol]*mt.m_k[isol]*mt.m_c[isol]*H[i]*detJ*dms;
ff+= D[isol]*BF.force(mp)/d0[isol]*M[isol]*mt.m_k[isol]*mt.m_c[isol]*H[i]*detJ*dms;
}
fe[ndpn*i+0] -= f.x;
fe[ndpn*i+1] -= f.y;
fe[ndpn*i+2] -= f.z;
fe[ndpn*i+3] -= ff.x;
fe[ndpn*i+4] -= ff.y;
fe[ndpn*i+5] -= ff.z;
for (int isol=0; isol<nsol; ++isol)
{
double fc = -gradN[i]*(D[isol]*BF.force(mp))*mt.m_k[isol]*M[isol]*mt.m_c[isol]*phif/(R*T)*detJ;
for(int jsol = 0; jsol<nsol; ++jsol)
{
fc += -gradN[i]*(D[jsol]*BF.force(mp))*z[jsol]*penalty*mt.m_k[jsol]*M[jsol]*mt.m_c[jsol]*phif/(R*T)*detJ;
}
fe[ndpn*i+7+isol] -= fc;
}
}
}
}
//-----------------------------------------------------------------------------
//! This function calculates the stiffness due to body forces
//! For now, we assume that the body force is constant
void FEMultiphasicFSIDomain3D::ElementBodyForceStiffness(FEBodyForce& BF, FESolidElement &el, matrix &ke)
{
const FETimeInfo& tp = GetFEModel()->GetTime();
int neln = el.Nodes();
// jacobian
double Ji[3][3], detJ;
double *H, *Gr, *Gs, *Gt;
double* gw = el.GaussWeights();
vec3d f, ff, fs, ffs, kwJ, kuJ;
mat3d Kwu, Kuu;
int nsol = m_pMat->Solutes();
int ndpn = 7+nsol;
const int nreact = m_pMat->Reactions();
// 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);
FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>();
FEFluidMaterialPoint& pt = *mp.ExtractData<FEFluidMaterialPoint>();
FEMultiphasicFSIMaterialPoint& mt = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
double Jf = 1 + pt.m_ef;
// 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 densf = m_pMat->FluidDensity(mp);
double densTf = m_pMat->TrueFluidDensity(mp);
double denss = m_pMat->SolidDensity(mp);
double densTs = m_pMat->TrueSolidDensity(mp);
// get the force
ff = BF.force(mp)*(densTf*detJ);
f = BF.force(mp)*(densf*detJ);
fs = BF.force(mp)*(densTs*detJ);
double phif = m_pMat->Porosity(mp);
double phis = m_pMat->SolidVolumeFrac(mp);
ffs = BF.force(mp)*((phis/phif*(densf+denss) - densTf*phis + denss)*detJ);
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<vector<double>> d0p(nsol, vector<double>(nsol));
vector<mat3ds> D(nsol);
vector<tens4dmm> dDdE(nsol);
vector<vector<mat3ds>> dDdc(nsol, vector<mat3ds>(nsol));
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);
D[isol] = m_pMat->Diffusivity(mp, isol);
dDdE[isol] = m_pMat->Diffusivity_Tangent_Strain(mp, isol);
for (int jsol=0; jsol<nsol; ++jsol)
{
d0p[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp, jsol);
dDdc[isol][jsol] = m_pMat->Diffusivity_Tangent_Concentration(mp, isol, jsol);
}
}
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, i7=0; i<neln; ++i, i7 += ndpn) {
for (int j=0, j7 = 0; j<neln; ++j, j7 += ndpn)
{
kwJ = ff*(-H[i]*H[j]/Jf);
kuJ = ff*(H[i]*H[j]*phis/Jf);
Kwu = (ff & gradN[j])*H[i];
Kuu = mat3d(0.0);
for (int isol = 0; isol < nsol; ++isol)
{
Kwu += (((D[isol]*BF.force(mp))&gradN[j])*M[isol]*mt.m_c[isol]*mt.m_dkdJ[isol]/d0[isol]*H[i]*et.m_J + (vdotTdotv(BF.force(mp), dDdE[isol], gradN[j]) + mat3dd(1.0)*((D[isol]*BF.force(mp))*gradN[j]) + D[isol]*(gradN[j] & BF.force(mp)))*M[isol]*mt.m_k[isol]*mt.m_c[isol]/d0[isol]*H[i])*detJ*dms;
Kuu += ((((mat3dd(1.0)*phif-D[isol]/d0[isol])*BF.force(mp))&gradN[j])*M[isol]*mt.m_c[isol]*mt.m_dkdJ[isol]*H[i]*et.m_J + ((BF.force(mp)&gradN[j]) - mat3dd(1.0)*((D[isol]*BF.force(mp))*gradN[j])/d0[isol])*M[isol]*mt.m_c[isol]*mt.m_k[isol]*H[i] - (vdotTdotv(BF.force(mp), dDdE[isol], gradN[j]) + D[isol]*(gradN[j] & BF.force(mp)))*M[isol]*mt.m_k[isol]*mt.m_c[isol]/d0[isol]*H[i])*detJ*dms;
}
ke[i7+0][j7+0] += Kuu(0,0); ke[i7+0][j7+1] += Kuu(0,1); ke[i7+0][j7+2] += Kuu(0,2);
ke[i7+1][j7+0] += Kuu(1,0); ke[i7+1][j7+1] += Kuu(1,1); ke[i7+1][j7+2] += Kuu(1,2);
ke[i7+2][j7+0] += Kuu(2,0); ke[i7+2][j7+1] += Kuu(2,1); ke[i7+2][j7+2] += Kuu(2,2);
ke[i7+3][j7+0] += Kwu(0,0); ke[i7+3][j7+1] += Kwu(0,1); ke[i7+3][j7+2] += Kwu(0,2);
ke[i7+4][j7+0] += Kwu(1,0); ke[i7+4][j7+1] += Kwu(1,1); ke[i7+4][j7+2] += Kwu(1,2);
ke[i7+5][j7+0] += Kwu(2,0); ke[i7+5][j7+1] += Kwu(2,1); ke[i7+5][j7+2] += Kwu(2,2);
ke[i7+0][j7+6] += kuJ.x;
ke[i7+1][j7+6] += kuJ.y;
ke[i7+2][j7+6] += kuJ.z;
ke[i7+3][j7+6] += kwJ.x;
ke[i7+4][j7+6] += kwJ.y;
ke[i7+5][j7+6] += kwJ.z;
for (int isol = 0; isol<nsol; ++isol)
{
vec3d kwc = vec3d(0.0);
vec3d kuc = vec3d(0.0);
vec3d kcu = ((gradN[i]&gradN[j])*D[isol]*BF.force(mp)*M[isol]*mt.m_k[isol]*mt.m_c[isol]/R/T*phif - gradN[j]*(gradN[i]*(D[isol]*BF.force(mp)))*M[isol]*mt.m_k[isol]*mt.m_c[isol]/R/T*phis - ((gradN[j]&BF.force(mp))*D[isol]*et.m_J*mt.m_dkdJ[isol] + mat3dd(1.0)*(D[isol]*BF.force(mp)*gradN[j])*mt.m_k[isol] + vdotTdotv(BF.force(mp), dDdE[isol], gradN[j]).transpose()*mt.m_k[isol] + (BF.force(mp)&gradN[j])*D[isol]*mt.m_k[isol]) *gradN[i]*M[isol]*mt.m_c[isol]/R/T*phif)*detJ*dms;
for(int jsol=0; jsol<nsol; ++jsol)
{
double kcc = 0;
kcu += ((gradN[i]&gradN[j])*D[jsol]*BF.force(mp)*M[jsol]*z[jsol]*penalty*mt.m_k[jsol]*mt.m_c[jsol]/R/T*phif - gradN[j]*(gradN[i]*(D[jsol]*BF.force(mp)))*M[jsol]*z[jsol]*penalty*mt.m_k[jsol]*mt.m_c[jsol]/R/T*phis - ((gradN[j]&BF.force(mp))*D[jsol]*et.m_J*mt.m_dkdJ[jsol] + mat3dd(1.0)*(D[jsol]*BF.force(mp)*gradN[j])*mt.m_k[jsol] + vdotTdotv(BF.force(mp), dDdE[jsol], gradN[j]).transpose()*mt.m_k[jsol] + (BF.force(mp)&gradN[j])*D[jsol]*mt.m_k[jsol]) *gradN[i]*M[jsol]*z[jsol]*penalty*mt.m_c[jsol]/R/T*phif)*detJ*dms;
if (isol == jsol)
{
kwc += (D[isol]*mt.m_dkdc[isol][isol]*mt.m_c[isol]/d0[isol] + D[isol]*mt.m_k[isol]/d0[isol] - D[isol]*mt.m_k[isol]*mt.m_c[isol]*d0p[isol][isol]/d0[isol]/d0[isol] + dDdc[isol][isol]*mt.m_k[isol]*mt.m_c[isol]/d0[isol])*BF.force(mp)*M[isol]*H[i]*H[j]*detJ*dms;
kuc += ((mat3dd(1.0)*phif - D[isol]/d0[isol])*BF.force(mp)*(mt.m_dkdc[isol][isol]*mt.m_c[isol] + mt.m_k[isol])*M[isol]*H[i]*H[j] + (D[isol]*d0p[isol][isol]/d0[isol]/d0[isol] - dDdc[isol][isol]/d0[isol])*BF.force(mp)*M[isol]*mt.m_k[isol]*mt.m_c[isol]*H[i]*H[j])*dms*detJ;
kcc = -(D[isol]*mt.m_dkdc[isol][isol]*mt.m_c[isol] + D[isol]*mt.m_k[isol] + dDdc[isol][isol]*mt.m_k[isol]*mt.m_c[isol])*BF.force(mp)*gradN[i]*M[isol]/R/T*H[j]*phif*detJ;
for (int ksol=0; ksol<nsol; ++ksol)
{
if(isol==ksol)
{
kcc += -(D[isol]*mt.m_dkdc[isol][isol]*mt.m_c[isol] + D[isol]*mt.m_k[isol] + dDdc[isol][isol]*mt.m_k[isol]*mt.m_c[isol])*BF.force(mp)*gradN[i]*M[isol]*z[isol]*penalty/R/T*H[j]*phif*detJ;
}
else
{
kcc += -(D[ksol]*mt.m_dkdc[ksol][isol]*mt.m_c[ksol] + dDdc[ksol][isol]*mt.m_k[ksol]*mt.m_c[ksol])*BF.force(mp)*gradN[i]*M[ksol]*z[ksol]*penalty/R/T*H[j]*phif*detJ;
}
}
}
else
{
kwc += (D[jsol]*mt.m_dkdc[jsol][isol]*mt.m_c[jsol]/d0[jsol] - D[jsol]*mt.m_k[jsol]*mt.m_c[jsol]*d0p[jsol][isol]/d0[jsol]/d0[jsol] + dDdc[jsol][isol]*mt.m_k[jsol]*mt.m_c[jsol]/d0[jsol])*BF.force(mp)*M[jsol]*H[i]*H[j]*detJ*dms;
kuc += ((mat3dd(1.0)*phif - D[jsol]/d0[jsol])*BF.force(mp)*mt.m_dkdc[jsol][isol]*mt.m_c[jsol]*M[jsol]*H[i]*H[j] + (D[jsol]*d0p[jsol][isol]/d0[jsol]/d0[jsol] - dDdc[jsol][isol]/d0[jsol])*BF.force(mp)*M[jsol]*mt.m_k[jsol]*mt.m_c[jsol]*H[i]*H[j])*dms*detJ;
kcc = -(D[isol]*mt.m_dkdc[isol][jsol]*mt.m_c[isol] + dDdc[isol][jsol]*mt.m_k[isol]*mt.m_c[isol])*BF.force(mp)*gradN[i]*M[isol]/R/T*H[j]*phif*detJ;
for (int ksol=0; ksol<nsol; ++ksol)
{
if(jsol==ksol)
{
kcc += -(D[jsol]*mt.m_dkdc[jsol][jsol]*mt.m_c[jsol] + D[jsol]*mt.m_k[jsol] + dDdc[jsol][jsol]*mt.m_k[jsol]*mt.m_c[jsol])*BF.force(mp)*gradN[i]*M[jsol]*z[jsol]*penalty/R/T*H[j]*phif*detJ;
}
else
{
kcc += -(D[ksol]*mt.m_dkdc[ksol][jsol]*mt.m_c[ksol] + dDdc[ksol][jsol]*mt.m_k[ksol]*mt.m_c[ksol])*BF.force(mp)*gradN[i]*M[ksol]*z[ksol]*penalty/R/T*H[j]*phif*detJ;
}
}
}
ke[i7+7+isol][j7+7+jsol] += kcc;
}
ke[i7+0][j7+7+isol] += kuc.x;
ke[i7+1][j7+7+isol] += kuc.y;
ke[i7+2][j7+7+isol] += kuc.z;
ke[i7+3][j7+7+isol] += kwc.x;
ke[i7+4][j7+7+isol] += kwc.y;
ke[i7+5][j7+7+isol] += kwc.z;
ke[i7+7+isol][j7+0] += kcu.x;
ke[i7+7+isol][j7+1] += kcu.y;
ke[i7+7+isol][j7+2] += kcu.z;
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Calculates element material stiffness element matrix
void FEMultiphasicFSIDomain3D::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();
const int nsol = m_pMat->Solutes();
const int ndpn = 7 + nsol;
const int nreact = m_pMat->Reactions();
// gradient of shape functions
vector<vec3d> gradN(neln);
vector<mat3d> gradgradN(neln);
double dt = tp.timeIncrement;
double a = tp.gamma/(tp.beta*dt);
double c = tp.alpham/(tp.alphaf*tp.gamma*dt);
double dtrans = m_btrans ? 1 : m_sseps;
double *H, *Gr, *Gs, *Gt;
vec3d g[3], dg[3][3];
// 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;
ContraBaseVectors(el, n, g, tp.alphaf);
ContraBaseVectorDerivatives(el, n, dg, 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);
// get the shape function derivatives
double* Grr = el.Grr(n); double* Grs = el.Grs(n); double* Grt = el.Grt(n);
double* Gsr = el.Gsr(n); double* Gss = el.Gss(n); double* Gst = el.Gst(n);
double* Gtr = el.Gtr(n); double* Gts = el.Gts(n); double* Gtt = el.Gtt(n);
// 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>());
FEBiphasicFSIMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& mt = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
double Jf = 1 + pt.m_ef;
// get the tangents
mat3ds se = 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 pa = m_pMat->PressureActual(mp);
double dp = m_pMat->Fluid()->Tangent_Pressure_Strain(mp);
double d2p = m_pMat->Fluid()->Tangent_Pressure_Strain_Strain(mp);
vec3d gradp = pt.m_gradef*dp;
// Jsdot/Js = div(vs)
double dJsoJ = fpt.m_Jdot/et.m_J;
mat3ds km1 = m_pMat->InvPermeability(mp);
//Include dependence of permeability on displacement
tens4dmm K = m_pMat->Permeability_Tangent(mp);
double phif = m_pMat->Porosity(mp);
double phis = m_pMat->SolidVolumeFrac(mp);
vec3d gradphif = m_pMat->gradPorosity(mp);
vec3d gradphifphis = m_pMat->gradPhifPhis(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;
double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp);
double dodJ = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Strain(mp);
vector<double> MM(nsol);
vector<int> z(nsol);
vector<double> d0(nsol);
vector<vector<double>> d0p(nsol, vector<double>(nsol));
vector<mat3ds> D(nsol);
vector<mat3ds> Dm1(nsol);
vector<tens4dmm> dDdE(nsol);
vector<vector<mat3ds>> dDdc(nsol, vector<mat3ds>(nsol));
vector<tens4d> Dm1Dm1(nsol);
vector<tens4d> dDdEfull(nsol);
vector<vec3d> flux(nsol);
vector<double> dodc(nsol);
for (int isol=0; isol<nsol; ++isol) {
// get the charge number
z[isol] = m_pMat->GetSolute(isol)->ChargeNumber();
MM[isol] = m_pMat->GetSolute(isol)->MolarMass();
d0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp);
D[isol] = m_pMat->Diffusivity(mp, isol);
Dm1[isol] = m_pMat->InvDiffusivity(mp, isol);
Dm1Dm1[isol] = dyad2(Dm1[isol],Dm1[isol]);
dDdE[isol] = m_pMat->Diffusivity_Tangent_Strain(mp, isol);
dDdEfull[isol] = tens4d(dDdE[isol]);
flux[isol] = -mt.m_gradc[isol]*phif + fpt.m_w*mt.m_c[isol]/d0[isol];
dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp, isol);
for (int jsol=0; jsol<nsol; ++jsol)
{
d0p[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp, jsol);
dDdc[isol][jsol] = m_pMat->Diffusivity_Tangent_Concentration(mp, isol, jsol);
}
}
vector<double> dkdt(nsol,0);
for (int isol=0; isol<nsol; ++isol)
{
dkdt[isol] = mt.m_dkdJ[isol]*fpt.m_Jdot;
for (int jsol=0; jsol<nsol; ++jsol)
{
dkdt[isol] += mt.m_dkdc[isol][jsol]*mt.m_cdot[jsol];
}
}
// evaluate the chat
double vbarzeta = 0.0;
vector<double> vzeta(nsol,0.0);
mat3ds vbardzdE = mat3ds(0.0);
vector<mat3ds> vdzdE(nsol,mat3ds(0.0));
vector<double> vbardzdc(nsol,0.0);
vector<vector<double>> vdzdc(nsol,vector<double>(nsol, 0.0));
// chemical reactions
for (i=0; i<nreact; ++i) {
double vbar = m_pMat->GetReaction(i)->m_Vbar;
mat3ds dzdE = m_pMat->GetReaction(i)->Tangent_ReactionSupply_Strain(mp);
double zeta = m_pMat->GetReaction(i)->ReactionSupply(mp);
vbarzeta += vbar*zeta;
vbardzdE += dzdE*vbar;
for (int isol = 0; isol < nsol; ++isol)
{
double v = m_pMat->GetReaction(i)->m_v[isol];
double dzdc1 = m_pMat->GetReaction(i)->Tangent_ReactionSupply_Concentration(mp,isol);
vzeta[isol] += v*zeta;
vdzdE[isol] += dzdE*v;
vbardzdc[isol] += vbar*dzdc1;
for (int jsol = 0; jsol<nsol; ++jsol)
{
double dzdc2 = m_pMat->GetReaction(i)->Tangent_ReactionSupply_Concentration(mp,jsol);
vdzdc[isol][jsol] += v*dzdc2;
}
}
}
// evaluate spatial gradient of shape functions
for (i=0; i<neln; ++i)
gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i];
// evaluate spatial gradgrad of shape functions
for (i=0; i<neln; ++i) {
gradgradN[i] = (((dg[0][0] & g[0]) + (dg[0][1] & g[1]) + (dg[0][2] & g[2]))*Gr[i]
+ ((dg[1][0] & g[0]) + (dg[1][1] & g[1]) + (dg[1][2] & g[2]))*Gs[i]
+ ((dg[2][0] & g[0]) + (dg[2][1] & g[1]) + (dg[2][2] & g[2]))*Gt[i]
+ (g[0] & g[0])*Grr[i] + (g[0] & g[1])*Gsr[i] + (g[0] & g[2])*Gtr[i]
+ (g[1] & g[0])*Grs[i] + (g[1] & g[1])*Gss[i] + (g[1] & g[2] )*Gts[i]
+ (g[2] & g[0])*Grt[i] + (g[2] & g[1])*Gst[i] + (g[2] & g[2])*Gtt[i]);
}
// evaluate stiffness matrix
for (i=0, i7=0; i<neln; ++i, i7 += ndpn)
{
for (j=0, j7 = 0; j<neln; ++j, j7 += ndpn)
{
mat3d M = mat3dd(a*dtrans) - et.m_L;
tens4d km1km1 = dyad2(km1,km1);
tens4d Kfull = tens4d(K);
mat3d Kuu = (sv*((gradN[i]&gradN[j])*phis/phif + (gradN[j]&gradN[i]))*phis - vdotTdotv(gradN[i], cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M)*phis - vdotTdotv(gradN[i], cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))*phis/(phif*phif) + vdotTdotv(gradN[i], cv, fpt.m_w) * ((-gradphif&gradN[j]) + gradgradN[j]*phis)*phis/(phif*phif) + mat3dd((se*gradN[i])*gradN[j]) + vdotTdotv(gradN[i], cs, gradN[j]) - sv*((gradphifphis&gradN[j])*2.0*phis*phis/phif + (gradN[j]&gradphifphis)*phis - gradgradN[j])*H[i]*phis/phif + vdotTdotv(gradphifphis, cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M)*phis*phis/phif*H[i] + vdotTdotv(gradphifphis, cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))*phis*phis/(phif*phif*phif)*H[i] - vdotTdotv(gradphifphis, cv, fpt.m_w) * ((-gradphif&gradN[j]) + gradgradN[j]*phis)*phis*phis/(phif*phif*phif)*H[i] + (-((km1*fpt.m_w)&gradN[j])*2.0 + (gradN[j]&(km1*fpt.m_w)) + km1*(gradN[j]*fpt.m_w) + ddot(ddot(km1km1,Kfull),mat3dd(gradN[j]*fpt.m_w)))*H[i])*detJ; //Old Nat BC
//mat3d Kuu = (sv*((gradN[i]&gradN[j])*phis/phif + (gradN[j]&gradN[i]))*phis - vdotTdotv(gradN[i], cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M)*phis - vdotTdotv(gradN[i], cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))*phis/(phif*phif) + vdotTdotv(gradN[i], cv, fpt.m_w) * ((-gradphif&gradN[j]) + gradgradN[j]*phis)*phis/(phif*phif) + mat3dd((se*gradN[i])*gradN[j]) + vdotTdotv(gradN[i], cs, gradN[j]) - sv*((gradphifphis&gradN[j])*2.0*phis*phis/phif + (gradN[j]&gradphifphis)*phis - gradgradN[j])*H[i]*phis/phif + vdotTdotv(gradphifphis, cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M)*phis*phis/phif*H[i] + vdotTdotv(gradphifphis, cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))*phis*phis/(phif*phif*phif)*H[i] - vdotTdotv(gradphifphis, cv, fpt.m_w) * ((-gradphif&gradN[j]) + gradgradN[j]*phis)*phis*phis/(phif*phif*phif)*H[i] + (-((km1*fpt.m_w)&gradN[j])*2.0 + (gradN[j]&(km1*fpt.m_w)) + km1*(gradN[j]*fpt.m_w) + ddot(ddot(km1km1,Kfull),mat3dd(gradN[j]*fpt.m_w)))*H[i] - ((gradp&gradN[j])-(gradN[j]&gradp))*H[i] - (gradN[i]&gradN[j])*pa + (gradN[j]&gradN[i])*pa)*detJ; //New Nat BC
mat3d Kuw = (vdotTdotv(gradN[i], cv, (gradphif*H[j]/phif-gradN[j]))*phis/phif + vdotTdotv(gradphifphis, cv, (-gradphif*H[j]/phif + gradN[j]))*H[i]*phis*phis/(phif*phif) - km1*H[i]*H[j])*detJ;
vec3d kuJ = ((-svJ*gradN[i])*H[j]*phis + svJ*gradphifphis*H[j]*H[i]*phis*phis/phif)*detJ; //Old Nat BC
//vec3d kuJ = (-(mat3dd(1.0)*dp+svJ*phis)*gradN[i]*H[j] + ((-pt.m_gradef*d2p + svJ*gradphifphis*phis*phis/phif)*H[j] - gradN[j]*dp)*H[i])*detJ; //New Nat BC
mat3d Kwu = (((gradp&gradN[j])-(gradN[j]&gradp))*H[i] + sv*((gradphif&gradN[j])*(2*phis/phif)+(gradN[j]&gradphif) - gradgradN[j]*phis)*(H[i]/phif) - vdotTdotv(gradphif, cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M)*H[i]/phif - vdotTdotv(gradphif, cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))*H[i]/(phif*phif*phif) + vdotTdotv(gradphif, cv, fpt.m_w) * (-(gradphif&gradN[j]) + gradgradN[j]*phis)*H[i]/(phif*phif*phif) + sv*((gradN[i]&gradN[j])*(1-phis/phif)-(gradN[j]&gradN[i])) + vdotTdotv(gradN[i], cv, gradN[j])*(-bpt.m_Lw.sym()*phis/(phif*phif) + M) + vdotTdotv(gradN[i], cv, fpt.m_w) * ((gradphif&gradN[j])*2.0*phis/phif + (gradN[j]&gradphif))/(phif*phif) + vdotTdotv(gradN[i], cv, fpt.m_w) * ((gradphif&gradN[j]) - gradgradN[j]*phis)/(phif*phif) + (((km1*fpt.m_w)&gradN[j])*2.0 - (gradN[j]&(km1*fpt.m_w)) - km1*(gradN[j]*fpt.m_w) - ddot(ddot(km1km1,Kfull),mat3dd(gradN[j]*fpt.m_w)))*H[i])*detJ;
mat3d Kww = ((vdotTdotv(gradphif, cv, (gradphif*H[j]/phif-gradN[j]))/(phif*phif) + km1*H[j])*H[i] + vdotTdotv(gradN[i], cv, (-gradphif*H[j]/phif+gradN[j]))/phif)*detJ;
vec3d kwJ = ((svJ*gradN[i])*H[j] +(gradN[j]*dp+(pt.m_gradef*d2p - svJ*gradphif/phif)*H[j])*H[i])*detJ;
vec3d kJu = (((gradN[j]&fpt.m_w) - mat3dd(gradN[j]*fpt.m_w)) * gradN[i] + ((gradN[j]*pt.m_efdot + ((gradN[j]&fpt.m_w) - mat3dd(gradN[j]*fpt.m_w))*pt.m_gradef)/Jf - gradN[j]*(dJsoJ + a*dtrans) + et.m_L.transpose()*gradN[j]*dtrans)*H[i] + (mat3dd(1.0)*vbarzeta + et.m_F*vbardzdE*et.m_F.transpose()*phif)*gradN[j]*H[i])*detJ;
vec3d kJw = ((pt.m_gradef*(H[i]/Jf) + gradN[i])*H[j])*detJ;
double kJJ = ((c*phif*dtrans - (pt.m_efdot*phif + pt.m_gradef*fpt.m_w)/Jf)*H[j] + gradN[j]*fpt.m_w)*H[i]/Jf*detJ;
for (int isol = 0; isol < nsol; ++isol)
{
Kuu += (-(gradN[i]&gradN[j])*(osmc + et.m_J*dodJ)*R*T*mt.m_k[isol]*mt.m_c[isol] + (-(gradN[i]&gradN[j])*et.m_J*mt.m_dkdJ[isol] + ((gradN[j]&gradN[i]))*mt.m_k[isol])*mt.m_c[isol]*R*T*osmc - (mt.m_gradc[isol]&gradN[j])*mt.m_k[isol]*R*T*H[i] + (-(mt.m_gradc[isol]&gradN[j])*et.m_J*mt.m_dkdJ[isol] + (gradN[j]&mt.m_gradc[isol])*mt.m_k[isol])*H[i]*phif*R*T + (-((Dm1[isol]*mt.m_j[isol])&gradN[j])*2.0 + (gradN[j]&(Dm1[isol]*mt.m_j[isol])) + Dm1[isol]*(gradN[j]*mt.m_j[isol]) + ddot(ddot(Dm1Dm1[isol],dDdEfull[isol]),mat3dd(gradN[j]*mt.m_j[isol])))*H[i]*R*T + Dm1[isol]*(mat3dd((D[isol]*flux[isol])*gradN[j]) - D[isol]*(flux[isol]&gradN[j]) - dDdEfull[isol].dot(mat3dd(gradN[j]*flux[isol])) - D[isol]*(gradN[j]&flux[isol]))*mt.m_k[isol]*H[i]*R*T - (flux[isol]&gradN[j])*et.m_J*mt.m_dkdJ[isol]*H[i]*R*T - (-(mt.m_gradc[isol]&gradN[j])*phis + (gradN[j]&mt.m_gradc[isol])*phif)*mt.m_k[isol]*H[i]*R*T + (mt.m_j[isol]&gradN[j])*H[i]*(1/phif - phis/(phif*phif))*R*T/d0[isol] + (mat3dd((D[isol]*flux[isol])*gradN[j]) - D[isol]*(flux[isol]&gradN[j]) + dDdEfull[isol].dot(mat3dd(gradN[j]*flux[isol])) + D[isol]*(gradN[j]&flux[isol]))*H[i]*R*T/phif/d0[isol]*mt.m_k[isol] + D[isol]*(flux[isol]&gradN[j])*H[i]*R*T/phif*et.m_J*mt.m_dkdJ[isol]/d0[isol] + D[isol]*(-(mt.m_gradc[isol]&gradN[j])*phis + (gradN[j]&mt.m_gradc[isol])*phif)*H[i]*R*T/phif*mt.m_k[isol]/d0[isol] + (fpt.m_w&gradN[j])*H[i]*(phis/phif*mt.m_k[isol] - et.m_J*mt.m_dkdJ[isol])*phis/phif*R*T*mt.m_c[isol]/d0[isol])*dms*detJ; //Old Nat BC
//Kuu += (-(gradN[i]&gradN[j])*et.m_J*dodJ*R*T*mt.m_k[isol]*mt.m_c[isol] -(gradN[i]&gradN[j])*et.m_J*mt.m_dkdJ[isol]*mt.m_c[isol]*R*T*osmc - (mt.m_gradc[isol]&gradN[j])*mt.m_k[isol]*R*T*H[i] + (-(mt.m_gradc[isol]&gradN[j])*et.m_J*mt.m_dkdJ[isol] + (gradN[j]&mt.m_gradc[isol])*mt.m_k[isol])*H[i]*phif*R*T + (-((Dm1[isol]*mt.m_j[isol])&gradN[j])*2.0 + (gradN[j]&(Dm1[isol]*mt.m_j[isol])) + Dm1[isol]*(gradN[j]*mt.m_j[isol]) + ddot(ddot(Dm1Dm1[isol],dDdEfull[isol]),mat3dd(gradN[j]*mt.m_j[isol])))*H[i]*R*T + Dm1[isol]*(mat3dd((D[isol]*flux[isol])*gradN[j]) - D[isol]*(flux[isol]&gradN[j]) - dDdEfull[isol].dot(mat3dd(gradN[j]*flux[isol])) - D[isol]*(gradN[j]&flux[isol]))*mt.m_k[isol]*H[i]*R*T - (flux[isol]&gradN[j])*et.m_J*mt.m_dkdJ[isol]*H[i]*R*T - (-(mt.m_gradc[isol]&gradN[j])*phis + (gradN[j]&mt.m_gradc[isol])*phif)*mt.m_k[isol]*H[i]*R*T + (mt.m_j[isol]&gradN[j])*H[i]*(1/phif - phis/(phif*phif))*R*T/d0[isol] + (mat3dd((D[isol]*flux[isol])*gradN[j]) - D[isol]*(flux[isol]&gradN[j]) + dDdEfull[isol].dot(mat3dd(gradN[j]*flux[isol])) + D[isol]*(gradN[j]&flux[isol]))*H[i]*R*T/phif/d0[isol]*mt.m_k[isol] + D[isol]*(flux[isol]&gradN[j])*H[i]*R*T/phif*et.m_J*mt.m_dkdJ[isol]/d0[isol] + D[isol]*(-(mt.m_gradc[isol]&gradN[j])*phis + (gradN[j]&mt.m_gradc[isol])*phif)*H[i]*R*T/phif*mt.m_k[isol]/d0[isol] + (fpt.m_w&gradN[j])*H[i]*(phis/phif*mt.m_k[isol] - et.m_J*mt.m_dkdJ[isol])*phis/phif*R*T*mt.m_c[isol]/d0[isol])*dms*detJ; //New Nat BC
Kwu += ((fpt.m_w&gradN[j])*H[i]*(1.0/phif-phis/(phif*phif))*R*T*mt.m_k[isol]*mt.m_c[isol]/d0[isol] + (fpt.m_w&gradN[j])*H[i]/phif*et.m_J*R*T*mt.m_dkdJ[isol]*mt.m_c[isol]/d0[isol] - (mt.m_j[isol]&gradN[j])*H[i]*(1.0/phif-phis/(phif*phif))*R*T/d0[isol] - (mat3dd((D[isol]*flux[isol])*gradN[j]) - D[isol]*(flux[isol]&gradN[j]) + dDdEfull[isol].dot(mat3dd(flux[isol]*gradN[j])) + D[isol]*(gradN[j]&flux[isol]) + D[isol]*(-(mt.m_gradc[isol]&gradN[j])*phis + (gradN[j]&mt.m_gradc[isol])*phif))*H[i]*R*T/phif/d0[isol]*mt.m_k[isol] - D[isol]*(flux[isol]&gradN[j])*et.m_J*mt.m_dkdJ[isol]*H[i]*R*T/phif/d0[isol])*detJ*dms;
Kww += (mat3dd(1.0) - D[isol]/d0[isol])*mt.m_k[isol]*mt.m_c[isol]/d0[isol]*R*T/phif*H[i]*H[j]*dms*detJ;
Kuw += -((mat3dd(1.0) - D[isol]/d0[isol]/phif)*mt.m_k[isol]*mt.m_c[isol]/d0[isol]*R*T*H[i]*H[j] + mat3dd(1.0)*mt.m_k[isol]*mt.m_c[isol]/d0[isol]*R*T*phis/phif*H[i]*H[j])*dms*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 ][j7+3] += Kuw(0,0); ke[i7 ][j7+4] += Kuw(0,1); ke[i7 ][j7+5] += Kuw(0,2);
ke[i7+1][j7+3] += Kuw(1,0); ke[i7+1][j7+4] += Kuw(1,1); ke[i7+1][j7+5] += Kuw(1,2);
ke[i7+2][j7+3] += Kuw(2,0); ke[i7+2][j7+4] += Kuw(2,1); ke[i7+2][j7+5] += Kuw(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+0][j7+6] += kuJ.x;
ke[i7+1][j7+6] += kuJ.y;
ke[i7+2][j7+6] += kuJ.z;
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;
for (int isol=0; isol<nsol; ++isol)
{
vec3d kcw = D[isol]*gradN[i]/d0[isol]*mt.m_k[isol]*mt.m_c[isol]*H[j]*detJ;
vec3d kcu = (((gradN[j]&mt.m_j[isol]) - mat3dd(mt.m_j[isol]*gradN[j]))*gradN[i] + (mat3dd((D[isol]*flux[isol])*gradN[j]) - (gradN[j]&(D[isol]*flux[isol])) + (dDdEfull[isol].dot(mat3dd(gradN[j]*flux[isol]))).transpose() + (flux[isol]&gradN[j])*D[isol])*gradN[i]*mt.m_k[isol] + gradN[j]*((D[isol]*flux[isol])*gradN[i])*et.m_J*mt.m_dkdJ[isol] + (-(gradN[j]&mt.m_gradc[isol])*phis + (mt.m_gradc[isol]&gradN[j])*phif)*D[isol]*gradN[i]*mt.m_k[isol] + (mat3dd(vzeta[isol]) + et.m_F*vdzdE[isol]*et.m_F.transpose()*phif)*gradN[j]*H[i] - (mat3dd(2*mt.m_dkdJ[isol]*fpt.m_Jdot*mt.m_c[isol]) + (mat3dd(dJsoJ + a*dtrans) - et.m_L.transpose())*mt.m_k[isol]*mt.m_c[isol])*gradN[j]*H[i] - (mat3dd(dJsoJ + a*dtrans) - et.m_L.transpose())*gradN[j]*H[i]*et.m_J*phif*mt.m_c[isol]*mt.m_dkdJ[isol] - gradN[j]*H[i]*(mt.m_k[isol] + et.m_J*phif*mt.m_dkdJ[isol])*mt.m_cdot[isol])*detJ;
vec3d kwc = vec3d(0);
vec3d kuc = vec3d(0);
double kJc = H[i]*H[j]*phif*vbardzdc[isol]*mt.m_k[isol]*detJ;
for(int jsol=0; jsol<nsol; ++jsol)
{
kcw += D[jsol]*gradN[i]/d0[jsol]*mt.m_k[jsol]*mt.m_c[jsol]*z[jsol]*H[j]*detJ;
kcu += (((gradN[j]&mt.m_j[jsol])*z[jsol]*penalty - mat3dd(mt.m_j[isol]*gradN[j]*z[jsol]*penalty))*gradN[i] + (mat3dd((D[jsol]*flux[jsol])*gradN[j]) - (gradN[j]&(D[jsol]*flux[jsol])) + (dDdEfull[jsol].dot(mat3dd(gradN[j]*flux[jsol]))).transpose() + (flux[jsol]&gradN[j])*D[jsol])*gradN[i]*mt.m_k[jsol]*z[jsol]*penalty + gradN[j]*((D[jsol]*flux[jsol])*gradN[i])*et.m_J*mt.m_dkdJ[jsol]*z[jsol]*penalty + (-(gradN[j]&mt.m_gradc[jsol])*phis + (mt.m_gradc[jsol]&gradN[j])*phif)*D[jsol]*gradN[i]*mt.m_k[jsol]*z[jsol]*penalty + mat3dd(vdzdc[isol][jsol]*mt.m_dkdJ[jsol]*mt.m_c[jsol])*gradN[j]*phif*et.m_J*H[i] - gradN[j]*H[i]*mt.m_dkdc[isol][jsol]*mt.m_c[isol]*mt.m_cdot[jsol])*detJ;
kJc += H[i]*H[j]*phif*vbardzdc[isol]*mt.m_dkdc[jsol][isol]*mt.m_c[jsol]*detJ;
double kcc = 0;
if (isol == jsol)
{
kwc += (fpt.m_w*H[i]*H[j]*R*T/phif*(mt.m_dkdc[isol][isol]*mt.m_c[isol]/d0[isol] + mt.m_k[isol]/d0[isol] - mt.m_k[isol]*mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol])) + mt.m_j[isol]*H[i]*H[j]*R*T/phif*d0p[isol][isol]/(d0[isol]*d0[isol]) - (dDdc[isol][isol]*mt.m_k[isol] + D[isol]*mt.m_dkdc[isol][isol])*flux[isol]*H[i]*H[j]*R*T/phif/d0[isol] - D[isol]*(-gradN[j]*phif + fpt.m_w*(1.0/d0[isol] - mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol]))*H[j])*H[i]*R*T/phif/d0[isol]*mt.m_k[isol])*detJ*dms;
kuc += (-gradN[i]*H[j]*R*T*(dodc[isol]*mt.m_k[isol]*mt.m_c[isol] + osmc*mt.m_dkdc[isol][isol]*mt.m_c[isol] + osmc*mt.m_k[isol]) - (mt.m_gradc[isol]*mt.m_dkdc[isol][isol]*H[j] + gradN[j]*mt.m_k[isol])*H[i]*R*T*phif + (Dm1Dm1[isol].dot(dDdc[isol][isol]) - mat3dd(d0p[isol][isol]/phif/d0[isol]/d0[isol]))*mt.m_j[isol]*H[i]*H[j]*R*T - (Dm1[isol] - mat3dd(1.0/phif/d0[isol]))*(dDdc[isol][isol]*mt.m_k[isol] + D[isol]*mt.m_dkdc[isol][isol])*flux[isol]*H[i]*H[j]*R*T - (mat3dd(1.0) - D[isol]/d0[isol]/phif)*(-gradN[j]*phif + fpt.m_w*H[j]*(1.0/d0[isol] - mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol])))*H[i]*R*T*mt.m_k[isol] - fpt.m_w*H[i]*H[j]*R*T*phis/phif*(mt.m_dkdc[isol][isol]*mt.m_c[isol]/d0[isol] + mt.m_k[isol]/d0[isol] - mt.m_k[isol]*mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol])))*detJ*dms;
kcc += (((dDdc[isol][isol]*mt.m_k[isol] + D[isol]*mt.m_dkdc[isol][isol])*flux[isol])*gradN[i]*H[j] + (D[isol]*(-gradN[j]*phif + fpt.m_w*H[j]*(1.0/d0[isol] - mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol]))))*gradN[i]*mt.m_k[isol] + H[i]*H[j]*phif*vdzdc[isol][isol]*mt.m_k[isol] - H[i]*H[j]*dJsoJ*(mt.m_dkdc[isol][isol]*mt.m_c[isol] + mt.m_k[isol]) - H[i]*H[j]*phif*mt.m_dkdJ[isol]*fpt.m_Jdot - H[i]*H[j]*phif*mt.m_c[isol]*mt.m_dkdc[isol][isol]*c*dtrans - H[i]*H[j]*phif*(mt.m_dkdc[isol][isol]*mt.m_cdot[isol] + mt.m_k[isol]*c*dtrans))*detJ;
for (int ksol=0; ksol<nsol; ++ksol)
{
if(isol==ksol)
{
kcc += (((dDdc[isol][isol]*mt.m_k[isol] + D[isol]*mt.m_dkdc[isol][isol])*flux[isol])*gradN[i]*H[j]*z[isol]*penalty + (D[isol]*(-gradN[j]*phif + fpt.m_w*H[j]*(1.0/d0[isol] - mt.m_c[isol]*d0p[isol][isol]/(d0[isol]*d0[isol]))))*gradN[i]*mt.m_k[isol]*z[isol]*penalty + H[i]*H[j]*phif*vdzdc[isol][isol]*mt.m_dkdc[isol][isol]*mt.m_c[isol] - H[i]*H[j]*phif*mt.m_dkdc[isol][isol]*mt.m_cdot[isol])*detJ;
}
else
{
kcc += (((dDdc[ksol][isol]*mt.m_k[ksol] + D[ksol]*mt.m_dkdc[ksol][isol])*flux[ksol])*gradN[i]*H[j]*z[ksol]*penalty - (D[ksol]*fpt.m_w*H[j]*mt.m_c[ksol]*d0p[ksol][isol]/(d0[ksol]*d0[ksol]))*gradN[i]*mt.m_k[ksol]*z[ksol]*penalty + H[i]*H[j]*phif*vdzdc[isol][isol]*mt.m_dkdc[ksol][isol]*mt.m_c[ksol] - H[i]*H[j]*phif*mt.m_dkdc[isol][ksol]*mt.m_cdot[ksol])*detJ;
}
}
}
else
{
kwc += (fpt.m_w*H[i]*H[j]*R*T/phif*(mt.m_dkdc[jsol][isol]*mt.m_c[jsol]/d0[jsol] - mt.m_k[jsol]*mt.m_c[jsol]*d0p[jsol][isol]/(d0[jsol]*d0[jsol])) + mt.m_j[jsol]*H[i]*H[j]*R*T/phif*d0p[jsol][isol]/(d0[jsol]*d0[jsol]) - (dDdc[jsol][isol]*mt.m_k[jsol] + D[jsol]*mt.m_dkdc[jsol][isol])*flux[jsol]*H[i]*H[j]*R*T/phif/d0[jsol] + D[jsol]*fpt.m_w*mt.m_k[jsol]*mt.m_c[jsol]*d0p[jsol][isol]/(d0[jsol]*d0[jsol]*d0[jsol])*H[j]*H[i]*R*T/phif)*detJ*dms;
kuc += (-gradN[i]*H[j]*R*T*(dodc[isol]*mt.m_k[jsol]*mt.m_c[jsol] + osmc*mt.m_dkdc[jsol][isol]*mt.m_c[jsol]) - mt.m_gradc[jsol]*mt.m_dkdc[jsol][isol]*H[i]*H[j]*R*T*phif + (Dm1Dm1[jsol].dot(dDdc[jsol][isol]) - mat3dd(d0p[jsol][isol]/phif/d0[jsol]/d0[jsol]))*mt.m_j[jsol]*H[i]*H[j]*R*T - (Dm1[jsol] - mat3dd(1.0/phif/d0[jsol]))*(dDdc[jsol][isol]*mt.m_k[jsol] + D[jsol]*mt.m_dkdc[jsol][isol])*flux[jsol]*H[i]*H[j]*R*T + (mat3dd(1.0) - D[jsol]/d0[jsol]/phif)*fpt.m_w*H[j]*mt.m_c[jsol]*d0p[jsol][isol]/(d0[jsol]*d0[jsol])*H[i]*R*T*mt.m_k[jsol] - fpt.m_w*H[i]*H[j]*R*T*phis/phif*(mt.m_dkdc[jsol][isol]*mt.m_c[jsol]/d0[jsol] - mt.m_k[jsol]*mt.m_c[jsol]*d0p[jsol][isol]/(d0[jsol]*d0[jsol])))*detJ*dms;
kcc += (((dDdc[isol][jsol]*mt.m_k[isol] + D[isol]*mt.m_dkdc[isol][jsol])*flux[isol])*gradN[i]*H[j] - (D[isol]*fpt.m_w*H[j]*mt.m_c[isol]*d0p[isol][jsol]/(d0[isol]*d0[isol]))*gradN[i]*mt.m_k[isol] + H[i]*H[j]*phif*vdzdc[isol][jsol]*mt.m_k[jsol] - H[i]*H[j]*dJsoJ*mt.m_dkdc[isol][jsol]*mt.m_c[isol] - H[i]*H[j]*phif*mt.m_c[isol]*mt.m_dkdc[isol][jsol]*c*dtrans - H[i]*H[j]*phif*mt.m_dkdc[isol][jsol]*mt.m_cdot[isol])*detJ;
for (int ksol=0; ksol<nsol; ++ksol)
{
if(jsol==ksol)
{
kcc += (((dDdc[jsol][jsol]*mt.m_k[jsol] + D[jsol]*mt.m_dkdc[jsol][jsol])*flux[jsol])*gradN[i]*H[j]*z[jsol]*penalty + (D[jsol]*(-gradN[j]*phif + fpt.m_w*H[j]*(1.0/d0[jsol] - mt.m_c[jsol]*d0p[jsol][jsol]/(d0[jsol]*d0[jsol]))))*gradN[i]*mt.m_k[jsol]*z[jsol]*penalty + H[i]*H[j]*phif*vdzdc[isol][jsol]*mt.m_dkdc[jsol][jsol]*mt.m_c[jsol])*detJ;
}
else
{
kcc += (((dDdc[ksol][jsol]*mt.m_k[ksol] + D[ksol]*mt.m_dkdc[ksol][jsol])*flux[ksol])*gradN[i]*H[j]*z[ksol]*penalty - (D[ksol]*fpt.m_w*H[j]*mt.m_c[ksol]*d0p[ksol][jsol]/(d0[ksol]*d0[ksol]))*gradN[i]*mt.m_k[ksol]*z[ksol]*penalty + H[i]*H[j]*phif*vdzdc[isol][jsol]*mt.m_dkdc[ksol][jsol]*mt.m_c[ksol])*detJ;
}
}
}
ke[i7+7+isol][j7+7+jsol] += kcc;
}
ke[i7 ][j7+7+isol] += kuc.x;
ke[i7+1][j7+7+isol] += kuc.y;
ke[i7+2][j7+7+isol] += kuc.z;
ke[i7+3][j7+7+isol] += kwc.x;
ke[i7+4][j7+7+isol] += kwc.y;
ke[i7+5][j7+7+isol] += kwc.z;
ke[i7+6][j7+7+isol] += kJc;
ke[i7+7+isol][j7 ] += kcu.x;
ke[i7+7+isol][j7+1] += kcu.y;
ke[i7+7+isol][j7+2] += kcu.z;
ke[i7+7+isol][j7+3] += kcw.x;
ke[i7+7+isol][j7+4] += kcw.y;
ke[i7+7+isol][j7+5] += kcw.z;
}
}
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::StiffnessMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
int nsol = m_pMat->Solutes();
int ndpn = 7 + nsol;
#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 = 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 FEMultiphasicFSIDomain3D::MassMatrix(FELinearSystem& LS)
{
// repeat over all solid elements
int NE = (int)m_Elem.size();
const int nsol = m_pMat->Solutes();
const int ndpn = 7 + nsol;
#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 = 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 FEMultiphasicFSIDomain3D::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf)
{
FEBiphasicFSI* pme = dynamic_cast<FEBiphasicFSI*>(GetMaterial()); assert(pme);
// repeat over all solid elements
int NE = (int)m_Elem.size();
const int nsol = m_pMat->Solutes();
const int ndpn = 7 + nsol;
#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 = ndpn*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 FEMultiphasicFSIDomain3D::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;
const int nsol = m_pMat->Solutes();
const int ndpn = 7 + nsol;
// gradient of shape functions
vector<vec3d> gradN(neln);
vector<mat3d> gradgradN(neln);
double *H;
double *Gr, *Gs, *Gt;
vec3d g[3], dg[3][3];
// 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;
ContraBaseVectors(el, n, g, tp.alphaf);
ContraBaseVectorDerivatives(el, n, dg, 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);
// get the shape function derivatives
double* Grr = el.Grr(n); double* Grs = el.Grs(n); double* Grt = el.Grt(n);
double* Gsr = el.Gsr(n); double* Gss = el.Gss(n); double* Gst = el.Gst(n);
double* Gtr = el.Gtr(n); double* Gts = el.Gts(n); double* Gtt = el.Gtt(n);
// 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>());
FEBiphasicFSIMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
double Jf = 1 + pt.m_ef;
double denss = m_pMat->SolidDensity(mp);
double densTf = m_pMat->TrueFluidDensity(mp);
// 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 spatial gradgrad of shape functions
for (i=0; i<neln; ++i) {
gradgradN[i] = (((dg[0][0] & g[0]) + (dg[0][1] & g[1]) + (dg[0][2] & g[2]))*Gr[i]
+ ((dg[1][0] & g[0]) + (dg[1][1] & g[1]) + (dg[1][2] & g[2]))*Gs[i]
+ ((dg[2][0] & g[0]) + (dg[2][1] & g[1]) + (dg[2][2] & g[2]))*Gt[i]
+ (g[0] & g[0])*Grr[i] + (g[0] & g[1])*Gsr[i] + (g[0] & g[2])*Gtr[i]
+ (g[1] & g[0])*Grs[i] + (g[1] & g[1])*Gss[i] + (g[1] & g[2] )*Gts[i]
+ (g[2] & g[0])*Grt[i] + (g[2] & g[1])*Gst[i] + (g[2] & g[2])*Gtt[i]);
}
double phif = m_pMat->Porosity(mp);
double phis = m_pMat->SolidVolumeFrac(mp);
vec3d gradphif = m_pMat->gradPorosity(mp);
// evaluate stiffness matrix
for (i=0, i7=0; i<neln; ++i, i7 += ndpn)
{
for (j=0, j7 = 0; j<neln; ++j, j7 += ndpn)
{
mat3d Kuu = ((mat3dd(b*H[j]*dtrans))*denss*H[i] + (((et.m_a*phis)&gradN[j]) + mat3dd(b*phif*H[j]*dtrans) - ((fpt.m_w&gradN[j]) * (-1.0/phif*dJsoJ + a*dtrans) - (fpt.m_w&(et.m_L.transpose()*gradN[j]*dtrans)))*phis/phif + mat3dd(gradN[j]*fpt.m_w*a*dtrans) - ((bpt.m_Lw*fpt.m_w)&gradN[j])*phis/(phif*phif) + ((fpt.m_w&gradN[j])*((gradphif*(phis+1.0)/phif)*fpt.m_w) - (fpt.m_w&(gradgradN[j].transpose()*fpt.m_w)))*phis/(phif*phif) - pt.m_Lf*(mat3dd(gradN[j]*fpt.m_w)) - (pt.m_aft&gradN[j])*phis)*(-H[i]*densTf*phis/phif))*detJ; //mixture 2
mat3d Kuw = ((mat3dd(c*dtrans-phis/phif*dJsoJ-(gradphif*fpt.m_w)/(phif*phif))+pt.m_Lf)*H[j] + mat3dd(gradN[j]*fpt.m_w)/phif)*(-H[i]*densTf/phif*phis*detJ); //mixture 2
vec3d kuJ = pt.m_aft*(densTf/Jf*H[i]*H[j]*phis*detJ); //mixture 2
mat3d Kwu = (((et.m_a&gradN[j])*phis + mat3dd(b*phif*H[j]*dtrans) - ((fpt.m_w&gradN[j]) * (-1.0/phif*dJsoJ + a*dtrans) - (fpt.m_w&(et.m_L.transpose()*gradN[j]*dtrans)))*phis/phif + mat3dd(gradN[j]*fpt.m_w*a*dtrans) - ((bpt.m_Lw*fpt.m_w)&gradN[j])*phis/(phif*phif) + ((fpt.m_w&gradN[j])*((gradphif*(phis+1.0)/phif)*fpt.m_w) - (fpt.m_w&(gradgradN[j].transpose()*fpt.m_w)))*phis/(phif*phif) - pt.m_Lf*mat3dd(gradN[j]*fpt.m_w))*(H[i]*densTf/phif) + (pt.m_aft&gradN[j])*H[i]*densTf*(1.0-phis/phif))*detJ;
mat3d Kww = ((mat3dd(c*dtrans-phis/phif*dJsoJ-(gradphif*fpt.m_w)/(phif*phif))+pt.m_Lf)*H[j] + mat3dd(gradN[j]*fpt.m_w)/phif)*(H[i]*densTf/phif*detJ);
vec3d kwJ = pt.m_aft*(-densTf/Jf*H[i]*H[j]*detJ);
ke[i7+0][j7 ] += Kuu(0,0); ke[i7+0][j7+1] += Kuu(0,1); ke[i7+0][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+0][j7+3] += Kuw(0,0); ke[i7+0][j7+4] += Kuw(0,1); ke[i7+0][j7+5] += Kuw(0,2);
ke[i7+1][j7+3] += Kuw(1,0); ke[i7+1][j7+4] += Kuw(1,1); ke[i7+1][j7+5] += Kuw(1,2);
ke[i7+2][j7+3] += Kuw(2,0); ke[i7+2][j7+4] += Kuw(2,1); ke[i7+2][j7+5] += Kuw(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+0][j7+6] += kuJ.x;
ke[i7+1][j7+6] += kuJ.y;
ke[i7+2][j7+6] += kuJ.z;
ke[i7+3][j7+6] += kwJ.x;
ke[i7+4][j7+6] += kwJ.y;
ke[i7+5][j7+6] += kwJ.z;
}
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::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 FEMultiphasicFSIDomain3D::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();
// number of solutes
const int nsol = m_pMat->Solutes();
// 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];
vector< vector<double> > ct(nsol, vector<double>(NELN));
vector< vector<double> > act(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]);
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);
for (int k=0; k<nsol; ++k) {
ct[k][j] = node.get(m_dofC + sid[k])*alphaf + node.get_prev(m_dofC + sid[k])*(1-alphaf);
act[k][j] = node.get(m_dofAC + sid[k])*alpham + node.get_prev(m_dofAC + sid[k])*(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>());
FEBiphasicFSIMaterialPoint& bt = *(mp.ExtractData<FEBiphasicFSIMaterialPoint>());
FEMultiphasicFSIMaterialPoint& spt = *(mp.ExtractData<FEMultiphasicFSIMaterialPoint>());
// 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);
//NOTE: Made these new function. Converts from GradJ to gradJ
vec3d GradJ = FESolidDomain::GradJ(el,n);
vec3d GradJp = FESolidDomain::GradJp(el, n);
//calculate gradJ gradphif
bt.m_gradJ = Fi.transpose()*(GradJ*alphaf + GradJp*(1-alphaf));
// 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;
for (int isol=0; isol < nsol; ++isol) {
spt.m_c[isol] = el.Evaluate(ct[isol], n);
vec3d Gradc = Gradient(el, ct[isol], n);
spt.m_gradc[isol] = Fi.transpose()*Gradc;
spt.m_cdot[isol] = el.Evaluate(act[isol], n)*dtrans;
}
bt.m_phi0 = m_pMat->SolidReferentialVolumeFraction(mp);
m_pMat->PartitionCoefficientFunctions(mp, spt.m_k, spt.m_dkdJ, spt.m_dkdc);
// fluid material point data
double phif = m_pMat->Porosity(mp);
double phis = m_pMat->SolidVolumeFrac(mp);
vec3d gradphif = m_pMat->gradPorosity(mp);
pt.m_efdot = el.Evaluate(ae, n)*dtrans;
pt.m_vft = ept.m_v + ft.m_w/phif;
mat3d Gradw = Gradient(el, w, n);
bt.m_Lw = Gradw*Fi;
pt.m_Lf = ept.m_L + bt.m_Lw/phif - (ft.m_w & gradphif)/(phif*phif);
pt.m_ef = el.Evaluate(e, n);
vec3d Gradef = Gradient(el, e, n);
pt.m_gradef = Fi.transpose()*Gradef;
double R = m_pMat->m_Rgas;
double T = m_pMat->m_Tabs;
double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp);
// fluid acceleration
pt.m_aft = (ft.m_aw + ept.m_a*phif - ft.m_w*ft.m_Jdot*phis/phif/ept.m_J + pt.m_Lf*ft.m_w)/phif;
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->SoluteFlux(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);
spt.m_cF = m_pMat->FixedChargeDensity(mp);
// calculate the solid stress at this material point
pt.m_sf = m_pMat->Fluid()->GetViscous()->Stress(mp); //Old Nat BC
ft.m_ss = m_pMat->Solid()->Stress(mp) - m_pMat->Fluid()->GetViscous()->Stress(mp)*phis; //Old NatBC
//Old Nat BC
for (int isol=0; isol<nsol; ++isol)
ft.m_ss += -mat3dd(1.0)*R*T*osmc*spt.m_ca[isol];
//pt.m_sf = m_pMat->Fluid()->GetViscous()->Stress(mp); //New Nat BC
//ft.m_ss = -mat3dd(1.0)*pt.m_pf + m_pMat->Solid()->Stress(mp) - m_pMat->Fluid()->GetViscous()->Stress(mp)*phis; //New NatBC
// calculate the mixture stress at this material point
ept.m_s = -mat3dd(1.0)*spt.m_pe + ft.m_ss + pt.m_sf;
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::InertialForces(FEGlobalVector& R)
{
int NE = (int)m_Elem.size();
const int nsol = m_pMat->Solutes();
const int ndpn = 7+nsol;
#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 = 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 FEMultiphasicFSIDomain3D::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();
const int nsol = m_pMat->Solutes();
const int ndpn = 7 + 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>());
FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>());
double densTf = m_pMat->TrueFluidDensity(mp);
double densTs = m_pMat->TrueSolidDensity(mp);
double phis = m_pMat->SolidVolumeFrac(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*(densTf*H[i]*detJ);
vec3d fs = (-pt.m_aft*densTf + ept.m_a*densTs)*H[i]*phis*detJ; //mixture 2
// calculate internal force
// the '-' sign is so that the internal forces get subtracted
// from the global residual vector
fe[ndpn*i+0] -= fs.x;
fe[ndpn*i+1] -= fs.y;
fe[ndpn*i+2] -= fs.z;
fe[ndpn*i+3] -= f.x;
fe[ndpn*i+4] -= f.y;
fe[ndpn*i+5] -= f.z;
}
}
}
//-----------------------------------------------------------------------------
void FEMultiphasicFSIDomain3D::Serialize(DumpStream& ar)
{
FESolidDomain::Serialize(ar);
if (ar.IsShallow()) return;
ar & m_sseps;
ar & m_pMat;
ar & m_dofU & m_dofV & m_dofW & m_dofAW;
ar & m_dofSU & m_dofR;
ar & m_dof;
ar & m_dofEF & m_dofAEF & m_dofC & m_dofAC;
}
| C++ |
3D | febiosoftware/FEBio | FEBioFluid/FECarreauYasudaFluid.h | .h | 2,593 | 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 "FEViscousFluid.h"
//-----------------------------------------------------------------------------
// This class evaluates the viscous stress in a Carreau-Yasuda power-law fluid
class FEBIOFLUID_API FECarreauYasudaFluid : public FEViscousFluid
{
public:
//! constructor
FECarreauYasudaFluid(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
double m_n; //!< power-law index
double m_a; //!< exponent
// declare parameter list
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/febio_cb.cpp | .cpp | 4,385 | 150 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "febio_cb.h"
#include <FEBioLib/FEBioModel.h>
#include <FEBioLib/version.h>
#include "console.h"
#include "Interrupt.h"
#include "breakpoint.h"
#include "FEBioApp.h"
#include <iostream>
//-----------------------------------------------------------------------------
// callback to update window title
bool update_console_cb(FEModel* pfem, unsigned int nwhen, void* pd)
{
FEBioModel& fem = static_cast<FEBioModel&>(*pfem);
// get the number of steps
int nsteps = fem.Steps();
// calculate progress
double starttime = fem.GetStartTime();
double endtime = fem.GetEndTime();
double f = 0.0;
if (nwhen != CB_INIT)
{
double ftime = fem.GetCurrentTime();
if (endtime != starttime) f = (ftime - starttime) / (endtime - starttime);
else
{
// this only happens (I think) when the model is solved
f = 1.0;
}
}
double pct = 100.0*f;
// check debug flag
int ndebug = fem.GetDebugLevel();
// obtain a pointer to the console object. We'll use this to
// set the title of the console window.
Console* pShell = Console::GetHandle();
char* szver = febio::getVersionString();
char szvers[64] = {0};
#ifndef NDEBUG
snprintf(szvers, sizeof(szvers), "FEBio (DEBUG) %s", szver);
#else
snprintf(szvers, sizeof(szvers), "FEBio %s", szver);
#endif
// print progress in title bar
const std::string& sfile = fem.GetFileTitle();
const char* szfile = sfile.c_str();
if (nsteps > 1)
pShell->SetTitle("(step %d/%d: %.f%%) %s - %s %s", fem.GetCurrentStepIndex() + 1, nsteps, pct, szfile, szvers, (ndebug?"(debug mode)": ""));
else
pShell->SetTitle("(%.f%%) %s - %s %s", pct, szfile, szvers, (ndebug?"(debug mode)": ""));
if (nsteps > 1)
{
int step = fem.GetCurrentStepIndex();
double w = (step + f) / nsteps;
pct = 100.0*w;
}
// set progress (will print progress on task bar)
if (nwhen == CB_SOLVED) pShell->SetProgress(100.0);
else pShell->SetProgress(pct);
return true;
}
//-----------------------------------------------------------------------------
// break points cb
bool break_point_cb(FEModel* pfem, unsigned int nwhen, void* pd)
{
// get the current simulation time
double t = pfem->GetTime().currentTime;
// see if a break point was reached
int bp = check_break(nwhen, t);
if (bp >= 0)
{
std::cout << "breakpoint " << bp + 1 << " reached\n";
// get a pointer to the app
FEBioApp* app = FEBioApp::GetInstance();
// process the commands
if (app) app->ProcessCommands();
}
return true;
}
//-----------------------------------------------------------------------------
// callback for ctrl+c interruptions
bool interrupt_cb(FEModel* pfem, unsigned int nwhen, void* pd)
{
// Do not process this when we are writing or reading the dump file since
// this may cause problems
if ((nwhen == CB_SERIALIZE_LOAD) || (nwhen == CB_SERIALIZE_SAVE)) return true;
Interruption itr;
if (itr.m_bsig)
{
itr.m_bsig = false;
std::cout << "User interruption\n";
// get a pointer to the app
FEBioApp* app = FEBioApp::GetInstance();
// process the commands
if (app) app->ProcessCommands();
}
return true;
}
| C++ |
3D | febiosoftware/FEBio | FEBio/FEBioCommand.h | .h | 7,619 | 273 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 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 "Command.h"
#include "CommandManager.h"
//-----------------------------------------------------------------------------
class FEBioModel;
//-----------------------------------------------------------------------------
//! Base class of FEBio commands
class FEBioCommand : public Command
{
public:
FEBioCommand();
virtual ~FEBioCommand(void);
protected:
FEBioModel* GetFEM();
};
//-----------------------------------------------------------------------------
// helper class for registering FEBio commands
class FERegisterCmd
{
public:
FERegisterCmd(Command* pcmd, const char* szname, const char* szdesc)
{
pcmd->SetName(szname);
pcmd->SetDescription(szdesc);
CommandManager* pCM = CommandManager::GetInstance();
pCM->AddCommand(pcmd);
}
};
#define DECLARE_COMMAND(theCmd) public: static FERegisterCmd m_##theCmd##_rc
#define REGISTER_COMMAND(theClass, theName, theDesc) FERegisterCmd theClass::m_##theClass##_rc(new theClass(), theName, theDesc)
//-----------------------------------------------------------------------------
class FEBioCmd_Run : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Run);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Restart : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Restart);
};
//-----------------------------------------------------------------------------
class FEBioCmd_LoadPlugin : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_LoadPlugin);
};
//-----------------------------------------------------------------------------
class FEBioCmd_UnLoadPlugin : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_UnLoadPlugin);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Config : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Config);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Plugins : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Plugins);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Help : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Help);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Events : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Events);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Quit : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Quit);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Cont : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Cont);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Conv : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Conv);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Debug : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Debug);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Fail : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Fail);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Plot : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Plot);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Print : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Print);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Version : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Version);
};
//-----------------------------------------------------------------------------
class FEBioCmd_Time : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_Time);
};
//-----------------------------------------------------------------------------
class FEBioCmd_svg : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_svg);
};
//-----------------------------------------------------------------------------
class FEBioCmd_out : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_out);
};
//-----------------------------------------------------------------------------
class FEBioCmd_where : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_where);
};
//-----------------------------------------------------------------------------
class FEBioCmd_break : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_break);
};
//-----------------------------------------------------------------------------
class FEBioCmd_breaks : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_breaks);
};
//-----------------------------------------------------------------------------
class FEBioCmd_clear_breaks : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_clear_breaks);
};
//-----------------------------------------------------------------------------
class FEBioCmd_list : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_list);
};
//-----------------------------------------------------------------------------
class FEBioCmd_hist: public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_hist);
};
//-----------------------------------------------------------------------------
class FEBioCmd_set : public FEBioCommand
{
public:
int run(int nargs, char** argv);
DECLARE_COMMAND(FEBioCmd_set);
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/FEBioCommand.cpp | .cpp | 21,381 | 784 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 <FEBioLib/plugin.h>
// TODO: On Windows the GetCurrentTime macro gets in here via plugin.h.
// I need to look into how to prevent this
#ifdef GetCurrentTime
#undef GetCurrentTime
#endif
#include <cstdlib>
#include <FEBioLib/FEBioModel.h>
#include <FEBioLib/version.h>
#include <FECore/FEException.h>
#include <FECore/FESolver.h>
#include <FECore/CompactMatrix.h>
#include <FECore/FEAnalysis.h>
#include <FECore/FEGlobalMatrix.h>
#include "FEBioCommand.h"
#include "console.h"
#include <FEBioLib/cmdoptions.h>
#include <FEBioLib/febio.h>
#include "FEBioApp.h"
#include "breakpoint.h"
#include <iostream>
#include <fstream>
//-----------------------------------------------------------------------------
#ifdef WIN32
#define szcmp _stricmp
#else
#define szcmp strcmp
#endif
//-----------------------------------------------------------------------------
REGISTER_COMMAND(FEBioCmd_break , "break" , "add a break point");
REGISTER_COMMAND(FEBioCmd_breaks , "breaks" , "print list of break points");
REGISTER_COMMAND(FEBioCmd_clear_breaks , "clear" , "clear one or all break points");
REGISTER_COMMAND(FEBioCmd_Config , "config" , "(re-)load a FEBio configuration file");
REGISTER_COMMAND(FEBioCmd_Cont , "cont" , "continues the current model");
REGISTER_COMMAND(FEBioCmd_Conv , "conv" , "force conversion of iteration");
REGISTER_COMMAND(FEBioCmd_Debug , "debug" , "toggle debug mode");
REGISTER_COMMAND(FEBioCmd_Events , "events" , "print list of events");
REGISTER_COMMAND(FEBioCmd_Fail , "fail" , "force iteratoin failer");
REGISTER_COMMAND(FEBioCmd_Help , "help" , "print available commands");
REGISTER_COMMAND(FEBioCmd_hist , "hist" , "lists history of commands");
REGISTER_COMMAND(FEBioCmd_LoadPlugin , "import" , "load a plugin");
REGISTER_COMMAND(FEBioCmd_Plot , "plot" , "store current state to plot file");
REGISTER_COMMAND(FEBioCmd_out , "out" , "write matrix and rhs file");
REGISTER_COMMAND(FEBioCmd_Plugins , "plugins", "list the plugins that are loaded");
REGISTER_COMMAND(FEBioCmd_Print , "print" , "print values of variables");
REGISTER_COMMAND(FEBioCmd_Quit , "quit" , "terminate the run and quit");
REGISTER_COMMAND(FEBioCmd_Restart , "restart", "toggle restart mode");
REGISTER_COMMAND(FEBioCmd_Run , "run" , "run an FEBio input file");
REGISTER_COMMAND(FEBioCmd_set , "set" , "set value of some model and config parameters");
REGISTER_COMMAND(FEBioCmd_svg , "svg" , "write matrix sparsity pattern to svg file");
REGISTER_COMMAND(FEBioCmd_Time , "time" , "print progress time statistics");
REGISTER_COMMAND(FEBioCmd_UnLoadPlugin , "unload" , "unload a plugin");
REGISTER_COMMAND(FEBioCmd_Version , "version", "print version information");
REGISTER_COMMAND(FEBioCmd_where , "where" , "current callback event");
REGISTER_COMMAND(FEBioCmd_list , "list" , "list factory classes");
int need_active_model()
{
printf("No active model.\n");
return 0;
}
int model_already_running()
{
printf("A model is running. You must stop the active model before running this command.\n");
return 0;
}
int invalid_nr_args()
{
printf("Invalid number of arguments.\n");
return 0;
}
int unknown_args()
{
printf("Unrecognized arguments.\n");
return 0;
}
//-----------------------------------------------------------------------------
FEBioCommand::FEBioCommand()
{
}
FEBioCommand::~FEBioCommand()
{
}
FEBioModel* FEBioCommand::GetFEM()
{
return FEBioApp::GetInstance()->GetCurrentModel();
}
//-----------------------------------------------------------------------------
int FEBioCmd_Run::run(int nargs, char** argv)
{
FEBioModel* fem = GetFEM();
if (fem) return model_already_running();
FEBioApp* febio = FEBioApp::GetInstance();
if (febio->ParseCmdLine(nargs, argv) == false) return 0;
// run FEBio on the ops
febio->RunModel();
// reset the title after computation.
Console* pShell = Console::GetHandle();
pShell->SetTitle("FEBio4");
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Restart::run(int nargs, char** argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
int dumpLevel = fem->GetDumpLevel();
if (dumpLevel == FE_DUMP_NEVER) fem->SetDumpLevel(FE_DUMP_MAJOR_ITRS);
else fem->SetDumpLevel(FE_DUMP_NEVER);
dumpLevel = fem->GetDumpLevel();
printf("Restart level set to: ");
switch (dumpLevel)
{
case FE_DUMP_NEVER : printf("NEVER (0)\n"); break;
case FE_DUMP_MAJOR_ITRS : printf("MAJOR_ITRS (1)\n"); break;
case FE_DUMP_STEP : printf("STEP (2)\n"); break;
case FE_DUMP_MUST_POINTS: printf("MUST POINTS (3)\n"); break;
default:
printf("(unknown value)\n");
break;
}
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_LoadPlugin::run(int nargs, char** argv)
{
FEBioModel* fem = GetFEM();
if (fem) return model_already_running();
if (nargs < 2) fprintf(stderr, "missing file name\n");
else febio::ImportPlugin(argv[1]);
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_UnLoadPlugin::run(int nargs, char* argv[])
{
FEBioModel* fem = GetFEM();
if (fem) return model_already_running();
FEBioPluginManager* PM = FEBioPluginManager::GetInstance();
if (PM == 0) return -1;
if (nargs == 1)
{
// unload all plugins
while (PM->Plugins() > 0)
{
const FEBioPlugin& pl = PM->GetPlugin(0);
string sname = pl.GetName();
bool b = PM->UnloadPlugin(0);
if (b) fprintf(stdout, "Success unloading %s\n", sname.c_str());
else fprintf(stdout, "Failed unloading %s\n", sname.c_str());
}
}
else if (nargs == 2)
{
const char* c = argv[1];
if (c[0] == '%')
{
int n = atoi(c+1);
if ((n > 0) && (n <= PM->Plugins()))
{
const FEBioPlugin& pl = PM->GetPlugin(n - 1);
string sname = pl.GetName();
bool b = PM->UnloadPlugin(n - 1);
if (b) fprintf(stdout, "Success unloading %s\n", sname.c_str());
else fprintf(stdout, "Failed unloading %s\n", sname.c_str());
}
else fprintf(stderr, "Invalid plugin index\n");
}
else
{
bool b = PM->UnloadPlugin(argv[1]);
if (b) fprintf(stdout, "Success unloading %s\n", argv[1]);
else fprintf(stdout, "Failed unloading %s\n", argv[1]);
}
}
else fprintf(stderr, "syntax error\n");
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Version::run(int nargs, char** argv)
{
char* szver = febio::getVersionString();
#ifndef NDEBUG
fprintf(stderr, "\nFEBio version %s (DEBUG)\n", szver);
#else
fprintf(stderr, "\nFEBio version %s\n", szver);
#endif
fprintf(stderr, "SDK Version %d.%d\n", FE_SDK_MAJOR_VERSION, FE_SDK_SUB_VERSION);
fprintf(stderr, "compiled on " __DATE__ "\n\n");
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Help::run(int nargs, char** argv)
{
CommandManager* pCM = CommandManager::GetInstance();
int N = pCM->Size();
if (N == 0) return 0;
printf("\nCommand overview:\n");
CommandManager::CmdIterator it = pCM->First();
for (int i=0; i<N; ++i, ++it)
{
const char* szn = (*it)->GetName();
int l = (int)strlen(szn);
printf("\t%s ", szn);
while (l++ - 15 < 0) putchar('.');
const char* szd = (*it)->GetDescription();
printf(" : %s\n", szd);
}
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Events::run(int nargs, char** argv)
{
printf("\n");
printf("\tALWAYS : break on any event.\n");
printf("\tINIT : break after model initialization.\n");
printf("\tSTEP_ACTIVE : break after step activation.\n");
printf("\tMAJOR_ITERS : break after major iteration converged.\n");
printf("\tMINOR_ITERS : break after minor iteration.\n");
printf("\tSOLVED : break after model is solved.\n");
printf("\tUPDATE_TIME : break before time is incremented.\n");
printf("\tAUGMENT : break before augmentation.\n");
printf("\tSTEP_SOLVED : break after step is solved.\n");
printf("\tMATRIX_REFORM : break after global matrix is reformed.\n");
printf("\n");
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Config::run(int nargs, char* argv[])
{
FEBioModel* fem = GetFEM();
if (fem) return model_already_running();
FEBioApp* feApp = FEBioApp::GetInstance();
febio::CMDOPTIONS& ops = feApp->CommandOptions();
if (nargs == 1)
{
feApp->Configure(ops.szcnf);
}
else if (nargs == 2)
{
snprintf(ops.szcnf, sizeof(ops.szcnf), "%s", argv[1]);
feApp->Configure(ops.szcnf);
}
else return invalid_nr_args();
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Plugins::run(int nargs, char** argv)
{
FEBioPluginManager* PM = FEBioPluginManager::GetInstance();
if (PM == 0) return 0;
int NP = PM->Plugins();
if (NP == 0)
{
fprintf(stdout, "no plugins loaded\n");
}
else
{
for (int i = 0; i < NP; ++i)
{
const FEBioPlugin& pl = PM->GetPlugin(i);
fprintf(stdout, "%%%d: %s\n", i + 1, pl.GetName());
}
}
return 0;
}
//-----------------------------------------------------------------------------
class ExitRequest : public std::runtime_error
{
public:
ExitRequest() throw() : std::runtime_error("Early termination by user request") {}
};
int FEBioCmd_Quit::run(int nargs, char** argv)
{
if (GetFEM()) throw ExitRequest();
return 1;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Cont::run(int nargs, char** argv)
{
if (GetFEM() == nullptr) return need_active_model();
return 1;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Conv::run(int nargs, char **argv)
{
if (GetFEM() == nullptr) return need_active_model();
throw ForceConversion();
return 1;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Debug::run(int nargs, char** argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr)
{
printf("No active model.\n");
return 0;
}
FEAnalysis* pstep = fem->GetCurrentStep();
int ndebug = fem->GetDebugLevel();
if (nargs == 1) ndebug = (ndebug? 0 : 1);
else
{
if (strcmp(argv[1], "on" ) == 0) ndebug = 1;
else if (strcmp(argv[1], "off") == 0) ndebug = 0;
else { fprintf(stderr, "%s is not a valid option for debug.\n", argv[1]); return 0; }
}
fem->SetDebugLevel(ndebug);
printf("Debug mode is %s\n", (ndebug?"on":"off"));
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Fail::run(int nargs, char **argv)
{
throw IterationFailure();
}
//-----------------------------------------------------------------------------
int FEBioCmd_Plot::run(int nargs, char **argv)
{
assert(false);
return 1;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Print::run(int nargs, char **argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
FEAnalysis* pstep = fem->GetCurrentStep();
if (nargs >= 2)
{
if (strcmp(argv[1], "time") == 0)
{
printf("Time : %lg\n", fem->GetCurrentTime());
}
else
{
// assume it is a material parameter
FEParamValue val = fem->GetParameterValue(ParamString(argv[1]));
if (val.isValid())
{
switch (val.type())
{
case FE_PARAM_DOUBLE: printf("%lg\n", val.value<double>()); break;
default:
printf("(cannot print value)\n");
}
}
else
{
printf("The variable %s is not recognized\n", argv[1]);
}
}
}
else invalid_nr_args();
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_Time::run(int nargs, char **argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
double sec = fem->GetSolveTimer().peek();
double sec0 = sec;
int nhour, nmin, nsec;
nhour = (int) (sec / 3600.0); sec -= nhour*3600;
nmin = (int) (sec / 60.0); sec -= nmin*60;
nsec = (int) (sec);
printf("Elapsed time : %d:%02d:%02d\n", nhour, nmin, nsec);
double endtime = fem->GetEndTime();
FETimeInfo& tp = fem->GetTime();
double pct = (tp.currentTime - tp.timeIncrement) / endtime;
if (pct != 0)
{
double sec1 = sec0*(1.0/pct - 1.0);
nhour = (int) (sec1 / 3600.0); sec1 -= nhour*3600;
nmin = (int) (sec1 / 60.0); sec1 -= nmin*60;
nsec = (int) (sec1);
printf("Est. time remaining: %d:%02d:%02d\n", nhour, nmin, nsec);
}
else
printf("Est. time remaining: (not available)\n");
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_svg::run(int nargs, char **argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
FESolver* solver = fem->GetCurrentStep()->GetFESolver();
SparseMatrix* M = solver->GetStiffnessMatrix()->GetSparseMatrixPtr();
std::vector<double> R = solver->GetLoadVector();
CompactMatrix* A = dynamic_cast<CompactMatrix*>(M);
if (A && (fem->GetFileTitle().empty() == false))
{
int rows = A->Rows();
int cols = A->Columns();
int i0 = 0, j0 = 0;
int i1 = -1, j1 = -1;
if (nargs == 3)
{
i1 = atoi(argv[1]);
if (i1 < 0) { i0 = rows + i1; i1 = rows - 1; }
j1 = atoi(argv[2]);
if (j1 < 0) { j0 = cols + j1; j1 = cols - 1; }
}
const char* szfile = fem->GetFileTitle().c_str();
char buf[1024] = { 0 }, szsvg[1024] = { 0 };
strcpy(buf, szfile);
char* ch = strrchr(buf, '.');
if (ch) *ch = 0;
snprintf(szsvg, sizeof(szsvg), "%s.svg", buf);
std::filebuf fb;
fb.open(szsvg, std::ios::out);
std::ostream out(&fb);
febio::print_svg(A, out, i0, j0, i1, j1);
fb.close();
cout << "\nFile written " << szsvg << endl;
}
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_out::run(int nargs, char **argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
int mode = 0; // binary
if (nargs > 1)
{
if (strcmp(argv[1], "-txt") == 0) mode = 1; // text
}
FESolver* solver = fem->GetCurrentStep()->GetFESolver();
SparseMatrix* M = solver->GetStiffnessMatrix()->GetSparseMatrixPtr();
std::vector<double> R = solver->GetLoadVector();
CompactMatrix* A = dynamic_cast<CompactMatrix*>(M);
if (A && (fem->GetFileTitle().empty() == false))
{
const char* szfile = fem->GetFileTitle().c_str();
char buf[1024] = { 0 }, szK[1024] = { 0 }, szR[1024] = { 0 };
strcpy(buf, szfile);
char* ch = strrchr(buf, '.');
if (ch) *ch = 0;
snprintf(szK, sizeof(szK), "%s.out", buf);
snprintf(szR, sizeof(szR), "%s_rhs.out", buf);
febio::write_hb(*A, szK, mode);
febio::write_vector(R, szR, mode);
cout << "\nFiles written: " << szK << ", " << szR << endl;
}
else cout << "ERROR: Don't know how to write matrix format.\n";
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_where::run(int nargs, char **argv)
{
FEBioModel* fem = GetFEM();
if (fem == nullptr) return need_active_model();
unsigned int nevent = fem->CurrentEvent();
if (nevent == 0) cout << "Not inside callback event\n";
else cout << "Callback event: ";
switch (nevent)
{
case CB_INIT : cout << "INIT"; break;
case CB_STEP_ACTIVE : cout << "STEP_ACTIVE"; break;
case CB_MAJOR_ITERS : cout << "MAJOR_ITERS"; break;
case CB_MINOR_ITERS : cout << "MINOR_ITERS"; break;
case CB_SOLVED : cout << "SOLVED"; break;
case CB_UPDATE_TIME : cout << "UPDATE_TIME"; break;
case CB_AUGMENT : cout << "AUGMENT"; break;
case CB_STEP_SOLVED : cout << "STEP_SOLVED"; break;
case CB_MATRIX_REFORM: cout << "MATRIX_REFORM"; break;
default:
cout << "(unknown)";
}
cout << endl;
return 0;
}
//-----------------------------------------------------------------------------
int FEBioCmd_break::run(int nargs, char **argv)
{
if (nargs != 2) return invalid_nr_args();
const char* szbuf = argv[1];
add_break_point(szbuf);
return 0;
}
int FEBioCmd_breaks::run(int nargs, char **argv)
{
print_break_points();
return 0;
}
int FEBioCmd_clear_breaks::run(int nargs, char **argv)
{
if (nargs == 1)
clear_break_points(-1);
else if (nargs == 2)
{
int bp = atoi(argv[1]);
clear_break_points(bp - 1);
}
return 0;
}
int FEBioCmd_hist::run(int nargs, char **argv)
{
Console* console = Console::GetHandle();
vector<string> hist = console->GetHistory();
int i = 1;
for (string& s : hist)
{
cout << "%" << i++ << ": " << s << endl;
}
return 0;
}
const char* super_id_to_string(SUPER_CLASS_ID superID)
{
const char* szclass = FECoreKernel::SuperClassString(superID);
if (szclass == nullptr) szclass = "(unknown)";
return szclass;
}
int FEBioCmd_list::run(int nargs, char** argv)
{
FECoreKernel& fecore = FECoreKernel::GetInstance();
const char* szmod = 0;
const char* sztype = 0;
const char* szpat = 0;
int nmax = 0;
int lpat = 0;
// process argumets
std::cin.clear();
int nc = 1;
while (nc < nargs)
{
if (strcmp(argv[nc], "-m") == 0)
{
if (nargs == 2)
{
int mods = fecore.Modules();
for (int i = 0; i < mods; ++i)
{
const char* szmod = fecore.GetModuleName(i);
printf("%d: %s\n", i+1, szmod);
}
printf("\n");
return 0;
}
if (nargs <= nc + 1) return invalid_nr_args();
szmod = argv[++nc];
}
else if (strcmp(argv[nc], "-c") == 0)
{
if (nargs <= nc + 1) return invalid_nr_args();
sztype = argv[++nc];
}
else if (strcmp(argv[nc], "-n") == 0)
{
if (nargs <= nc + 1) return invalid_nr_args();
nmax = atoi(argv[++nc]);
}
else if (strcmp(argv[nc], "-s") == 0)
{
if (nargs <= nc + 1) return invalid_nr_args();
szpat = argv[++nc];
lpat = (int)strlen(szpat);
if (lpat == 0) szpat = 0;
}
else return unknown_args();
++nc;
}
int facs = fecore.FactoryClasses();
int n = 1, m = 0;
for (int i = 0; i < facs; ++i)
{
const FECoreFactory* fac = fecore.GetFactoryClass(i);
if (fac == nullptr) { printf("%3d: %s\n", n++, "(null)"); m++; }
else
{
SUPER_CLASS_ID superID = fac->GetSuperClassID();
const char* szclass = super_id_to_string(superID);
int moduleId = fac->GetModuleID();
const char* szmodule = fecore.GetModuleNameFromId(moduleId);
if ((szmod == 0) || (szmodule && (strcmp(szmodule, szmod) == 0)))
{
if ((sztype == 0) || (szcmp(szclass, sztype) == 0))
{
const char* facType = fac->GetTypeStr();
if ((szpat == 0) || (strstr(facType, szpat)))
{
if (szmodule) printf("%3d: %s.%s [%s]\n", n++, szmodule, facType, szclass);
else printf("%3d: %s [%s]\n", n++, facType, szclass);
m++;
}
}
}
}
if ((nmax != 0) && (m >= nmax))
{
char ch = 0;
do {
printf("Continue (y or n)?");
std::cin.get(ch);
} while ((ch != 'y') && (ch != 'n'));
m = 0;
if (ch == 'n') break;
}
}
printf("\n");
return 0;
}
int FEBioCmd_set::run(int nargs, char** argv)
{
FEBioModel* fem = GetFEM();
if (nargs == 1)
{
printf("output_negative_jacobians = %d\n", NegativeJacobian::m_maxout);
if (fem)
{
printf("print_model_params = %d\n", (fem->GetPrintParametersFlag() ? 1 : 0));
printf("show_warnings_and_errors = %d\n", (fem->ShowWarningsAndErrors() ? 1 : 0));
}
return 0;
}
if (nargs != 3)
{
printf("insufficient arguments.");
return 0;
}
int n = atoi(argv[2]);
if (strcmp(argv[1], "output_negative_jacobians") == 0)
{
NegativeJacobian::m_maxout = n;
printf("output_negative_jacobians = %d", n);
}
else if (fem && strcmp(argv[1], "print_model_params") == 0)
{
fem->SetPrintParametersFlag(n != 0);
printf("print_model_params = %d", n);
}
else if (fem && strcmp(argv[1], "show_warnings_and_errors") == 0)
{
fem->ShowWarningsAndErrors(n != 0);
printf("show_warnings_and_errors = %d", n);
}
else
{
printf("don't know \"%s\"", argv[1]);
}
return 0;
}
| C++ |
3D | febiosoftware/FEBio | FEBio/FEBioApp.cpp | .cpp | 14,937 | 602 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEBioApp.h"
#include "console.h"
#include "CommandManager.h"
#include <FECore/log.h>
#include "console.h"
#include "breakpoint.h"
#include <FEBioLib/febio.h>
#include <FEBioLib/version.h>
#include "febio_cb.h"
#include "Interrupt.h"
#include "ping.h"
FEBioApp* FEBioApp::m_This = nullptr;
FEBioApp::FEBioApp()
{
assert(m_This == nullptr);
m_This = this;
m_fem = nullptr;
}
FEBioApp* FEBioApp::GetInstance()
{
assert(m_This);
return m_This;
}
febio::CMDOPTIONS& FEBioApp::CommandOptions()
{
return m_ops;
}
bool FEBioApp::Init(int argc, char* argv[])
{
// Initialize kernel
FECoreKernel::SetInstance(febio::GetFECoreKernel());
// parse the command line
if (ParseCmdLine(argc, argv) == false) return false;
// say hello
ConsoleStream s;
if (m_ops.bsplash && (!m_ops.bsilent)) febio::Hello(s);
// Initialize FEBio library
febio::InitLibrary();
// copy some flags to configuration
m_config.SetOutputLevel(m_ops.bsilent ? 0 : 1);
// read the configration file if specified
if (m_ops.szcnf[0])
{
fprintf(stdout, "Reading configuration file: %s\n", m_ops.szcnf);
if (febio::Configure(m_ops.szcnf, m_config) == false)
{
fprintf(stderr, "FATAL ERROR: An error occurred reading the configuration file.\n");
return false;
}
}
else
{
fprintf(stdout, "Starting without configuration file\n");
}
if (m_config.m_noutput != 0) fprintf(stdout, "Default linear solver: %s\n", febio::GetFECoreKernel()->GetLinearSolverType());
// read command line plugin if specified
if (m_ops.szimp[0] != 0)
{
febio::ImportPlugin(m_ops.szimp);
}
// ping repo server
// Removed for the time being, pending further instruction
// ping();
return true;
}
//-----------------------------------------------------------------------------
bool FEBioApp::Configure(const char* szconfig)
{
return febio::Configure(szconfig, m_config);
}
//-----------------------------------------------------------------------------
int FEBioApp::Run()
{
// activate interruption handler
Interruption I;
// run FEBio either interactively or directly
if (m_ops.binteractive)
return prompt();
else
return RunModel();
}
//-----------------------------------------------------------------------------
void FEBioApp::Finish()
{
febio::FinishLibrary();
Console::GetHandle()->CleanUp();
}
//-----------------------------------------------------------------------------
// get the current model
FEBioModel* FEBioApp::GetCurrentModel()
{
return m_fem;
}
//-----------------------------------------------------------------------------
// set the currently active model
void FEBioApp::SetCurrentModel(FEBioModel* fem)
{
m_fem = fem;
}
//-----------------------------------------------------------------------------
// Run an FEBio input file.
int FEBioApp::RunModel()
{
// create the FEBioModel object
FEBioModel fem;
SetCurrentModel(&fem);
// add console stream to log file
if (m_ops.bsilent == false)
{
fem.GetLogFile().SetLogStream(new ConsoleStream);
if (m_ops.bupdateTitle == false)
Console::GetHandle()->Deactivate(); // This doesn't really deactive the console, it just prevents the title from getting updated.
}
else
Console::GetHandle()->Deactivate();
// register callbacks
fem.AddCallback(update_console_cb, CB_MAJOR_ITERS | CB_INIT | CB_SOLVED | CB_STEP_ACTIVE, 0);
fem.AddCallback(interrupt_cb, CB_ALWAYS, 0);
fem.AddCallback(break_point_cb, CB_ALWAYS, 0);
// set options that were passed on the command line
fem.SetDebugLevel(m_ops.ndebug);
fem.SetDumpLevel(m_ops.dumpLevel);
fem.SetDumpStride(m_ops.dumpStride);
// set the output filenames
fem.SetLogFilename(m_ops.szlog);
fem.SetPlotFilename(m_ops.szplt);
fem.SetDumpFilename(m_ops.szdmp);
fem.SetAppendOnRestart(m_ops.bappendFiles);
if (!m_ops.boutputLog) fem.SetLogLevel(0);
// read the input file if specified
int nret = 0;
if (m_ops.szfile[0])
{
// read the input file
if (fem.Input(m_ops.szfile) == false) nret = 1;
}
// solve the model with the task and control file
if (nret == 0)
{
// apply configuration overrides
ApplyConfig(fem);
bool bret = febio::SolveModel(fem, m_ops.sztask, m_ops.szctrl);
nret = (bret ? 0 : 1);
}
// reset the current model pointer
SetCurrentModel(nullptr);
return nret;
}
//-----------------------------------------------------------------------------
// apply configuration changes to model
void FEBioApp::ApplyConfig(FEBioModel& fem)
{
if (m_config.m_printParams != -1)
{
fem.SetPrintParametersFlag(m_config.m_printParams != 0);
}
fem.ShowWarningsAndErrors(m_config.m_bshowErrors);
}
//-----------------------------------------------------------------------------
//! Prints the FEBio prompt. If the user did not enter anything on the command
//! line when running FEBio then commands can be entered at the FEBio prompt.
//! This function returns the command arguments as a CMDOPTIONS structure.
int FEBioApp::prompt()
{
// get a pointer to the console window
Console* pShell = Console::GetHandle();
// set the title
pShell->SetTitle("FEBio4");
// process commands
ProcessCommands();
return 0;
}
//-----------------------------------------------------------------------------
//! Parses the command line and returns a CMDOPTIONS structure
//
bool FEBioApp::ParseCmdLine(int nargs, char* argv[])
{
febio::CMDOPTIONS& ops = m_ops;
// set default options
ops.ndebug = 0;
ops.bsplash = true;
ops.bsilent = false;
ops.binteractive = true;
ops.bappendFiles = true;
// these flags indicate whether the corresponding file name
// was defined on the command line. Otherwise, a default name will be generated.
bool blog = false;
bool bplt = false;
bool bdmp = false;
bool brun = true;
// initialize file names
ops.szfile[0] = 0;
ops.szplt[0] = 0;
ops.szlog[0] = 0;
ops.szdmp[0] = 0;
ops.sztask[0] = 0;
ops.szctrl[0] = 0;
ops.szimp[0] = 0;
// set initial configuration file name
if (ops.szcnf[0] == 0)
{
char szpath[512] = { 0 };
febio::get_app_path(szpath, 511);
snprintf(ops.szcnf, sizeof(ops.szcnf), "%sfebio.xml", szpath);
// if there is an febio.xml file next to the binary, we use it, otherwise
// we set the contig name to an empty string
FILE* file = fopen(ops.szcnf, "r");
if (file)
{
fclose(file);
}
else
{
ops.szcnf[0] = 0;
}
}
// loop over the arguments
char* sz;
for (int i=1; i<nargs; ++i)
{
sz = argv[i];
if (strcmp(sz,"-r") == 0)
{
if (ops.sztask[0] != 0) { fprintf(stderr, "-r is incompatible with other command line option.\n"); return false; }
strcpy(ops.sztask, "restart");
strcpy(ops.szctrl, argv[++i]);
ops.binteractive = false;
}
else if (strcmp(sz, "-noappend") == 0)
{
ops.bappendFiles = false;
}
else if (strcmp(sz, "-d") == 0)
{
if (ops.sztask[0] != 0) { fprintf(stderr, "-d is incompatible with other command line option.\n"); return false; }
strcpy(ops.sztask, "diagnose");
strcpy(ops.szctrl, argv[++i]);
ops.binteractive = false;
}
else if (strcmp(sz, "-p") == 0)
{
bplt = true;
strcpy(ops.szplt, argv[++i]);
}
else if (strncmp(sz, "-dump_stride", 12) == 0)
{
if (sz[12] == '=')
{
ops.dumpStride = atoi(sz + 13);
if (ops.dumpStride < 1)
{
fprintf(stderr, "FATAL ERROR: invalid dump stride.\n");
return false;
}
}
else
{
fprintf(stderr, "FATAL ERROR: missing '=' after -dump_stride.\n");
return false;
}
}
else if (strncmp(sz, "-dump", 5) == 0)
{
ops.dumpLevel = FE_DUMP_MAJOR_ITRS;
if (sz[5] == '=') ops.dumpLevel = atoi(sz + 6);
if ((ops.dumpLevel < 0) || (ops.dumpLevel > 3))
{
fprintf(stderr, "FATAL ERROR: invalid restart level.\n");
return false;
}
if (i<nargs - 1)
{
char* szi = argv[i + 1];
if (szi[0] != '-')
{
// assume this is the name of the dump file
strcpy(ops.szdmp, argv[++i]);
bdmp = true;
}
}
}
else if (strcmp(sz, "-o") == 0)
{
blog = true;
strcpy(ops.szlog, argv[++i]);
}
else if (strcmp(sz, "-i") == 0)
{
++i;
const char* szext = strrchr(argv[i], '.');
if (szext == 0)
{
// we assume a default extension of .feb if none is provided
snprintf(ops.szfile, sizeof(ops.szfile), "%s.feb", argv[i]);
}
else strcpy(ops.szfile, argv[i]);
ops.binteractive = false;
}
else if (strcmp(sz, "-s") == 0)
{
if (ops.sztask[0] != 0) { fprintf(stderr, "-s is incompatible with other command line option.\n"); return false; }
strcpy(ops.sztask, "optimize");
strcpy(ops.szctrl, argv[++i]);
}
else if ((strcmp(sz, "-g") == 0) || (strcmp(sz, "-g1") == 0))
{
ops.ndebug = 1;
}
else if (strcmp(sz, "-g2") == 0)
{
ops.ndebug = 2;
}
else if (strcmp(sz, "-nosplash") == 0)
{
// don't show the welcome message
ops.bsplash = false;
}
else if (strcmp(sz, "-silent") == 0)
{
// no output to screen
ops.bsilent = true;
}
else if (strcmp(sz, "-no_title") == 0)
{
ops.bupdateTitle = false;
}
else if (strcmp(sz, "-no_log") == 0)
{
ops.boutputLog = false;
}
else if (strcmp(sz, "-cnf") == 0) // obsolete: use -config instead
{
strcpy(ops.szcnf, argv[++i]);
}
else if (strcmp(sz, "-config") == 0)
{
strcpy(ops.szcnf, argv[++i]);
}
else if (strcmp(sz, "-noconfig") == 0)
{
ops.szcnf[0] = 0;
}
else if (strncmp(sz, "-task", 5) == 0)
{
if (sz[5] != '=') { fprintf(stderr, "command line error when parsing task\n"); return false; }
strcpy(ops.sztask, sz+6);
if (i<nargs-1)
{
char* szi = argv[i+1];
if (szi[0] != '-')
{
// assume this is a control file for the specified task
strcpy(ops.szctrl, argv[++i]);
}
}
}
else if (strcmp(sz, "-break") == 0)
{
char szbuf[32]={0};
strcpy(szbuf, argv[++i]);
add_break_point(szbuf);
}
else if (strcmp(sz, "-info")==0)
{
FILE* fp = stdout;
if ((i<nargs-1) && (argv[i+1][0] != '-'))
{
fp = fopen(argv[++i], "wt");
if (fp == 0) fp = stdout;
}
fprintf(fp, "compiled on " __DATE__ "\n");
char* szver = febio::getVersionString();
#ifndef NDEBUG
fprintf(fp, "FEBio version = %s (DEBUG)\n", szver);
#else
fprintf(fp, "FEBio version = %s\n", szver);
#endif
if (fp != stdout) fclose(fp);
}
else if (strcmp(sz, "-norun") == 0)
{
brun = false;
}
else if (strcmp(sz, "-import") == 0)
{
if ((i < nargs - 1) && (argv[i+1][0] != '-'))
strcpy(ops.szimp, argv[++i]);
else
{
fprintf(stderr, "FATAL ERROR: insufficient number of arguments for -import.\n");
return false;
}
}
else if (strncmp(sz, "-output_negative_jacobians", 26) == 0)
{
int n = -1;
if (sz[26] == '=')
{
const char* szval = sz + 27;
n = atoi(szval);
}
NegativeJacobian::m_maxout = n;
}
else if (sz[0] == '-')
{
fprintf(stderr, "FATAL ERROR: Invalid command line option '%s'.\n", sz);
return false;
}
else
{
// if no input file is given yet, we'll assume this is the input file
if (ops.szfile[0] == 0)
{
const char* szext = strrchr(sz, '.');
if (szext == 0)
{
// we assume a default extension of .feb if none is provided
snprintf(ops.szfile, sizeof(ops.szfile), "%s.feb", sz);
}
else
{
strcpy(ops.szfile, sz);
}
ops.binteractive = false;
}
else
{
fprintf(stderr, "FATAL ERROR: Invalid command line option '%s'\n", sz);
return false;
}
}
}
// do some sanity checks
if (strcmp(ops.sztask, "optimize") == 0)
{
// make sure we have an input file
if (ops.szfile[0]==0)
{
fprintf(stderr, "FATAL ERROR: no model input file was defined (use -i to define the model input file)\n\n");
return false;
}
}
// if no task is defined, we assume a std solve is wanted
if (ops.sztask[0] == 0) strcpy(ops.sztask, "solve");
// derive the other filenames
if (ops.szfile[0])
{
char szbase[256]; strcpy(szbase, ops.szfile);
char* ch = strrchr(szbase, '.');
if (ch) *ch = 0;
char szlogbase[256];
if (ops.szctrl[0])
{
strcpy(szlogbase, ops.szctrl);
ch = strrchr(szlogbase, '.');
if (ch) *ch = 0;
}
else strcpy(szlogbase, szbase);
if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szlogbase);
if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase);
if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase);
}
else if (ops.szctrl[0])
{
char szbase[256]; strcpy(szbase, ops.szfile);
strcpy(szbase, ops.szctrl);
char* ch = strrchr(szbase, '.');
if (ch) *ch = 0;
if (!blog) snprintf(ops.szlog, sizeof(ops.szlog), "%s.log", szbase);
if (!bplt) snprintf(ops.szplt, sizeof(ops.szplt), "%s.xplt", szbase);
if (!bdmp) snprintf(ops.szdmp, sizeof(ops.szdmp), "%s.dmp", szbase);
}
return brun;
}
void FEBioApp::ProcessCommands()
{
// get a pointer to the console window
Console* pShell = Console::GetHandle();
// get the command manager
CommandManager* CM = CommandManager::GetInstance();
// enter command loop
int nargs;
char* argv[32];
while (1)
{
// get a command from the shell
pShell->GetCommand(nargs, argv);
if (nargs > 0)
{
// find the command that has this name
Command* pcmd = CM->Find(argv[0]);
if (pcmd)
{
int nret = pcmd->run(nargs, argv);
if (nret == 1) break;
}
else
{
printf("Unknown command: %s\n", argv[0]);
}
}
else if (nargs == 0) break;
// make sure to clear the progress on the console
FEBioModel* fem = GetCurrentModel();
if ((fem == nullptr) || fem->IsSolved()) pShell->SetProgress(0);
}
}
| C++ |
3D | febiosoftware/FEBio | FEBio/stdafx.h | .h | 1,436 | 37 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
// TODO: reference additional headers your program requires here
| Unknown |
3D | febiosoftware/FEBio | FEBio/Command.h | .h | 1,899 | 68 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <string.h>
class Command
{
public:
Command()
{
m_pszname = 0;
m_pszdesc = 0;
}
virtual ~Command() {}
void SetName(const char* szname)
{
int l = (int)strlen(szname);
assert(l);
m_pszname = new char[l+1];
strcpy(m_pszname, szname);
}
void SetDescription(const char* szdesc)
{
int l = (int)strlen(szdesc);
assert(l);
m_pszdesc = new char[l+1];
strcpy(m_pszdesc, szdesc);
}
const char* GetName() { return m_pszname; }
const char* GetDescription() { return m_pszdesc; }
virtual int run(int nargs, char** argv) = 0;
protected:
char* m_pszname;
char* m_pszdesc;
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/FEBio.cpp | .cpp | 1,706 | 51 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEBioApp.h"
//-----------------------------------------------------------------------------
// The starting point of the application
//
int main(int argc, char* argv[])
{
// create the FEBio app
FEBioApp febio;
// initialize the app
if (febio.Init(argc, argv) == false) return 1;
// start the FEBio app
int nret = febio.Run();
// Don't forget to cleanup
febio.Finish();
return nret;
}
| C++ |
3D | febiosoftware/FEBio | FEBio/breakpoint.cpp | .cpp | 5,148 | 176 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "breakpoint.h"
#include <FECore/Callback.h>
#include <vector>
#include <iostream>
using namespace std;
//-----------------------------------------------------------------------------
// list of current break points
std::vector<BREAK_POINT> break_points;
//-----------------------------------------------------------------------------
void clear_break_points()
{
break_points.clear();
}
//-----------------------------------------------------------------------------
void add_time_break_point(double t)
{
BREAK_POINT bp;
bp.nwhen = -1;
bp.time = t;
bp.flag = 1;
break_points.push_back(bp);
}
//-----------------------------------------------------------------------------
void add_event_break_point(int nwhen)
{
BREAK_POINT bp;
bp.nwhen = nwhen;
bp.time = 0;
bp.flag = 1;
break_points.push_back(bp);
}
//-----------------------------------------------------------------------------
#ifdef WIN32
#define szcmp _stricmp
#else
#define szcmp strcasecmp
#endif
//-----------------------------------------------------------------------------
void add_break_point(const char* szcond)
{
if (szcmp(szcond, "ALWAYS" ) == 0) add_event_break_point(CB_ALWAYS);
else if (szcmp(szcond, "INIT" ) == 0) add_event_break_point(CB_INIT);
else if (szcmp(szcond, "STEP_ACTIVE" ) == 0) add_event_break_point(CB_STEP_ACTIVE);
else if (szcmp(szcond, "MAJOR_ITERS" ) == 0) add_event_break_point(CB_MAJOR_ITERS);
else if (szcmp(szcond, "MINOR_ITERS" ) == 0) add_event_break_point(CB_MINOR_ITERS);
else if (szcmp(szcond, "SOLVED" ) == 0) add_event_break_point(CB_SOLVED);
else if (szcmp(szcond, "UPDATE_TIME" ) == 0) add_event_break_point(CB_UPDATE_TIME);
else if (szcmp(szcond, "AUGMENT" ) == 0) add_event_break_point(CB_AUGMENT);
else if (szcmp(szcond, "STEP_SOLVED" ) == 0) add_event_break_point(CB_STEP_SOLVED);
else if (szcmp(szcond, "REFORM" ) == 0) add_event_break_point(CB_MATRIX_REFORM);
else if (szcmp(szcond, "MATRIX_SOLVE" ) == 0) add_event_break_point(CB_PRE_MATRIX_SOLVE);
else
{
double f = atof(szcond);
add_time_break_point(f);
}
}
//-----------------------------------------------------------------------------
void clear_break_points(int n)
{
if (n == -1)
{
break_points.clear();
}
else
{
if ((n >= 0) && (n < break_points.size())) break_points.erase(break_points.begin() + n);
}
}
//-----------------------------------------------------------------------------
// break points cb
void print_break_points()
{
int nbp = (int)break_points.size();
if (nbp == 0)
{
cout << "No breakpoints defined.\n";
return;
}
for (int i = 0; i < nbp; ++i)
{
BREAK_POINT& bpi = break_points[i];
cout << i + 1 << ": ";
if (bpi.nwhen > 0)
{
cout << "event = ";
switch (bpi.nwhen)
{
case CB_ALWAYS: cout << "ALWAYS"; break;
case CB_INIT: cout << "INIT"; break;
case CB_STEP_ACTIVE: cout << "STEP ACTIVE"; break;
case CB_MAJOR_ITERS: cout << "MAJOR_ITERS"; break;
case CB_MINOR_ITERS: cout << "MINOR_ITERS"; break;
case CB_SOLVED: cout << "SOLVED"; break;
case CB_UPDATE_TIME: cout << "UPDATE_TIME"; break;
case CB_AUGMENT: cout << "AUGMENT"; break;
case CB_STEP_SOLVED: cout << "STEP_SOLVED"; break;
case CB_MATRIX_REFORM: cout << "MATRIX_REFORM"; break;
default:
cout << "(unknown)"; break;
}
cout << endl;
}
else
{
cout << "time = " << bpi.time << endl;
}
}
}
// see if a break point is reached
int check_break(int nwhen, double t)
{
const double eps = 1e-12;
int nbp = (int)break_points.size();
for (int i = 0; i<nbp; ++i)
{
BREAK_POINT& bpi = break_points[i];
if (bpi.nwhen > 0)
{
if ((int)nwhen & bpi.nwhen)
{
return i;
}
}
else if (nwhen == CB_MAJOR_ITERS)
{
if (bpi.flag && (bpi.time <= t + eps))
{
bpi.flag = 0;
return i;
}
}
}
return -1;
}
| C++ |
3D | febiosoftware/FEBio | FEBio/Interrupt.h | .h | 1,419 | 40 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
class Interruption
{
public:
Interruption();
virtual ~Interruption();
static void handler(int sig);
static bool m_bsig;
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/febio_cb.h | .h | 1,622 | 41 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
class FEModel;
// callback to update window title
bool update_console_cb(FEModel* pfem, unsigned int nwhen, void* pd);
// callback that manages the break points
bool break_point_cb(FEModel* pfem, unsigned int nwhen, void* pd);
// callback for ctrl+c interruptions
bool interrupt_cb(FEModel* pfem, unsigned int nwhen, void* pd);
| Unknown |
3D | febiosoftware/FEBio | FEBio/ping.cpp | .cpp | 2,422 | 103 | // #include <stdio.h>
// #include <string.h>
// #include <thread>
// #ifdef WIN32
// #include <winsock2.h>
// #include <ws2tcpip.h>
// #else
// #include <sys/types.h>
// #include <unistd.h>
// #include <sys/socket.h>
// #include <arpa/inet.h>
// #include <netinet/in.h>
// #include <netdb.h>
// #endif
#include "ping.h"
// #include <FEBioLib/version.h>
// #define PORT 8560
// #define MSGLEN 50
// #ifdef WIN32
// #define PLAT "Windows"
// #elif __APPLE__
// #define PLAT "macOS"
// #else
// #define PLAT "Linux"
// #endif
// // Main work done in a thread so that the DNS lookup doesn't pause execution
// void pingThread() {
// int sockfd;
// struct sockaddr_in servaddr;
// char message[MSGLEN];
// sprintf(message, "%s %d.%d.%d", PLAT, VERSION, SUBVERSION, SUBSUBVERSION);
// #ifdef WIN32
// WSADATA wsaData;
// int iResult;
// // Initialize Winsock
// iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
// if (iResult != 0) {
// return;
// }
// #endif
// // Creating socket descriptor
// sockfd = socket(AF_INET, SOCK_DGRAM, 0);
// #ifdef WIN32
// if(sockfd == INVALID_SOCKET)
// #else
// if (sockfd < 0)
// #endif
// {
// return;
// }
// // Strucs for DNS lookup
// struct addrinfo *result = NULL;
// struct addrinfo hints;
// //--------------------------------
// // Setup the hints address info structure
// // which is passed to the getaddrinfo() function
// memset(&hints, 0, sizeof(hints));
// hints.ai_family = AF_UNSPEC;
// hints.ai_socktype = SOCK_STREAM;
// hints.ai_protocol = IPPROTO_TCP;
// const char address[] = "repo.febio.org";
// const char port[] = "";
// // DNS Lookup
// int dwRetval = getaddrinfo(address, port, &hints, &result);
// if (dwRetval == 0 && result->ai_family == AF_INET)
// {
// // Filling server information
// memset(&servaddr, 0, sizeof(servaddr));
// servaddr.sin_family = AF_INET;
// servaddr.sin_port = htons(PORT);
// servaddr.sin_addr.s_addr = ((struct sockaddr_in *) result->ai_addr)->sin_addr.s_addr;
// sendto(sockfd, (const char *)message, strlen(message),
// 0, (const struct sockaddr *) &servaddr,
// sizeof(servaddr));
// freeaddrinfo(result);
// }
// #ifdef WIN32
// closesocket(sockfd);
// WSACleanup();
// #else
// close(sockfd);
// #endif
// }
void ping()
{
// std::thread (pingThread).detach();
} | C++ |
3D | febiosoftware/FEBio | FEBio/console.cpp | .cpp | 6,459 | 288 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "console.h"
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#ifdef WIN32
#include <shobjidl.h>
#include <windows.h>
#include <conio.h>
#else
//These are for the wait command
#include <termios.h>
#include <unistd.h>
#endif
#ifdef WIN32
ITaskbarList3* taskBar = NULL;
#endif
//--------------------------------------------------------------------
// pointer to the one and only console object. This pointer
// will be initialized during the first call to GetHandle.
Console* Console::m_pShell = 0;
//--------------------------------------------------------------------
//! This class returns the pointer to the console object. On the first
//! call, the pointer is allocated.
Console* Console::GetHandle()
{
if (m_pShell == 0)
{
m_pShell = new Console;
}
return m_pShell;
}
Console::~Console()
{
CleanUp();
}
void Console::CleanUp()
{
#ifdef WIN32
if (taskBar != NULL)
{
taskBar->Release();
CoUninitialize();
taskBar = NULL;
}
#endif
}
//--------------------------------------------------------------------
//! Sets the title of the console window.
void Console::SetTitle(const char* sz, ...)
{
if (m_bActive)
{
// get a pointer to the argument list
va_list args;
// make the message
char sztitle[512];
va_start(args, sz);
vsnprintf(sztitle, sizeof(sztitle), sz, args);
va_end(args);
#ifdef WIN32
SetConsoleTitleA(sztitle);
#endif
#ifdef LINUX
printf("%c]0;%s%c", '\033', sztitle, '\007');
#endif
}
}
//--------------------------------------------------------------------
//! gets a line from the user
void Console::Wait()
{
// notify the user.
fprintf(stderr, "Press any key to continue...\n");
// flush the standard stream
fflush(stdin);
// wait until user inputs a character with no return symbol.
#ifdef WIN32
_getch();
#else
// change mode of termios so echo is off.
struct termios oldt,
newt;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
getchar();
// reset stdin.
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
#endif
}
//--------------------------------------------------------------------
//! get a command from the user
void Console::GetCommand(int& nargs, char **argv)
{
static char szcmd[512] = { 0 };
szcmd[0] = 0;
// print the command prompt
Write("\nfebio>", 0x0E);
// you must flush the input buffer before using gets
fflush(stdin);
// get the command
fgets(szcmd, 255, stdin);
// fgets does not remove '\n' so we'll do it ourselves
char* ch = strrchr(szcmd, '\n');
if (ch) *ch = 0;
// check for a percentage sign
if (szcmd[0] == '%')
{
int n = atoi(szcmd + 1) - 1;
if ((n >= 0) && (n < m_history.size()))
{
strcpy(szcmd, m_history[n].c_str());
}
else { nargs = 0; return; }
}
// store a copy of the input to the history
// (unless it's the history command)
if (strcmp(szcmd, "hist") != 0)
m_history.push_back(szcmd);
// parse the arguments
nargs = 0;
int n = 0;
int b = 0;
ch = szcmd;
while (*ch)
{
switch (*ch)
{
case ' ':
if ((b == 0) && (n != 0))
{
*ch = 0;
n = 0;
}
break;
case '"':
if ((b == 0) && (n==0)) b = 1;
else
{
b = 0;
*ch = 0;
n = 0;
}
break;
default:
if (n == 0) argv[nargs++] = ch;
n++;
}
ch++;
}
}
//--------------------------------------------------------------------
const std::vector<std::string>& Console::GetHistory() const
{
return m_history;
}
//--------------------------------------------------------------------
//! this function draws an image to the console
void Console::Draw(unsigned char *img, int nx, int ny)
{
#ifdef WIN32
int i, j, n = 0;
WORD att;
printf("\n");
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD col[] = {0x00, 0x04, 0x02, 0x01, 0x0C, 0x0A, 0x09, 0x08, 0x07};
for (j=0; j<ny; ++j)
{
for (i=0; i<nx; ++i)
{
att = (WORD) ((col[img[n++]] << 4)%0xFF);
SetConsoleTextAttribute(hout, att);
printf(" ");
}
printf("\n");
}
SetConsoleTextAttribute(hout, 0x0F);
#endif
}
//--------------------------------------------------------------------
void Console::Write(const char *sz, unsigned short att)
{
#ifdef WIN32
printf("\n");
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hout, (WORD) att);
printf("%s", sz);
SetConsoleTextAttribute(hout, 0x0F);
#else
printf("%s", sz);
#endif
}
//--------------------------------------------------------------------
void Console::SetProgress(double pct)
{
#ifdef WIN32
// Get the console window's handle
HWND hwnd = GetConsoleWindow();
if (hwnd == NULL) return;
// initialize task bar
if (taskBar == NULL)
{
CoInitialize(NULL);
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (void **)&taskBar);
}
if (taskBar)
{
if ((pct <= 0.0) || (pct >= 100.0))
{
taskBar->SetProgressState(hwnd, TBPF_NOPROGRESS);
}
else
{
taskBar->SetProgressState(hwnd, TBPF_NORMAL);
taskBar->SetProgressValue(hwnd, (ULONGLONG)pct, 100);
}
}
else CoUninitialize();
#endif
}
void ConsoleStream::print(const char* sz)
{
fprintf(stdout, "%s", sz);
fflush(stdout);
}
| C++ |
3D | febiosoftware/FEBio | FEBio/FEBioApp.h | .h | 2,204 | 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 <FEBioLib/cmdoptions.h>
#include <FEBioLib/FEBioConfig.h>
class FEBioModel;
class FEBioApp
{
public:
FEBioApp();
bool Init(int nargs, char* argv[]);
bool Configure(const char* szconfig);
int Run();
void Finish();
void ProcessCommands();
febio::CMDOPTIONS& CommandOptions();
bool ParseCmdLine(int argc, char* argv[]);
// run an febio model
int RunModel();
public:
// get the current model
FEBioModel* GetCurrentModel();
protected:
// show FEBio prompt
int prompt();
// set the currently active model
void SetCurrentModel(FEBioModel* fem);
// apply configuration changes to model
void ApplyConfig(FEBioModel& fem);
public:
static FEBioApp* GetInstance();
private:
febio::CMDOPTIONS m_ops; // command line options
FEBioConfig m_config; // configuration options
FEBioModel* m_fem; // current model (or null if not model is running)
static FEBioApp* m_This;
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/ping.h | .h | 1,287 | 27 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
void ping(); | Unknown |
3D | febiosoftware/FEBio | FEBio/stdafx.cpp | .cpp | 1,385 | 33 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
| C++ |
3D | febiosoftware/FEBio | FEBio/CommandManager.cpp | .cpp | 1,367 | 33 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "CommandManager.h"
CommandManager* CommandManager::m_pMngr;
| C++ |
3D | febiosoftware/FEBio | FEBio/CommandManager.h | .h | 2,075 | 72 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "Command.h"
#include <list>
class CommandManager
{
public:
static CommandManager* GetInstance()
{
static bool bfirst = true;
if (bfirst) { m_pMngr = new CommandManager; bfirst = false; }
return m_pMngr;
}
public:
void AddCommand(Command* pcmd) { m_Cmd.push_back(pcmd); }
int Size() { return (int)m_Cmd.size(); }
Command* Find(const char* szcmd)
{
int N = (int)m_Cmd.size();
if (N == 0) return 0;
std::list<Command*>::iterator ic = m_Cmd.begin();
for (int i=0; i<N; ++i, ++ic)
{
if (strcmp(szcmd, (*ic)->GetName()) == 0) return (*ic);
}
return 0;
}
typedef std::list<Command*>::iterator CmdIterator;
CmdIterator First() { return m_Cmd.begin(); }
protected:
std::list<Command*> m_Cmd;
protected:
static CommandManager* m_pMngr;
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/Interrupt.cpp | .cpp | 1,814 | 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 "Interrupt.h"
#include "FEBioApp.h"
#include <signal.h>
bool Interruption::m_bsig = false;
Interruption::Interruption()
{
static bool binit = false;
if (!binit)
{
signal(SIGINT, Interruption::handler);
binit = true;
}
}
//-----------------------------------------------------------------------------
//! Destructor
// TODO: Restore original intteruption handler
Interruption::~Interruption()
{
}
void Interruption::handler(int sig)
{
m_bsig = true;
signal(SIGINT, Interruption::handler);
}
| C++ |
3D | febiosoftware/FEBio | FEBio/console.h | .h | 2,702 | 85 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <FEBioLib/LogStream.h>
#include <vector>
#include <string>
//-----------------------------------------------------------------------------
//! The Console class manages the shell window. This class is implemented as
//! a singleton, i.e. there can only be one console class in the entire
//! application. Users obtain a pointer to the Console by calling the GetHandle
//! function.
class Console
{
public:
//! return the pointer to the one and only console object
static Console* GetHandle();
public:
Console() { m_bActive = true; }
~Console();
void CleanUp();
//! set the title of the console
void SetTitle(const char* sz, ...);
void Activate() { m_bActive = true; }
void Deactivate() { m_bActive = false; }
void GetCommand(int& nargs, char** argv);
//! waits for user input (similar to system("pause"))
void Wait();
void Draw(unsigned char* img, int nx, int ny);
void Write(const char* sz, unsigned short att);
void SetProgress(double pct);
const std::vector<std::string>& GetHistory() const;
protected:
bool m_bActive;
std::vector<std::string> m_history; //!< command history
protected:
static Console* m_pShell; //!< pointer to the one and only console class
};
//-----------------------------------------------------------------------------
// we use the console to log output
class ConsoleStream : public LogStream
{
public:
void print(const char* sz);
};
| Unknown |
3D | febiosoftware/FEBio | FEBio/breakpoint.h | .h | 1,998 | 59 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
// break point class
struct BREAK_POINT
{
int nwhen; // break on callback
double time; // break at time (nwhen == -1)
int flag; // flag to see if break point was hit
};
// clear all break points
void clear_break_points();
// clear a particular break point
void clear_break_points(int n);
// add a break point
void add_break_point(const char* szcond);
// add a break point that breaks at (sim) time t
void add_time_break_point(double t);
// add a break point that breats at an event
void add_event_break_point(const char* szwhen);
// break points cb
void print_break_points();
// see if a break point is reached (return -1 if break point was not reached)
int check_break(int nwhen, double t);
| Unknown |
3D | febiosoftware/FEBio | FECore/ParamString.cpp | .cpp | 5,355 | 214 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "ParamString.h"
//=============================================================================
void cstrncpy(char* pd, char* ps, int l)
{
for (int i = 0; i <= l; ++i) pd[i] = ps[i];
}
ParamString::ParamString(const char* szparam)
{
ParamRef p;
std::string tmp;
const char* sz = szparam;
int in = 0;
while (*sz)
{
if (*sz == '.')
{
// add parameter
m_param.push_back(p);
// reset
p.clear();
tmp.clear();
in = 0;
}
else if (*sz == '[')
{
in = 1;
}
else if (*sz == ']')
{
if (in == 1)
{
const char* s = tmp.c_str();
p._index = atoi(s);
}
}
else if (*sz == '(')
{
in = 2;
}
else if (*sz == ')')
{
if (in == 2)
{
const char* s = tmp.c_str();
p._id = atoi(s);
}
}
else if (*sz == '\'')
{
if (in == 2)
{
in = 3;
}
}
else if (*sz == '"')
{
if (in == 2)
{
in = 3;
}
}
else
{
if (in == 0) p._name.push_back(*sz);
else if (in == 1) tmp.push_back(*sz);
else if (in == 2) tmp.push_back(*sz);
else if (in == 3) p._idName.push_back(*sz);
}
// next char
sz++;
}
// don't forget to add the last ref
m_param.push_back(p);
}
//-----------------------------------------------------------------------------
ParamString::ParamString(const ParamString& p)
{
m_param = p.m_param;
}
//-----------------------------------------------------------------------------
void ParamString::operator=(const ParamString& p)
{
m_param = p.m_param;
}
//-----------------------------------------------------------------------------
ParamString::~ParamString()
{
}
//-----------------------------------------------------------------------------
//! number of refs in string
int ParamString::count() const
{
return (int) m_param.size();
}
//-----------------------------------------------------------------------------
ParamString ParamString::next() const
{
ParamString p;
if (m_param.size() > 1)
{
p.m_param.insert(p.m_param.end(), m_param.begin() + 1, m_param.end());
}
return p;
}
//-----------------------------------------------------------------------------
bool ParamString::isValid() const { return (m_param.empty() == false); }
//-----------------------------------------------------------------------------
void ParamString::clear() { m_param.clear(); }
//-----------------------------------------------------------------------------
ParamString ParamString::last() const
{
ParamString p;
if (m_param.size() > 1)
{
p.m_param.push_back(m_param[m_param.size()-1]);
}
return p;
}
//-----------------------------------------------------------------------------
bool ParamString::operator==(const std::string& s) const
{
if (m_param.empty()) return false;
return m_param[0]._name == s;
}
//-----------------------------------------------------------------------------
bool ParamString::operator!=(const std::string& s) const
{
if (m_param.empty()) return false;
return m_param[0]._name != s;
}
//-----------------------------------------------------------------------------
const char* ParamString::c_str() const
{
if (m_param.empty()) return 0;
return m_param[0]._name.c_str();
}
//-----------------------------------------------------------------------------
std::string ParamString::string() const
{
if (m_param.empty()) return 0;
return m_param[0]._name;
}
//-----------------------------------------------------------------------------
//! get the index (-1 if index not a number)
int ParamString::Index() const
{
if (m_param.empty()) return -1;
return m_param[0]._index;
}
//-----------------------------------------------------------------------------
//! get the ID (-1 if index not a number)
int ParamString::ID() const
{
if (m_param.empty()) return -1;
return m_param[0]._id;
}
//-----------------------------------------------------------------------------
//! get the index name (null if not defined)
const char* ParamString::IDString() const
{
if (m_param.empty()) return 0;
if (m_param[0]._idName.empty()) return 0;
return m_param[0]._idName.c_str();
}
| C++ |
3D | febiosoftware/FEBio | FECore/FESurfaceToSurfaceVectorMap.h | .h | 1,698 | 53 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEDataGenerator.h"
class FESurface;
class FESurfaceToSurfaceVectorMap : public FEElemDataGenerator
{
public:
FESurfaceToSurfaceVectorMap(FEModel* fem);
~FESurfaceToSurfaceVectorMap();
bool Init() override;
FEDataMap* Generate() override;
private:
FESurface* m_surf[2];
vec3d m_normal;
double m_inAngle;
double m_outAngle;
bool m_cross;
int m_smoothIters;
DECLARE_FECORE_CLASS();
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEDofList.cpp | .cpp | 3,515 | 151 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEDofList.h"
#include "FEModel.h"
FEDofList::FEDofList(FEModel* fem)
{
m_fem = fem;
}
FEDofList::FEDofList(const FEDofList& dofs)
{
m_fem = dofs.m_fem;
m_dofList = dofs.m_dofList;
}
void FEDofList::operator = (const FEDofList& dofs)
{
assert(m_fem == dofs.m_fem);
m_dofList = dofs.m_dofList;
}
void FEDofList::Clear()
{
m_dofList.clear();
}
bool FEDofList::AddDof(const char* szdof)
{
int dof = m_fem->GetDOFIndex(szdof);
if (dof == -1) return false;
m_dofList.push_back(dof);
return true;
}
void FEDofList::operator = (const std::vector<int>& dofs)
{
m_dofList = dofs;
}
bool FEDofList::AddDof(int ndof)
{
m_dofList.push_back(ndof);
return true;
}
bool FEDofList::AddVariable(const char* szvar)
{
DOFS& Dofs = m_fem->GetDOFS();
std::vector<int> dofList;
Dofs.GetDOFList(szvar, dofList);
if (dofList.empty()) { return false; }
m_dofList.insert(m_dofList.end(), dofList.begin(), dofList.end());
return true;
}
// Add all the dofs a variable
bool FEDofList::AddVariable(int nvar)
{
DOFS& Dofs = m_fem->GetDOFS();
std::vector<int> dofList;
Dofs.GetDOFList(nvar, dofList);
if (dofList.empty()) return false;
m_dofList.insert(m_dofList.end(), dofList.begin(), dofList.end());
return true;
}
// Add degrees of freedom
bool FEDofList::AddDofs(const FEDofList& dofs)
{
for (int i = 0; i < dofs.Size(); ++i) {
if (AddDof(dofs[i]) == false) return false;
}
return true;
}
bool FEDofList::IsEmpty() const
{
return m_dofList.empty();
}
int FEDofList::Size() const
{
return (int)m_dofList.size();
}
int FEDofList::operator [] (int n) const
{
return m_dofList[n];
}
void FEDofList::Serialize(DumpStream& ar)
{
ar & m_dofList;
}
bool FEDofList::Contains(int dof)
{
for (size_t i = 0; i < m_dofList.size(); ++i)
{
if (dof == m_dofList[i]) return true;
}
return false;
}
bool FEDofList::Contains(const FEDofList& dof)
{
// see if we have all the dofs in dof
for (int i = 0; i < dof.Size(); ++i)
{
int dof_i = dof[i];
if (Contains(dof_i) == false) return false;
}
// we can only get here if all dofs are accounted for
return true;
}
int FEDofList::InterpolationOrder(int index) const
{
return m_fem->GetDOFS().GetDOFInterpolationOrder(m_dofList[index]);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMat3dsValuator.cpp | .cpp | 2,804 | 91 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEMat3dsValuator.h"
#include "FEModel.h"
#include "FEMesh.h"
#include "FEDataMap.h"
#include "DumpStream.h"
//=============================================================================
// FEConstValueMat3ds
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEConstValueMat3ds, FEMat3dsValuator)
ADD_PARAMETER(m_val, "const");
END_FECORE_CLASS();
FEConstValueMat3ds::FEConstValueMat3ds(FEModel* fem) : FEMat3dsValuator(fem)
{
m_val.zero();
}
FEMat3dsValuator* FEConstValueMat3ds::copy()
{
FEConstValueMat3ds* map = fecore_alloc(FEConstValueMat3ds, GetFEModel());
map->m_val = m_val;
return map;
}
//=============================================================================
// FEMappedValueMat3ds
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMappedValueMat3ds, FEMat3dsValuator)
ADD_PARAMETER(m_mapName, "map");
END_FECORE_CLASS();
FEMappedValueMat3ds::FEMappedValueMat3ds(FEModel* fem) : FEMat3dsValuator(fem)
{
m_val = nullptr;
}
void FEMappedValueMat3ds::setDataMap(FEDataMap* val)
{
m_val = val;
}
mat3ds FEMappedValueMat3ds::operator()(const FEMaterialPoint& pt)
{
return m_val->valueMat3ds(pt);
}
FEMat3dsValuator* FEMappedValueMat3ds::copy()
{
FEMappedValueMat3ds* map = fecore_alloc(FEMappedValueMat3ds, GetFEModel());
map->m_val = m_val;
return map;
}
void FEMappedValueMat3ds::Serialize(DumpStream& ar)
{
FEMat3dsValuator::Serialize(ar);
ar & m_val;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEShellElement.h | .h | 4,973 | 140 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEElement.h"
//-----------------------------------------------------------------------------
//! This class defines the shell element.
//! A shell element is similar to a surface
//! element except that it has a thickness.
class FECORE_API FEShellElement : public FEElement
{
public:
FEShellElement();
//! copy constructor
FEShellElement(const FEShellElement& el);
//! assignment operator
FEShellElement& operator = (const FEShellElement& el);
virtual void SetTraits(FEElementTraits* ptraits) override;
double gr(int n) { return ((FEShellElementTraits*)(m_pT))->gr[n]; }
double gs(int n) { return ((FEShellElementTraits*)(m_pT))->gs[n]; }
double gt(int n) { return ((FEShellElementTraits*)(m_pT))->gt[n]; }
double* GaussWeights() { return &((FEShellElementTraits*)(m_pT))->gw[0]; } // weights of integration points
double* Hr(int n) { return ((FEShellElementTraits*)(m_pT))->Hr[n]; } // shape function derivative to r
double* Hs(int n) { return ((FEShellElementTraits*)(m_pT))->Hs[n]; } // shape function derivative to s
//! values of shape functions
void shape_fnc(double* H, double r, double s) const { ((FEShellElementTraits*)(m_pT))->shape_fnc(H, r, s); }
//! values of shape function derivatives
void shape_deriv(double* Hr, double* Hs, double r, double s) const { ((FEShellElementTraits*)(m_pT))->shape_deriv(Hr, Hs, r, s); }
//! serialize data associated with this element
void Serialize(DumpStream &ar) override;
public:
std::vector<double> m_h0; //!< initial shell thicknesses
std::vector<double> m_ht; //!< current shell thickness
std::vector<vec3d> m_d0; //!< initial shell director
std::vector<vec3d> m_g0[3];//!< reference covariant base vectors
std::vector<vec3d> m_gt[3];//!< current covariant base vectors
std::vector<vec3d> m_gp[3];//!< previous covariant base vectors
std::vector<vec3d> m_G0[3];//!< reference contravariant base vectors
std::vector<vec3d> m_Gt[3];//!< current contravariant base vectors
// indices of solid elements this shell element is attached to.
// the first element is attached to the back of the shell
// and the second element is attached to the front.
// the index is -1 if no solid is attached on that side.
int m_elem[2];
};
//-----------------------------------------------------------------------------
// Shell element used by old shell formulation
class FECORE_API FEShellElementOld : public FEShellElement
{
public:
FEShellElementOld();
//! copy constructor
FEShellElementOld(const FEShellElementOld& el);
//! assignment operator
FEShellElementOld& operator = (const FEShellElementOld& el);
// set the element traits class
void SetTraits(FEElementTraits* ptraits) override;
//! serialize data associated with this element
void Serialize(DumpStream &ar) override;
public:
std::vector<vec3d> m_D0; //!< initial shell directors
};
//-----------------------------------------------------------------------------
// Shell element used by new shell formulations
class FECORE_API FEShellElementNew : public FEShellElement
{
public:
FEShellElementNew();
//! copy constructor
FEShellElementNew(const FEShellElementNew& el);
//! assignment operator
FEShellElementNew& operator = (const FEShellElementNew& el);
// set the element traits class
void SetTraits(FEElementTraits* ptraits) override;
//! serialize data associated with this element
void Serialize(DumpStream &ar) override;
public: // EAS parameters
matrix m_Kaai;
matrix m_fa;
matrix m_alpha;
matrix m_alphat;
matrix m_alphai;
std::vector<matrix> m_Kua;
std::vector<matrix> m_Kwa;
std::vector<mat3ds> m_E;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEEdgeLoad.h | .h | 1,876 | 58 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FEModelLoad.h"
//-----------------------------------------------------------------------------
class FEEdge;
class FEModel;
class FELinearSystem;
class FEGlobalVector;
//-----------------------------------------------------------------------------
class FECORE_API FEEdgeLoad : public FEModelLoad
{
FECORE_BASE_CLASS(FEEdgeLoad)
public:
FEEdgeLoad(FEModel* pfem);
virtual ~FEEdgeLoad(void);
//! Set the edge to apply the load to
void SetEdge(FEEdge* pe);
//! Get the edge
FEEdge& Edge();
void Serialize(DumpStream& ar) override;
protected:
FEEdge* m_pedge;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEParam.cpp | .cpp | 20,734 | 809 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEParam.h"
#include "FEParamValidator.h"
#include "DumpStream.h"
#include "FEDataArray.h"
#include "tens3d.h"
#include "FEModelParam.h"
using namespace std;
FEParamValue FEParamValue::component(int n)
{
switch (m_itype)
{
case FE_PARAM_VEC2D:
{
vec2d& r = value<vec2d>();
if (n == 0) return FEParamValue(m_param, &r.x(), FE_PARAM_DOUBLE);
if (n == 1) return FEParamValue(m_param, &r.y(), FE_PARAM_DOUBLE);
}
break;
case FE_PARAM_VEC3D:
{
vec3d& r = value<vec3d>();
if (n == 0) return FEParamValue(m_param, &r.x, FE_PARAM_DOUBLE);
if (n == 1) return FEParamValue(m_param, &r.y, FE_PARAM_DOUBLE);
if (n == 2) return FEParamValue(m_param, &r.z, FE_PARAM_DOUBLE);
}
break;
case FE_PARAM_MAT3DS:
{
mat3ds& a = value<mat3ds>();
if (n == 0) return FEParamValue(m_param, &a.xx(), FE_PARAM_DOUBLE);
if (n == 1) return FEParamValue(m_param, &a.xy(), FE_PARAM_DOUBLE);
if (n == 2) return FEParamValue(m_param, &a.yy(), FE_PARAM_DOUBLE);
if (n == 3) return FEParamValue(m_param, &a.xz(), FE_PARAM_DOUBLE);
if (n == 4) return FEParamValue(m_param, &a.yz(), FE_PARAM_DOUBLE);
if (n == 5) return FEParamValue(m_param, &a.zz(), FE_PARAM_DOUBLE);
}
break;
}
assert(false);
return FEParamValue();
}
//-----------------------------------------------------------------------------
FEParam::FEParam(void* pdata, FEParamType itype, int ndim, const char* szname, bool* watch)
{
m_pv = pdata;
m_type = itype;
m_dim = ndim;
m_watch = watch;
if (m_watch) *m_watch = false;
// default flags depend on type
// (see also FEModel::EvaluateLoadParameters())
m_flag = 0;
if (ndim == 1)
{
switch (itype)
{
case FE_PARAM_DOUBLE:
case FE_PARAM_VEC3D:
case FE_PARAM_DOUBLE_MAPPED:
case FE_PARAM_VEC3D_MAPPED:
// all these types can be modified via a load curve
m_flag = FE_PARAM_VOLATILE;
break;
}
}
m_group = -1;
// set the name
// note that we just copy the pointer, not the actual string
// this is okay as long as the name strings are defined
// as literal strings
m_szname = szname;
m_szlongname = szname;
m_szenum = nullptr;
m_pvalid = nullptr; // no default validator
m_parent = nullptr;
m_szunit = nullptr;
}
//-----------------------------------------------------------------------------
FEParam::FEParam(const FEParam& p)
{
m_pv = p.m_pv;
m_type = p.m_type;
m_dim = p.m_dim;
m_watch = p.m_watch;
m_flag = p.m_flag;
m_group = p.m_group;
m_szname = p.m_szname;
m_szlongname = p.m_szlongname;
m_szenum = 0;
m_parent = p.m_parent;
m_szunit = p.m_szunit;
m_pvalid = (p.m_pvalid ? p.m_pvalid->copy() : 0);
}
//-----------------------------------------------------------------------------
int FEParam::GetParamGroup() const
{
return m_group;
}
//-----------------------------------------------------------------------------
void FEParam::SetParamGroup(int i)
{
m_group = i;
}
//-----------------------------------------------------------------------------
FEParam::~FEParam()
{
if (m_flag & FEParamFlag::FE_PARAM_USER)
{
free((void*)m_szname);
assert(m_type == FE_PARAM_DOUBLE);
delete (double*)m_pv;
}
}
//-----------------------------------------------------------------------------
FEParam& FEParam::operator=(const FEParam& p)
{
m_pv = p.m_pv;
m_type = p.m_type;
m_dim = p.m_dim;
m_watch = p.m_watch;
m_flag = p.m_flag;
m_szname = p.m_szname;
m_szenum = 0;
m_parent = p.m_parent;
m_szunit = p.m_szunit;
if (m_pvalid) delete m_pvalid;
m_pvalid = (p.m_pvalid ? p.m_pvalid->copy() : 0);
return *this;
}
//-----------------------------------------------------------------------------
bool FEParam::is_valid() const
{
if (m_pvalid) return m_pvalid->is_valid(*this);
return true;
}
//-----------------------------------------------------------------------------
// return the name of the parameter
const char* FEParam::name() const
{
return m_szname;
}
//-----------------------------------------------------------------------------
const char* FEParam::longName() const
{
return m_szlongname;
}
//-----------------------------------------------------------------------------
// return the enum values
const char* FEParam::enums() const
{
return m_szenum;
}
//-----------------------------------------------------------------------------
// get the current enum value (or nullptr)
const char* FEParam::enumKey() const
{
const char* sz = enums();
if (sz == nullptr) return nullptr;
if (sz[0] == '$') return nullptr;
int n = value<int>();
if (n < 0) return nullptr;
for (int i = 0; i < n; ++i)
{
sz += strlen(sz) + 1;
if ((sz == nullptr) || (*sz == 0)) return nullptr;
}
return sz;
}
//-----------------------------------------------------------------------------
const char* FEParam::units() const
{
return m_szunit;
}
//-----------------------------------------------------------------------------
FEParam* FEParam::setUnits(const char* szunit) { m_szunit = szunit; return this; }
//-----------------------------------------------------------------------------
// set the enum values (\0 separated. Make sure the end of the string has two \0's)
FEParam* FEParam::setEnums(const char* sz) { m_szenum = sz; return this; }
//-----------------------------------------------------------------------------
FEParam* FEParam::setLongName(const char* sz)
{
m_szlongname = sz;
return this;
}
//-----------------------------------------------------------------------------
// parameter dimension
int FEParam::dim() const { return m_dim; }
//-----------------------------------------------------------------------------
// parameter type
FEParamType FEParam::type() const { return m_type; }
//-----------------------------------------------------------------------------
// data pointer
void* FEParam::data_ptr() const { return m_pv; }
//-----------------------------------------------------------------------------
//! override the template for char pointers
char* FEParam::cvalue() { return (char*)data_ptr(); }
//-----------------------------------------------------------------------------
FEParamValue FEParam::paramValue(int i)
{
switch (m_type)
{
case FE_PARAM_DOUBLE:
{
if (i == -1)
{
assert(m_dim == 1);
return FEParamValue(this, &value<double>(), FE_PARAM_DOUBLE);
}
else return FEParamValue(this, &value<double>(i), FE_PARAM_DOUBLE);
}
break;
case FE_PARAM_VEC3D:
{
if (i == -1)
{
assert(m_dim == 1);
return FEParamValue(this, &value<vec3d>(), FE_PARAM_VEC3D);
}
else return FEParamValue(this, &value<vec3d>(i), FE_PARAM_VEC3D);
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
if (i == -1)
{
assert(m_dim == 1);
FEParamDouble& p = value<FEParamDouble>();
if (p.isConst()) return FEParamValue(this, &p.constValue(), FE_PARAM_DOUBLE);
else return FEParamValue(this, m_pv, m_type);
}
else
{
FEParamDouble& data = value<FEParamDouble>(i);
return FEParamValue(this, &data, FE_PARAM_DOUBLE_MAPPED);
}
}
break;
case FE_PARAM_VEC3D_MAPPED:
{
if (i == -1)
{
assert(m_dim == 1);
FEParamVec3& p = value<FEParamVec3>();
if (p.isConst()) return FEParamValue(this, &p.constValue(), FE_PARAM_VEC3D);
else return FEParamValue(this, m_pv, m_type);
}
else
{
FEParamVec3& data = value<FEParamVec3>(i);
return FEParamValue(this, &data, FE_PARAM_VEC3D_MAPPED);
}
}
break;
case FE_PARAM_MAT3D_MAPPED:
{
if (i == -1)
{
assert(m_dim == 1);
FEParamMat3d& p = value<FEParamMat3d>();
if (p.isConst()) return FEParamValue(this, &p.constValue(), FE_PARAM_MAT3D);
else return FEParamValue(this, m_pv, m_type);
}
else
{
FEParamMat3d& data = value<FEParamMat3d>(i);
return FEParamValue(this, &data, FE_PARAM_MAT3D_MAPPED);
}
}
break;
case FE_PARAM_STD_VECTOR_DOUBLE:
{
vector<double>& data = value< vector<double> >();
if ((i >= 0) && (i < (int)data.size()))
return FEParamValue(this, &data[i], FE_PARAM_DOUBLE);
else assert(false);
}
break;
case FE_PARAM_STD_VECTOR_VEC2D:
{
vector<vec2d>& data = value< vector<vec2d> >();
if ((i >= 0) && (i < (int)data.size()))
return FEParamValue(this, &data[i], FE_PARAM_VEC2D);
else assert(false);
}
break;
case FE_PARAM_STD_VECTOR_STRING:
{
vector<string>& data = value< vector<string> >();
if ((i >= 0) && (i < (int)data.size()))
return FEParamValue(this, &data[i], FE_PARAM_STD_STRING);
}
break;
default:
{
if (i == -1)
{
assert(m_dim == 1);
return FEParamValue(this, m_pv, m_type);
}
}
}
return FEParamValue();
}
//-----------------------------------------------------------------------------
//! This function deletes the existing validator and replaces it with the parameter
//! passed in the function.
//! The pvalid can be null in which case the parameter will no longer be validated.
//! (i.e. is_valid() will always return true.
//! TODO: Should I delete the validator here? What if it was allocated in a plugin?
//! Perhaps I should just return the old validator?
void FEParam::SetValidator(FEParamValidator* pvalid)
{
if (m_pvalid) delete m_pvalid;
m_pvalid = pvalid;
}
FEParamValidator* FEParam::GetValidator()
{
return m_pvalid;
}
void FEParam::Serialize(DumpStream& ar)
{
if (ar.IsSaving())
{
ar << (int) m_type << m_flag;
bool b = (m_watch ? *m_watch : false);
ar << (b ? 1 : 0);
if ((ar.IsShallow() == false) && (m_flag & FEParamFlag::FE_PARAM_USER))
{
assert(m_type == FE_PARAM_DOUBLE);
ar << m_szname;
}
if (m_dim == 1)
{
switch (m_type)
{
case FE_PARAM_INT : ar << value<int>(); break;
case FE_PARAM_BOOL : ar << value<bool>(); break;
case FE_PARAM_DOUBLE : ar << value<double>(); break;
case FE_PARAM_VEC3D : ar << value<vec3d>(); break;
case FE_PARAM_MAT3D : ar << value<mat3d>(); break;
case FE_PARAM_MAT3DS : ar << value<mat3ds>(); break;
case FE_PARAM_TENS3DRS : ar << value<tens3ds>(); break;
case FE_PARAM_DATA_ARRAY:
{
FEDataArray& m = value<FEDataArray>();
m.Serialize(ar);
}
break;
case FE_PARAM_STRING: ar << (const char*)data_ptr(); break;
case FE_PARAM_STD_STRING: ar << value<string>(); break;
case FE_PARAM_STD_VECTOR_VEC2D: ar << value< std::vector<vec2d> >(); break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble& p = value<FEParamDouble>();
ar << p;
}
break;
case FE_PARAM_VEC3D_MAPPED:
{
FEParamVec3& p = value<FEParamVec3>();
ar << p;
}
break;
case FE_PARAM_MAT3D_MAPPED:
{
FEParamMat3d& p = value<FEParamMat3d>();
ar << p;
}
break;
case FE_PARAM_STD_VECTOR_INT:
{
vector<int>& p = value< vector<int> >();
ar << p;
}
break;
case FE_PARAM_STD_VECTOR_DOUBLE:
{
vector<double>& p = value< vector<double> >();
ar << p;
}
break;
default:
assert(false);
}
}
else
{
ar << m_dim;
switch (m_type)
{
case FE_PARAM_INT:
{
int* pi = (int*) m_pv;
for (int i = 0; i<m_dim; ++i) ar << pi[i];
}
break;
case FE_PARAM_DOUBLE:
{
double* pv = (double*) m_pv;
for (int i = 0; i<m_dim; ++i) ar << pv[i];
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble* p = (FEParamDouble*)(m_pv);
for (int i = 0; i < m_dim; ++i)
{
ar << p[i];
}
}
break;
default:
assert(false);
}
}
}
else
{
int ntype;
ar >> ntype >> m_flag;
if (ntype != (int) m_type) throw DumpStream::ReadError();
int watch = 0;
ar >> watch;
if (m_watch) *m_watch = (watch == 1);
if ((ar.IsShallow() == false) && (m_flag & FEParamFlag::FE_PARAM_USER))
{
assert(m_type == FE_PARAM_DOUBLE);
char sz[512] = { 0 };
ar >> sz;
m_szname = strdup(sz);
m_pv = new double(0);
}
if (m_dim == 1)
{
switch (m_type)
{
case FE_PARAM_INT : ar >> value<int >(); break;
case FE_PARAM_BOOL : ar >> value<bool >(); break;
case FE_PARAM_DOUBLE : ar >> value<double >(); break;
case FE_PARAM_VEC3D : ar >> value<vec3d >(); break;
case FE_PARAM_MAT3D : ar >> value<mat3d >(); break;
case FE_PARAM_MAT3DS : ar >> value<mat3ds >(); break;
case FE_PARAM_TENS3DRS : ar >> value<tens3drs>(); break;
case FE_PARAM_DATA_ARRAY:
{
FEDataArray& m = value<FEDataArray>();
m.Serialize(ar);
}
break;
case FE_PARAM_STRING: ar >> (char*)data_ptr(); break;
case FE_PARAM_STD_STRING: ar >> value<string>(); break;
case FE_PARAM_STD_VECTOR_VEC2D: ar >> value< std::vector<vec2d> >(); break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble& p = value<FEParamDouble>();
ar >> p;
}
break;
case FE_PARAM_VEC3D_MAPPED:
{
FEParamVec3& p = value<FEParamVec3>();
ar >> p;
}
break;
case FE_PARAM_MAT3D_MAPPED:
{
FEParamMat3d& p = value<FEParamMat3d>();
ar >> p;
}
break;
case FE_PARAM_STD_VECTOR_INT:
{
vector<int>& p = value< vector<int> >();
ar >> p;
}
break;
case FE_PARAM_STD_VECTOR_DOUBLE:
{
vector<double>& p = value< vector<double> >();
ar >> p;
}
break;
default:
assert(false);
}
}
else
{
int ndim = 0;
ar >> ndim;
if (ndim != (int) m_dim) throw DumpStream::ReadError();
switch (m_type)
{
case FE_PARAM_INT:
{
int* pi = (int*)data_ptr();
for (int i = 0; i<m_dim; ++i) ar >> pi[i];
}
break;
case FE_PARAM_DOUBLE:
{
double* pv = (double*)data_ptr();
for (int i = 0; i<m_dim; ++i) ar >> pv[i];
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble* p = (FEParamDouble*)(m_pv);
for (int i = 0; i < m_dim; ++i)
{
ar >> p[i];
}
}
break;
default:
assert(false);
}
}
}
// serialize the validator
if (m_pvalid) m_pvalid->Serialize(ar);
}
void FEParam::SaveClass(DumpStream& ar, FEParam* p)
{
}
FEParam* FEParam::LoadClass(DumpStream& ar, FEParam* p)
{
return p;
}
//-----------------------------------------------------------------------------
//! This function copies the state of a parameter to this parameter.
//! This assumes that the parameters are compatible (i.e. have the same type)
//! This is used in FEParamContainer::CopyParameterListState()
bool FEParam::CopyState(const FEParam& p)
{
if (p.type() != type()) return false;
return true;
}
//-----------------------------------------------------------------------------
void FEParam::setParent(FEParamContainer* pc) { m_parent = pc; }
FEParamContainer* FEParam::parent() { return m_parent; }
//-----------------------------------------------------------------------------
void FEParam::SetWatchVariable(bool* watchvar)
{
m_watch = watchvar;
}
//-----------------------------------------------------------------------------
bool* FEParam::GetWatchVariable()
{
return m_watch;
}
//-----------------------------------------------------------------------------
void FEParam::SetWatchFlag(bool b)
{
if (m_watch) *m_watch = b;
}
//-----------------------------------------------------------------------------
bool FEParam::IsHidden() const
{
return (m_flag & FEParamFlag::FE_PARAM_HIDDEN);
}
bool FEParam::IsObsolete() const
{
return (m_flag & FEParamFlag::FE_PARAM_OBSOLETE);
}
//-----------------------------------------------------------------------------
bool FEParam::IsVolatile() const
{
return (m_flag & FEParamFlag::FE_PARAM_VOLATILE);
}
//-----------------------------------------------------------------------------
FEParam* FEParam::MakeVolatile(bool b)
{
if (b) m_flag = (m_flag | FEParamFlag::FE_PARAM_VOLATILE);
else m_flag = (m_flag & ~FEParamFlag::FE_PARAM_VOLATILE);
return this;
}
//-----------------------------------------------------------------------------
bool FEParam::IsTopLevel() const
{
return (m_flag & FEParamFlag::FE_PARAM_TOPLEVEL);
}
//-----------------------------------------------------------------------------
FEParam* FEParam::MakeTopLevel(bool b)
{
if (b) m_flag = (m_flag | FEParamFlag::FE_PARAM_TOPLEVEL);
else m_flag = (m_flag & ~FEParamFlag::FE_PARAM_TOPLEVEL);
return this;
}
//-----------------------------------------------------------------------------
FEParam* FEParam::SetFlags(unsigned int flags) { m_flag = flags; return this; }
unsigned int FEParam::GetFlags() const { return m_flag; }
//-----------------------------------------------------------------------------
// helper functions for accessing components of parameters via parameter strings
FEParamValue GetParameterComponent(const ParamString& paramName, FEParam* param)
{
// make sure we have something to do
if (param == 0) return FEParamValue();
if (param->type() == FE_PARAM_DOUBLE)
{
return param->paramValue(paramName.Index());
}
else if (param->type() == FE_PARAM_VEC3D)
{
vec3d* v = param->pvalue<vec3d>(0);
assert(v);
if (v)
{
if (paramName == "x") return FEParamValue(param, &v->x, FE_PARAM_DOUBLE);
else if (paramName == "y") return FEParamValue(param, &v->y, FE_PARAM_DOUBLE);
else if (paramName == "z") return FEParamValue(param, &v->z, FE_PARAM_DOUBLE);
else return FEParamValue();
}
else return FEParamValue();
}
else if (param->type() == FE_PARAM_STD_VECTOR_DOUBLE)
{
int index = paramName.Index();
return param->paramValue(index);
}
else if (param->type() == FE_PARAM_STD_VECTOR_VEC2D)
{
int index = paramName.Index();
return param->paramValue(index);
}
else if (param->type() == FE_PARAM_STD_VECTOR_STRING)
{
int index = paramName.Index();
return param->paramValue(index);
}
else if (param->type() == FE_PARAM_DOUBLE_MAPPED)
{
return param->paramValue(paramName.Index());
}
else if (param->type() == FE_PARAM_VEC3D_MAPPED)
{
return param->paramValue(paramName.Index());
}
else if (param->type() == FE_PARAM_MAT3D_MAPPED)
{
return param->paramValue(paramName.Index());
}
else if (param->type() == FE_PARAM_MATERIALPOINT)
{
return param->paramValue(paramName.Index());
}
return FEParamValue();
}
FECORE_API FEParamValue GetParameterComponent(FEParamValue& paramVal, int index)
{
switch (paramVal.type())
{
case FE_PARAM_STD_VECTOR_INT:
{
std::vector<int>& d = paramVal.value<std::vector<int>>();
if ((index >= 0) && (index < d.size())) return FEParamValue(d[index]);
}
break;
case FE_PARAM_STD_VECTOR_DOUBLE:
{
std::vector<double>& d = paramVal.value<std::vector<double>>();
if ((index >= 0) && (index < d.size())) return FEParamValue(d[index]);
}
break;
case FE_PARAM_STD_VECTOR_VEC2D:
{
std::vector<vec2d>& d = paramVal.value<std::vector<vec2d>>();
if ((index >= 0) && (index < d.size())) return FEParamValue(d[index]);
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParam* p = paramVal.param(); assert(p);
if (p->dim() > 0)
{
FEParamDouble* d = p->pvalue<FEParamDouble>(index);
return FEParamValue(p, d, p->type());
}
}
break;
}
assert(false);
return FEParamValue();
}
FECORE_API FEParamValue GetParameterComponent(FEParamValue& paramVal, const char* szcomp)
{
switch (paramVal.type())
{
case FE_PARAM_VEC2D:
{
vec3d& v = paramVal.value<vec3d>();
if (strcmp(szcomp, "x") == 0) return FEParamValue(v.x);
else if (strcmp(szcomp, "y") == 0) return FEParamValue(v.y);
}
break;
case FE_PARAM_VEC3D:
{
vec3d& v = paramVal.value<vec3d>();
if (strcmp(szcomp, "x") == 0) return FEParamValue(v.x);
else if (strcmp(szcomp, "y") == 0) return FEParamValue(v.y);
else if (strcmp(szcomp, "z") == 0) return FEParamValue(v.z);
}
break;
}
assert(false);
return FEParamValue();
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEGlobalVector.cpp | .cpp | 2,955 | 97 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "FEGlobalVector.h"
#include "vec3d.h"
#include "FEModel.h"
//-----------------------------------------------------------------------------
FEGlobalVector::FEGlobalVector(FEModel& fem, vector<double>& R, vector<double>& Fr) : m_fem(fem), m_R(R), m_Fr(Fr)
{
}
//-----------------------------------------------------------------------------
FEGlobalVector::~FEGlobalVector()
{
}
//-----------------------------------------------------------------------------
void FEGlobalVector::Assemble(vector<int>& en, vector<int>& elm, vector<double>& fe, bool bdom)
{
vector<double>& R = m_R;
// assemble the element residual into the global residual
int ndof = (int)fe.size();
for (int i=0; i<ndof; ++i)
{
int I = elm[i];
if ( I >= 0) {
#pragma omp atomic
R[I] += fe[i];
}
// TODO: Find another way to store reaction forces
else if (-I-2 >= 0) {
#pragma omp atomic
m_Fr[-I-2] -= fe[i];
}
}
}
//-----------------------------------------------------------------------------
//! \todo This function does not add to m_Fr. Is this a problem?
void FEGlobalVector::Assemble(vector<int>& lm, vector<double>& fe)
{
vector<double>& R = m_R;
const int n = (int) lm.size();
for (int i=0; i<n; ++i)
{
int nid = lm[i];
if (nid >= 0) {
#pragma omp atomic
R[nid] += fe[i];
}
}
}
//-----------------------------------------------------------------------------
//! assemble a nodel value
void FEGlobalVector::Assemble(int nodeId, int dof, double f)
{
// get the equation number
FENode& node = m_fem.GetMesh().Node(nodeId);
int n = node.m_ID[dof];
// assemble into global vector
if (n >= 0) {
#pragma omp atomic
m_R[n] += f;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/DenseMatrix.h | .h | 2,563 | 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 "SparseMatrix.h"
namespace FECore {
//=============================================================================
//! This class implements a full matrix
//! that is a matrix that stores all its elements.
class FECORE_API DenseMatrix : public SparseMatrix
{
public:
// con/de-structor
DenseMatrix();
~DenseMatrix();
// create a matrix of particular size
void Create(int rows, int cols);
// retrieve matrix data
double& operator () (int i, int j) { return m_pr[i][j]; }
public:
// zero matrix elements
void Zero() override;
// create a matrix from a spares matrix profile
void Create(SparseMatrixProfile& mp) override;
// assemble matrix into sparse matrix
void Assemble(const matrix& ke, const std::vector<int>& lm) override;
//! assemble a matrix into the sparse matrix
void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) override;
// clear all data
void Clear() override;
bool check(int i, int j) override { return true; }
void add(int i, int j, double v) override { m_pr[i][j] += v; }
void set(int i, int j, double v) override { m_pr[i][j] = v; }
double diag(int i) override { return m_pr[i][i]; }
protected:
double* m_pd; //!< matrix values
double** m_pr; //!< pointers to rows
};
}
| Unknown |
3D | febiosoftware/FEBio | FECore/CompactSymmMatrix64.cpp | .cpp | 7,848 | 326 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "CompactSymmMatrix64.h"
using namespace std;
CompactSymmMatrix64::CompactSymmMatrix64(int offset) : m_offset(offset)
{
m_pvalues = nullptr;
m_pindices = nullptr;
m_ppointers = nullptr;
}
CompactSymmMatrix64::~CompactSymmMatrix64()
{
Clear();
}
void CompactSymmMatrix64::Clear()
{
delete[] m_pvalues; m_pvalues = nullptr;
delete[] m_pindices; m_pindices = nullptr;
delete[] m_ppointers; m_ppointers = nullptr;
}
void CompactSymmMatrix64::Create(SparseMatrixProfile& mp)
{
// TODO: we should probably enforce that the matrix is square
m_nrow = mp.Rows();
m_ncol = mp.Columns();
size_t nr = m_nrow;
size_t nc = m_ncol;
assert(nr == nc);
Clear();
// allocate pointers to column offsets
m_ppointers = new long long[nc + 1];
for (int i = 0; i <= nc; ++i) m_ppointers[i] = 0;
size_t nsize = 0;
for (size_t i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
size_t n = a.size();
for (size_t j = 0; j<n; j++)
{
size_t a0 = a[j].start;
size_t a1 = a[j].end;
// only grab lower-triangular
if (a1 >= i)
{
if (a0 < i) a0 = i;
size_t asize = a1 - a0 + 1;
nsize += asize;
m_ppointers[i] += asize;
}
}
}
// allocate indices which store row index for each matrix element
m_pindices = new long long[nsize];
size_t m = 0;
for (size_t i = 0; i <= nc; ++i)
{
long long n = m_ppointers[i];
m_ppointers[i] = m;
m += n;
}
for (size_t i = 0; i<nc; ++i)
{
SparseMatrixProfile::ColumnProfile& a = mp.Column(i);
size_t n = a.size();
size_t nval = 0;
for (size_t j = 0; j<n; j++)
{
size_t a0 = a[j].start;
size_t a1 = a[j].end;
// only grab lower-triangular
if (a1 >= i)
{
if (a0 < i) a0 = i;
for (size_t k = a0; k <= a1; ++k)
{
m_pindices[m_ppointers[i] + nval] = (long long)k;
++nval;
}
}
}
}
// offset the indicies for fortran arrays
if (Offset())
{
for (size_t i = 0; i <= nc; ++i) m_ppointers[i]++;
for (size_t i = 0; i<nsize; ++i) m_pindices[i]++;
}
// create the values array
m_nsize = nsize;
m_pvalues = new double[nsize];
}
//-----------------------------------------------------------------------------
// this sort function is defined in qsort.cpp
void qsort(int n, const int* arr, int* indx);
//-----------------------------------------------------------------------------
//! This function assembles the local stiffness matrix
//! into the global stiffness matrix which is in compact column storage
//!
void CompactSymmMatrix64::Assemble(const matrix& ke, const vector<int>& LM)
{
// get the number of degrees of freedom
const int N = ke.rows();
// find the permutation array that sorts LM in ascending order
// we can use this to speed up the row search (i.e. loop over n below)
std::vector<int> P(N);
qsort(N, &LM[0], &P[0]);
// get the data pointers
long long* indices = Indices64();
long long* pointers = Pointers64();
double* pd = Values();
// find the starting index
size_t N0 = 0;
while ((N0<N) && (LM[P[N0]]<0)) ++N0;
// assemble element stiffness
for (size_t m = N0; m<N; ++m)
{
size_t j = P[m];
size_t J = LM[j];
size_t n = 0;
double* pm = pd + (pointers[J] - m_offset);
long long* pi = indices + (pointers[J] - m_offset);
long long l = pointers[J + 1] - pointers[J];
size_t M0 = m;
while ((M0>N0) && (LM[P[M0 - 1]] == J)) M0--;
for (size_t k = M0; k<N; ++k)
{
size_t i = P[k];
size_t I = LM[i] + (size_t)m_offset;
for (; n<l; ++n)
if (pi[n] == I)
{
#pragma omp atomic
pm[n] += ke[i][j];
break;
}
}
}
}
void CompactSymmMatrix64::Assemble(const matrix& ke, const vector<int>& LMi, const vector<int>& LMj)
{
const int N = ke.rows();
const int M = ke.columns();
long long* indices = Indices64();
long long* pointers = Pointers64();
double* values = Values();
for (size_t i = 0; i<N; ++i)
{
int I = LMi[i];
for (size_t j = 0; j<M; ++j)
{
int J = LMj[j];
// only add values to lower-diagonal part of stiffness matrix
if ((I >= J) && (J >= 0))
{
double* pv = values + (pointers[J] - m_offset);
long long* pi = indices + (pointers[J] - m_offset);
long long l = pointers[J + 1] - pointers[J];
for (size_t n = 0; n<l; ++n)
if (pi[n] - m_offset == I)
{
#pragma omp atomic
pv[n] += ke[i][j];
break;
}
}
}
}
}
void CompactSymmMatrix64::add(int i, int j, double v)
{
// only add to lower triangular part
// since FEBio only works with the upper triangular part
// we have to swap the indices
i ^= j; j ^= i; i ^= j;
if (j <= i)
{
double* pd = m_pvalues + (m_ppointers[j] - m_offset);
long long* pi = m_pindices + m_ppointers[j];
pi -= m_offset;
i += m_offset;
long long n1 = m_ppointers[j + 1] - m_ppointers[j] - 1;
long long n0 = 0;
long long n = n1 / 2;
do
{
long long m = pi[n];
if (m == i)
{
#pragma omp atomic
pd[n] += v;
return;
}
else if (m < i)
{
n0 = n;
n = (n0 + n1 + 1) >> 1;
}
else
{
n1 = n;
n = (n0 + n1) >> 1;
}
} while (n0 != n1);
assert(false);
}
}
//! check fo a matrix item
bool CompactSymmMatrix64::check(int i, int j)
{
// only the lower-triangular part is stored, so swap indices if necessary
if (i<j) { i ^= j; j ^= i; i ^= j; }
// only add to lower triangular part
if (j <= i)
{
long long* pi = m_pindices + m_ppointers[j];
pi -= m_offset;
long long l = m_ppointers[j + 1] - m_ppointers[j];
for (long long n = 0; n<l; ++n)
if (pi[n] == i + m_offset)
{
return true;
}
}
return false;
}
//! set matrix item
void CompactSymmMatrix64::set(int i, int j, double v)
{
if (j <= i)
{
long long* pi = m_pindices + m_ppointers[j];
pi -= m_offset;
long long l = m_ppointers[j + 1] - m_ppointers[j];
for (long long n = 0; n<l; ++n)
if (pi[n] == i + m_offset)
{
long long k = m_ppointers[j] + n;
k -= m_offset;
#pragma omp critical (CSM_set)
m_pvalues[k] = v;
return;
}
assert(false);
}
}
//! get a matrix item
double CompactSymmMatrix64::get(int i, int j)
{
// only the lower-triangular part is stored, so swap indices if necessary
if (i<j) { i ^= j; j ^= i; i ^= j; }
long long *pi = m_pindices + m_ppointers[j], k;
pi -= m_offset;
long long l = m_ppointers[j + 1] - m_ppointers[j];
for (long long n = 0; n<l; ++n)
if (pi[n] == i + m_offset)
{
k = m_ppointers[j] + n;
k -= m_offset;
return m_pvalues[k];
}
return 0;
}
void CompactSymmMatrix64::Zero()
{
for (size_t i = 0; i < m_nsize; ++i) m_pvalues[i] = 0.0;
}
| C++ |
3D | febiosoftware/FEBio | FECore/CSRMatrix.cpp | .cpp | 5,258 | 195 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#include "stdafx.h"
#include "CSRMatrix.h"
#include <assert.h>
CSRMatrix::CSRMatrix() : m_nr(0), m_nc(0), m_offset(0)
{
}
// create a matrix of given size
CSRMatrix::CSRMatrix(int rows, int cols, int noffset) : m_nr(rows), m_nc(cols), m_offset(noffset)
{
m_rowIndex.resize(rows+1, m_offset);
}
// Create matrix
void CSRMatrix::create(int nr, int nc, int noffset)
{
m_nr = nr;
m_nc = nc;
m_offset = noffset;
m_rowIndex.resize(nr+1, noffset);
m_columns.clear();
m_values.clear();
}
// copy constructor
CSRMatrix::CSRMatrix(const CSRMatrix& A)
{
m_nr = A.m_nr;
m_nc = A.m_nc;
m_offset = A.m_offset;
m_rowIndex = A.m_rowIndex;
m_columns = A.m_columns;
m_values = A.m_values;
}
// assignment operator
void CSRMatrix::operator = (const CSRMatrix& A)
{
m_nr = A.m_nr;
m_nc = A.m_nc;
m_offset = A.m_offset;
m_rowIndex = A.m_rowIndex;
m_columns = A.m_columns;
m_values = A.m_values;
}
// sets a value, inserting it if necessary
void CSRMatrix::set(int i, int j, double val)
{
assert((i >= 0) && (i < m_nr));
assert((j >= 0) && (j < m_nc));
// get the start column index for the given row and the non-zero count for that row
int col = m_rowIndex[i] - m_offset;
int count = m_rowIndex[i+1] - m_rowIndex[i];
// see if the row is empty
if (count == 0)
{
m_columns.insert(m_columns.begin() + col, j);
m_values.insert(m_values.begin() + col, val);
}
else
{
// see if this column would be before the first entry
if (j < m_columns[col] - m_offset)
{
m_columns.insert(m_columns.begin() + col, j);
m_values.insert(m_values.begin() + col, val);
}
// see if this column would be past the last entry
else if (j > m_columns[col + count - 1] - m_offset)
{
m_columns.insert(m_columns.begin() + col + count, j);
m_values.insert(m_values.begin() + col + count, val);
}
else {
// find the column index
for (int n=0; n<count; ++n)
{
// see if it alreay exists
if (m_columns[col + n] - m_offset == j)
{
// if so, replace the value and return
m_values[col+n] = val;
return;
}
else if (m_columns[col + n] - m_offset > j)
{
// we found an index that is bigger so insert this value before this one
m_columns.insert(m_columns.begin() + col + n, j);
m_values.insert(m_values.begin() + col + n, val);
break;
}
}
}
}
// increase row counts
for (int n = i + 1; n <= m_nr; ++n) m_rowIndex[n]++;
assert(m_rowIndex[m_nr] == m_values.size());
assert(m_columns.size() == m_values.size());
}
// get a value
double CSRMatrix::operator () (int i, int j) const
{
assert((i >= 0) && (i < m_nr));
assert((j >= 0) && (j < m_nc));
int col = m_rowIndex[i] - m_offset;
int count = m_rowIndex[i + 1] - m_rowIndex[i];
if (count == 0) return 0.0;
if (j < m_columns[col] - m_offset) return 0.0;
if (j > m_columns[col + count - 1] - m_offset) return 0.0;
for (int n=0; n<count; ++n)
{
if (m_columns[col + n] - m_offset == j) return m_values[col + n];
}
return 0.0;
}
// see if a matrix entry was allocated
bool CSRMatrix::isAlloc(int i, int j) const
{
assert((i >= 0) && (i < m_nr));
assert((j >= 0) && (j < m_nc));
int col = m_rowIndex[i] - m_offset;
int count = m_rowIndex[i + 1] - m_rowIndex[i];
if (count == 0) return false;
if (j < m_columns[col] - m_offset) return false;
if (j > m_columns[col + count - 1] - m_offset) return false;
for (int n = 0; n<count; ++n)
{
if (m_columns[col + n] - m_offset == j) return true;
}
return false;
}
void CSRMatrix::multv(const std::vector<double>& x, std::vector<double>& r)
{
multv(&x[0], &r[0]);
}
void CSRMatrix::multv(const double* x, double* r)
{
const int nr = rows();
const int nc = cols();
// loop over all rows
for (int i = 0; i<nr; ++i)
{
int col = m_rowIndex[i] - m_offset;
int count = m_rowIndex[i + 1] - m_rowIndex[i];
double* pv = &m_values[col];
int* pi = &m_columns[col];
double ri = 0.0;
for (int j = 0; j<count; ++j) ri += pv[j] * x[pi[j] - m_offset];
r[i] = ri;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMat3dValuator.cpp | .cpp | 12,881 | 508 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMat3dValuator.h"
#include "FEModel.h"
#include "FEMesh.h"
#include "FEDataMap.h"
#include "DumpStream.h"
//=============================================================================
// FELocalMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEConstValueMat3d, FEMat3dValuator)
ADD_PARAMETER(m_val, "const");
END_FECORE_CLASS();
FEConstValueMat3d::FEConstValueMat3d(FEModel* fem) : FEMat3dValuator(fem)
{
m_val.zero();
}
FEMat3dValuator* FEConstValueMat3d::copy()
{
FEConstValueMat3d* map = fecore_alloc(FEConstValueMat3d, GetFEModel());
map->m_val = m_val;
return map;
}
//=============================================================================
// FELocalMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMat3dLocalElementMap, FEMat3dValuator)
ADD_PARAMETER(m_n, 3, "local");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dLocalElementMap::FEMat3dLocalElementMap(FEModel* pfem) : FEMat3dValuator(pfem)
{
m_n[0] = 0;
m_n[1] = 0;
m_n[2] = 0;
}
//-----------------------------------------------------------------------------
bool FEMat3dLocalElementMap::Init()
{
// check values
if ((m_n[0] <= 0) && (m_n[1] <= 0) && (m_n[2] <= 0)) { m_n[0] = 1; m_n[1] = 2; m_n[2] = 4; }
if (m_n[2] <= 0) m_n[2] = m_n[1];
return true;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dLocalElementMap::operator () (const FEMaterialPoint& mp)
{
FEMesh& mesh = GetFEModel()->GetMesh();
FEElement& el = *mp.m_elem;
vec3d r0[FEElement::MAX_NODES];
for (int i=0; i<el.Nodes(); ++i) r0[i] = mesh.Node(el.m_node[i]).m_r0;
vec3d a, b, c, d;
mat3d Q;
a = r0[m_n[1] - 1] - r0[m_n[0] - 1];
a.unit();
if (m_n[2] != m_n[1])
{
d = r0[m_n[2] - 1] - r0[m_n[0] - 1];
}
else
{
d = vec3d(0,1,0);
if (fabs(d*a) > 0.999) d = vec3d(1,0,0);
}
c = a^d;
b = c^a;
b.unit();
c.unit();
Q[0][0] = a.x; Q[0][1] = b.x; Q[0][2] = c.x;
Q[1][0] = a.y; Q[1][1] = b.y; Q[1][2] = c.y;
Q[2][0] = a.z; Q[2][1] = b.z; Q[2][2] = c.z;
return Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dLocalElementMap::copy()
{
FEMat3dLocalElementMap* map = new FEMat3dLocalElementMap(GetFEModel());
map->m_n[0] = m_n[0];
map->m_n[1] = m_n[1];
map->m_n[2] = m_n[2];
return map;
}
//-----------------------------------------------------------------------------
void FEMat3dLocalElementMap::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
ar & m_n;
}
//=============================================================================
// FESphericalMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMat3dSphericalMap, FEMat3dValuator)
ADD_PARAMETER(m_c, "center");
ADD_PARAMETER(m_r, "vector");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dSphericalMap::FEMat3dSphericalMap(FEModel* pfem): FEMat3dValuator(pfem)
{
m_c = vec3d(0,0,0);
m_r = vec3d(1,0,0);
}
//-----------------------------------------------------------------------------
bool FEMat3dSphericalMap::Init()
{
return true;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dSphericalMap::operator () (const FEMaterialPoint& mp)
{
vec3d a = mp.m_r0;
a -= m_c;
a.unit();
// setup the rotation vector
vec3d x_unit(1,0,0);
quatd q(x_unit, a);
vec3d v = m_r;
v.unit();
q.RotateVector(v);
a = v;
vec3d d(0,1,0);
d.unit();
if (fabs(a*d) > .99)
{
d = vec3d(0,0,1);
d.unit();
}
vec3d c = a^d;
vec3d b = c^a;
a.unit();
b.unit();
c.unit();
mat3d Q;
Q[0][0] = a.x; Q[0][1] = b.x; Q[0][2] = c.x;
Q[1][0] = a.y; Q[1][1] = b.y; Q[1][2] = c.y;
Q[2][0] = a.z; Q[2][1] = b.z; Q[2][2] = c.z;
return Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dSphericalMap::copy()
{
FEMat3dSphericalMap* map = new FEMat3dSphericalMap(GetFEModel());
map->m_c = m_c;
map->m_r = m_r;
return map;
}
//=============================================================================
// FECylindricalMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMat3dCylindricalMap, FEMat3dValuator)
ADD_PARAMETER(m_c, "center");
ADD_PARAMETER(m_a, "axis" );
ADD_PARAMETER(m_r, "vector");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dCylindricalMap::FEMat3dCylindricalMap(FEModel* pfem) : FEMat3dValuator(pfem)
{
m_c = vec3d(0,0,0);
m_a = vec3d(0,0,1);
m_r = vec3d(1,0,0);
}
//-----------------------------------------------------------------------------
bool FEMat3dCylindricalMap::Init()
{
m_a.unit();
m_r.unit();
return true;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dCylindricalMap::operator () (const FEMaterialPoint& mp)
{
// get the position of the material point
vec3d p = mp.m_r0;
// find the vector to the axis
vec3d b = (p - m_c) - m_a*(m_a*(p - m_c)); b.unit();
// setup the rotation vector
vec3d x_unit(vec3d(1,0,0));
quatd q(x_unit, b);
// rotate the reference vector
vec3d r(m_r); r.unit();
q.RotateVector(r);
// setup a local coordinate system with r as the x-axis
vec3d d(0,1,0);
q.RotateVector(d);
if (fabs(d*r) > 0.99)
{
d = vec3d(0,0,1);
q.RotateVector(d);
}
// find basis vectors
vec3d e1 = r;
vec3d e3 = (e1 ^ d); e3.unit();
vec3d e2 = e3 ^ e1;
// setup rotation matrix
mat3d Q;
Q[0][0] = e1.x; Q[0][1] = e2.x; Q[0][2] = e3.x;
Q[1][0] = e1.y; Q[1][1] = e2.y; Q[1][2] = e3.y;
Q[2][0] = e1.z; Q[2][1] = e2.z; Q[2][2] = e3.z;
return Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dCylindricalMap::copy()
{
FEMat3dCylindricalMap* val = new FEMat3dCylindricalMap(GetFEModel());
val->m_c = m_c;
val->m_a = m_a;
val->m_r = m_r;
return val;
}
//=============================================================================
// FEPolarMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMat3dPolarMap, FEMat3dValuator)
ADD_PARAMETER(m_c, "center");
ADD_PARAMETER(m_a, "axis" );
ADD_PARAMETER(m_d0, "vector1");
ADD_PARAMETER(m_d1, "vector2");
ADD_PARAMETER(m_R0, "radius1");
ADD_PARAMETER(m_R1, "radius2");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dPolarMap::FEMat3dPolarMap(FEModel* pfem) : FEMat3dValuator(pfem)
{
m_c = vec3d(0,0,0);
m_a = vec3d(0,0,1);
m_d0 = m_d1 = vec3d(1,0,0);
m_R0 = 0;
m_R1 = 1;
}
//-----------------------------------------------------------------------------
bool FEMat3dPolarMap::Init()
{
m_a.unit();
m_d0.unit();
m_d1.unit();
return true;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dPolarMap::operator () (const FEMaterialPoint& mp)
{
// get the nodal position of material point
vec3d p = mp.m_r0;
// find the vector to the axis and its length
vec3d b = (p - m_c) - m_a*(m_a*(p - m_c));
double R = b.unit();
// get the relative radius
double R0 = m_R0;
double R1 = m_R1;
if (R1 == R0) R1 += 1;
double w = (R - R0)/(R1 - R0);
// get the fiber vectors
vec3d v0 = m_d0;
vec3d v1 = m_d1;
quatd Q0(0,vec3d(0,0,1)), Q1(v0,v1);
quatd Qw = quatd::slerp(Q0, Q1, w);
vec3d v = v0; Qw.RotateVector(v);
// setup the rotation vector
vec3d x_unit(vec3d(1,0,0));
quatd q(x_unit, b);
// rotate the reference vector
q.RotateVector(v);
// setup a local coordinate system with r as the x-axis
vec3d d(vec3d(0,1,0));
q.RotateVector(d);
if (fabs(d*v) > 0.99)
{
d = vec3d(0,0,1);
q.RotateVector(d);
}
// find basis vectors
vec3d e1 = v;
vec3d e3 = (e1 ^ d); e3.unit();
vec3d e2 = e3 ^ e1;
// setup rotation matrix
mat3d Q;
Q[0][0] = e1.x; Q[0][1] = e2.x; Q[0][2] = e3.x;
Q[1][0] = e1.y; Q[1][1] = e2.y; Q[1][2] = e3.y;
Q[2][0] = e1.z; Q[2][1] = e2.z; Q[2][2] = e3.z;
return Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dPolarMap::copy()
{
FEMat3dPolarMap* map = new FEMat3dPolarMap(GetFEModel());
map->m_c = m_c;
map->m_a = m_a;
map->m_d0 = m_d0;
map->m_d1 = m_d1;
map->m_R0 = m_R0;
map->m_R1 = m_R1;
return map;
}
//=============================================================================
// FEVectorMap
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMat3dVectorMap, FEMat3dValuator)
ADD_PARAMETER(m_a, "a");
ADD_PARAMETER(m_d, "d");
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMat3dVectorMap::FEMat3dVectorMap(FEModel* pfem) : FEMat3dValuator(pfem)
{
m_a = vec3d(1,0,0);
m_d = vec3d(0,1,0);
m_Q.unit();
}
//-----------------------------------------------------------------------------
bool FEMat3dVectorMap::Init()
{
// generators have to be unit vectors
m_a.unit();
m_d.unit();
// make sure the vectors are not 0-vectors
if ((m_a.norm2() == 0.0) || (m_d.norm2() == 0.0)) return false;
// make sure that a, d are not aligned
if (fabs(m_a*m_d) > 0.999)
{
// if they are, find a different value for d
// Note: If this is used for a mat_axis parameter, then this
// would modify the user specified value.
m_d = vec3d(1,0,0);
if (fabs(m_a*m_d) > 0.999) m_d = vec3d(0,1,0);
}
vec3d a = m_a;
vec3d d = m_d;
vec3d c = a^d;
vec3d b = c^a;
a.unit();
b.unit();
c.unit();
m_Q[0][0] = a.x; m_Q[0][1] = b.x; m_Q[0][2] = c.x;
m_Q[1][0] = a.y; m_Q[1][1] = b.y; m_Q[1][2] = c.y;
m_Q[2][0] = a.z; m_Q[2][1] = b.z; m_Q[2][2] = c.z;
return true;
}
//-----------------------------------------------------------------------------
void FEMat3dVectorMap::SetVectors(vec3d a, vec3d d)
{
m_a = a;
m_d = d;
}
//-----------------------------------------------------------------------------
mat3d FEMat3dVectorMap::operator () (const FEMaterialPoint& mp)
{
return m_Q;
}
//-----------------------------------------------------------------------------
FEMat3dValuator* FEMat3dVectorMap::copy()
{
FEMat3dVectorMap* map = new FEMat3dVectorMap(GetFEModel());
map->m_a = m_a;
map->m_d = m_d;
map->m_Q = m_Q;
return map;
}
//-----------------------------------------------------------------------------
void FEMat3dVectorMap::Serialize(DumpStream &ar)
{
if (ar.IsShallow()) return;
ar & m_a & m_d & m_Q;
}
//=============================================================================
// FEMappedValueMat3d
//-----------------------------------------------------------------------------
BEGIN_FECORE_CLASS(FEMappedValueMat3d, FEMat3dValuator)
ADD_PARAMETER(m_mapName, "map");
END_FECORE_CLASS();
FEMappedValueMat3d::FEMappedValueMat3d(FEModel* fem) : FEMat3dValuator(fem)
{
m_val = nullptr;
}
void FEMappedValueMat3d::setDataMap(FEDataMap* val)
{
m_val = val;
}
FEDataMap* FEMappedValueMat3d::dataMap()
{
return m_val;
}
mat3d FEMappedValueMat3d::operator()(const FEMaterialPoint& pt)
{
assert(m_val);
return (m_val ? m_val->valueMat3d(pt) : mat3d::identity());
}
FEMat3dValuator* FEMappedValueMat3d::copy()
{
FEMappedValueMat3d* map = fecore_alloc(FEMappedValueMat3d, GetFEModel());
map->m_val = m_val;
return map;
}
void FEMappedValueMat3d::Serialize(DumpStream& ar)
{
FEMat3dValuator::Serialize(ar);
ar & m_val;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEDiscreteSet.cpp | .cpp | 2,420 | 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.*/
#include "stdafx.h"
#include "FEDiscreteSet.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
void FEDiscreteSet::NodePair::Serialize(DumpStream& ar)
{
ar & n0 & n1;
}
//-----------------------------------------------------------------------------
FEDiscreteSet::FEDiscreteSet(FEMesh* pm) : m_pmesh(pm)
{
}
//-----------------------------------------------------------------------------
void FEDiscreteSet::create(int n)
{
m_pair.resize(n);
}
//-----------------------------------------------------------------------------
void FEDiscreteSet::add(int n0, int n1)
{
NodePair p = { n0, n1 };
m_pair.push_back(p);
}
//-----------------------------------------------------------------------------
void FEDiscreteSet::SetName(const std::string& name)
{
m_name = name;
}
//-----------------------------------------------------------------------------
const std::string& FEDiscreteSet::GetName() const
{
return m_name;
}
//-----------------------------------------------------------------------------
void FEDiscreteSet::Serialize(DumpStream& ar)
{
ar & m_name;
ar & m_pair;
}
| C++ |
3D | febiosoftware/FEBio | FECore/FENNQuery.h | .h | 2,402 | 80 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "vec3d.h"
#include <vector>
#include "fecore_api.h"
class FESurface;
//-----------------------------------------------------------------------------
//! This class is a helper class to locate the nearest neighbour on a surface
class FECORE_API FENNQuery
{
public:
struct NODE
{
int i; // index of node
vec3d r; // position of node
double d1; // distance to pivot 1
double d2; // distance to pivot 2
};
public:
FENNQuery(FESurface* ps = 0);
virtual ~FENNQuery();
//! initialize search structures
void Init();
void InitReference();
//! attach to a surface
void Attach(FESurface* ps) { m_ps = ps; }
//! find the neirest neighbour of r
int Find(vec3d x);
int FindReference(vec3d x);
protected:
int FindRadius(double r);
protected:
FESurface* m_ps; //!< the surface to search
std::vector<NODE> m_bk; // BK tree
vec3d m_q1; // pivot 1
vec3d m_q2; // pivot 2
int m_imin; // last found index
};
// function for finding the k closest neighbors
int FECORE_API findNeirestNeighbors(const std::vector<vec3d>& point, const vec3d& x, int k, std::vector<int>& closestNodes);
| Unknown |
3D | febiosoftware/FEBio | FECore/FESegmentSet.h | .h | 2,400 | 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_api.h"
#include "FEElement.h"
#include <vector>
#include <string>
#include "FEItemList.h"
#include "FENodeList.h"
//-----------------------------------------------------------------------------
//! This class defines a set of segments. This can be used in the creation of edges.
class FECORE_API FESegmentSet : public FEItemList
{
public:
struct SEGMENT
{
enum SegmentType {
INVALID=0,
LINE2 = 2,
LINE3 = 3
};
int node[3];
int ntype; // 2=line2
void Serialize(DumpStream& ar);
SEGMENT() { ntype = SEGMENT::INVALID; }
};
public:
// constructor
FESegmentSet(FEModel* fem);
// allocate segments
void Create(int n);
// return nr of segments
int Segments() const { return (int)m_Seg.size(); }
// return a segment
SEGMENT& Segment(int i);
const SEGMENT& Segment(int i) const;
FENodeList GetNodeList() const;
public:
// serialization
void Serialize(DumpStream& ar);
static void SaveClass(DumpStream& ar, FESegmentSet* p);
static FESegmentSet* LoadClass(DumpStream& ar, FESegmentSet* p);
private:
vector<SEGMENT> m_Seg; // the actual segment list
};
| Unknown |
3D | febiosoftware/FEBio | FECore/DumpFile.h | .h | 2,443 | 79 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include <stdio.h>
#include "DumpStream.h"
//-----------------------------------------------------------------------------
//! Class for serializing data to a binary archive.
//! This class is used to read data from or write
//! data to a binary file. The class defines several operators to
//! simplify in- and output.
//! \sa FEM::Serialize()
class FECORE_API DumpFile : public DumpStream
{
public:
// overloaded from DumpStream
size_t write(const void* pd, size_t size, size_t count) override;
size_t read(void* pd, size_t size, size_t count) override;
void clear() override {}
bool EndOfStream() const override;
public:
DumpFile(FEModel& fem);
virtual ~DumpFile();
//! Open archive for reading
bool Open(const char* szfile);
//! Open archive for writing
bool Create(const char* szfile);
//! Open archive for appending
bool Append(const char* szfile);
//! Close archive
void Close();
//! See if the archive is valid
bool IsValid() { return (m_fp != 0); }
//! Flush the archive
void Flush() { fflush(m_fp); }
size_t Size() { return m_size; }
protected:
FILE* m_fp; //!< The actual file pointer
size_t m_size;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEPlotData.h | .h | 7,764 | 219 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#include "FECoreBase.h"
#include "fecore_enum.h"
#include "FEDataStream.h"
#include <functional>
//-----------------------------------------------------------------------------
// Region types
enum Region_Type {
FE_REGION_GLOBAL,
FE_REGION_NODE,
FE_REGION_DOMAIN,
FE_REGION_SURFACE,
FE_REGION_EDGE
};
//-----------------------------------------------------------------------------
// forward declarations
class FEModel;
class FEMesh;
class FENode;
class FEEdge;
class FESurface;
class FEDomain;
class FESolidDomain;
class FEMaterialPoint;
class FENodeSet;
class FEElement;
//-----------------------------------------------------------------------------
//! This is the base class for all classes that wish to store data to the
//! plot file. However, classes will not use this class directly as their
//! base class. Instead they'll use one of the more specialized classes
//! defined below.
//!
class FECORE_API FEPlotData : public FECoreBase
{
FECORE_SUPER_CLASS(FEPLOTDATA_ID)
public:
FEPlotData(FEModel* fem);
FEPlotData(FEModel* fem, Region_Type R, Var_Type t, Storage_Fmt s);
// The filter can be used to pass additional information to the plot field.
// The interpretation of this filter is up to the derived class, but could
// be used e.g. for disambiguation. There are currently two flavors of this
// function: one that takes a const char* and one that takes an int. Derived
// classes can overload both or just the one that makes sense for that plot field.
// Note that these functions return false by default. This implies that trying
// to specify a filter on a variable that doesn't support it will automatically cause
// an error.
virtual bool SetFilter(const char* sz) { return false; }
virtual bool SetFilter(int n) { return false;}
Region_Type RegionType() { return m_nregion; }
Var_Type DataType() { return m_ntype; }
Storage_Fmt StorageFormat() { return m_sfmt; }
int VarSize(Var_Type t);
void SetItemList(vector<int>& item) { m_item = item; }
vector<int> GetItemList() { return m_item; }
void SetDomainName(const char* szdom);
const char* GetDomainName() { return m_szdom; }
protected:
void SetRegionType(Region_Type rt) { m_nregion = rt; }
void SetVarType(Var_Type vt) { m_ntype = vt; }
void SetStorageFormat(Storage_Fmt sf) { m_sfmt = sf; }
public: // override one of these functions depending on the Region_Type
virtual bool Save(FEDataStream& a) { return false; } // for FE_REGION_GLOBAL
virtual bool Save(FEMesh& m, FEDataStream& a) { return false; } // for FE_REGION_NODE
virtual bool Save(FEDomain& D, FEDataStream& a) { return false; } // for FE_REGION_DOMAIN
virtual bool Save(FESurface& S, FEDataStream& a) { return false; } // for FE_REGION_SURFACE
virtual bool Save(FEEdge& E, FEDataStream& a) { return false; } // for FE_REGION_EDGE
public:
// will be called before Save
virtual bool PreSave() { return true; }
public: // used by array variables
void SetArraySize(int n);
int GetArraysize() const;
void SetArrayNames(vector<string>& s) { m_arrayNames = s; }
vector<string>& GetArrayNames() { return m_arrayNames; }
public:
void SetUnits(const char* sz) { m_szunit = sz; }
const char* GetUnits() const { return m_szunit; }
private:
Region_Type m_nregion; //!< region type
Var_Type m_ntype; //!< data type
Storage_Fmt m_sfmt; //!< data storage format
vector<int> m_item; //!< Data will only be stored for the item's in this list
char m_szdom[64]; //!< Data will only be stored for the domain with this name
const char* m_szunit;
int m_arraySize; //!< size of arrays (used by arrays)
vector<string> m_arrayNames; //!< optional names of array components (used by arrays)
};
//-----------------------------------------------------------------------------
//! Base class for global data. Data that wish to store data that is not directly
//! evaluated on a part of the mesh should inherit from this class.
class FECORE_API FEPlotGlobalData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotGlobalData)
public:
FEPlotGlobalData(FEModel* fem, Var_Type t) : FEPlotData(fem, FE_REGION_GLOBAL, t, FMT_ITEM) {}
};
//-----------------------------------------------------------------------------
//! This is the base class for node data. Classes that wish to store data
//! associated with each node of the mesh, will use this base class.
class FECORE_API FEPlotNodeData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotNodeData)
public:
FEPlotNodeData(FEModel* fem, Var_Type t, Storage_Fmt s) : FEPlotData(fem, FE_REGION_NODE, t, s) {}
};
//-----------------------------------------------------------------------------
//! This is the base class for domain data. Classes that wish to store data
//! associated with each element or node of a domain, will use this base class.
class FECORE_API FEPlotDomainData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotDomainData)
public:
FEPlotDomainData(FEModel* fem, Var_Type t, Storage_Fmt s) : FEPlotData(fem, FE_REGION_DOMAIN, t, s) {}
};
//-----------------------------------------------------------------------------
//! This is the base class for surface data. Classes that wish to store data
//! associated with each node or facet of a surface, will use this base class.
class FECORE_API FEPlotSurfaceData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotSurfaceData)
public:
FEPlotSurfaceData(FEModel* fem, Var_Type t, Storage_Fmt s) : FEPlotData(fem, FE_REGION_SURFACE, t, s) {}
};
//! This is the base class for edge data. Classes that wish to store data
//! associated with each node or facet of a FEEdge, will use this base class.
class FECORE_API FEPlotEdgeData : public FEPlotData
{
FECORE_BASE_CLASS(FEPlotEdgeData)
public:
FEPlotEdgeData(FEModel* fem, Var_Type t, Storage_Fmt s) : FEPlotData(fem, FE_REGION_EDGE, t, s) {}
};
// helper class for parsing the type string of plot fields
class FECORE_API FEPlotFieldDescriptor
{
private:
enum FilterType {
NO_FILTER,
NUMBER_FILTER,
STRING_FILTER
};
public:
FEPlotFieldDescriptor(const std::string& typeString);
bool isValid() const { return m_valid; }
bool HasFilter() const { return (m_filterType != NO_FILTER); }
bool IsNumberFilter() const { return (m_filterType == NUMBER_FILTER); }
bool IsStringFilter() const { return (m_filterType == STRING_FILTER); }
public:
string fieldName;
string alias;
int numFilter = -1;
string strFilter;
private:
FilterType m_filterType = NO_FILTER;
bool m_valid = false;
};
| Unknown |
3D | febiosoftware/FEBio | FECore/FEMathIntervalController.cpp | .cpp | 3,301 | 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.*/
#include "stdafx.h"
#include "FEMathIntervalController.h"
#include "FEModel.h"
BEGIN_FECORE_CLASS(FEMathIntervalController, FELoadController)
ADD_PARAMETER(m_rng, 2, "interval");
ADD_PARAMETER(m_leftExtend , "left_extend", 0, "zero\0constant\0repeat\0");
ADD_PARAMETER(m_rightExtend, "right_extend", 0, "zero\0constant\0repeat\0");
ADD_PARAMETER(m_var, "var");
ADD_PARAMETER(m_math, "math");
END_FECORE_CLASS();
FEMathIntervalController::FEMathIntervalController(FEModel* fem) : FELoadController(fem)
{
m_rng[0] = 0.0;
m_rng[1] = 1.0;
m_leftExtend = ExtendMode::CONSTANT;
m_rightExtend = ExtendMode::CONSTANT;
}
bool FEMathIntervalController::Init()
{
double Dt = m_rng[1] - m_rng[0];
if (Dt <= 0.0) return false;
FEModel& fem = *GetFEModel();
m_val.AddVariable("t");
char sz[64] = { 0 };
for (int i = 0; i < (int)m_var.size(); ++i)
{
ParamString ps(m_var[i].c_str());
FEParamValue param = fem.GetParameterValue(ps);
if (param.isValid() == false) return false;
if (param.type() != FE_PARAM_DOUBLE) return false;
m_param.push_back(param);
snprintf(sz, sizeof(sz), "var_%d", i);
m_val.AddVariable(sz);
}
if (m_val.Create(m_math) == false) return false;
return FELoadController::Init();
}
double FEMathIntervalController::GetValue(double time)
{
if (time <= m_rng[0])
{
switch (m_leftExtend)
{
case ExtendMode::ZERO: return 0.0; break;
case ExtendMode::CONSTANT: time = m_rng[0]; break;
case ExtendMode::REPEAT:
{
double Dt = m_rng[1] - m_rng[0];
time = m_rng[1] - fmod(m_rng[0] - time, Dt);
}
break;
}
}
else if (time >= m_rng[1])
{
switch (m_rightExtend)
{
case ExtendMode::ZERO: return 0.0; break;
case ExtendMode::CONSTANT: time = m_rng[1]; break;
case ExtendMode::REPEAT:
{
double Dt = m_rng[1] - m_rng[0];
time = m_rng[0] + fmod(time - m_rng[0], Dt);
}
break;
}
}
vector<double> p(1 + m_param.size());
p[0] = time;
for (int i = 0; i < m_param.size(); ++i) p[1 + i] = m_param[i].value<double>();
return m_val.value_s(p);
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEParameterList.cpp | .cpp | 17,943 | 521 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEParameterList.h"
#include "FECoreKernel.h"
#include "DumpStream.h"
#include "tens3d.h"
#include "FEModelParam.h"
#include <string>
#include <assert.h>
using namespace std;
//-----------------------------------------------------------------------------
FEParameterList::FEParameterList(FEParamContainer* pc) : m_pc(pc)
{
m_currentGroup = -1;
}
//-----------------------------------------------------------------------------
FEParameterList::~FEParameterList()
{
}
//-----------------------------------------------------------------------------
//! This function copies the parameter data from the passed parameter list.
//! This assumes that the two parameter lists are identical.
void FEParameterList::operator = (FEParameterList& l)
{
if (m_pl.size() != l.m_pl.size()) { assert(false); return; }
list<FEParam>::iterator ps, pd;
ps = l.m_pl.begin();
pd = m_pl.begin();
for (; pd != m_pl.end(); ++pd, ++ps)
{
FEParam& s = *ps;
FEParam& d = *pd;
if (s.type() != d.type()) { assert(false); return; }
if (s.dim() != d.dim()) { assert(false); return; }
if (s.dim() == 1)
{
switch (s.type())
{
case FE_PARAM_INT : d.value<int >() = s.value<int >(); break;
case FE_PARAM_BOOL : d.value<bool >() = s.value<bool >(); break;
case FE_PARAM_DOUBLE: d.value<double>() = s.value<double>(); break;
case FE_PARAM_VEC3D : d.value<vec3d >() = s.value<vec3d >(); break;
case FE_PARAM_MAT3D : d.value<mat3d >() = s.value<mat3d >(); break;
case FE_PARAM_MAT3DS: d.value<mat3ds>() = s.value<mat3ds>(); break;
case FE_PARAM_TENS3DRS: d.value<tens3drs>() = s.value<tens3drs>(); break;
case FE_PARAM_STD_STRING: d.value<std::string>() = s.value<std::string>(); break;
case FE_PARAM_DOUBLE_MAPPED:
{
FEParamDouble& mat3d = d.value<FEParamDouble>();
FEParamDouble& src = s.value<FEParamDouble>();
mat3d.setValuator(src.valuator()->copy());
}
break;
case FE_PARAM_MAT3D_MAPPED:
{
FEParamMat3d& mat3d = d.value<FEParamMat3d>();
FEParamMat3d& src = s.value<FEParamMat3d>();
mat3d.setValuator(src.valuator()->copy());
}
break;
case FE_PARAM_STD_VECTOR_VEC2D:
{
d.value< std::vector<vec2d> >() = s.value< std::vector<vec2d> >();
}
break;
default:
assert(false);
}
}
else
{
switch (s.type())
{
case FE_PARAM_INT:
{
for (int i=0; i<s.dim(); ++i) d.pvalue<int>()[i] = s.pvalue<int>()[i];
}
break;
case FE_PARAM_DOUBLE:
{
for (int i=0; i<s.dim(); ++i) d.pvalue<double>()[i] = s.pvalue<double>()[i];
}
break;
case FE_PARAM_DOUBLE_MAPPED:
{
for (int i=0; i<s.dim(); ++i)
{
FEParamDouble& pd = d.value<FEParamDouble>(i);
FEParamDouble& ps = s.value<FEParamDouble>(i);
assert(ps.isConst());
pd = ps.constValue();
}
}
break;
default:
assert(false);
}
}
}
}
//-----------------------------------------------------------------------------
// This function adds a parameter to the parameter list
FEParam* FEParameterList::AddParameter(void *pv, FEParamType itype, int ndim, const char *sz, bool* watch)
{
// sanity checks
assert(pv);
assert(sz);
// create a new parameter object
FEParam p(pv, itype, ndim, sz, watch);
p.SetParamGroup(m_currentGroup);
// add the parameter to the list
m_pl.push_back(p);
return &(m_pl.back());
}
//-----------------------------------------------------------------------------
// This function adds a parameter to the parameter list
FEParam* FEParameterList::AddParameter(void *pv, FEParamType itype, int ndim, FEParamRange rng, double fmin, double fmax, const char *sz)
{
assert(pv);
assert(sz);
// create a new parameter object
FEParam p(pv, itype, ndim, sz);
p.SetParamGroup(m_currentGroup);
// set the range
// (range checking is only supported for int and double params)
if (rng != FE_DONT_CARE)
{
if (itype == FE_PARAM_INT) p.SetValidator(new FEIntValidator(rng, (int) fmin, (int) fmax));
else if (itype == FE_PARAM_DOUBLE) p.SetValidator(new FEDoubleValidator(rng, fmin, fmax));
else if (itype == FE_PARAM_DOUBLE_MAPPED) p.SetValidator(new FEParamDoubleValidator(rng, fmin, fmax));
}
// add the parameter to the list
m_pl.push_back(p);
return &(m_pl.back());
}
//-----------------------------------------------------------------------------
// Find a parameter using its data pointer
FEParam* FEParameterList::FindFromData(void* pv)
{
FEParam* pp = 0;
if (m_pl.empty() == false)
{
list<FEParam>::iterator it;
for (it = m_pl.begin(); it != m_pl.end(); ++it)
{
if (it->dim() <= 1)
{
if (it->data_ptr() == pv)
{
pp = &(*it);
return pp;
}
}
else
{
for (int i = 0; i < it->dim(); ++i)
{
void* pd = nullptr;
switch (it->type())
{
case FE_PARAM_DOUBLE_MAPPED: pd = &(it->value<FEParamDouble>(i)); break;
case FE_PARAM_INT: pd = &(it->value<int>(i)); break;
default:
assert(false);
}
if (pv == pd)
{
pp = &(*it);
return pp;
}
}
}
}
}
return pp;
}
//-----------------------------------------------------------------------------
// This function searches the parameters in the list for a parameter
// with the name given by the input argument
// \param sz name of parameter to find
FEParam* FEParameterList::FindFromName(const char* sz)
{
if (sz == 0) return 0;
FEParam* pp = 0;
if (m_pl.size() > 0)
{
list<FEParam>::iterator it;
for (it = m_pl.begin(); it != m_pl.end(); ++it)
{
if (strcmp(it->name(), sz) == 0)
{
pp = &(*it);
break;
}
}
}
return pp;
}
//-----------------------------------------------------------------------------
int FEParameterList::SetActiveGroup(const char* szgroup)
{
if (szgroup == nullptr) m_currentGroup = -1;
else
{
m_currentGroup = -1;
for (size_t i = 0; i < m_pg.size(); ++i)
{
if (strcmp(m_pg[i], szgroup) == 0)
{
m_currentGroup = i;
}
}
if (m_currentGroup == -1)
{
m_currentGroup = (int)m_pg.size();
m_pg.push_back(szgroup);
}
}
return m_currentGroup;
}
//-----------------------------------------------------------------------------
int FEParameterList::GetActiveGroup()
{
return m_currentGroup;
}
//-----------------------------------------------------------------------------
int FEParameterList::ParameterGroups() const
{
return (int)m_pg.size();
}
//-----------------------------------------------------------------------------
const char* FEParameterList::GetParameterGroupName(int i)
{
return m_pg[i];
}
//=============================================================================
FEParamContainer::FEParamContainer()
{
m_pParam = 0;
}
//-----------------------------------------------------------------------------
FEParamContainer::~FEParamContainer()
{
delete m_pParam;
m_pParam = 0;
}
//-----------------------------------------------------------------------------
FEParameterList& FEParamContainer::GetParameterList()
{
if (m_pParam == 0)
{
m_pParam = new FEParameterList(this);
BuildParamList();
}
return *m_pParam;
}
//-----------------------------------------------------------------------------
const FEParameterList& FEParamContainer::GetParameterList() const
{
assert(m_pParam);
return *m_pParam;
}
//-----------------------------------------------------------------------------
// Find a parameter from its name
FEParam* FEParamContainer::GetParameter(const char* szname)
{
FEParameterList& pl = GetParameterList();
return pl.FindFromName(szname);
}
//-----------------------------------------------------------------------------
// Find a parameter from its name
FEParam* FEParamContainer::FindParameter(const ParamString& s)
{
FEParameterList& pl = GetParameterList();
return pl.FindFromName(s.c_str());
}
//-----------------------------------------------------------------------------
FEParam* FEParamContainer::FindParameterFromData(void* pv)
{
FEParameterList& pl = GetParameterList();
return pl.FindFromData(pv);
}
//-----------------------------------------------------------------------------
//! This function will be overridden by each class that defines a parameter list
void FEParamContainer::BuildParamList()
{
}
//-----------------------------------------------------------------------------
// Add a parameter to the parameter list
FEParam* FEParamContainer::AddParameter(void* pv, FEParamType itype, int ndim, const char* sz, bool* watch)
{
assert(m_pParam);
FEParam* p = m_pParam->AddParameter(pv, itype, ndim, sz, watch);
p->setParent(this);
return p;
}
//-----------------------------------------------------------------------------
// Add a parameter to the parameter list
FEParam* FEParamContainer::AddParameter(void* pv, FEParamType itype, int ndim, RANGE rng, const char* sz)
{
assert(m_pParam);
FEParam* p = m_pParam->AddParameter(pv, itype, ndim, rng.m_rt, rng.m_fmin, rng.m_fmax, sz);
p->setParent(this);
return p;
}
//-----------------------------------------------------------------------------
FEParam* FEParamContainer::AddParameter(int& v, const char* sz) { return AddParameter(&v, FE_PARAM_INT, 1, sz); }
FEParam* FEParamContainer::AddParameter(bool& v, const char* sz) { return AddParameter(&v, FE_PARAM_BOOL, 1, sz); }
FEParam* FEParamContainer::AddParameter(double& v, const char* sz) { return AddParameter(&v, FE_PARAM_DOUBLE, 1, sz); }
FEParam* FEParamContainer::AddParameter(vec2d& v, const char* sz) { return AddParameter(&v, FE_PARAM_VEC2D, 1, sz); }
FEParam* FEParamContainer::AddParameter(vec3d& v, const char* sz) { return AddParameter(&v, FE_PARAM_VEC3D, 1, sz); }
FEParam* FEParamContainer::AddParameter(mat3d& v, const char* sz) { return AddParameter(&v, FE_PARAM_MAT3D, 1, sz); }
FEParam* FEParamContainer::AddParameter(mat3ds& v, const char* sz) { return AddParameter(&v, FE_PARAM_MAT3DS, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEParamDouble& v, const char* sz) { return AddParameter(&v, FE_PARAM_DOUBLE_MAPPED, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEParamVec3& v, const char* sz) { return AddParameter(&v, FE_PARAM_VEC3D_MAPPED, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEParamMat3d& v, const char* sz) { return AddParameter(&v, FE_PARAM_MAT3D_MAPPED, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEParamMat3ds& v, const char* sz) { return AddParameter(&v, FE_PARAM_MAT3DS_MAPPED, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEDataArray& v, const char* sz) { return AddParameter(&v, FE_PARAM_DATA_ARRAY, 1, sz); }
FEParam* FEParamContainer::AddParameter(tens3drs& v, const char* sz) { return AddParameter(&v, FE_PARAM_TENS3DRS, 1, sz); }
FEParam* FEParamContainer::AddParameter(std::string& v, const char* sz) { return AddParameter(&v, FE_PARAM_STD_STRING, 1, sz); }
FEParam* FEParamContainer::AddParameter(std::vector<int>& v, const char* sz) { return AddParameter(&v, FE_PARAM_STD_VECTOR_INT, 1, sz); }
FEParam* FEParamContainer::AddParameter(std::vector<double>& v, const char* sz) { return AddParameter(&v, FE_PARAM_STD_VECTOR_DOUBLE, 1, sz); }
FEParam* FEParamContainer::AddParameter(std::vector<vec2d>& v, const char* sz) { return AddParameter(&v, FE_PARAM_STD_VECTOR_VEC2D, 1, sz); }
FEParam* FEParamContainer::AddParameter(std::vector<std::string>& v, const char* sz) { return AddParameter(&v, FE_PARAM_STD_VECTOR_STRING, 1, sz); }
FEParam* FEParamContainer::AddParameter(FEMaterialPointProperty& v, const char* sz) { return AddParameter(&v, FE_PARAM_MATERIALPOINT, 1, sz); }
//FEParam* FEParamContainer::AddParameter(Image& v , const char* sz) { return AddParameter(&v, FE_PARAM_IMAGE_3D, 1, sz); }
FEParam* FEParamContainer::AddParameter(int& v, RANGE rng, const char* sz) { return AddParameter(&v, FE_PARAM_INT, 1, rng, sz); }
FEParam* FEParamContainer::AddParameter(double& v, RANGE rng, const char* sz) { return AddParameter(&v, FE_PARAM_DOUBLE, 1, rng, sz); }
FEParam* FEParamContainer::AddParameter(FEParamDouble& v, RANGE rng, const char* sz) { return AddParameter(&v, FE_PARAM_DOUBLE_MAPPED, 1, rng, sz); }
FEParam* FEParamContainer::AddParameter(double& v, const char* sz, bool& watch) { return AddParameter(&v, FE_PARAM_DOUBLE, 1, sz, &watch); }
FEParam* FEParamContainer::AddParameter(int* v, int ndim, const char* sz) { return AddParameter(v, FE_PARAM_INT, ndim, sz); }
FEParam* FEParamContainer::AddParameter(double* v, int ndim, const char* sz) { return AddParameter(v, FE_PARAM_DOUBLE, ndim, sz); }
FEParam* FEParamContainer::AddParameter(FEParamDouble* v, int ndim, const char* sz) { return AddParameter(v, FE_PARAM_DOUBLE_MAPPED, ndim, sz); }
FEParam* FEParamContainer::AddParameter(int* v, int ndim, RANGE rng, const char* sz) { return AddParameter(v, FE_PARAM_INT, ndim, rng, sz); }
FEParam* FEParamContainer::AddParameter(double* v, int ndim, RANGE rng, const char* sz) { return AddParameter(v, FE_PARAM_DOUBLE, ndim, rng, sz); }
FEParam* FEParamContainer::AddParameter(FEParamDouble* v, int ndim, RANGE rng, const char* sz) { return AddParameter(v, FE_PARAM_DOUBLE_MAPPED, ndim, rng, sz); }
//-----------------------------------------------------------------------------
FEParam* FEParamContainer::AddParameter(int& v, const char* sz, unsigned int flags, const char* szenum)
{
FEParam* p = AddParameter(&v, FE_PARAM_INT, 1, sz);
p->setParent(this);
p->SetFlags(flags);
p->setEnums(szenum);
return p;
}
//-----------------------------------------------------------------------------
FEParam* FEParamContainer::AddParameter(std::vector<int>& v, const char* sz, unsigned int flags, const char* szenum)
{
FEParam* p = AddParameter(&v, FE_PARAM_STD_VECTOR_INT, 1, sz);
p->setParent(this);
p->SetFlags(flags);
p->setEnums(szenum);
return p;
}
//-----------------------------------------------------------------------------
FEParam* FEParamContainer::AddParameter(std::string& s, const char* sz, unsigned int flags, const char* szenum)
{
FEParam* p = AddParameter(&s, FE_PARAM_STD_STRING, 1, sz);
p->setParent(this);
p->SetFlags(flags);
p->setEnums(szenum);
return p;
}
//-----------------------------------------------------------------------------
// Serialize parameters to archive
void FEParamContainer::Serialize(DumpStream& ar)
{
if (ar.IsShallow()) return;
if (ar.IsSaving())
{
int NP = 0;
list<FEParam>::iterator it;
if (m_pParam) // If the input file doesn't set any parameters, the parameter list won't be created.
{
NP = m_pParam->Parameters();
it = m_pParam->first();
}
ar << NP;
for (int i=0; i<NP; ++i)
{
FEParam& p = *it++;
ar << p;
}
}
else
{
int NP = 0;
ar >> NP;
if (NP)
{
FEParameterList& pl = GetParameterList();
if (NP != pl.Parameters()) throw DumpStream::ReadError();
list<FEParam>::iterator it = pl.first();
for (int i=0; i<NP; ++i)
{
FEParam& p = *it++;
ar >> p;
}
}
}
}
//-----------------------------------------------------------------------------
//! This function validates all parameters.
//! It fails on the first parameter that is outside its allowed range.
//! Use fecore_get_error_string() to find out which parameter failed validation.
bool FEParamContainer::Validate()
{
FEParameterList& pl = GetParameterList();
int N = pl.Parameters();
list<FEParam>::iterator pi = pl.first();
for (int i=0; i<N; ++i, pi++)
{
FEParam& p = *pi;
if (p.is_valid() == false)
{
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
void FEParamContainer::CopyParameterListState(const FEParameterList& pl)
{
FEParameterList& pl_this = GetParameterList();
assert(pl_this.Parameters() == pl.Parameters());
int NP = pl.Parameters();
FEParamIteratorConst it_s = pl.first();
FEParamIterator it_d = pl_this.first();
for (int i=0; i<NP; ++i, ++it_s, ++it_d)
{
const FEParam& ps = *it_s;
FEParam& pd = *it_d;
if (pd.CopyState(ps) == false) { assert(false); }
}
}
//-----------------------------------------------------------------------------
void FEParamContainer::BeginParameterGroup(const char* szname)
{
FEParameterList& pl_this = GetParameterList();
pl_this.SetActiveGroup(szname);
}
//-----------------------------------------------------------------------------
void FEParamContainer::EndParameterGroup()
{
FEParameterList& pl_this = GetParameterList();
pl_this.SetActiveGroup(nullptr);
}
| C++ |
3D | febiosoftware/FEBio | FECore/MFunctions.cpp | .cpp | 3,675 | 155 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "MFunctions.h"
#include <assert.h>
double fl (double x) { return x; }
double csc (double x) { return 1.0 / sin(x); }
double sec (double x) { return 1.0 / cos(x); }
double cot (double x) { return 1.0 / tan(x); }
double sinc(double x) { return (x == 0? 1 : sin(x)/x); }
double sgn (double x) { return (x<0?-1.0 : 1.0); }
double heaviside (double x) { return (x> 0 ? 1.0 : (x < 0.0 ? 0.0 : 0.5)); }
double unit_step (double x) { return (x< 0 ? 0.0 : 1.0); }
#ifdef WIN32
double jn(double x, double y)
{
return _jn((int) x, y);
}
double yn(double x, double y)
{
return _yn((int) x, y);
}
#endif
double fmax(double* x, int n)
{
double v = x[0];
for (int i=1; i<n; ++i)
if (x[i] > v) v = x[i];
return v;
}
double fmin(double* x, int n)
{
double v = x[0];
for (int i=1; i<n; ++i)
if (x[i] < v) v = x[i];
return v;
}
double avg(double* x, int n)
{
double v = x[0];
for (int i=1; i<n; ++i) v += x[i];
return (v/n);
}
double chebyshev(double f, double x)
{
int n = (int)(f);
if (n<=0) return 1;
if (n==1) return x;
double T0 = 0;
double T1 = 1;
double Tn = x;
for (int i=2; i<=n; ++i)
{
T0 = T1;
T1 = Tn;
Tn = 2*x*T1 - T0;
}
return Tn;
}
double fac(double n)
{
assert(n >= 0.0);
if (n <= 1) return 1.0;
double p = 1.0;
while (n > 1.0) p *= (n--);
return p;
}
double prod(double a, double b)
{
double p = 1;
if (a >= b)
{
while (a >= b) p *= a--;
}
else
{
while (b >= a) p *= b--;
}
return p;
}
double binomial(double n, double r)
{
assert(r <= n);
if (n == r) return 1.0;
if (r == 0.0) return 1.0;
double b = 0;
if (r >= n/2)
{
b = prod(n, r+1)/fac(n - r);
}
else b = prod(n, n-r+1) / fac(r);
return b;
}
//-----------------------------------------------------------------------------
// approximation of gamma function using Lanczos approximation
double gamma(double z)
{
const int g = 7;
const double p[] = {0.99999999999980993, 676.5203681218851, -1259.1392167224028,
771.32342877765313, -176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7};
const double pi = 4.0*atan(1.0);
if (z < 0.5)
{
return pi / (sin(pi*z) * gamma(1-z));
}
else
{
z -= 1;
double x = p[0];
for (int i=1; i<g+2; ++i) x += p[i]/(z+i);
double t = z + g + 0.5;
return sqrt(2*pi) * pow(t, z+0.5) * exp(-t) * x;
}
}
| C++ |
3D | febiosoftware/FEBio | FECore/FEMaterial.cpp | .cpp | 4,607 | 142 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION 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 "FEMaterial.h"
#include "DumpStream.h"
//-----------------------------------------------------------------------------
FEMaterialBase::FEMaterialBase(FEModel* fem) : FEModelComponent(fem)
{
}
//-----------------------------------------------------------------------------
//! returns a pointer to a new material point object
FEMaterialPointData* FEMaterialBase::CreateMaterialPointData() { return nullptr; };
//-----------------------------------------------------------------------------
//! Update specialized material points at each iteration
void FEMaterialBase::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp)
{
}
//=============================================================================
BEGIN_FECORE_CLASS(FEMaterial, FEMaterialBase)
// ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional);
END_FECORE_CLASS();
//-----------------------------------------------------------------------------
FEMaterial::FEMaterial(FEModel* fem) : FEMaterialBase(fem)
{
m_Q = nullptr;
}
//-----------------------------------------------------------------------------
FEMaterial::~FEMaterial()
{
for (size_t i = 0; i < m_param.size(); ++i) delete m_param[i];
m_param.clear();
}
//-----------------------------------------------------------------------------
// evaluate local coordinate system at material point
mat3d FEMaterial::GetLocalCS(const FEMaterialPoint& mp)
{
mat3d Q = (m_Q ? m_Q->operator()(mp) : mat3d::identity());
FEMaterial* parent = dynamic_cast<FEMaterial*>(GetParent());
if (parent)
{
mat3d Qp = parent->GetLocalCS(mp);
return Qp*Q;
}
else
{
mat3d A = mp.m_Q.RotationMatrix();
return A*Q;
}
}
//-----------------------------------------------------------------------------
// set the (local) material axis valuator
void FEMaterial::SetMaterialAxis(FEMat3dValuator* val)
{
if (m_Q) delete m_Q;
m_Q = val;
}
//-----------------------------------------------------------------------------
//! Initial material.
bool FEMaterial::Init()
{
// initialize base class
return FECoreBase::Init();
}
//-----------------------------------------------------------------------------
void FEMaterial::AddDomain(FEDomain* dom)
{
m_domList.AddDomain(dom);
}
//-----------------------------------------------------------------------------
FEDomainParameter* FEMaterial::FindDomainParameter(const std::string& paramName)
{
for (int i = 0; i < m_param.size(); ++i)
{
FEDomainParameter* pi = m_param[i];
if (pi->name() == paramName) return pi;
}
return nullptr;
}
//-----------------------------------------------------------------------------
void FEMaterial::AddDomainParameter(FEDomainParameter* p)
{
assert(p);
m_param.push_back(p);
}
//==============================================================================
BEGIN_FECORE_CLASS(FEMaterialProperty, FEMaterialBase)
END_FECORE_CLASS();
FEMaterialProperty::FEMaterialProperty(FEModel* fem) : FEMaterialBase(fem)
{
}
//-----------------------------------------------------------------------------
// Since properties don't have local coordinate system,
// we return the parent's
mat3d FEMaterialProperty::GetLocalCS(const FEMaterialPoint& mp)
{
FEMaterialBase* parent = dynamic_cast<FEMaterialBase*>(GetParent()); assert(parent);
return parent->GetLocalCS(mp);
}
| C++ |
3D | febiosoftware/FEBio | FECore/sys.h | .h | 1,747 | 56 | /*This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#pragma once
#ifdef WIN32
#include <float.h>
#define ISNAN(x) _isnan(x)
#endif
#ifdef LINUX
#ifdef CENTOS
#define ISNAN(x) isnan(x)
#else
#define ISNAN(x) std::isnan(x)
#endif
#endif
#ifdef __APPLE__
#include <math.h>
#define ISNAN(x) isnan(x)
#endif
#ifdef WIN32
extern "C" int __cdecl omp_get_num_threads(void);
extern "C" int __cdecl omp_get_thread_num(void);
#else
extern "C" int omp_get_num_threads(void);
extern "C" int omp_get_thread_num(void);
#endif
| Unknown |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.