diff --git a/src/.pmpo_MPMesh_assembly.hpp.swp b/src/.pmpo_MPMesh_assembly.hpp.swp new file mode 100644 index 0000000..4eb414f Binary files /dev/null and b/src/.pmpo_MPMesh_assembly.hpp.swp differ diff --git a/src/pmpo_MPMesh.cpp b/src/pmpo_MPMesh.cpp index 3d3992a..022c9f8 100644 --- a/src/pmpo_MPMesh.cpp +++ b/src/pmpo_MPMesh.cpp @@ -293,6 +293,8 @@ void MPMesh::T2LTracking(Vec2dView dx){ } void MPMesh::reconstructSlices() { + + std::cout<<__FUNCTION__<computeRotLatLonIncr(); sphericalInterpolation(*this); diff --git a/src/pmpo_MPMesh_assembly.hpp b/src/pmpo_MPMesh_assembly.hpp index 2f81aa6..984d08a 100644 --- a/src/pmpo_MPMesh_assembly.hpp +++ b/src/pmpo_MPMesh_assembly.hpp @@ -69,10 +69,14 @@ void MPMesh::assemblyVtx0(){ template void MPMesh::assemblyElm0() { + + std::cout<<__FUNCTION__<; auto mpData = p_MPs->getData(); const int numEntries = mpSliceToNumEntries(); + auto mpPositions = p_MPs->getData(); + auto mpAppID = p_MPs->getData(); int numElms = p_mesh->getNumElements(); p_mesh->fillMeshField(numElms, numEntries, 0.0); @@ -100,29 +104,106 @@ void MPMesh::assemblyElm0() { template void MPMesh::assemblyVtx1() { + + std::cout<<__FUNCTION__<; auto elm2VtxConn = p_mesh->getElm2VtxConn(); - auto mpData = p_MPs->getData(); const int numEntries = mpSliceToNumEntries(); int numVtx = p_mesh->getNumVertices(); + auto mpData = p_MPs->getData(); + auto weight = p_MPs->getData(); + auto mpPositions = p_MPs->getData(); + auto mpAppID = p_MPs->getData(); + p_mesh->fillMeshField(numVtx, numEntries, 0.0); auto meshField = p_mesh->getMeshField(); + Kokkos::View VtxMatrices("VtxMatrices", p_mesh->getNumVertices()); + auto vtxCoords = p_mesh->getMeshField(); + + double radius = p_mesh->getSphereRadius(); + + //Assemble matrix for each vertex auto assemble = PS_LAMBDA(const int& elm, const int& mp, const int& mask) { if(mask) { //if material point is 'active'/'enabled' int nVtxE = elm2VtxConn(elm,0); //number of vertices bounding the element for(int i=0; iparallel_for(assemble, "assembly"); + + //Solve Ax=b for each vertex + Kokkos::View VtxCoeffs("VtxMatrices", p_mesh->getNumVertices()); + Kokkos::parallel_for("solving Ax=b", numVtx, KOKKOS_LAMBDA(const int vtx){ + Vec4d v0 = {VtxMatrices(vtx,0,0), VtxMatrices(vtx,0,1), VtxMatrices(vtx,0,2), VtxMatrices(vtx,0,3)}; + Vec4d v1 = {VtxMatrices(vtx,1,0), VtxMatrices(vtx,1,1), VtxMatrices(vtx,1,2), VtxMatrices(vtx,1,3)}; + Vec4d v2 = {VtxMatrices(vtx,2,0), VtxMatrices(vtx,2,1), VtxMatrices(vtx,2,2), VtxMatrices(vtx,2,3)}; + Vec4d v3 = {VtxMatrices(vtx,3,0), VtxMatrices(vtx,3,1), VtxMatrices(vtx,3,2), VtxMatrices(vtx,3,3)}; + Matrix A = {v0,v1,v2,v3}; + double coeff[4]={0.0, 0.0, 0.0, 0.0}; + CholeskySolve(A, coeff); + for (int i=0; i<4; i++) VtxCoeffs(vtx,i)=coeff[i]; + + if(vtx >= 20 && vtx<=24){ + printf("Vtx %d coeff %.15e %.15e %.15e %.15e \n", vtx, coeff[0], coeff[1], coeff[2], coeff[3]); + } + }); + + //Reconstruct + Kokkos::View reconVals("meshField", p_mesh->getNumVertices()); + auto reconstruct = PS_LAMBDA(const int& elm, const int& mp, const int& mask) { + if(mask) { //if material point is 'active'/'enabled' + int nVtxE = elm2VtxConn(elm,0); //number of vertices bounding the element + for(int i=0; i=20 && vID<=24){ + printf("Vtx %d coeff val %.15e value %.15e\n", vID, val, reconVals(vID)); + } + } + } + }; + p_MPs->parallel_for(reconstruct, "reconstruct"); + + Kokkos::parallel_for("averaging", numVtx, KOKKOS_LAMBDA(const int vtx){ + meshField(vtx, 0) = reconVals(vtx); + }); + + count++; + //if(count>1) exit(1); + //Debugging + bool debug=false; + if(!debug) return; + int numElms = p_mesh->getNumElements(); + Kokkos::parallel_for("counting", numElms, KOKKOS_LAMBDA(const int elm){ + int nVtxE = elm2VtxConn(elm,0); + if(elm==4 || elm==5){ + for(int i=0; i diff --git a/src/pmpo_c.cpp b/src/pmpo_c.cpp index b37baa7..fef4b94 100644 --- a/src/pmpo_c.cpp +++ b/src/pmpo_c.cpp @@ -255,6 +255,8 @@ void polympo_setMPPositions_f(MPMesh_ptr p_mpmesh, mpPositions(mp,0) = mpPositionsIn_d(0, mpAppID(mp)); mpPositions(mp,1) = mpPositionsIn_d(1, mpAppID(mp)); mpPositions(mp,2) = mpPositionsIn_d(2, mpAppID(mp)); + //printf("Mp %d Map mpAppID(mp) %d Pos %.15e %.15e %.15e \n", mp, mpAppID(mp), + //mpPositions(mp,0), mpPositions(mp,1), mpPositions(mp,2)); } }; p_MPs->parallel_for(setPos, "setMPPositions"); @@ -926,6 +928,8 @@ void polympo_push_f(MPMesh_ptr p_mpmesh){ //TODO skeleton of reconstruction functions void polympo_setReconstructionOfMass_f(MPMesh_ptr p_mpmesh, const int order, const int meshEntType){ + + std::cout<<__FUNCTION__<(meshEntType); diff --git a/src/pmpo_utils.hpp b/src/pmpo_utils.hpp index af6e397..c3fd754 100644 --- a/src/pmpo_utils.hpp +++ b/src/pmpo_utils.hpp @@ -21,14 +21,22 @@ void PMT_Assert_Fail(const char* msg) __attribute__ ((noreturn)); namespace polyMPO{ +const double EPSILON = std::numeric_limits::epsilon(); + #define vec2d_nEntries 2 typedef double vec2d_t[vec2d_nEntries]; #define vec3d_nEntries 3 typedef double vec3d_t[vec3d_nEntries]; +#define vec4d_nEntries 4 +typedef double vec4d_t[vec4d_nEntries]; + typedef double doubleSclr_t[1]; class Vec2d; class Vec3d; +class Vec4d; +class Matrix; + using Vec2dView = Kokkos::View; using Vec3dView = Kokkos::View; using DoubleView = Kokkos::View; @@ -145,6 +153,103 @@ class Vec3d{ } }; + +class Vec4d{ + private: + vec4d_t coords_; + public: + + //constructors + KOKKOS_INLINE_FUNCTION + Vec4d():coords_{0.0, 0.0, 0.0, 0.0}{} + ~Vec4d() = default; + + KOKKOS_INLINE_FUNCTION + Vec4d(double x1, double x2, double x3, double x4):coords_{x1,x2,x3,x4}{} + + KOKKOS_INLINE_FUNCTION + Vec4d(double x[4]):coords_{x[0], x[1], x[2], x[3]}{} + + //operators + KOKKOS_INLINE_FUNCTION + double operator[](int i) const { return coords_[i]; } + + KOKKOS_INLINE_FUNCTION + double &operator[](int i) { return coords_[i]; } + + KOKKOS_INLINE_FUNCTION + Vec4d operator+(const Vec4d& v) const { + return Vec4d(coords_[0] + v.coords_[0], coords_[1] + v.coords_[1], + coords_[2] + v.coords_[2], coords_[3] + v.coords_[3]); + } + + KOKKOS_INLINE_FUNCTION + Vec4d operator-(const Vec4d& v) const { + return Vec4d(coords_[0] - v.coords_[0], coords_[1] - v.coords_[1], + coords_[2] - v.coords_[2], coords_[3] - v.coords_[3]); + } + + KOKKOS_INLINE_FUNCTION + Vec4d operator-() { return Vec4d(-coords_[0], -coords_[1], -coords_[2], -coords_[3]); } + + KOKKOS_INLINE_FUNCTION + Vec4d operator*(double scalar) const { + return Vec4d(coords_[0] * scalar, coords_[1] * scalar, coords_[2] * scalar, coords_[3] * scalar); + } + + KOKKOS_INLINE_FUNCTION + double dot(const Vec4d& v) const { + return coords_[0] * v.coords_[0] + coords_[1] * v.coords_[1] + coords_[2] * v.coords_[2] + coords_[3] * v.coords_[3]; + } + + KOKKOS_INLINE_FUNCTION + double magnitude() const { + return std::sqrt(coords_[0] * coords_[0] + coords_[1] * coords_[1] + coords_[2] * coords_[2] + coords_[3] * coords_[3]); + } +}; + +class Matrix { + + private: + + double** data_; + int rows_; + int cols_; + + public: + + KOKKOS_INLINE_FUNCTION + Matrix(Vec4d v0, Vec4d v1, Vec4d v2, Vec4d v3){ + rows_ = 4; + cols_ = 4; + data_ = new double*[rows_]; + + for (int i=0; iEPSILON){ + A(1,1)=std::sqrt(diag); + A(1,2)=(A(1,2)-A(0,1)*A(0,2))/A(1,1); + A(1,3)=(A(1,3)-A(0,1)*A(0,3))/A(1,1); + } + else{ + A(1,1)=0.0; + A(1,2)=0.0; + A(1,3)=0.0; + } + + diag = A(2,2) - A(0,2)*A(0,2)-A(1,2)*A(1,2); + if(diag>EPSILON){ + A(2,2)=std::sqrt(diag); + A(2,3)=(A(2,3)-A(0,2)*A(0,3)-A(1,2)*A(1,3))/A(2,2); + } + else{ + A(2,2)=0.0; + A(2,3)=0.0; + } + + diag=A(3,3)-A(0,3)*A(0,3)-A(1,3)*A(1,3)-A(2,3)*A(2,3); + if(diag>EPSILON) + A(3,3)=std::sqrt(diag); + else + A(3,3)=0.0; + + if(A(1,1)