From be8c67a242a8697417bd6c7253207429c8b668df Mon Sep 17 00:00:00 2001 From: graham Date: Tue, 11 May 2010 12:09:58 +0100 Subject: [PATCH 1/2] ENH: sixDoFRigidBodyDisplacement rho field handling. Removing rhoInf from uncoupledSixDoF... patch, not needed. Adding optional rhoName entry to sixDoF... so no rhoInf entry is needed for simulations that have a rho field, and require than a rhoInf value is read for those that don't. --- ...gidBodyDisplacementPointPatchVectorField.C | 20 +++++++++++++++---- ...gidBodyDisplacementPointPatchVectorField.H | 7 ++++++- ...gidBodyDisplacementPointPatchVectorField.C | 14 ++++--------- ...gidBodyDisplacementPointPatchVectorField.H | 5 ----- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C index 554e482c21..ed771efa6f 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C @@ -49,7 +49,8 @@ sixDoFRigidBodyDisplacementPointPatchVectorField fixedValuePointPatchField(p, iF), motion_(), initialPoints_(p.localPoints()), - rhoInf_(1.0) + rhoInf_(1.0), + rhoName_("rho") {} @@ -63,8 +64,14 @@ sixDoFRigidBodyDisplacementPointPatchVectorField : fixedValuePointPatchField(p, iF, dict), motion_(dict), - rhoInf_(readScalar(dict.lookup("rhoInf"))) + rhoInf_(1.0), + rhoName_(dict.lookupOrDefault("rhoName", "rho")) { + if (rhoName_ == "rhoInf") + { + rhoInf_ = readScalar(dict.lookup("rhoInf")); + } + if (!dict.found("value")) { updateCoeffs(); @@ -93,7 +100,8 @@ sixDoFRigidBodyDisplacementPointPatchVectorField fixedValuePointPatchField(ptf, p, iF, mapper), motion_(ptf.motion_), initialPoints_(ptf.initialPoints_, mapper), - rhoInf_(ptf.rhoInf_) + rhoInf_(ptf.rhoInf_), + rhoName_(ptf.rhoName_) {} @@ -107,7 +115,8 @@ sixDoFRigidBodyDisplacementPointPatchVectorField fixedValuePointPatchField(ptf, iF), motion_(ptf.motion_), initialPoints_(ptf.initialPoints_), - rhoInf_(ptf.rhoInf_) + rhoInf_(ptf.rhoInf_), + rhoName_(ptf.rhoName_) {} @@ -160,6 +169,7 @@ void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs() forcesDict.add("patches", wordList(1, ptPatch.name())); forcesDict.add("rhoInf", rhoInf_); + forcesDict.add("rhoName", rhoName_); forcesDict.add("CofR", motion_.centreOfMass()); forces f("forces", db(), forcesDict); @@ -200,6 +210,8 @@ void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const motion_.write(os); os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl; + os.writeKeyword("rhoName") + << rhoName_ << token::END_STATEMENT << nl; initialPoints_.writeEntry("initialPoints", os); writeEntry("value", os); } diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H index fa30a7eff2..9c512ab9d3 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H @@ -60,9 +60,14 @@ class sixDoFRigidBodyDisplacementPointPatchVectorField pointField initialPoints_; //- Reference density required by the forces object for - // incompressible calculations + // incompressible calculations, required if rhoName == rhoInf scalar rhoInf_; + //- Name of density field, optional unless used for an + // incompressible simulation, when this needs to be specified + // as rhoInf + word rhoName_; + public: diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.C b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.C index f63607c99c..7b7537eec3 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.C +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.C @@ -47,8 +47,7 @@ uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField : fixedValuePointPatchField(p, iF), motion_(), - initialPoints_(p.localPoints()), - rhoInf_(1.0) + initialPoints_(p.localPoints()) {} @@ -61,8 +60,7 @@ uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField ) : fixedValuePointPatchField(p, iF, dict), - motion_(dict), - rhoInf_(readScalar(dict.lookup("rhoInf"))) + motion_(dict) { if (!dict.found("value")) { @@ -91,8 +89,7 @@ uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField : fixedValuePointPatchField(ptf, p, iF, mapper), motion_(ptf.motion_), - initialPoints_(ptf.initialPoints_, mapper), - rhoInf_(ptf.rhoInf_) + initialPoints_(ptf.initialPoints_, mapper) {} @@ -105,8 +102,7 @@ uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField : fixedValuePointPatchField(ptf, iF), motion_(ptf.motion_), - initialPoints_(ptf.initialPoints_), - rhoInf_(ptf.rhoInf_) + initialPoints_(ptf.initialPoints_) {} @@ -182,8 +178,6 @@ void uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField::write { pointPatchField::write(os); motion_.write(os); - os.writeKeyword("rhoInf") - << rhoInf_ << token::END_STATEMENT << nl; initialPoints_.writeEntry("initialPoints", os); writeEntry("value", os); } diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.H b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.H index 631c732a93..d5a17c09c7 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.H +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/uncoupledSixDoFRigidBodyDisplacement/uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField.H @@ -59,11 +59,6 @@ class uncoupledSixDoFRigidBodyDisplacementPointPatchVectorField //- Initial positions of points on the patch pointField initialPoints_; - //- Reference density required by the forces object for - // incompressible calculations. Retained here to give - // dictionary compatibility with other sixDoF patches. - scalar rhoInf_; - public: From a0aa574dd221cb3770230e2662090c8a3bb30fe9 Mon Sep 17 00:00:00 2001 From: graham Date: Tue, 11 May 2010 16:28:05 +0100 Subject: [PATCH 2/2] ENH: sixDoFRigidBodyDisplacement. Adding g lookup from BC dict when not available from db. --- ...gidBodyDisplacementPointPatchVectorField.C | 74 +++++++++++++++---- ...gidBodyDisplacementPointPatchVectorField.H | 16 ++++ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C index ed771efa6f..8b248991d5 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.C @@ -50,7 +50,9 @@ sixDoFRigidBodyDisplacementPointPatchVectorField motion_(), initialPoints_(p.localPoints()), rhoInf_(1.0), - rhoName_("rho") + rhoName_("rho"), + lookupGravity_(-1), + g_(vector::zero) {} @@ -65,13 +67,22 @@ sixDoFRigidBodyDisplacementPointPatchVectorField fixedValuePointPatchField(p, iF, dict), motion_(dict), rhoInf_(1.0), - rhoName_(dict.lookupOrDefault("rhoName", "rho")) + rhoName_(dict.lookupOrDefault("rhoName", "rho")), + lookupGravity_(-1), + g_(vector::zero) { if (rhoName_ == "rhoInf") { rhoInf_ = readScalar(dict.lookup("rhoInf")); } + if (dict.found("g")) + { + lookupGravity_ = -2; + + g_ = dict.lookup("g"); + } + if (!dict.found("value")) { updateCoeffs(); @@ -101,7 +112,9 @@ sixDoFRigidBodyDisplacementPointPatchVectorField motion_(ptf.motion_), initialPoints_(ptf.initialPoints_, mapper), rhoInf_(ptf.rhoInf_), - rhoName_(ptf.rhoName_) + rhoName_(ptf.rhoName_), + lookupGravity_(ptf.lookupGravity_), + g_(ptf.g_) {} @@ -116,7 +129,9 @@ sixDoFRigidBodyDisplacementPointPatchVectorField motion_(ptf.motion_), initialPoints_(ptf.initialPoints_), rhoInf_(ptf.rhoInf_), - rhoName_(ptf.rhoName_) + rhoName_(ptf.rhoName_), + lookupGravity_(ptf.lookupGravity_), + g_(ptf.g_) {} @@ -155,6 +170,33 @@ void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs() return; } + if (lookupGravity_ < 0) + { + if (db().foundObject("g")) + { + if (lookupGravity_ == -2) + { + FatalErrorIn + ( + "void sixDoFRigidBodyDisplacementPointPatchVectorField" + "::updateCoeffs()" + ) + << "Specifying the value of g in this boundary condition " + << "when g is available from the database is considered " + << "a fatal error to avoid the possibility of inconsistency" + << exit(FatalError); + } + else + { + lookupGravity_ = 1; + } + } + else + { + lookupGravity_ = 0; + } + } + const polyMesh& mesh = this->dimensionedInternalField().mesh()(); const Time& t = mesh.time(); const pointPatch& ptPatch = this->patch(); @@ -178,19 +220,17 @@ void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs() // Get the forces on the patch faces at the current positions - vector gravity = vector::zero; - - if (db().foundObject("g")) + if (lookupGravity_ == 1) { uniformDimensionedVectorField g = db().lookupObject("g"); - gravity = g.value(); + g_ = g.value(); } motion_.updateForce ( - fm.first().first() + fm.first().second() + gravity*motion_.mass(), + fm.first().first() + fm.first().second() + g_*motion_.mass(), fm.second().first() + fm.second().second(), t.deltaTValue() ); @@ -207,12 +247,20 @@ void sixDoFRigidBodyDisplacementPointPatchVectorField::updateCoeffs() void sixDoFRigidBodyDisplacementPointPatchVectorField::write(Ostream& os) const { pointPatchField::write(os); + + os.writeKeyword("rhoInf") << rhoInf_ << token::END_STATEMENT << nl; + + os.writeKeyword("rhoName") << rhoName_ << token::END_STATEMENT << nl; + + if (lookupGravity_ == 0 || lookupGravity_ == -2) + { + os.writeKeyword("g") << g_ << token::END_STATEMENT << nl; + } + motion_.write(os); - os.writeKeyword("rhoInf") - << rhoInf_ << token::END_STATEMENT << nl; - os.writeKeyword("rhoName") - << rhoName_ << token::END_STATEMENT << nl; + initialPoints_.writeEntry("initialPoints", os); + writeEntry("value", os); } diff --git a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H index 9c512ab9d3..ca1a3715e4 100644 --- a/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H +++ b/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyDisplacement/sixDoFRigidBodyDisplacementPointPatchVectorField.H @@ -68,6 +68,22 @@ class sixDoFRigidBodyDisplacementPointPatchVectorField // as rhoInf word rhoName_; + //- State of gravity lookup: + // -1 = not determined yet, as the BC may be instantiated before g has + // been read into the db yet. Determination deferred until first + // call to updateCoeffs. A g keyword was not supplied to the + // dictionary. + // -2 = as for -1, but a gravity value was specified in the dictionary, + // specifying a value in the dictionary is considered a fatal + // error if g is available from the db. + // 0 = Use this boundary condition's own value of gravity, as not + // available from the db. + // 1 = Lookup gravity from db. + label lookupGravity_; + + //- Gravity vector to store when not available from the db + vector g_; + public: