CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   A question related to defining a variable (http://www.cfd-online.com/Forums/openfoam/79123-question-related-defining-variable.html)

daveatstyacht August 13, 2010 07:25

A question related to defining a variable
 
Hi all,
I am attempting to modify the forces.C file to include a point "CofE" (similar to the built in CofR in purpose). My question is what files besides forces.C and forces.H must be modified to make OF read a user inputed value of CofE in the controlDict file such as given below:

functions
(
forces
{
type forces;
functionObjectLibs ("libforces.so"); //Lib to load -> dylib on Mac and so on Linux
log true;
outputControl timeStep;
outputInterval 1;
patches (hull hull_hull); //Name of patche to integrate forces
rhoInf 1025.0; //Reference density for fluid - can be changed later ...
CofR (-7.069 0 -0.67); //Origin for moment calculations
CofE (-7.069 0 7); //location of center of effort of sail
}

I ask all of this because I copied verbatim the format of CofR in both files yet the error "CofE was not declared in this scope" shows up when I go to compile it. Any suggestions would be greatly appreciated.

-Dave

kathrin_kissling August 16, 2010 07:37

Hi Dave,

I'm not very into the forces calculation, but your problem seems to be quite basic c++.

Could you post your constructor part of the .C file and the declaration part of the private data from the .H file. This might clear the clouds. Without source code it will get very had to clarfy this.

Best

Kathrin

daveatstyacht August 17, 2010 04:33

Below is the relevant sections of forces.C and forces.H (I only am posting the sections that make any mention of CofR_ because the rest of files are unchanged). I think that this should work (I made some changes, particularly to the conditional statement), but I have yet to run it (it does spit out some compiler errors which I am looking into, but I am hoping to test it with a known test case later today). Any insights would certainly be appreciated. -Dave

//From forces.H:

protected:

// Private data
// Read from dictionary
//- Centre of rotation
vector CofR_;
//- Centre of Effort
vector CofE_;

//From forces.C:
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::forces::forces
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
log_(false),
patchSet_(),
pName_(word::null),
UName_(word::null),
rhoName_(word::null),
directForceDensity_(false),
fDName_(""),
rhoRef_(VGREAT),
pRef_(0),
CofR_(vector::zero),
CofE_(vector::zero),
forcesFilePtr_(NULL)

// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

void Foam::forces::read(const dictionary& dict)
{
// Centre of rotation for moment calculations
CofR_ = dict.lookup("CofR");
// Centre of effort for moment calculations
CofE_ = dict.lookup("CofE");
}

Foam::forces::forcesMoments Foam::forces::calcForcesMoment() const
{
//Original forces.C version in line below:
//vectorField Md = mesh.C().boundaryField()[patchi] - CofR_;

//revised version that has a conditional to use CofE_ or CofR_ depending on if CofE_ //is zero or not
vectorField Md = (CofE_ == zero) ? mesh.C().boundaryField()[patchi] - CofR_
: vectorField Md = 1.5*mesh.C().boundaryField()[patchi] - 0.5*CofE_;

vectorField pf = Sfb[patchi]*(p.boundaryField()[patchi] - pRef);
fm.first().first() += rho(p)*sum(pf);
fm.second().first() += rho(p)*sum(Md ^ pf);
//fm.third().first() += rho(p)*sum(Md ^ pf);

vectorField vf = Sfb[patchi] & devRhoReffb[patchi];

fm.first().second() += sum(vf);
fm.second().second() += sum(Md ^ vf);
//fm.third().second() += sum(Md ^ vf);
}

daveatstyacht August 17, 2010 20:53

Solution found
 
I figured out the problem, the line below is correctly written to work:

vectorField Md = (CofE_ == vector::zero) ? mesh.C().boundaryField()[patchi] - CofR_
: 1.5*mesh.C().boundaryField()[patchi] - 0.5*CofE_;

both the 1st part of the statement (CofE_ == vector::zero) and the last part of the statement were incorrect. Unfortunately for me I discovered that the basic formula is incorrect for what I need so I am back to square one.


All times are GMT -4. The time now is 20:10.