Commit cbf807ca authored by graham's avatar graham
Browse files

ENH: sixDoFRigidBodyMotion. Rewritten write function.

Now storing name of restrain or constraint in list in the
sixDoFRigidBodyMotion object.  Added a write method to all constraints
and restraints.
parent c0b236ec
......@@ -39,6 +39,11 @@ void Foam::sixDoFRigidBodyMotion::applyRestraints()
{
forAll(restraints_, rI)
{
if (report_)
{
Info<< "Restraint " << restraintNames_[rI];
}
// restraint position
point rP = vector::zero;
......@@ -85,6 +90,11 @@ void Foam::sixDoFRigidBodyMotion::applyConstraints(scalar deltaT)
forAll(constraints_, cI)
{
if (report_)
{
Info<< "Constraint " << constraintNames_[cI];
}
// constraint position
point cP = vector::zero;
......
......@@ -123,8 +123,7 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::constrain
if (motion.report())
{
Info<< "Constraint " << this->name()
<< " angle " << theta
Info<< " angle " << theta
<< " force " << constraintForceIncrement
<< " moment " << constraintMomentIncrement;
......@@ -175,4 +174,14 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::read
return true;
}
void Foam::sixDoFRigidBodyMotionConstraints::fixedAxis::write
(
Ostream& os
) const
{
os.writeKeyword("axis")
<< fixedAxis_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -111,6 +111,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -109,8 +109,7 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::constrain
if (motion.report())
{
Info<< "Constraint " << this->name()
<< " error << " << error
Info<< " error " << error
<< " force " << constraintForceIncrement
<< " moment " << constraintMomentIncrement;
......@@ -163,4 +162,17 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedLine::read
return true;
}
void Foam::sixDoFRigidBodyMotionConstraints::fixedLine::write
(
Ostream& os
) const
{
os.writeKeyword("refPoint")
<< refPt_ << token::END_STATEMENT << nl;
os.writeKeyword("direction")
<< dir_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -112,6 +112,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -150,8 +150,7 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::constrain
if (motion.report())
{
Info<< "Constraint " << this->name()
<< " max angle " << maxTheta
Info<< " max angle " << maxTheta
<< " force " << constraintForceIncrement
<< " moment " << constraintMomentIncrement;
......@@ -198,4 +197,14 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::read
return true;
}
void Foam::sixDoFRigidBodyMotionConstraints::fixedOrientation::write
(
Ostream& os
) const
{
os.writeKeyword("fixedOrientation")
<< fixedOrientation_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -112,6 +112,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -109,8 +109,7 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::constrain
if (motion.report())
{
Info<< "Constraint " << this->name()
<< " error " << error
Info<< " error " << error
<< " force " << constraintForceIncrement
<< " moment " << constraintMomentIncrement;
......@@ -146,4 +145,17 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::read
return true;
}
void Foam::sixDoFRigidBodyMotionConstraints::fixedPlane::write
(
Ostream& os
) const
{
os.writeKeyword("refPoint")
<< fixedPlane_.refPoint() << token::END_STATEMENT << nl;
os.writeKeyword("normal")
<< fixedPlane_.normal() << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -110,6 +110,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -118,8 +118,7 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::constrain
if (motion.report())
{
Info<< "Constraint " << this->name()
<< " error " << error
Info<< " error " << error
<< " force " << constraintForceIncrement
<< " moment " << constraintMomentIncrement;
......@@ -151,4 +150,14 @@ bool Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::read
return true;
}
void Foam::sixDoFRigidBodyMotionConstraints::fixedPoint::write
(
Ostream& os
) const
{
os.writeKeyword("fixedPoint")
<< fixedPoint_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -111,6 +111,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -39,7 +39,6 @@ Foam::sixDoFRigidBodyMotionConstraint::sixDoFRigidBodyMotionConstraint
const dictionary& sDoFRBMCDict
)
:
name_(fileName(sDoFRBMCDict.name().name()).components(token::COLON).last()),
sDoFRBMCCoeffs_
(
sDoFRBMCDict.subDict
......@@ -69,9 +68,6 @@ bool Foam::sixDoFRigidBodyMotionConstraint::read
const dictionary& sDoFRBMCDict
)
{
name_ =
fileName(sDoFRBMCDict.name().name()).components(token::COLON).last();
tolerance_ = (readScalar(sDoFRBMCDict.lookup("tolerance")));
relaxationFactor_ = sDoFRBMCDict.lookupOrDefault<scalar>
......@@ -86,4 +82,13 @@ bool Foam::sixDoFRigidBodyMotionConstraint::read
}
void Foam::sixDoFRigidBodyMotionConstraint::write(Ostream& os) const
{
os.writeKeyword("tolerance")
<< tolerance_ << token::END_STATEMENT << nl;
os.writeKeyword("relaxationFactor")
<< relaxationFactor_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -70,9 +70,6 @@ protected:
// Protected data
//- Name of the constraint in dictionary
word name_;
//- Constraint model specific coefficient dictionary
dictionary sDoFRBMCCoeffs_;
......@@ -145,16 +142,10 @@ public:
) const = 0;
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMCDict) = 0;
virtual bool read(const dictionary& sDoFRBMCDict);
// Access
//- Return access to the name of the restraint
inline const word& name() const
{
return name_;
}
// Return access to sDoFRBMCCoeffs
inline const dictionary& coeffDict() const
{
......@@ -172,6 +163,9 @@ public:
{
return relaxationFactor_;
}
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -42,68 +42,67 @@ void Foam::sixDoFRigidBodyMotion::write(Ostream& os) const
os.writeKeyword("report")
<< report_ << token::END_STATEMENT << nl;
if (restraints_.size())
if (!restraints_.empty())
{
dictionary restraintsDict;
os << indent << "restraints" << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
forAll(restraints_, rI)
{
word restraintType = restraints_[rI].type();
dictionary restraintDict;
os << indent << restraintNames_[rI] << nl
<< indent << token::BEGIN_BLOCK << incrIndent << endl;
restraintDict.add("sixDoFRigidBodyMotionRestraint", restraintType);
os.writeKeyword("sixDoFRigidBodyMotionRestraint")
<< restraintType << token::END_STATEMENT << nl;
restraintDict.add
(
word(restraintType + "Coeffs"), restraints_[rI].coeffDict()
);
os.writeKeyword(word(restraintType + "Coeffs")) << nl;
restraintsDict.add(restraints_[rI].name(), restraintDict);
os << indent << token::BEGIN_BLOCK << nl << incrIndent;
restraints_[rI].write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
os << decrIndent << indent << token::END_BLOCK << endl;
}
os.writeKeyword("restraints") << restraintsDict;
os << decrIndent << indent << token::END_BLOCK << nl;
}
if (constraints_.size())
if (!constraints_.empty())
{
dictionary constraintsDict;
os << indent << "constraints" << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
constraintsDict.add("maxIterations", maxConstraintIterations_);
os.writeKeyword("maxIterations")
<< maxConstraintIterations_ << token::END_STATEMENT << nl;
forAll(constraints_, rI)
{
word constraintType = constraints_[rI].type();
dictionary constraintDict;
os << indent << constraintNames_[rI] << nl
<< indent << token::BEGIN_BLOCK << incrIndent << endl;
os.writeKeyword("sixDoFRigidBodyMotionConstraint")
<< constraintType << token::END_STATEMENT << nl;
constraints_[rI].sixDoFRigidBodyMotionConstraint::write(os);
constraintDict.add
(
"sixDoFRigidBodyMotionConstraint",
constraintType
);
os.writeKeyword(word(constraintType + "Coeffs")) << nl;
constraintDict.add
(
"tolerance",
constraints_[rI].tolerance()
);
os << indent << token::BEGIN_BLOCK << nl << incrIndent;
constraintDict.add
(
"relaxationFactor",
constraints_[rI].relaxationFactor()
);
constraints_[rI].write(os);
constraintDict.add
(
word(constraintType + "Coeffs"), constraints_[rI].coeffDict()
);
os << decrIndent << indent << token::END_BLOCK << nl;
constraintsDict.add(constraints_[rI].name(), constraintDict);
os << decrIndent << indent << token::END_BLOCK << endl;
}
os.writeKeyword("constraints") << constraintsDict;
os << decrIndent << indent << token::END_BLOCK << nl;
}
}
......
......@@ -136,8 +136,7 @@ Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::restrain
if (motion.report())
{
Info<< "Restraint " << this->name()
<< " angle " << theta
Info<< " angle " << theta
<< " force " << restraintForce
<< " moment " << restraintMoment
<< endl;
......@@ -199,4 +198,23 @@ bool Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::read
return true;
}
void Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::write
(
Ostream& os
) const
{
os.writeKeyword("referenceOrientation")
<< refQ_ << token::END_STATEMENT << nl;
os.writeKeyword("axis")
<< axis_ << token::END_STATEMENT << nl;
os.writeKeyword("stiffness")
<< stiffness_ << token::END_STATEMENT << nl;
os.writeKeyword("damping")
<< damping_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -114,6 +114,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMRCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -96,8 +96,7 @@ void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
if (motion.report())
{
Info<< "Restraint " << this->name()
<< " spring length " << magR
Info<< " spring length " << magR
<< " force " << restraintForce
<< " moment " << restraintMoment
<< endl;
......@@ -125,4 +124,26 @@ bool Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read
return true;
}
void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write
(
Ostream& os
) const
{
os.writeKeyword("anchor")
<< anchor_ << token::END_STATEMENT << nl;
os.writeKeyword("refAttachmentPt")
<< refAttachmentPt_ << token::END_STATEMENT << nl;
os.writeKeyword("stiffness")
<< stiffness_ << token::END_STATEMENT << nl;
os.writeKeyword("damping")
<< damping_ << token::END_STATEMENT << nl;
os.writeKeyword("restLength")
<< restLength_ << token::END_STATEMENT << nl;
}
// ************************************************************************* //
......@@ -117,6 +117,9 @@ public:
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMRCoeff);
//- Write
virtual void write(Ostream&) const;
};
......
/*---------------------------------------------------------------------------*\
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
......@@ -39,7 +39,6 @@ Foam::sixDoFRigidBodyMotionRestraint::sixDoFRigidBodyMotionRestraint
const dictionary& sDoFRBMRDict
)
:
name_(fileName(sDoFRBMRDict.name().name()).components(token::COLON).last()),
sDoFRBMRCoeffs_
(
sDoFRBMRDict.subDict
......@@ -64,9 +63,6 @@ bool Foam::sixDoFRigidBodyMotionRestraint::read
const dictionary& sDoFRBMRDict
)
{
name_ =
fileName(sDoFRBMRDict.name().name()).components(token::COLON).last();
sDoFRBMRCoeffs_ = sDoFRBMRDict.subDict(type() + "Coeffs");
return true;
......
......@@ -70,9 +70,6 @@ protected:
// Protected data
//- Name of the constraint in dictionary
word name_;
//- Restraint model specific coefficient dictionary
dictionary sDoFRBMRCoeffs_;
......@@ -134,21 +131,18 @@ public:
) const = 0;
//- Update properties from given dictionary
virtual bool read(const dictionary& sDoFRBMRDict) = 0;
virtual bool read(const dictionary& sDoFRBMRDict);
// Access
//- Return access to the name of the restraint
inline const word& name() const
{
return name_;
}
// Return access to sDoFRBMRCoeffs
inline const dictionary& coeffDict() const
{
return sDoFRBMRCoeffs_;
}
//- Write
virtual void write(Ostream&) const = 0;