mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STY: Clearing up code and updating tutrial
This commit is contained in:
@ -70,19 +70,6 @@ Foam::IOobject Foam::points0MotionSolver::points0IO(const polyMesh& mesh)
|
||||
io.rename("points");
|
||||
}
|
||||
|
||||
// Choose the latest points if points0 is not present
|
||||
// if (!io.typeHeaderOk<pointIOField>())
|
||||
// {
|
||||
// const word instance =
|
||||
// mesh.time().findInstance
|
||||
// (
|
||||
// mesh.meshDir(),
|
||||
// "points",
|
||||
// IOobject::MUST_READ
|
||||
// );
|
||||
// io.instance() = instance;
|
||||
// io.rename("points");
|
||||
// }
|
||||
return io;
|
||||
}
|
||||
|
||||
|
||||
@ -55,12 +55,12 @@ Foam::solidBodyMotionFunctions::drivenLinearMotion::drivenLinearMotion
|
||||
)
|
||||
:
|
||||
solidBodyMotionFunction(SBMFCoeffs, runTime),
|
||||
CofGvelocity_(SBMFCoeffs.get<word>("CofGvelocity")),
|
||||
CofGvel_
|
||||
cOfGdisplacement_(SBMFCoeffs.get<word>("cOfGdisplacement")),
|
||||
CofGdisp_
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
CofGvelocity_,
|
||||
cOfGdisplacement_,
|
||||
time_.timeName(),
|
||||
"uniform",
|
||||
time_,
|
||||
@ -80,9 +80,9 @@ Foam::septernion
|
||||
Foam::solidBodyMotionFunctions::drivenLinearMotion::transformation() const
|
||||
{
|
||||
|
||||
DebugInFunction << "displacement :" << CofGvel_.value() << endl;
|
||||
DebugInFunction << "displacement :" << CofGdisp_.value() << endl;
|
||||
quaternion R(1);
|
||||
septernion TR(septernion(-CofGvel_.value())*R);
|
||||
septernion TR(septernion(-CofGdisp_.value())*R);
|
||||
|
||||
DebugInFunction << "Time = " << time_.value()
|
||||
<< " transformation: " << TR << endl;
|
||||
|
||||
@ -63,11 +63,11 @@ class drivenLinearMotion
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Name of the meshObject to dum CofG velocity
|
||||
word CofGvelocity_;
|
||||
//- Name of the meshObject to dum CofG displacement
|
||||
word cOfGdisplacement_;
|
||||
|
||||
//- Uniform vector to follow
|
||||
uniformDimensionedVectorField CofGvel_;
|
||||
uniformDimensionedVectorField CofGdisp_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -63,7 +63,7 @@ Foam::RBD::restraints::prescribedRotation::prescribedRotation
|
||||
restraint(name, dict, model),
|
||||
omegaSet_(model_.time(), "omega"),
|
||||
omega_(Zero),
|
||||
prevMom_(Zero),
|
||||
oldMom_(Zero),
|
||||
error0_(Zero),
|
||||
integral0_(Zero)
|
||||
{
|
||||
@ -86,7 +86,7 @@ void Foam::RBD::restraints::prescribedRotation::restrain
|
||||
const rigidBodyModelState& state
|
||||
) const
|
||||
{
|
||||
vector refDir = rotationTensor(vector(1, 0, 0), axis_) & vector(0, 1, 0);
|
||||
vector refDir = rotationTensor(vector(1, 0, 0), axis_)&vector(0, 1, 0);
|
||||
|
||||
vector oldDir = refQ_ & refDir;
|
||||
vector newDir = model_.X0(bodyID_).E() & refDir;
|
||||
@ -137,21 +137,10 @@ void Foam::RBD::restraints::prescribedRotation::restrain
|
||||
vector integral = integral0_ + error;
|
||||
vector derivative = (error - error0_);
|
||||
|
||||
vector moment = ((p_*error + i_*integral + d_*derivative) & a ) * a;
|
||||
moment = moment*Inertia/model_.time().deltaTValue();
|
||||
vector moment = ((p_*error + i_*integral + d_*derivative)&a)*a;
|
||||
moment *= Inertia/model_.time().deltaTValue();
|
||||
|
||||
// vector moment
|
||||
// (
|
||||
// (
|
||||
// Inertia
|
||||
// * (omegaSet_.value(model_.time().value()) - omega)
|
||||
// / model_.time().deltaTValue()/relax_
|
||||
// & a
|
||||
// )
|
||||
// * a
|
||||
// );
|
||||
|
||||
moment = relax_*moment + (1- relax_)*prevMom_;
|
||||
moment = relax_*moment + (1- relax_)*oldMom_;
|
||||
|
||||
if (model_.debug)
|
||||
{
|
||||
@ -172,7 +161,7 @@ void Foam::RBD::restraints::prescribedRotation::restrain
|
||||
// Accumulate the force for the restrained body
|
||||
fx[bodyIndex_] += model_.X0(bodyID_).T() & spatialVector(moment, Zero);
|
||||
|
||||
prevMom_ = moment;
|
||||
oldMom_ = moment;
|
||||
error0_ = error;
|
||||
integral0_ = integral;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ class prescribedRotation
|
||||
mutable vector omega_;
|
||||
|
||||
//- Cache previous momentum
|
||||
mutable vector prevMom_;
|
||||
mutable vector oldMom_;
|
||||
|
||||
//- Relax momentum
|
||||
scalar relax_;
|
||||
|
||||
@ -121,9 +121,11 @@ Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
|
||||
rhoName_(coeffDict().getOrDefault<word>("rho", "rho")),
|
||||
ramp_(Function1<scalar>::NewIfPresent("ramp", coeffDict())),
|
||||
curTimeIndex_(-1),
|
||||
CofGvelocity_(coeffDict().getOrDefault<word>("CofGvelocity", "none")),
|
||||
cOfGdisplacement_
|
||||
(
|
||||
coeffDict().getOrDefault<word>("cOfGdisplacement", "none")
|
||||
),
|
||||
bodyIdCofG_(coeffDict().getOrDefault<label>("bodyIdCofG", -1))
|
||||
//points0_(points0IO(mesh))
|
||||
{
|
||||
if (rhoName_ == "rhoInf")
|
||||
{
|
||||
@ -211,8 +213,6 @@ Foam::rigidBodyMeshMotion::rigidBodyMeshMotion
|
||||
Foam::tmp<Foam::pointField>
|
||||
Foam::rigidBodyMeshMotion::curPoints() const
|
||||
{
|
||||
//return points0() + pointDisplacement_.primitiveField();
|
||||
|
||||
tmp<pointField> newPoints(points0() + pointDisplacement_.primitiveField());
|
||||
|
||||
if (moveAllCells())
|
||||
@ -311,7 +311,7 @@ void Foam::rigidBodyMeshMotion::solve()
|
||||
);
|
||||
}
|
||||
|
||||
if (CofGvelocity_ != "none")
|
||||
if (cOfGdisplacement_ != "none")
|
||||
{
|
||||
if (bodyIdCofG_ != -1)
|
||||
{
|
||||
@ -319,14 +319,14 @@ void Foam::rigidBodyMeshMotion::solve()
|
||||
(
|
||||
db().time().foundObject<uniformDimensionedVectorField>
|
||||
(
|
||||
CofGvelocity_
|
||||
cOfGdisplacement_
|
||||
)
|
||||
)
|
||||
{
|
||||
uniformDimensionedVectorField& disp =
|
||||
auto& disp =
|
||||
db().time().lookupObjectRef<uniformDimensionedVectorField>
|
||||
(
|
||||
CofGvelocity_
|
||||
cOfGdisplacement_
|
||||
);
|
||||
|
||||
disp.value() += model_.cCofR(bodyIdCofG_) - oldPos;
|
||||
@ -335,8 +335,8 @@ void Foam::rigidBodyMeshMotion::solve()
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "CofGvelocity is different of none." << endl
|
||||
<< "The model need the entry body reference Id: bodyIdCofG."
|
||||
<< "CofGdisplacement is different to none." << endl
|
||||
<< "The model needs the entry body reference Id: bodyIdCofG."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,10 +128,10 @@ class rigidBodyMeshMotion
|
||||
//- Current time index (used for updating)
|
||||
label curTimeIndex_;
|
||||
|
||||
//- Name of the uniformVectorField for CofG velocity
|
||||
word CofGvelocity_;
|
||||
//- Name of the uniformVectorField for CofG displacement
|
||||
word cOfGdisplacement_;
|
||||
|
||||
//- Body Id for the body to write CofG velocity
|
||||
//- Body Id for the body to write CofG displacement
|
||||
label bodyIdCofG_;
|
||||
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ Foam::sixDoFRigidBodyMotionSolver::sixDoFRigidBodyMotionSolver
|
||||
dimensionedScalar(dimless, Zero)
|
||||
),
|
||||
curTimeIndex_(-1),
|
||||
CofGvelocity_(coeffDict().getOrDefault<word>("CofGvelocity", "none"))
|
||||
cOfGdisplacement_(coeffDict().getOrDefault<word>("cOfGdisplacement", "none"))
|
||||
{
|
||||
if (rhoName_ == "rhoInf")
|
||||
{
|
||||
@ -262,20 +262,20 @@ void Foam::sixDoFRigidBodyMotionSolver::solve()
|
||||
t.deltaT0Value()
|
||||
);
|
||||
|
||||
if (CofGvelocity_ != "none")
|
||||
if (cOfGdisplacement_ != "none")
|
||||
{
|
||||
if
|
||||
(
|
||||
db().time().foundObject<uniformDimensionedVectorField>
|
||||
(
|
||||
CofGvelocity_
|
||||
cOfGdisplacement_
|
||||
)
|
||||
)
|
||||
{
|
||||
uniformDimensionedVectorField& disp =
|
||||
auto& disp =
|
||||
db().time().lookupObjectRef<uniformDimensionedVectorField>
|
||||
(
|
||||
CofGvelocity_
|
||||
cOfGdisplacement_
|
||||
);
|
||||
|
||||
disp += (motion_.centreOfRotation() - oldPos);
|
||||
|
||||
@ -94,8 +94,8 @@ class sixDoFRigidBodyMotionSolver
|
||||
//- Current time index (used for updating)
|
||||
label curTimeIndex_;
|
||||
|
||||
//- Name of the uniformVectorField for CofG velocity
|
||||
word CofGvelocity_;
|
||||
//- Name of the uniformVectorField for CofG displacement
|
||||
word cOfGdisplacement_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -26,7 +26,7 @@ solvers
|
||||
solidBodyMotionFunction drivenLinearMotion;
|
||||
|
||||
cellSet c0;
|
||||
CofGvelocity CofG;
|
||||
cOfGdisplacement CofG;
|
||||
}
|
||||
|
||||
cube
|
||||
@ -41,7 +41,7 @@ solvers
|
||||
outerDistance 1001.0;
|
||||
|
||||
centreOfMass (0.5 0.5 0.4);
|
||||
CofGvelocity CofG;
|
||||
cOfGdisplacement CofG;
|
||||
|
||||
// Cuboid dimensions
|
||||
Lx 0.24;
|
||||
|
||||
Reference in New Issue
Block a user