phasicFlow/src/Property/property.hpp

188 lines
3.9 KiB
C++
Raw Normal View History

2022-09-04 21:26:29 +00:00
/*------------------------------- 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.
-----------------------------------------------------------------------------*/
2022-12-09 22:02:54 +00:00
#ifndef __property_hpp__
#define __property_hpp__
2022-09-04 21:26:29 +00:00
2022-12-09 22:02:54 +00:00
#include "Vectors.hpp"
#include "hashMap.hpp"
2024-01-21 21:26:23 +00:00
#include "fileDictionary.hpp"
#include "iFstream.hpp"
2022-09-04 21:26:29 +00:00
namespace pFlow
{
// forward
2022-09-04 21:26:29 +00:00
class dictionary;
/**
* property holds the pure properties of materials.
*
* This class holds a list of all materials name and their densities that are
* used in the simulation: for walls and particles.
*/
2022-09-04 21:26:29 +00:00
class property
2024-01-21 21:26:23 +00:00
:
public fileDictionary
2022-09-04 21:26:29 +00:00
{
2024-01-21 21:26:23 +00:00
private:
2022-09-04 21:26:29 +00:00
// - protected data members
/// list of name of materials
wordVector materials_;
2022-09-04 21:26:29 +00:00
/// list of density of materials
realVector densities_;
2022-09-04 21:26:29 +00:00
/// rapid mapping from name to index
wordHashMap<uint32> nameIndex_;
2022-09-04 21:26:29 +00:00
/// number of materials
uint32 numMaterials_ = 0;
// - protected member functions
2022-09-04 21:26:29 +00:00
/// read from dict
2024-01-21 21:26:23 +00:00
bool readDictionary();
2022-09-04 21:26:29 +00:00
/// write to dict
2024-01-21 21:26:23 +00:00
bool writeDictionary();
2022-09-04 21:26:29 +00:00
/// creates a mapp
bool makeNameIndex();
2022-09-04 21:26:29 +00:00
public:
/// Type info
2024-01-21 21:26:23 +00:00
TypeInfo("property");
2022-09-04 21:26:29 +00:00
// - Constructors
2024-01-21 21:26:23 +00:00
explicit
property(
const word& fileName,
repository* owner=nullptr);
2024-01-25 11:09:08 +00:00
property(const word& fileName,
2024-01-21 21:26:23 +00:00
const wordVector& materials,
const realVector& densities,
repository* owner=nullptr);
2022-09-04 21:26:29 +00:00
/// Default copy
2022-09-04 21:26:29 +00:00
property(const property& ) = default;
/// Default move
2022-09-04 21:26:29 +00:00
property(property&& ) = default;
/// Default copy assignment
2022-09-04 21:26:29 +00:00
property& operator= (const property&) = default;
/// Default move assignment
2022-09-04 21:26:29 +00:00
property& operator= (property&&) = default;
/// Default destructor
2024-01-21 21:26:23 +00:00
~property() override = default;
2022-09-04 21:26:29 +00:00
// - Methods
2022-09-04 21:26:29 +00:00
/// Return number of materials
2022-09-04 21:26:29 +00:00
inline auto numMaterials()const
{
return numMaterials_;
}
/// Return list of material names
2022-09-04 21:26:29 +00:00
inline const auto& materials()const{
return materials_;
}
/// Return the list of densities
2022-09-04 21:26:29 +00:00
inline const auto& densities()const{
return densities_;
}
/// Return the material name of material i
2022-09-04 21:26:29 +00:00
inline const word& material(uint32 i)const
{
return materials_[i];
}
/// Get the name of material i.
/// Return true, if i is in the range and otherwise false
2022-09-04 21:26:29 +00:00
inline bool material(uint32 i, word& name)const
{
if(i<numMaterials_)
{
name = material(i);
return true;
}
else
{
name.clear();
return false;
}
}
/// Return density of material i
2022-09-04 21:26:29 +00:00
inline real density(uint32 i)const
{
return densities_[i];
}
/// Get the density of material i.
/// Return true, if i is in the range and otherwise false
2022-09-04 21:26:29 +00:00
inline bool density(uint32 i, real& rho)const
{
if(i<numMaterials_)
{
rho = density(i);
return true;
}
else
{
rho = 0.00001;
return false;
}
}
/// Get the name of material in index idx
/// Return true, if the name found, otherwise false
2022-09-04 21:26:29 +00:00
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;
}
}
};
}
2022-12-09 22:02:54 +00:00
#endif // __property_hpp__