mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-22 16:28:30 +00:00
src folder
This commit is contained in:
11
src/Property/CMakeLists.txt
Normal file
11
src/Property/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
set(SourceFiles
|
||||
property.C
|
||||
)
|
||||
|
||||
set(link_libs Kokkos::kokkos phasicFlow)
|
||||
|
||||
pFlow_add_library_install(Property SourceFiles link_libs)
|
||||
|
||||
|
||||
|
155
src/Property/property.C
Normal file
155
src/Property/property.C
Normal file
@ -0,0 +1,155 @@
|
||||
/*------------------------------- 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 "property.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
bool pFlow::property::readDictionary
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
|
||||
materials_ = dict.getVal<wordVector>("materials");
|
||||
|
||||
densities_ = dict.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;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!makeNameIndex())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::property::writeDictionary
|
||||
(
|
||||
dictionary& dict
|
||||
)const
|
||||
{
|
||||
|
||||
if(!dict.add("materials", materials_))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in writing materials to dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!dict.add("densities", densities_))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in writing densities to dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::property::makeNameIndex()
|
||||
{
|
||||
nameIndex_.clear();
|
||||
|
||||
uint32 i=0;
|
||||
for(auto& nm:materials_)
|
||||
{
|
||||
if(!nameIndex_.insertIf(nm, i++))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" repeated material name in the list of materials: " << materials_;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
nameIndex_.rehash(0);
|
||||
numMaterials_ = materials_.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
pFlow::property::property
|
||||
(
|
||||
const wordVector& materials,
|
||||
const realVector& densities
|
||||
)
|
||||
:
|
||||
materials_(materials),
|
||||
densities_(densities)
|
||||
{
|
||||
if(!makeNameIndex())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in the input parameters of constructor. \n";
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
||||
pFlow::property::property
|
||||
(
|
||||
const fileSystem& file
|
||||
)
|
||||
:
|
||||
dict_
|
||||
(
|
||||
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)
|
||||
)
|
||||
{
|
||||
|
||||
if(!readDictionary(dict_()))
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
172
src/Property/property.H
Normal file
172
src/Property/property.H
Normal file
@ -0,0 +1,172 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __property_H__
|
||||
|
||||
#include "Vectors.H"
|
||||
#include "hashMap.H"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class dictionary;
|
||||
|
||||
class property
|
||||
{
|
||||
protected:
|
||||
|
||||
uniquePtr<dictionary> dict_ = nullptr;
|
||||
|
||||
// - name of materials
|
||||
wordVector materials_;
|
||||
|
||||
// - density of materials
|
||||
realVector densities_;
|
||||
|
||||
// fast mapping from name to index
|
||||
wordHashMap<uint32> nameIndex_;
|
||||
|
||||
// - number of properties
|
||||
uint32 numMaterials_ = 0;
|
||||
|
||||
bool readDictionary(const dictionary& dict);
|
||||
|
||||
bool writeDictionary(dictionary& dict)const;
|
||||
|
||||
bool makeNameIndex();
|
||||
|
||||
public:
|
||||
|
||||
// type info
|
||||
TypeNameNV("property");
|
||||
|
||||
// - emptry, for reading from file
|
||||
property(){}
|
||||
|
||||
property(const wordVector& materils, 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_;
|
||||
}
|
||||
|
||||
// - densities
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//// - IO operatoins
|
||||
|
||||
// - read from dictionary
|
||||
bool read(const dictionary& dict)
|
||||
{
|
||||
return readDictionary(dict);
|
||||
}
|
||||
|
||||
// - write to dictionary
|
||||
bool write(dictionary& dict)const
|
||||
{
|
||||
return writeDictionary(dict);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __property_H__
|
Reference in New Issue
Block a user