# PhasicFlow: src/phasicFlow/setFieldList/setFieldEntryTemplates.cpp Source File

setFieldEntryTemplates.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.
-----------------------------------------------------------------------------*/
template <typename Type>
bool pFlow::setFieldEntry::checkForType()const
{
word typeName( entry_.firstPart() );
return basicTypeName<Type>() == typeName;
};
template <typename Type>
bool pFlow::setFieldEntry::checkForTypeAndValue()const
{
if( !checkForType<Type>() ) return false;
Type defValue = entry_.secondPartVal<Type>();
CONSUME_PARAM(defValue);
return true;
}
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldDefaultValueNew
(
repository& owner,
pointStructure& pStruct,
bool verbose
)
{
if( !checkForType<Type>() ) return nullptr;
Type defValue = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<<
" in repository "<< owner.name() <<endREPORT;
auto& field =
owner.emplaceObject<pointField<VectorSingle,Type>>
(
objectFile
(
fieldName(),
"",
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
pStruct,
defValue
);
return &field;
}
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldDefaultValueStdNew
(
repository& owner,
pointStructure& pStruct,
bool verbose
)
{
if( !checkForType<Type>() ) return nullptr;
Type defValue = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<<
" in repository "<< owner.name() <<endREPORT;
// by default we perform operations on host
auto& field =
owner.emplaceObject<pointField<Vector,Type, vecAllocator<Type>>>
(
objectFile
(
fieldName(),
"",
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
pStruct,
defValue
);
return &field;
}
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldSelected
(
repository& owner,
int32IndexContainer& selected,
bool verbose
)
{
if( !checkForType<Type>() ) return nullptr;
auto fName = fieldName();
if( !owner.lookupObjectName(fName) )
{
fatalErrorInFunction<<
"Cannot find "<< fName << " in repository " << owner.name() << ". \n";
return nullptr;
}
Type value = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<< "Setting selected points of " << greenText(fName)
<< " to value " << cyanText(value) <<endREPORT;
auto fieldTypeName = owner.lookupObjectTypeName(fName);
if( pointField<VectorSingle,Type>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorSingle,Type>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}
if( pointField<VectorSingle,Type, HostSpace>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorSingle,Type,HostSpace>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}
if( pointField<VectorDual,Type>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<VectorDual,Type>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}
fatalErrorInFunction<<
fieldTypeName<< " is not a supported field type for setFieldEntry.\n";
return nullptr;
}
template <typename Type>
void* pFlow::setFieldEntry::setPointFieldSelectedStd
(
repository& owner,
int32IndexContainer& selected,
bool verbose
)
{
if( !checkForType<Type>() ) return nullptr;
auto fName = fieldName();
if( !owner.lookupObjectName(fName) )
{
fatalErrorInFunction<<
" Cannot find "<< fName << " in repository " << owner.name() << ". \n";
return nullptr;
}
Type value = entry_.secondPartVal<Type>();
if(verbose)
REPORT(2)<< "Setting selected points of " << greenText(fName)
<< " to value " << cyanText(value) <<endREPORT;
auto fieldTypeName = owner.lookupObjectTypeName(fName);
if( pointField<Vector, Type, vecAllocator<Type>>::TYPENAME() == fieldTypeName )
{
auto& field = owner.lookupObject<pointField<Vector,Type, vecAllocator<Type>>>(fName);
if(field.insertSetElement(selected, value))
return &field;
else
return nullptr;
}
return nullptr;
}
endREPORT
#define endREPORT
Definition: streams.hpp:41
REPORT
#define REPORT(n)
Definition: streams.hpp:40
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::repository::lookupObject
T & lookupObject(const word &name)
Definition: repositoryTemplates.cpp:146
pFlow::repository::lookupObjectName
bool lookupObjectName(const word &nm) const
Definition: repository.cpp:117
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:46
pFlow::repository::lookupObjectTypeName
word lookupObjectTypeName(const word &nm) const
Definition: repository.cpp:122
pFlow::repository::emplaceObject
T & emplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:38
pFlow::setFieldEntry::setPointFieldSelectedStd
void * setPointFieldSelectedStd(repository &owner, int32IndexContainer &selected, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:176
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::vecAllocator
std::allocator< T > vecAllocator
Definition: Vector.hpp:62
pFlow::repository::name
word name() const
Definition: repository.cpp:51
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::setFieldEntry::setPointFieldDefaultValueNew
void * setPointFieldDefaultValueNew(repository &owner, pointStructure &pStruct, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:41
pFlow::setFieldEntry::checkForType
bool checkForType() const
Definition: setFieldEntryTemplates.cpp:23
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::setFieldEntry::setPointFieldSelected
void * setPointFieldSelected(repository &owner, int32IndexContainer &selected, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:111
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::setFieldEntry::checkForTypeAndValue
bool checkForTypeAndValue() const
Definition: setFieldEntryTemplates.cpp:30
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:40
pFlow::setFieldEntry::entry_
twoPartEntry entry_
Definition: setFieldEntry.hpp:37
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::repository
Definition: repository.hpp:34
pFlow::twoPartEntry::firstPart
const word & firstPart() const
Definition: twoPartEntry.hpp:51
pFlow::Vector
Definition: Vector.hpp:46
pFlow::setFieldEntry::setPointFieldDefaultValueStdNew
void * setPointFieldDefaultValueStdNew(repository &owner, pointStructure &pStruct, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:76
pFlow::indexContainer< int32 >