# PhasicFlow: utilities/particlesPhasicFlow/particlesPhasicFlow.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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 "vocabs.hpp"
#include "commandLine.hpp"
#include "positionParticles.hpp"
#include "pointStructure.hpp"
#include "setFields.hpp"
#include "systemControl.hpp"
#include "baseShapeNames.hpp"
//#include "readControlDict.hpp"
int main( int argc, char* argv[] )
{
pFlow::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"<<END_ERR;
return 1;
}
// this should be palced in each main
#include "initialize_Control.hpp"
pFlow::fileDictionary cpDict("particlesDict", Control.settings().path());
pFlow::uniquePtr<pFlow::pointStructure> pStructPtr = nullptr;
if(!setOnly)
{
// position particles based on the dict content
REPORT(0)<< "Positioning points . . . \n"<<END_REPORT;
auto pointPosition = pFlow::positionParticles::create(Control, cpDict.subDict("positionParticles"));
pFlow::fileSystem pStructPath = Control.time().path()+pFlow::pointStructureFile__;
auto finalPos = pointPosition().getFinalPosition();
pStructPtr = pFlow::makeUnique<pFlow::pointStructure>(Control, finalPos);
REPORT(1)<< "Created pStruct with "<< pStructPtr().size() << " points and capacity "<<
pStructPtr().capacity()<<" . . ."<< END_REPORT;
}
else
{
// read the content of pStruct from 0/pStructure
pStructPtr = pFlow::makeUnique<pFlow::pointStructure>(Control);
}
pFlow::List<pFlow::uniquePtr<pFlow::IOobject>> allObjects;
if(!positionOnly)
{
auto& pStruct = pStructPtr();
auto& sfDict = cpDict.subDict("setFields");
pFlow::setFieldList defValueList(sfDict.subDict("defaultValue"));
for(auto& sfEntry: defValueList)
{
if( auto Ptr = sfEntry.setPointFieldDefaultValueNewAll( pStruct, true); Ptr)
{
allObjects.push_back(std::move(Ptr));
}
else
{
ERR<< "\n error occured in setting default value fields.\n"<<END_ERR;
return 1;
}
}
pFlow::output<<pFlow::endl;
auto& selectorsDict = sfDict.subDict("selectors");
auto selNames = selectorsDict.dictionaryKeywords();
for(auto name: selNames)
{
REPORT(1)<< "Applying selector " << Green_Text(name) <<END_REPORT;
if(
!applySelector(Control, pStruct, selectorsDict.subDict(name))
)
{
ERR<<"\n error occured in setting selector. \n"<<END_ERR;
return 1;
}
pFlow::output<<pFlow::endl;
}
}
Control.clearIncludeExclude();
Control.addExclude("shapeName");
pFlow::uint64PointField_H shapeHash
(
pFlow::objectFile
(
"shapeHash",
"",
pFlow::objectFile::READ_NEVER,
pFlow::objectFile::WRITE_ALWAYS
),
pStructPtr(),
0u
);
pFlow::uint32PointField_H shapeIndex
(
pFlow::objectFile
(
"shapeIndex",
"",
pFlow::objectFile::READ_NEVER,
pFlow::objectFile::WRITE_ALWAYS
),
pStructPtr(),
0u
);
pFlow::baseShapeNames shapes(
pFlow::shapeFile__,
&Control.caseSetup()
);
auto& shapeName = Control.time().template lookupObject<pFlow::wordPointField_H>("shapeName");
REPORT(0)<< "Converting shapeName field to shapeIndex field"<<END_REPORT;
auto shapeName_D = shapeName.deviceView();
auto shapeHash_D = shapeHash.deviceView();
auto shapeIndex_D = shapeIndex.deviceView();
REPORT(1)<<"List of shape names in "<<shapes.globalName()<<
" is: "<<Green_Text(shapes.shapeNameList())<<END_REPORT;
ForAll(i, shapeHash)
{
if(pFlow::uint32 index; shapes.shapeNameToIndex(shapeName_D[i], index))
{
shapeHash_D[i] = shapes.hashes()[index];
shapeIndex_D[i] = index;
}
else
{
fatalErrorInFunction<<"Found shape name "<< Yellow_Text(shapeName_D[i])<<
"in shapeName field. But the list of shape names in file "<<
shapes.globalName()<<" is : \n"<<
shapes.shapeNames()<<pFlow::endl;
}
}
if( !Control.time().write(true))
{
fatalErrorInFunction<<
"ERRor in writing to file. \n ";
return 1;
}
REPORT(0)<< Green_Text("\nFinished successfully.\n")<<END_REPORT;
// this should be palced in each main
#include "finalize.hpp"
return 0;
}
initialize_Control.hpp
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::List
Definition: List.hpp:39
pFlow::baseShapeNames::hashes
const auto & hashes() const
Definition: baseShapeNames.hpp:87
END_ERR
#define END_ERR
Definition: streams.hpp:47
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::baseShapeNames::shapeNames
const wordVector & shapeNames() const
Definition: baseShapeNames.hpp:73
ERR
#define ERR
Definition: streams.hpp:46
systemControl.hpp
pFlow::baseShapeNames
Definition: baseShapeNames.hpp:33
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::baseShapeNames::shapeNameList
wordList shapeNameList() const
Definition: baseShapeNames.hpp:79
baseShapeNames.hpp
pFlow::commandLine
Definition: commandLine.hpp:36
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructureFile__
const char *const pointStructureFile__
Definition: vocabs.hpp:42
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::output
Ostream output
pFlow::baseShapeNames::shapeNameToIndex
bool shapeNameToIndex(const word &name, uint32 &index) const
Definition: baseShapeNames.hpp:100
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::shapeFile__
const char *const shapeFile__
Definition: vocabs.hpp:41
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::positionParticles::create
static uniquePtr< positionParticles > create(systemControl &control, const dictionary &dict)
Definition: positionParticles.cpp:128
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:37
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
main
int main(int argc, char *argv[])
Definition: particlesPhasicFlow.cpp:32
pFlow::applySelector
bool applySelector(systemControl &control, const pointStructure &pStruct, const dictionary &selDict)
Definition: setFields.hpp:34
vocabs.hpp
setFields.hpp
positionParticles.hpp
commandLine.hpp
pointStructure.hpp
Control
auto & Control
Definition: initialize_Control.hpp:47
pFlow::internalField::deviceView
auto deviceView() const
Definition: internalField.hpp:97
finalize.hpp