From 88e3bcf2ddf7b55042d871edbc9e85d0c49e4bdc Mon Sep 17 00:00:00 2001 From: Paul Kieckhefen Date: Thu, 13 Sep 2018 15:55:17 +0200 Subject: [PATCH] use PtrLists for subModels. includes some cleanup for commandModel acessors. --- .../cfdemParticle/cfdemCloud/cfdemCloud.C | 92 ++++++++++--------- .../cfdemParticle/cfdemCloud/cfdemCloud.H | 12 +-- .../cfdemParticle/cfdemCloud/cfdemCloudI.H | 4 +- .../dataExchangeModel/twoWayMPI/twoWayMPI.C | 37 ++++---- .../twoWayMany2Many/twoWayMany2Many.C | 6 +- .../forceModel/forceModel/forceModel.C | 26 +++--- .../forceModel/forceModel/forceModel.H | 4 +- 7 files changed, 92 insertions(+), 89 deletions(-) diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C index 1be5d2b1..fff4ccb1 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloud.C @@ -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[momCoupleModels_.size()]; - for (int i=0;i[nrForceModels()]; - for (int i=0;i[liggghtsCommandModelList_.size()]; - for (int i=0;i[otherForceModels_.size()]; + forAll(otherForceModel_, modeli) for (int i=0;i("cgWarnOnly", true)); + Switch cgWarnOnly(couplingProperties_.lookupOrDefault("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* forceModel_; + PtrList forceModel_; autoPtr locateModel_; - autoPtr* momCoupleModel_; + PtrList momCoupleModel_; autoPtr dataExchangeModel_; @@ -202,9 +202,9 @@ protected: autoPtr meshMotionModel_; - autoPtr* liggghtsCommand_; + mutable PtrList liggghtsCommand_; - autoPtr* otherForceModel_; + PtrList 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* liggghtsCommand() const; + inline liggghtsCommandModel& liggghtsCommand(const label) const; inline const turbulenceModel& turbulence() const; diff --git a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H index 02b3a7dc..5c7b6e70 100644 --- a/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H +++ b/src/lagrangian/cfdemParticle/cfdemCloud/cfdemCloudI.H @@ -349,9 +349,9 @@ inline const wordList& cfdemCloud::liggghtsCommandModelList() const return liggghtsCommandModelList_; } -inline autoPtr* cfdemCloud::liggghtsCommand() const +inline liggghtsCommandModel& cfdemCloud::liggghtsCommand(const label modeli) const { - return liggghtsCommand_; + return liggghtsCommand_[modeli]; } inline const turbulenceModel& cfdemCloud::turbulence() const diff --git a/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMPI/twoWayMPI.C b/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMPI/twoWayMPI.C index 9411b6a1..9d142ed1 100644 --- a/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMPI/twoWayMPI.C +++ b/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMPI/twoWayMPI.C @@ -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 h = particleCloud_.liggghtsCommand()[i]().executionsWithinPeriod(TSstart(),TSend()); + DynamicList 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;jinput->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;jinput->one(command); } diff --git a/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMany2Many/twoWayMany2Many.C b/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMany2Many/twoWayMany2Many.C index 74d50569..bbdf952d 100644 --- a/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMany2Many/twoWayMany2Many.C +++ b/src/lagrangian/cfdemParticle/subModels/dataExchangeModel/twoWayMany2Many/twoWayMany2Many.C @@ -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; jinput->one(command); } diff --git a/src/lagrangian/cfdemParticle/subModels/forceModel/forceModel/forceModel.C b/src/lagrangian/cfdemParticle/subModels/forceModel/forceModel/forceModel.C index 4abb55af..3bca651c 100644 --- a/src/lagrangian/cfdemParticle/subModels/forceModel/forceModel/forceModel.C +++ b/src/lagrangian/cfdemParticle/subModels/forceModel/forceModel/forceModel.C @@ -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 forceModel::provideScalarField() @@ -180,17 +178,21 @@ void forceModel::setForceSubModels(dictionary& dict) forceSubModels_.setSize(1, "ImEx"); } - delete[] forceSubModel_; - forceSubModel_ = new autoPtr[nrForceSubModels()]; + forceSubModel_.clear(); + forceSubModel_.setSize(nrForceSubModels()); Info << "nrForceSubModels()=" << nrForceSubModels() << endl; - for (int i=0;i* forceSubModel_; + mutable PtrList 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(); }