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