From 8beaec448aed4ee7e083e1ab9f8ab264ccc3dd97 Mon Sep 17 00:00:00 2001
From: Hamidreza Norouzi <hamid.r.norouzi@gmail.com>
Date: Sun, 24 Mar 2024 02:49:47 -0700
Subject: [PATCH] modifications for version (1.0)

---
 src/CMakeLists.txt                            |  6 +--
 .../entities/vibrating/vibrating.hpp          |  2 +-
 .../sphereShape/sphereShape.cpp               |  2 +-
 src/Property/property.cpp                     | 34 +++++++++++-
 src/Property/property.hpp                     |  9 +++-
 src/phasicFlow/CMakeLists.txt                 |  1 +
 src/phasicFlow/Kokkos/ViewAlgorithms.hpp      | 54 +++++++++++++++++--
 src/phasicFlow/streams/iStream/iIstream.cpp   |  7 ++-
 src/phasicFlow/typeSelection/typeInfo.hpp     |  2 +-
 src/setHelpers/setProperty.hpp                |  2 +-
 10 files changed, 101 insertions(+), 18 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6f4967e6..7b403304 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,11 +9,7 @@ add_subdirectory(Particles)
 
 add_subdirectory(Geometry)
 
-#add_subdirectory(Interaction)
+add_subdirectory(Interaction)
 
 add_subdirectory(MotionModel)
 
-
-
-
-#add_subdirectory(MPIParallelization)
diff --git a/src/MotionModel/entities/vibrating/vibrating.hpp b/src/MotionModel/entities/vibrating/vibrating.hpp
index 42e73451..62241dfa 100644
--- a/src/MotionModel/entities/vibrating/vibrating.hpp
+++ b/src/MotionModel/entities/vibrating/vibrating.hpp
@@ -126,7 +126,7 @@ public:
 	realx3 transferPoint(const realx3& p, real dt)const
 	{
 		if(!inTimeRange()) return p;
-		return p + 0.5*dt*(velocity0_+velocity_);
+		return p + static_cast<real>(0.5*dt)*(velocity0_+velocity_);
 	}
 
 	// - IO operation
diff --git a/src/Particles/SphereParticles/sphereShape/sphereShape.cpp b/src/Particles/SphereParticles/sphereShape/sphereShape.cpp
index 75ec21e3..fac52d3c 100644
--- a/src/Particles/SphereParticles/sphereShape/sphereShape.cpp
+++ b/src/Particles/SphereParticles/sphereShape/sphereShape.cpp
@@ -166,7 +166,7 @@ pFlow::real pFlow::sphereShape::Inertia(uint32 index) const
 
 pFlow::realVector pFlow::sphereShape::Inertia() const
 {
-    return realVector("I", 0.4*mass()*pow(0.5*diameters_,(real)2.0));
+    return realVector("I", (real)0.4*mass()*pow((real)0.5*diameters_,(real)2.0));
 }
 
 bool pFlow::sphereShape::Inertia_xx(uint32 index, real &Ixx) const
diff --git a/src/Property/property.cpp b/src/Property/property.cpp
index 25573665..d6af1f47 100644
--- a/src/Property/property.cpp
+++ b/src/Property/property.cpp
@@ -64,15 +64,17 @@ bool pFlow::property::makeNameIndex()
 {
 	nameIndex_.clear();
 
+
 	uint32 i=0;
 	for(auto const& nm:materials_)
 	{
-		if(!nameIndex_.insertIf(nm, i++))
+		if(!nameIndex_.insertIf(nm, i))
 		{
 			fatalErrorInFunction<<
 			"  repeated material name in the list of materials: " << materials_;
 			return false;
 		}
+		i++;
 	}
 	nameIndex_.rehash(0);
 	numMaterials_ = static_cast<uint32>(materials_.size());
@@ -149,3 +151,33 @@ pFlow::property::property
 
 }
 
+pFlow::property::property
+(
+	const word &fileName, 
+	const fileSystem &dir
+)
+:
+	fileDictionary
+	(
+		objectFile
+		(
+			fileName,
+			dir,
+			objectFile::READ_ALWAYS,
+			objectFile::WRITE_NEVER
+		),
+		nullptr
+	)
+{
+	if(!readDictionary())
+	{
+		fatalExit;
+	}
+
+	if(!makeNameIndex())
+	{
+		fatalErrorInFunction<<
+		"error in dictionary "<< globalName()<<endl;
+		fatalExit;
+	}
+}
diff --git a/src/Property/property.hpp b/src/Property/property.hpp
index 81222d16..e7539b04 100644
--- a/src/Property/property.hpp
+++ b/src/Property/property.hpp
@@ -28,7 +28,6 @@ Licence:
 namespace pFlow
 {
 
-
 /** 
  * property holds the pure properties of materials.
  * 
@@ -52,6 +51,7 @@ private:
 		/// rapid mapping from name to index
 		wordHashMap<uint32>		nameIndex_;
 
+
 		/// number of materials
 		uint32 			numMaterials_ = 0;
 
@@ -78,6 +78,11 @@ public:
 		property(
 			const word& fileName, 
 			repository* owner=nullptr);
+
+		property(
+			const word& fileName,
+			const fileSystem& dir
+		);
 		
 		property(const word& fileName, 
 				const wordVector& materials,
@@ -177,6 +182,8 @@ public:
 				return false;
 			}	
 		}
+
+		
 		
 };
 
diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt
index 822f5cc6..d9d23fb7 100644
--- a/src/phasicFlow/CMakeLists.txt
+++ b/src/phasicFlow/CMakeLists.txt
@@ -53,6 +53,7 @@ demComponent/demComponent.cpp
 containers/Vector/Vectors.cpp
 containers/VectorHD/VectorSingles.cpp
 containers/Field/Fields.cpp
+containers/symArrayHD/symArrays.cpp
 containers/List/anyList/anyList.cpp
 containers/pointField/pointFields.cpp
 containers/triSurfaceField/triSurfaceFields.cpp
diff --git a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp
index 1ee86959..d765e014 100644
--- a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp
+++ b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp
@@ -63,8 +63,24 @@ void fill
 	T val
 )
 {
+	using exe_space = typename ViewType1D<T, properties...>::execution_space;
 	auto subV = Kokkos::subview(view, span.getPair() );
-	Kokkos::deep_copy(subV, val);
+	if constexpr ( std::is_trivially_copyable_v<T>)
+	{
+		Kokkos::deep_copy(subV, val);
+	}
+	else if constexpr( isHostAccessible<exe_space>())
+	{
+		for(auto i=span.start(); i<span.end(); i++ )
+		{
+			view[i] = val;
+		}
+	}
+	else
+	{
+		static_assert("fill is not valid for non-trivially-copyable data type");
+	}
+	
 }
 
 template<typename T, typename... properties>
@@ -79,6 +95,32 @@ void fill
 	fill(view, rangeU32(start, end),val);
 }
 
+template<typename T, typename... properties>
+void fill
+(
+	ViewType3D<T, properties...>& view,
+	rangeU32 range1,
+	rangeU32 range2,
+	rangeU32 range3,
+	const T& val
+)
+{
+	static_assert(std::is_trivially_copyable_v<T>, "Not valid type for fill");
+	auto subV = Kokkos::subview(view, range1, range2, range3);
+	Kokkos::deep_copy(subV, val);
+}
+
+template<typename T, typename... properties>
+void fill
+(
+	ViewType3D<T, properties...>& view,
+	const T& val
+)
+{
+	static_assert(std::is_trivially_copyable_v<T>, "Not valid type for fill");
+	Kokkos::deep_copy(view, val);
+}
+
 template<
 	typename Type,
 	typename... properties>
@@ -89,7 +131,7 @@ void fillSequence(
 	const Type startVal
 	)
 {
-
+	static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fill");
 	using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
 	uint32 numElems = end-start;
 
@@ -115,6 +157,8 @@ bool fillSelected
 	Type val
 )
 {
+
+	static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected");
 	static_assert(
       areAccessible<
 			typename ViewType1D<Type, properties...>::execution_space,
@@ -146,7 +190,7 @@ bool fillSelected(
 	const ViewType1D<Type, properties...> vals,
 	const uint32 numElems )
 {
-
+	static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected");
 	static_assert(
       areAccessible<
 			typename ViewType1D<Type, properties...>::execution_space,
@@ -404,7 +448,7 @@ template<
 	typename Type,
 	typename... properties>
 INLINE_FUNCTION_HD
-int32 binarySearch(
+uint32 binarySearch(
 	const ViewType1D<Type, properties...>& view,
 	uint32 start,
 	uint32 end,
@@ -414,7 +458,7 @@ int32 binarySearch(
 	if(end<=start)return -1;
 
 	if(auto res = 
-		binarySearch_(view.data()+start,end-start,val); res>=0) {
+		binarySearch_(view.data()+start,end-start,val); res!=-1) {
 		return res+start;
 	}
 	else{
diff --git a/src/phasicFlow/streams/iStream/iIstream.cpp b/src/phasicFlow/streams/iStream/iIstream.cpp
index b909b999..a74d9620 100755
--- a/src/phasicFlow/streams/iStream/iIstream.cpp
+++ b/src/phasicFlow/streams/iStream/iIstream.cpp
@@ -102,10 +102,13 @@ bool pFlow::iIstream::findTokenResume(const word& w)
             " at line number "<< lineNumber()<<endl;
             return false;
         }
-
+        
         if( next.isWord() && isFirstToken)
         {   
-            if(next.wordToken() == w ) return true;   
+            if(next.wordToken() == w ) 
+            {
+                return true;   
+            }
         }
 
         if(next.isEndStatement()|| next.isEndBlock())
diff --git a/src/phasicFlow/typeSelection/typeInfo.hpp b/src/phasicFlow/typeSelection/typeInfo.hpp
index 24f568a9..44f0bb0a 100644
--- a/src/phasicFlow/typeSelection/typeInfo.hpp
+++ b/src/phasicFlow/typeSelection/typeInfo.hpp
@@ -154,7 +154,7 @@ namespace pFlow
 #define TypeInfoTemplate12(tName, Type1, Type2)								\
 	inline static word TYPENAME()											\
 	{ 																		\
-		return word(tName)+"<"+getTypeName<Type1>()+","+getTypeName<Type2>()+">";}	\
+		return word(tName)+"<"+getTypeName<Type1>()+","+getTypeName<Type2>()+">";	\
 	}																		\
 	virtual word typeName() const { return TYPENAME();}
 
diff --git a/src/setHelpers/setProperty.hpp b/src/setHelpers/setProperty.hpp
index a35a1026..43ec5ef2 100644
--- a/src/setHelpers/setProperty.hpp
+++ b/src/setHelpers/setProperty.hpp
@@ -23,6 +23,6 @@ Licence:
 
 REPORT(0)<<"\nReading proprties . . . "<<END_REPORT;
 
-auto proprties = property(propertyFile__, &Control.caseSetup());
+auto proprties = property(propertyFile__, Control.caseSetup().path());
 
 #endif // __setProperty_hpp__