# PhasicFlow: utilities/particlesPhasicFlow/particlesPhasicFlow.cpp Source File

particlesPhasicFlow.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "positionParticles.hpp"
#include "pointStructure.hpp"
#include "setFields.hpp"
#include "systemControl.hpp"
#include "commandLine.hpp"
#include "readControlDict.hpp"
using pFlow::output;
using pFlow::endl;
using pFlow::dictionary;
using pFlow::uniquePtr;
using pFlow::IOobject;
using pFlow::objectFile;
using pFlow::fileSystem;
using pFlow::pointStructure;
using pFlow::pointStructureFile__;
using pFlow::positionParticles;
using pFlow::commandLine;
using pFlow::setFieldList;
int main( int argc, char* argv[] )
{
commandLine cmds(
"createParticles",
"Read the dictionary createParticles and create particles"
" based on the two sub-dictionaries positionParticles and setFields.\n"
"First executes positionParticles and then setFields, except "
"otherwise selected in the command line.");
bool positionOnly = false;
cmds.add_flag(
"--positionParticles-only",
positionOnly,
"Exectue the positionParticles part only and store the created "
"pointStructure in the time folder.");
bool setOnly = false;
cmds.add_flag("--setFields-only",
setOnly,
"Exectue the setFields part only. Read the pointStructure from "
"time folder and setFields and save the result in the same time folder.");
bool isCoupling = false;
cmds.add_flag(
"-c,--coupling",
isCoupling,
"Is this a fluid-particle coupling simulation");
if(!cmds.parse(argc, argv)) return 0;
if(setOnly && positionOnly)
{
ERR<<
"Options --positionParticles-only and --setFields-only cannot be used simeltanuously. \n"<<endERR;
return 1;
}
// this should be palced in each main
#include "initialize_Control.hpp"
auto objCPDict = IOobject::make<dictionary>
(
objectFile
(
"particlesDict",
Control.settings().path(),
objectFile::READ_ALWAYS,
objectFile::WRITE_ALWAYS
),
"particlesDict",
true
);
auto& cpDict = objCPDict().getObject<dictionary>();
uniquePtr<IOobject> pStructObj{nullptr};
if(!setOnly)
{
// position particles based on the dict content
REPORT(0)<< "Positioning points . . . \n"<<endREPORT;
auto pointPosition = positionParticles::create(cpDict.subDict("positionParticles"));
fileSystem pStructPath = Control.time().path()+pointStructureFile__;
auto finalPos = pointPosition().getFinalPosition();
pStructObj = IOobject::make<pointStructure>
(
objectFile
(
pointStructureFile__,
Control.time().path(),
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
finalPos
);
auto& pSruct = pStructObj().getObject<pointStructure>();
REPORT(1)<< "Created pStruct with "<< pSruct.size() << " points and capacity "<<
pSruct.capacity()<<" . . ."<< endREPORT;
REPORT(1)<< "Writing pStruct to " << pStructObj().path() << endREPORT<<endl<<endl;
if( !pStructObj().write())
{
fatalErrorInFunction<<
"ERRor in writing to file. \n ";
return 1;
}
}else
{
pStructObj = IOobject::make<pointStructure>
(
objectFile
(
pointStructureFile__,
Control.time().path(),
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
)
);
}
if(!positionOnly)
{
auto& pStruct = pStructObj().getObject<pointStructure>();
auto& sfDict = cpDict.subDict("setFields");
setFieldList defValueList(sfDict.subDict("defaultValue"));
for(auto& sfEntry: defValueList)
{
if( !sfEntry.setPointFieldDefaultValueNewAll(Control.time(), pStruct, true))
{
ERR<< "\n error occured in setting default value fields.\n"<<endERR;
return 1;
}
}
output<<endl;
auto& selectorsDict = sfDict.subDict("selectors");
auto selNames = selectorsDict.dictionaryKeywords();
for(auto name: selNames)
{
REPORT(1)<< "Applying selector " << greenText(name) <<endREPORT;
if(
!applySelector(Control, pStruct, selectorsDict.subDict(name))
)
{
ERR<<"\n error occured in setting selector. \n"<<endERR;
return 1;
}
output<<endl;
}
}
Control.time().write(true);
REPORT(0)<< greenText("\nFinished successfully.\n")<<endREPORT;
// this should be palced in each main
#include "finalize.hpp"
return 0;
}
initialize_Control.hpp
pFlow::pointStructureFile__
const char * pointStructureFile__
Definition: vocabs.hpp:42
endREPORT
#define endREPORT
Definition: streams.hpp:41
REPORT
#define REPORT(n)
Definition: streams.hpp:40
ERR
#define ERR
Definition: streams.hpp:47
systemControl.hpp
pFlow::commandLine
Definition: commandLine.hpp:36
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::output
Ostream output
endERR
#define endERR
Definition: streams.hpp:48
pFlow::objectFile
Definition: objectFile.hpp:33
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::positionParticles
Definition: positionParticles.hpp:102
main
int main(int argc, char *argv[])
Definition: particlesPhasicFlow.cpp:42
pFlow::applySelector
bool applySelector(systemControl &control, const pointStructure &pStruct, const dictionary &selDict)
Definition: setFields.hpp:34
readControlDict.hpp
setFields.hpp
positionParticles.hpp
commandLine.hpp
pointStructure.hpp
pFlow::dictionary
Definition: dictionary.hpp:38
Control
auto & Control
Definition: initialize_Control.hpp:47
finalize.hpp