From 5b338b35f353da757f3b191493bbc18f596d9f76 Mon Sep 17 00:00:00 2001 From: SteveMaas1978 Date: Mon, 29 Apr 2024 09:15:50 -0600 Subject: [PATCH] Added "fluid moving frame" body force. --- FEBioFluid/FEBioFluid.cpp | 2 + FEBioFluid/FEFluidMovingFrameLoad.cpp | 106 ++++++++++++++++++++++++++ FEBioFluid/FEFluidMovingFrameLoad.h | 52 +++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 FEBioFluid/FEFluidMovingFrameLoad.cpp create mode 100644 FEBioFluid/FEFluidMovingFrameLoad.h diff --git a/FEBioFluid/FEBioFluid.cpp b/FEBioFluid/FEBioFluid.cpp index eb27470a8..706c4fc49 100644 --- a/FEBioFluid/FEBioFluid.cpp +++ b/FEBioFluid/FEBioFluid.cpp @@ -83,6 +83,7 @@ SOFTWARE.*/ #include "FEConstFluidBodyForce.h" #include "FECentrifugalFluidBodyForce.h" +#include "FEFluidMovingFrameLoad.h" #include "FEFluidModule.h" @@ -171,6 +172,7 @@ REGISTER_FECORE_CLASS(FEFluidRCLoad , "fluid RC" // body loads REGISTER_FECORE_CLASS(FEConstFluidBodyForce , "fluid body force"); REGISTER_FECORE_CLASS(FECentrifugalFluidBodyForce, "fluid centrifugal force"); +REGISTER_FECORE_CLASS(FEFluidMovingFrameLoad , "fluid moving frame"); //----------------------------------------------------------------------------- // boundary conditions diff --git a/FEBioFluid/FEFluidMovingFrameLoad.cpp b/FEBioFluid/FEFluidMovingFrameLoad.cpp new file mode 100644 index 000000000..4d071e812 --- /dev/null +++ b/FEBioFluid/FEFluidMovingFrameLoad.cpp @@ -0,0 +1,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.*/ +#include "stdafx.h" +#include "FEFluidMovingFrameLoad.h" +#include "FEFluidMaterialPoint.h" +#include + +BEGIN_FECORE_CLASS(FEFluidMovingFrameLoad, FEBodyForce) + ADD_PARAMETER(m_w.x, "wx")->setLongName("x-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); + ADD_PARAMETER(m_w.y, "wy")->setLongName("y-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); + ADD_PARAMETER(m_w.z, "wz")->setLongName("z-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); + ADD_PARAMETER(m_a.x, "ax")->setLongName("x-linear acceleration")->setUnits(UNIT_ACCELERATION); + ADD_PARAMETER(m_a.y, "ay")->setLongName("y-linear acceleration")->setUnits(UNIT_ACCELERATION); + ADD_PARAMETER(m_a.z, "az")->setLongName("z-linear acceleration")->setUnits(UNIT_ACCELERATION); +END_FECORE_CLASS(); + +FEFluidMovingFrameLoad::FEFluidMovingFrameLoad(FEModel* fem) : FEBodyForce(fem) +{ + m_w = vec3d(0, 0, 0); + m_al = vec3d(0, 0, 0); + m_q = quatd(0, vec3d(0, 0, 1)); +} + +void FEFluidMovingFrameLoad::Activate() +{ + m_wp = m_w; + FEBodyForce::Activate(); +} + +void FEFluidMovingFrameLoad::PrepStep() +{ + double dt = GetTimeInfo().timeIncrement; + m_al = (m_w - m_wp) / dt; + + vec3d wa = (m_w + m_wp) * 0.5; + + quatd qn = m_q; + quatd wn(wa.x, wa.y, wa.z, 0.0); + m_q = qn + (wn * qn) * (0.5 * dt); + m_q.MakeUnit(); + m_wp = m_w; + + vec3d R = m_q.GetRotationVector(); + + feLogDebug("al : %lg, %lg, %lg\n", m_al.x, m_al.y, m_al.z); + feLogDebug("R : %lg, %lg, %lg\n", R.x, R.y, R.z); +} + +vec3d FEFluidMovingFrameLoad::force(FEMaterialPoint& pt) +{ + FEFluidMaterialPoint& fp = *pt.ExtractData(); + + quatd qi = m_q.Inverse(); + + vec3d r = pt.m_rt; + vec3d v = fp.m_vft; + vec3d w = qi * m_w; + vec3d al = qi * m_al; + vec3d f = qi*m_a + (al ^ r) + (w ^ (w ^ r)) + (w ^ v) * 2.0; + return f; +} + +mat3d FEFluidMovingFrameLoad::stiffness(FEMaterialPoint& pt) +{ + FEFluidMaterialPoint& fp = *pt.ExtractData(); + vec3d v = fp.m_vft; + + const FETimeInfo& tp = GetTimeInfo(); + double gamma = tp.gamma; + double dt = tp.timeIncrement; + + quatd qi = m_q.Inverse(); + vec3d w = qi * m_w; + vec3d al = qi * m_al; + + mat3da Sw(w); + mat3da A(al); + mat3d S2 = Sw * Sw; + mat3d K = S2 + A + Sw * (4.0 * gamma / dt); + + // NOTE: we need a negative sign, since the external load stiffness needs to be subtracted from the global stiffness + return -K; +} diff --git a/FEBioFluid/FEFluidMovingFrameLoad.h b/FEBioFluid/FEFluidMovingFrameLoad.h new file mode 100644 index 000000000..948c78edd --- /dev/null +++ b/FEBioFluid/FEFluidMovingFrameLoad.h @@ -0,0 +1,52 @@ +/*This file is part of the FEBio source code and is licensed under the MIT license +listed below. + +See Copyright-FEBio.txt for details. + +Copyright (c) 2021 University of Utah, The Trustees of Columbia University in +the City of New York, and others. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.*/ +#pragma once +#include + +//! This body load emulates the effect of a moving frame +class FEFluidMovingFrameLoad : public FEBodyForce +{ +public: + FEFluidMovingFrameLoad(FEModel* fem); + + void Activate() override; + + void PrepStep() override; + + vec3d force(FEMaterialPoint& pt) override; + + mat3d stiffness(FEMaterialPoint& pt) override; + +private: + vec3d m_w; // angular velocity of frame + vec3d m_a; // linear acceleration of frame + + quatd m_q; + vec3d m_wp; + vec3d m_al; + + DECLARE_FECORE_CLASS(); +};