use PtrLists for subModels. includes some cleanup for commandModel acessors.

This commit is contained in:
Paul Kieckhefen
2018-09-13 15:55:17 +02:00
parent 9dcd9351c5
commit 88e3bcf2dd
7 changed files with 92 additions and 89 deletions

View File

@ -154,6 +154,7 @@ cfdemCloud::cfdemCloud
turbulenceModelType_
)
),
forceModel_(nrForceModels()),
locateModel_
(
locateModel::New
@ -162,14 +163,7 @@ cfdemCloud::cfdemCloud
*this
)
),
/*momCoupleModel_
(
momCoupleModel::New
(
couplingProperties_,
*this
)
),*/
momCoupleModel_(nrMomCoupleModels()),
dataExchangeModel_
(
dataExchangeModel::New
@ -235,7 +229,9 @@ cfdemCloud::cfdemCloud
couplingProperties_,
*this
)
)
),
liggghtsCommand_(liggghtsCommandModelList_.size()),
otherForceModel_(otherForceModels_.size())
{
#include "versionInfo.H"
global buildInfo(couplingProperties_,*this);
@ -276,57 +272,70 @@ cfdemCloud::cfdemCloud
FatalError << "CFDEMcoupling does not support adjustable time steps."
<< abort(FatalError);
momCoupleModel_ = new autoPtr<momCoupleModel>[momCoupleModels_.size()];
for (int i=0;i<momCoupleModels_.size();i++)
forAll(momCoupleModel_, modeli)
{
momCoupleModel_[i] = momCoupleModel::New
momCoupleModel_.set
(
couplingProperties_,
*this,
momCoupleModels_[i]
modeli,
momCoupleModel::New
(
couplingProperties_,
*this,
momCoupleModels_[modeli]
)
);
}
forceModel_ = new autoPtr<forceModel>[nrForceModels()];
for (int i=0;i<nrForceModels();i++)
forAll(forceModels_, modeli)
{
forceModel_[i] = forceModel::New
forceModel_.set
(
couplingProperties_,
*this,
forceModels_[i]
modeli,
forceModel::New
(
couplingProperties_,
*this,
forceModels_[modeli]
)
);
}
// run liggghts commands from cfdem
liggghtsCommand_ = new autoPtr<liggghtsCommandModel>[liggghtsCommandModelList_.size()];
for (int i=0;i<liggghtsCommandModelList_.size();i++)
forAll(liggghtsCommand_, modeli)
{
liggghtsCommand_[i] = liggghtsCommandModel::New
liggghtsCommand_.set
(
liggghtsCommandDict_,
*this,
liggghtsCommandModelList_[i],
i
modeli,
liggghtsCommandModel::New
(
liggghtsCommandDict_,
*this,
liggghtsCommandModelList_[modeli],
modeli
)
);
}
otherForceModel_ = new autoPtr<otherForceModel>[otherForceModels_.size()];
forAll(otherForceModel_, modeli)
for (int i=0;i<otherForceModels_.size();i++)
{
otherForceModel_[i] = otherForceModel::New
otherForceModel_.set
(
couplingProperties_,
*this,
otherForceModels_[i]
modeli,
otherForceModel::New
(
couplingProperties_,
*this,
otherForceModels_[modeli]
)
);
}
dataExchangeM().setCG();
Switch cgWarnOnly_(couplingProperties_.lookupOrDefault<Switch>("cgWarnOnly", true));
Switch cgWarnOnly(couplingProperties_.lookupOrDefault<Switch>("cgWarnOnly", true));
if (!cgOK_ && cg_ > 1)
{
if (cgWarnOnly_)
if (cgWarnOnly)
Warning << "at least one of your models is not fit for cg !!!" << endl;
else
FatalError << "at least one of your models is not fit for cg !!!" << abort(FatalError);
@ -575,16 +584,9 @@ scalar cfdemCloud::voidfraction(int index) const
return voidfractions()[index][0];
}
label cfdemCloud::liggghtsCommandModelIndex(word name) const
label cfdemCloud::liggghtsCommandModelIndex(const word& name) const
{
forAll(liggghtsCommandModelList_,i)
{
if(liggghtsCommand()[i]().name() == name)
{
return i;
}
}
return -1;
return findIndex(liggghtsCommandModelList_, name);
}
// * * * * * * * * * * * * * * * WRITE * * * * * * * * * * * * * //
@ -841,7 +843,7 @@ void cfdemCloud::otherForces(volVectorField& forcefield)
forcefield.primitiveFieldRef() = vector::zero;
forcefield.boundaryFieldRef() = vector::zero;
for (int i=0;i<otherForceModels_.size();i++)
forcefield += otherForceModel_[i]().exportForceField();
forcefield += otherForceModel_[i].exportForceField();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -180,11 +180,11 @@ protected:
const turbulenceModel& turbulence_;
autoPtr<forceModel>* forceModel_;
PtrList<forceModel> forceModel_;
autoPtr<locateModel> locateModel_;
autoPtr<momCoupleModel>* momCoupleModel_;
PtrList<momCoupleModel> momCoupleModel_;
autoPtr<dataExchangeModel> dataExchangeModel_;
@ -202,9 +202,9 @@ protected:
autoPtr<meshMotionModel> meshMotionModel_;
autoPtr<liggghtsCommandModel>* liggghtsCommand_;
mutable PtrList<liggghtsCommandModel> liggghtsCommand_;
autoPtr<otherForceModel>* otherForceModel_;
PtrList<otherForceModel> otherForceModel_;
// Protected member functions
virtual void getDEMdata();
@ -272,7 +272,7 @@ public:
scalar voidfraction(int) const;
label liggghtsCommandModelIndex(word) const;
label liggghtsCommandModelIndex(const word&) const;
inline void setCG(double);
@ -395,7 +395,7 @@ public:
inline const wordList& liggghtsCommandModelList() const;
inline autoPtr<liggghtsCommandModel>* liggghtsCommand() const;
inline liggghtsCommandModel& liggghtsCommand(const label) const;
inline const turbulenceModel& turbulence() const;

View File

@ -349,9 +349,9 @@ inline const wordList& cfdemCloud::liggghtsCommandModelList() const
return liggghtsCommandModelList_;
}
inline autoPtr<liggghtsCommandModel>* cfdemCloud::liggghtsCommand() const
inline liggghtsCommandModel& cfdemCloud::liggghtsCommand(const label modeli) const
{
return liggghtsCommand_;
return liggghtsCommand_[modeli];
}
inline const turbulenceModel& cfdemCloud::turbulence() const

View File

@ -229,10 +229,11 @@ bool twoWayMPI::couple(int i) const
// Check if exact timing is needed
// get time for execution
// store time for execution in list
if(particleCloud_.liggghtsCommand()[i]().exactTiming())
liggghtsCommandModel& lcm = particleCloud_.liggghtsCommand(i);
if(lcm.exactTiming())
{
exactTiming = true;
DynamicList<scalar> h = particleCloud_.liggghtsCommand()[i]().executionsWithinPeriod(TSstart(),TSend());
DynamicList<scalar> h = lcm.executionsWithinPeriod(TSstart(),TSend());
forAll(h,j)
{
@ -261,7 +262,7 @@ bool twoWayMPI::couple(int i) const
Info << "Foam::twoWayMPI::couple(i): lcModel=" << lcModel << endl;
}
if(particleCloud_.liggghtsCommand()[i]().type()=="runLiggghts")
if(lcm.type()=="runLiggghts")
runComNr=i;
}
@ -278,22 +279,22 @@ bool twoWayMPI::couple(int i) const
{
// set run command till interrupt
DEMstepsRun += DEMstepsToInterrupt[j];
particleCloud_.liggghtsCommand()[runComNr]().set(DEMstepsToInterrupt[j]);
const char* command = particleCloud_.liggghtsCommand()[runComNr]().command(0);
particleCloud_.liggghtsCommand(runComNr).set(DEMstepsToInterrupt[j]);
const char* command = particleCloud_.liggghtsCommand(runComNr).command(0);
Info << "Executing run command: '"<< command <<"'"<< endl;
lmp->input->one(command);
// run liggghts command with exact timing
command = particleCloud_.liggghtsCommand()[lcModel[j]]().command(0);
command = particleCloud_.liggghtsCommand(lcModel[j]).command(0);
Info << "Executing command: '"<< command <<"'"<< endl;
lmp->input->one(command);
}
// do the run
if(particleCloud_.liggghtsCommand()[runComNr]().runCommand(couplingStep()))
if(particleCloud_.liggghtsCommand(runComNr).runCommand(couplingStep()))
{
particleCloud_.liggghtsCommand()[runComNr]().set(couplingInterval() - DEMstepsRun);
const char* command = particleCloud_.liggghtsCommand()[runComNr]().command(0);
particleCloud_.liggghtsCommand(runComNr).set(couplingInterval() - DEMstepsRun);
const char* command = particleCloud_.liggghtsCommand(runComNr).command(0);
Info << "Executing run command: '"<< command <<"'"<< endl;
lmp->input->one(command);
}
@ -301,16 +302,13 @@ bool twoWayMPI::couple(int i) const
// do the other non exact timing models
forAll(particleCloud_.liggghtsCommandModelList(),i)
{
if
(
! particleCloud_.liggghtsCommand()[i]().exactTiming() &&
particleCloud_.liggghtsCommand()[i]().runCommand(couplingStep())
)
liggghtsCommandModel& lcm = particleCloud_.liggghtsCommand(i);
if (! lcm.exactTiming() && lcm.runCommand(couplingStep()) )
{
commandLines=particleCloud_.liggghtsCommand()[i]().commandLines();
commandLines = lcm.commandLines();
for(int j=0;j<commandLines;j++)
{
const char* command = particleCloud_.liggghtsCommand()[i]().command(j);
const char* command = lcm.command(j);
Info << "Executing command: '"<< command <<"'"<< endl;
lmp->input->one(command);
}
@ -322,12 +320,13 @@ bool twoWayMPI::couple(int i) const
{
forAll(particleCloud_.liggghtsCommandModelList(),i)
{
if(particleCloud_.liggghtsCommand()[i]().runCommand(couplingStep()))
liggghtsCommandModel& lcm = particleCloud_.liggghtsCommand(i);
if (lcm.runCommand(couplingStep()))
{
commandLines=particleCloud_.liggghtsCommand()[i]().commandLines();
commandLines = lcm.commandLines();
for(int j=0;j<commandLines;j++)
{
const char* command = particleCloud_.liggghtsCommand()[i]().command(j);
const char* command = lcm.command(j);
Info << "Executing command: '"<< command <<"'"<< endl;
lmp->input->one(command);
}

View File

@ -401,12 +401,12 @@ bool twoWayMany2Many::couple(int i) const
forAll(particleCloud_.liggghtsCommandModelList(),i)
{
if (particleCloud_.liggghtsCommand()[i]().runCommand(couplingStep()))
if (particleCloud_.liggghtsCommand(i).runCommand(couplingStep()))
{
label commandLines = particleCloud_.liggghtsCommand()[i]().commandLines();
label commandLines = particleCloud_.liggghtsCommand(i).commandLines();
for (int j=0; j<commandLines; j++)
{
const char* command = particleCloud_.liggghtsCommand()[i]().command(j);
const char* command = particleCloud_.liggghtsCommand(i).command(j);
Info << "Executing command: '" << command << "'" << endl;
lmp->input->one(command);
}

View File

@ -88,16 +88,14 @@ forceModel::forceModel
probeIt_(sm.probeM().active()),
requiresEx_(false),
forceSubModels_(0),
forceSubModel_(NULL)
forceSubModel_(0)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
forceModel::~forceModel()
{
delete [] forceSubModel_;
}
{}
// * * * * * * * * * * * * * * * * Member Fct * * * * * * * * * * * * * * * //
/*tmp<volScalarField> forceModel::provideScalarField()
@ -180,17 +178,21 @@ void forceModel::setForceSubModels(dictionary& dict)
forceSubModels_.setSize(1, "ImEx");
}
delete[] forceSubModel_;
forceSubModel_ = new autoPtr<forceSubModel>[nrForceSubModels()];
forceSubModel_.clear();
forceSubModel_.setSize(nrForceSubModels());
Info << "nrForceSubModels()=" << nrForceSubModels() << endl;
for (int i=0;i<nrForceSubModels();i++)
forAll(forceSubModels_, modeli)
{
forceSubModel_[i] = forceSubModel::New
forceSubModel_.set
(
dict,
particleCloud_,
*this,
forceSubModels_[i]
modeli,
forceSubModel::New
(
dict,
particleCloud_,
*this,
forceSubModels_[modeli]
)
);
}
}

View File

@ -76,7 +76,7 @@ protected:
wordList forceSubModels_;
autoPtr<forceSubModel>* forceSubModel_;
mutable PtrList<forceSubModel> forceSubModel_;
public:
@ -157,7 +157,7 @@ public:
inline const wordList& forceSubModels() { return forceSubModels_; }
inline forceSubModel& forceSubM(int i) const { return forceSubModel_[i](); }
inline forceSubModel& forceSubM(int i) const { return forceSubModel_[i]; }
inline int nrForceSubModels() const { return forceSubModels_.size(); }