From 278ba86d7d663e7eaf84eccf2d06f03ccdc1b1d2 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 4 Oct 2019 16:52:55 +0100 Subject: [PATCH] rigidBodyDynamics::restraints::externalForce: New restraint to apply a time-varying force Description Time-dependent external force restraint using Function1. Usage Example applying a constant force to the floatingObject: restraints { force { type externalForce; body floatingObject; location (0 0 0); force (100 0 0); } } Based on code contributed by SeongMo Yeon Resolves contribution request https://bugs.openfoam.org/view.php?id=3358 --- .../restraints/externalForce/externalForce.C | 128 ++++++++++++++++ .../restraints/externalForce/externalForce.H | 141 ++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 src/rigidBodyDynamics/restraints/externalForce/externalForce.C create mode 100644 src/rigidBodyDynamics/restraints/externalForce/externalForce.H diff --git a/src/rigidBodyDynamics/restraints/externalForce/externalForce.C b/src/rigidBodyDynamics/restraints/externalForce/externalForce.C new file mode 100644 index 0000000000..eccdc74c8d --- /dev/null +++ b/src/rigidBodyDynamics/restraints/externalForce/externalForce.C @@ -0,0 +1,128 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2019 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "externalForce.H" +#include "rigidBodyModel.H" +#include "rigidBodyModelState.H" +#include "OneConstant.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace restraints +{ + defineTypeNameAndDebug(externalForce, 0); + + addToRunTimeSelectionTable + ( + restraint, + externalForce, + dictionary + ); +} +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::RBD::restraints::externalForce::externalForce +( + const word& name, + const dictionary& dict, + const rigidBodyModel& model +) +: + restraint(name, dict, model), + externalForce_(nullptr) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::restraints::externalForce::~externalForce() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::RBD::restraints::externalForce::restrain +( + scalarField& tau, + Field& fx, + const rigidBodyModelState& state +) const +{ + const vector force = externalForce_().value(state.t()); + const vector moment(location_ ^ force); + + if (model_.debug) + { + Info<< " location " << location_ + << " force " << force + << " moment " << moment + << endl; + } + + // Accumulate the force for the restrained body + fx[bodyIndex_] += spatialVector(moment, force); +} + + +bool Foam::RBD::restraints::externalForce::read +( + const dictionary& dict +) +{ + restraint::read(dict); + + coeffs_.lookup("location") >> location_; + + externalForce_ = Function1::New("force", coeffs_); + + return true; +} + + +void Foam::RBD::restraints::externalForce::write +( + Ostream& os +) const +{ + restraint::write(os); + + writeEntry(os, "location", location_); + + writeEntry(os, externalForce_()); +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/restraints/externalForce/externalForce.H b/src/rigidBodyDynamics/restraints/externalForce/externalForce.H new file mode 100644 index 0000000000..c82ecaef62 --- /dev/null +++ b/src/rigidBodyDynamics/restraints/externalForce/externalForce.H @@ -0,0 +1,141 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2019 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::RBD::restraints::externalForce + +Description + Time-dependent external force restraint using Function1. + +Usage + Example applying a constant force to the floatingObject: + \verbatim + restraints + { + force + { + type externalForce; + body floatingObject; + location (0 0 0); + force (100 0 0); + } + } + \endverbatim + +SourceFiles + externalForce.C + +\*---------------------------------------------------------------------------*/ + +#ifndef RBD_restraints_externalForce_H +#define RBD_restraints_externalForce_H + +#include "rigidBodyRestraint.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace restraints +{ + +/*---------------------------------------------------------------------------*\ + Class externalForce Declaration +\*---------------------------------------------------------------------------*/ + +class externalForce +: + public restraint +{ + // Private data + + //- External force (N) + autoPtr> externalForce_; + + //- Point of application of the force + vector location_; + + +public: + + //- Runtime type information + TypeName("externalForce"); + + + // Constructors + + //- Construct from components + externalForce + ( + const word& name, + const dictionary& dict, + const rigidBodyModel& model + ); + + //- Construct and return a clone + virtual autoPtr clone() const + { + return autoPtr + ( + new externalForce(*this) + ); + } + + + //- Destructor + virtual ~externalForce(); + + + // Member Functions + + //- Accumulate the retraint internal joint forces into the tau field and + // external forces into the fx field + virtual void restrain + ( + scalarField& tau, + Field& fx, + const rigidBodyModelState& state + ) const; + + //- Update properties from given dictionary + virtual bool read(const dictionary& dict); + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace restraints +} // End namespace RBD +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //