# PhasicFlow: src/Property/property.hpp Source File

property.hpp
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.
-----------------------------------------------------------------------------*/
#ifndef __property_hpp__
#define __property_hpp__
#include "Vectors.hpp"
#include "hashMap.hpp"
#include "fileSystem.hpp"
#include "iFstream.hpp"
namespace pFlow
{
// forward
class dictionary;
class property
{
protected:
// - protected data members
uniquePtr<dictionary> dict_ = nullptr;
wordVector materials_;
realVector densities_;
wordHashMap<uint32> nameIndex_;
uint32 numMaterials_ = 0;
// - protected member functions
bool readDictionary(const dictionary& dict);
bool writeDictionary(dictionary& dict)const;
bool makeNameIndex();
public:
TypeInfoNV("property");
// - Constructors
property(){}
property(const wordVector& materials, const realVector& densities);
property(const fileSystem& file);
property(const dictionary& dict);
property(const property& ) = default;
property(property&& ) = default;
property& operator= (const property&) = default;
property& operator= (property&&) = default;
~property() = default;
// - Methods
inline const auto& dict()const
{
return dict_();
}
inline auto numMaterials()const
{
return numMaterials_;
}
inline const auto& materials()const{
return materials_;
}
inline const auto& densities()const{
return densities_;
}
inline const word& material(uint32 i)const
{
return materials_[i];
}
inline bool material(uint32 i, word& name)const
{
if(i<numMaterials_)
{
name = material(i);
return true;
}
else
{
name.clear();
return false;
}
}
inline real density(uint32 i)const
{
return densities_[i];
}
inline bool density(uint32 i, real& rho)const
{
if(i<numMaterials_)
{
rho = density(i);
return true;
}
else
{
rho = 0.00001;
return false;
}
}
inline bool nameToIndex(const word& name, uint32& idx)const
{
if(auto[iter, found] = nameIndex_.findIf(name); found )
{
idx = iter->second;
return true;
}
else
{
idx = 0;
return false;
}
}
bool read(const dictionary& dict)
{
return readDictionary(dict);
}
bool write(dictionary& dict)const
{
return writeDictionary(dict);
}
};
}
#endif // __property_hpp__
pFlow::property::dict_
uniquePtr< dictionary > dict_
pointer to the dictionary, if it is constructed from a file/dictionary
Definition: property.hpp:47
pFlow::property::densities_
realVector densities_
list of density of materials
Definition: property.hpp:53
hashMap.hpp
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:76
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::property::materials_
wordVector materials_
list of name of materials
Definition: property.hpp:50
pFlow::property::writeDictionary
bool writeDictionary(dictionary &dict) const
write to dict
Definition: property.cpp:54
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::property::dict
const auto & dict() const
Return dictionary.
Definition: property.hpp:112
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::property::densities
const auto & densities() const
Return the list of densities.
Definition: property.hpp:129
Vectors.hpp
pFlow::property::material
const word & material(uint32 i) const
Return the material name of material i.
Definition: property.hpp:134
pFlow::property::read
bool read(const dictionary &dict)
Read from dictionary.
Definition: property.hpp:196
fileSystem.hpp
pFlow
Definition: demComponent.hpp:28
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::property::materials
const auto & materials() const
Return list of material names.
Definition: property.hpp:124
pFlow::property::readDictionary
bool readDictionary(const dictionary &dict)
read from dict
Definition: property.cpp:26
pFlow::property::material
bool material(uint32 i, word &name) const
Get the name of material i.
Definition: property.hpp:141
pFlow::property::nameIndex_
wordHashMap< uint32 > nameIndex_
rapid mapping from name to index
Definition: property.hpp:56
pFlow::property::operator=
property & operator=(const property &)=default
Default copy assignment.
pFlow::property::nameToIndex
bool nameToIndex(const word &name, uint32 &idx) const
Get the name of material in index idx Return true, if the name found, otherwise false.
Definition: property.hpp:179
pFlow::property::~property
~property()=default
Default destructor.
pFlow::property::numMaterials
auto numMaterials() const
Return number of materials.
Definition: property.hpp:118
pFlow::property::property
property()
Emptry constructor, used for reading from a file.
Definition: property.hpp:82
pFlow::property::TypeInfoNV
TypeInfoNV("property")
Type info.
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::property::density
bool density(uint32 i, real &rho) const
Get the density of material i.
Definition: property.hpp:163
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::property::numMaterials_
uint32 numMaterials_
number of materials
Definition: property.hpp:59
pFlow::property::density
real density(uint32 i) const
Return density of material i.
Definition: property.hpp:156
iFstream.hpp
pFlow::Vector< word >
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::property::write
bool write(dictionary &dict) const
Write to dictionary.
Definition: property.hpp:202