View Issue Details

IDProjectCategoryView StatusLast Update
0003358OpenFOAMContributionpublic2019-10-08 15:05
Reporterhandrake0724 Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Versiondev 
Fixed in Versiondev 
Summary0003358: external force restraint class
DescriptionI have made a restraint class mimicking external force using Function1 class.

When simulating towing tunnel test or roll damping or VIM test,
it is necessary to have a external force like force compensation of drag as a static force.
or it is useful to give a initial excitation force for roll or initial offset for decay test with morphing mesh.

At the moment, it is not possible to use time information in restraint class and static force is only available.
but, once time information is available later, this class can be modified and find more flexible usages.

Please review this class if it is useful.
TagsNo tags attached.

Activities

handrake0724

2019-10-02 11:09

viewer  

henry

2019-10-02 11:22

manager   ~0010786

> At the moment, it is not possible to use time information in restraint class and static force is only available.
> but, once time information is available later, this class can be modified and find more flexible usages.

Would it make sense for this to wait until you have completed the updates to provide time to the restraint classes?

handrake0724

2019-10-02 16:04

viewer   ~0010789

I have updated externalFunction1Force class after updating restraint class.
Also, I have created inverseLinearRamp Function1<scalar> class in order to implement initial excitation force.
Please review if it is useful.
patch.diff (17,781 bytes)   
diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index c32da4d9b..f6d30fa6b 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -92,6 +92,7 @@ primitives/triad/triad.C
 primitives/functions/Function1/makeFunction1s.C
 primitives/functions/Function1/ramp/ramp.C
 primitives/functions/Function1/linearRamp/linearRamp.C
+primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.C
 primitives/functions/Function1/quadraticRamp/quadraticRamp.C
 primitives/functions/Function1/quarterSineRamp/quarterSineRamp.C
 primitives/functions/Function1/quarterCosineRamp/quarterCosineRamp.C
diff --git a/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.C b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.C
new file mode 100644
index 000000000..6b1e726c0
--- /dev/null
+++ b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.C
@@ -0,0 +1,57 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2017-2018 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "inverseLinearRamp.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace Function1Types
+{
+    makeScalarFunction1(inverseLinearRamp);
+}
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::Function1Types::inverseLinearRamp::inverseLinearRamp
+(
+    const word& entryName,
+    const dictionary& dict
+)
+:
+    ramp(entryName, dict)
+{}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::Function1Types::inverseLinearRamp::~inverseLinearRamp()
+{}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.H b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.H
new file mode 100644
index 000000000..89ce9feaf
--- /dev/null
+++ b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRamp.H
@@ -0,0 +1,106 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2017-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 <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::Function1Types::inverseLinearRamp
+
+Description
+    Linear ramp function starting from 1 and decreasing linearly to 0 from
+    \c start over the \c duration and remaining at 0 thereafter.
+
+See also
+    Foam::Function1Types::ramp
+
+SourceFiles
+    inverseLinearRamp.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef inverseLinearRamp_H
+#define inverseLinearRamp_H
+
+#include "ramp.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace Function1Types
+{
+
+/*---------------------------------------------------------------------------*\
+                           Class inverseLinearRamp Declaration
+\*---------------------------------------------------------------------------*/
+
+class inverseLinearRamp
+:
+    public ramp
+{
+
+public:
+
+    // Runtime type information
+    TypeName("inverseLinearRamp");
+
+
+    // Constructors
+
+        //- Construct from entry name and dictionary
+        inverseLinearRamp
+        (
+            const word& entryName,
+            const dictionary& dict
+        );
+
+
+    //- Destructor
+    virtual ~inverseLinearRamp();
+
+
+    // Member Functions
+
+        //- Return value for time t
+        virtual inline scalar value(const scalar t) const;
+
+
+    // Member Operators
+
+        //- Disallow default bitwise assignment
+        void operator=(const inverseLinearRamp&) = delete;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Function1Types
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#include "inverseLinearRampI.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRampI.H b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRampI.H
new file mode 100644
index 000000000..08130c424
--- /dev/null
+++ b/src/OpenFOAM/primitives/functions/Function1/inverseLinearRamp/inverseLinearRampI.H
@@ -0,0 +1,39 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2017-2018 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "inverseLinearRamp.H"
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+inline Foam::scalar Foam::Function1Types::inverseLinearRamp::value
+(
+    const scalar t
+) const
+{
+    return 1.0 - ramp::linearRamp(t);
+}
+
+
+// ************************************************************************* //
diff --git a/src/rigidBodyDynamics/Make/files b/src/rigidBodyDynamics/Make/files
index 74b99e7a0..65ba85409 100644
--- a/src/rigidBodyDynamics/Make/files
+++ b/src/rigidBodyDynamics/Make/files
@@ -36,6 +36,7 @@ restraints/linearSpring/linearSpring.C
 restraints/linearDamper/linearDamper.C
 restraints/linearAxialAngularSpring/linearAxialAngularSpring.C
 restraints/sphericalAngularDamper/sphericalAngularDamper.C
+restraints/externalFunction1Force/externalFunction1Force.C
 
 rigidBodyModel/rigidBodyModel.C
 rigidBodyModel/forwardDynamics.C
diff --git a/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.C b/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.C
new file mode 100644
index 000000000..b3005c0fb
--- /dev/null
+++ b/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.C
@@ -0,0 +1,148 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2016-2018 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 <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "externalFunction1Force.H"
+#include "rigidBodyModel.H"
+#include "rigidBodyModelState.H"
+#include "OneConstant.H"
+#include "addToRunTimeSelectionTable.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace RBD
+{
+namespace restraints
+{
+    defineTypeNameAndDebug(externalFunction1Force, 0);
+
+    addToRunTimeSelectionTable
+    (
+        restraint,
+        externalFunction1Force,
+        dictionary
+    );
+}
+}
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::RBD::restraints::externalFunction1Force::externalFunction1Force
+(
+    const word& name,
+    const dictionary& dict,
+    const rigidBodyModel& model
+)
+:
+    restraint(name, dict, model),
+    externalForce_(nullptr),
+    ramp_(nullptr)
+{
+    read(dict);
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+Foam::RBD::restraints::externalFunction1Force::~externalFunction1Force()
+{}
+
+
+// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
+
+void Foam::RBD::restraints::externalFunction1Force::restrain
+(
+    scalarField& tau,
+    Field<spatialVector>& fx,
+    const rigidBodyModelState& state
+) const
+{
+    const scalar factor = ramp_().value(state.t());
+    const vector force = factor*externalForce_().value(state.t());
+    const vector moment(location_ ^ force);
+
+    if (model_.debug)
+    {
+        Info<< " location " << location_ << endl;
+    }
+
+    // Accumulate the force for the restrained body
+    fx[bodyIndex_] += spatialVector(moment, force);
+}
+
+
+bool Foam::RBD::restraints::externalFunction1Force::read
+(
+    const dictionary& dict
+)
+{
+    restraint::read(dict);
+
+
+    coeffs_.lookup("location") >> location_;
+    const word& type = coeffs_.lookup("Function1Type");
+    const dictionary& subDict = coeffs_.subDict(type+"Coeffs");
+    externalForce_ = Function1<vector>::New
+    (
+        type,
+        subDict
+    );
+
+    if (coeffs_.found("ramp"))
+    {
+        ramp_ = Function1<scalar>::New("ramp", coeffs_);
+    }
+    else
+    {
+        ramp_ = new Function1Types::OneConstant<scalar>("ramp");
+    }
+
+    return true;
+}
+
+
+void Foam::RBD::restraints::externalFunction1Force::write
+(
+    Ostream& os
+) const
+{
+    restraint::write(os);
+    const word subDictName = externalForce_().name() + "Coeffs";
+
+    os.writeKeyword("location")
+        << location_ << token::END_STATEMENT << nl;
+    os.writeKeyword("Function1Type")
+        << externalForce_().name() << token::END_STATEMENT << nl;
+    os.writeKeyword(subDictName) << nl;
+    os << token::BEGIN_BLOCK << incrIndent << nl;
+    os << externalForce_() << nl;
+    os << decrIndent << token::END_BLOCK << endl;
+}
+
+
+// ************************************************************************* //
diff --git a/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.H b/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.H
new file mode 100644
index 000000000..ba3dac31a
--- /dev/null
+++ b/src/rigidBodyDynamics/restraints/externalFunction1Force/externalFunction1Force.H
@@ -0,0 +1,146 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     | Website:  https://openfoam.org
+    \\  /    A nd           | Copyright (C) 2016-2018 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 <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::RBD::restraints::externalFunction1Force
+
+Description
+    external force restraint using Function1 class.
+    external force is able to make dependent on time by using ramp function.
+    For instance, inverseLinearRamp make external force valid only for the
+    time span from the begining to start. It is useful for the initial excitation
+    of motion.
+
+    externalForce
+    {
+        type    externalFunction1Force;
+        body    hull;
+        location    (0 0 0);
+        Function1Type   constant;
+        constantCoeffs
+        {
+            constant    (1 0 0);
+        }
+        ramp inverseLinearRamp;
+        start 1;
+        duration 1;
+    }
+
+
+SourceFiles
+    externalFunction1Force.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef RBD_restraints_externalFunction1Force_H
+#define RBD_restraints_externalFunction1Force_H
+
+#include "rigidBodyRestraint.H"
+#include "Function1.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace RBD
+{
+namespace restraints
+{
+
+/*---------------------------------------------------------------------------*\
+                          Class externalFunction1Force Declaration
+\*---------------------------------------------------------------------------*/
+
+class externalFunction1Force
+:
+    public restraint
+{
+    // Private data
+
+        //- External force (N)
+        autoPtr<Function1<vector>> externalForce_;
+        autoPtr<Function1<scalar>> ramp_;
+
+        //- Point of Application
+        vector location_;
+
+public:
+
+    //- Runtime type information
+    TypeName("externalFunction1Force");
+
+
+    // Constructors
+
+        //- Construct from components
+        externalFunction1Force
+        (
+            const word& name,
+            const dictionary& dict,
+            const rigidBodyModel& model
+        );
+
+        //- Construct and return a clone
+        virtual autoPtr<restraint> clone() const
+        {
+            return autoPtr<restraint>
+            (
+                new externalFunction1Force(*this)
+            );
+        }
+
+
+    //- Destructor
+    virtual ~externalFunction1Force();
+
+
+    // 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<spatialVector>& 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
+
+// ************************************************************************* //
patch.diff (17,781 bytes)   

henry

2019-10-02 16:43

manager   ~0010790

It makes more sense to name inverseLinearRamp reverseLinearRamp as inverse implies reciprocal for a scalar. Also if reverse ramps are needed I assume that any form might need to be reversed and rather than implement reverse versions of all of them it would make more sense to implement a wrapper class which instantiates a ramp and evaluates and returns the corresponding reverse. The alternative would be to implement a generic linear function in which the start and end values are specified so that it can either ramp up or down.

handrake0724

2019-10-02 17:12

viewer   ~0010791

Thanks for the comments.
about the reverse ramp idea, in my opinion, it would be simpler if reverse switch is provided in ramp class such that linearRamp would return either
  max(min( (t - start_)/duration, 1), 0)
or
  max(min( 1- (t - start_)/duration, 1), 0)

Then, all the subclasses of ramp can remain without changes while providing reverse ramp functionality.
What do you make of it?

henry

2019-10-02 17:43

manager   ~0010792

It is more flexible, less code and easier to maintain to add a wrapper class rather than add complexity to each of the current and all future ramp classes.

handrake0724

2019-10-02 19:22

viewer   ~0010794

henry, I wrote a wrapper class which reverses original ramp classes.
reverseRamp.tar.gz (1,549 bytes)

henry

2019-10-04 15:38

manager   ~0010797

There are a lot of issues with the reverseRamp implementation and it does not work properly as provided, at least it needs a copy constructor so that the ramp it stores is duplicated as necessary and a writeData function otherwise it is not written out post-processing and restart is not possible. I am updating the code now and will push after completing the tests.

henry

2019-10-04 16:09

manager   ~0010798

The updated reverseRamp is now in OpenFOAM-dev: commit 8756e82afdb0a0eba32383a999f907bfc572dfcc

henry

2019-10-04 16:55

manager   ~0010799

I had some problems with IO inconsistency in the externalFunction1Force class and resolved it by removing the ramp which is not necessary as the force is already time-varying.
I have pushed the updated class into OpenFOAM-dev: commit 278ba86d7d663e7eaf84eccf2d06f03ccdc1b1d2

henry

2019-10-08 15:05

manager   ~0010807

Resolved by commit 278ba86d7d663e7eaf84eccf2d06f03ccdc1b1d2

Issue History

Date Modified Username Field Change
2019-10-02 11:09 handrake0724 New Issue
2019-10-02 11:09 handrake0724 File Added: externalFunction1Force.tar.gz
2019-10-02 11:22 henry Note Added: 0010786
2019-10-02 16:04 handrake0724 File Added: patch.diff
2019-10-02 16:04 handrake0724 Note Added: 0010789
2019-10-02 16:43 henry Note Added: 0010790
2019-10-02 17:12 handrake0724 Note Added: 0010791
2019-10-02 17:43 henry Note Added: 0010792
2019-10-02 19:22 handrake0724 File Added: reverseRamp.tar.gz
2019-10-02 19:22 handrake0724 Note Added: 0010794
2019-10-04 15:38 henry Note Added: 0010797
2019-10-04 16:09 henry Note Added: 0010798
2019-10-04 16:55 henry Note Added: 0010799
2019-10-08 15:05 henry Assigned To => henry
2019-10-08 15:05 henry Status new => resolved
2019-10-08 15:05 henry Resolution open => fixed
2019-10-08 15:05 henry Fixed in Version => dev
2019-10-08 15:05 henry Note Added: 0010807