mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-07-08 03:07:03 +00:00
refactor up to particles.hpp
This commit is contained in:
@ -18,55 +18,42 @@ Licence:
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "property.hpp"
|
||||
#include "dictionary.hpp"
|
||||
|
||||
bool pFlow::property::readDictionary
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
bool pFlow::property::readDictionary()
|
||||
{
|
||||
|
||||
materials_ = dict.getVal<wordVector>("materials");
|
||||
materials_ = getVal<wordVector>("materials");
|
||||
|
||||
densities_ = dict.getVal<realVector>("densities");
|
||||
densities_ = getVal<realVector>("densities");
|
||||
|
||||
if(materials_.size() != densities_.size() )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" number of elements in material ("<<materials_.size()<<
|
||||
") is not equal to number of elements in densities ("<<densities_.size()<<
|
||||
") in dictionary "<< dict.globalName()<<endl;
|
||||
") in dictionary "<< globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!makeNameIndex())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::property::writeDictionary
|
||||
(
|
||||
dictionary& dict
|
||||
)const
|
||||
bool pFlow::property::writeDictionary()
|
||||
{
|
||||
|
||||
if(!dict.add("materials", materials_))
|
||||
if(!add("materials", materials_))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in writing materials to dictionary "<< dict.globalName()<<endl;
|
||||
" error in writing materials to dictionary "<< globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!dict.add("densities", densities_))
|
||||
if(!add("densities", densities_))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in writing densities to dictionary "<< dict.globalName()<<endl;
|
||||
" error in writing densities to dictionary "<< globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -78,7 +65,7 @@ bool pFlow::property::makeNameIndex()
|
||||
nameIndex_.clear();
|
||||
|
||||
uint32 i=0;
|
||||
for(auto& nm:materials_)
|
||||
for(auto const& nm:materials_)
|
||||
{
|
||||
if(!nameIndex_.insertIf(nm, i++))
|
||||
{
|
||||
@ -88,68 +75,77 @@ bool pFlow::property::makeNameIndex()
|
||||
}
|
||||
}
|
||||
nameIndex_.rehash(0);
|
||||
numMaterials_ = materials_.size();
|
||||
numMaterials_ = static_cast<uint32>(materials_.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
pFlow::property::property
|
||||
(
|
||||
const word& name,
|
||||
const wordVector& materials,
|
||||
const realVector& densities
|
||||
const realVector& densities,
|
||||
repository* owner
|
||||
)
|
||||
:
|
||||
fileDictionary
|
||||
(
|
||||
objectFile
|
||||
(
|
||||
name,
|
||||
"",
|
||||
objectFile::READ_NEVER,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
owner
|
||||
),
|
||||
materials_(materials),
|
||||
densities_(densities)
|
||||
{
|
||||
|
||||
if(!writeDictionary())
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
if(!makeNameIndex())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in the input parameters of constructor. \n";
|
||||
"error in the input parameters of constructor. \n";
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
||||
pFlow::property::property
|
||||
(
|
||||
const fileSystem& file
|
||||
const word& fileName,
|
||||
repository* owner
|
||||
)
|
||||
:
|
||||
dict_
|
||||
fileDictionary
|
||||
(
|
||||
makeUnique<dictionary>
|
||||
("property", true)
|
||||
)
|
||||
{
|
||||
iFstream dictStream(file);
|
||||
|
||||
if(!dict_().read(dictStream))
|
||||
{
|
||||
ioErrorInFile(dictStream.name(), dictStream.lineNumber());
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
if(!readDictionary(dict_()))
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pFlow::property::property
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
dict_
|
||||
(
|
||||
makeUnique<dictionary>(dict)
|
||||
objectFile
|
||||
(
|
||||
fileName,
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_NEVER
|
||||
),
|
||||
owner
|
||||
)
|
||||
{
|
||||
|
||||
if(!readDictionary(dict_()))
|
||||
if(!readDictionary())
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
if(!makeNameIndex())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
"error in dictionary "<< globalName()<<endl;
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ Licence:
|
||||
|
||||
#include "Vectors.hpp"
|
||||
#include "hashMap.hpp"
|
||||
#include "fileSystem.hpp"
|
||||
#include "fileDictionary.hpp"
|
||||
#include "iFstream.hpp"
|
||||
|
||||
namespace pFlow
|
||||
@ -38,14 +38,13 @@ class dictionary;
|
||||
* used in the simulation: for walls and particles.
|
||||
*/
|
||||
class property
|
||||
:
|
||||
public fileDictionary
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
// - protected data members
|
||||
|
||||
/// pointer to the dictionary, if it is constructed from a file/dictionary
|
||||
uniquePtr<dictionary> dict_ = nullptr;
|
||||
|
||||
/// list of name of materials
|
||||
wordVector materials_;
|
||||
|
||||
@ -62,10 +61,10 @@ protected:
|
||||
// - protected member functions
|
||||
|
||||
/// read from dict
|
||||
bool readDictionary(const dictionary& dict);
|
||||
bool readDictionary();
|
||||
|
||||
/// write to dict
|
||||
bool writeDictionary(dictionary& dict)const;
|
||||
bool writeDictionary();
|
||||
|
||||
/// creates a mapp
|
||||
bool makeNameIndex();
|
||||
@ -73,22 +72,19 @@ protected:
|
||||
public:
|
||||
|
||||
/// Type info
|
||||
TypeInfoNV("property");
|
||||
TypeInfo("property");
|
||||
|
||||
|
||||
// - Constructors
|
||||
|
||||
/// Emptry constructor, used for reading from a file
|
||||
property(){}
|
||||
|
||||
/// Constructe from materials and densities
|
||||
property(const wordVector& materials, const realVector& densities);
|
||||
|
||||
/// Construct from file
|
||||
property(const fileSystem& file);
|
||||
|
||||
/// Construct from dictionary dict
|
||||
property(const dictionary& dict);
|
||||
explicit
|
||||
property(
|
||||
const word& fileName,
|
||||
repository* owner=nullptr);
|
||||
|
||||
property(const word& name,
|
||||
const wordVector& materials,
|
||||
const realVector& densities,
|
||||
repository* owner=nullptr);
|
||||
|
||||
/// Default copy
|
||||
property(const property& ) = default;
|
||||
@ -103,17 +99,11 @@ public:
|
||||
property& operator= (property&&) = default;
|
||||
|
||||
/// Default destructor
|
||||
~property() = default;
|
||||
~property() override = default;
|
||||
|
||||
|
||||
// - Methods
|
||||
|
||||
/// Return dictionary
|
||||
inline const auto& dict()const
|
||||
{
|
||||
return dict_();
|
||||
}
|
||||
|
||||
/// Return number of materials
|
||||
inline auto numMaterials()const
|
||||
{
|
||||
@ -190,20 +180,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//// - IO operatoins
|
||||
|
||||
/// Read from dictionary
|
||||
bool read(const dictionary& dict)
|
||||
{
|
||||
return readDictionary(dict);
|
||||
}
|
||||
|
||||
/// Write to dictionary
|
||||
bool write(dictionary& dict)const
|
||||
{
|
||||
return writeDictionary(dict);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user