156typename ErrorEstimation<SC,LO,GO,NO>::MultiVectorPtr_Type
ErrorEstimation<SC,LO,GO,NO>::estimateError(MeshUnstrPtr_Type inputMeshP12, MeshUnstrPtr_Type inputMeshP1, BlockMultiVectorConstPtr_Type valuesSolution, RhsFunc_Type rhsFunc, std::string FETypeV){
159 inputMesh_ = inputMeshP12;
160 inputMeshP1_ = inputMeshP1;
171 if(FEType2_ !=
"P1" && FEType2_ !=
"P2"){
172 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Error Estimation only works for Triangular P1 or P2 Elements");
176 ElementsPtr_Type elements = inputMesh_->getElementsC();
177 EdgeElementsPtr_Type edgeElements = inputMesh_->getEdgeElements();
178 MapConstPtr_Type elementMap = inputMesh_->getElementMap();
179 vec2D_dbl_ptr_Type points = inputMesh_->getPointsRepeated();
180 int myRank = inputMesh_->comm_->getRank();
181 surfaceElements_ = inputMesh_->getSurfaceTriangleElements();
183 this->dim_ = inputMesh_->dim_;
189 MESH_TIMER_START(errorEstimation,
" Error Estimation ");
191 edgeElements->matchEdgesToElements(elementMap);
193 vec2D_GO_Type elementsOfEdgesGlobal = edgeElements->getElementsOfEdgeGlobal();
194 vec2D_LO_Type elementsOfEdgesLocal = edgeElements->getElementsOfEdgeLocal();
197 MultiVectorPtr_Type errorElementMv = Teuchos::rcp(
new MultiVector_Type( elementMap) );
198 Teuchos::ArrayRCP<SC> errorElement = errorElementMv->getDataNonConst(0);
201 double maxErrorElLoc=0.0;
207 vec_int_Type edgeNumbers(3);
216 vec_dbl_Type areaTriangles(elements->numberElements());
217 vec_dbl_Type rho_T(elements->numberElements());
218 vec_dbl_Type C_T(elements->numberElements());
219 vec_dbl_Type h_T =
calcDiamTriangles(elements,points, areaTriangles, rho_T, C_T);
222 double divUElement=0;
225 for(
int k=0; k< elements->numberElements();k++){
226 edgeNumbers = edgeElements->getEdgesOfElement(k);
228 if(problemType_ ==
"Stokes" || problemType_ ==
"NavierStokes"){
232 errorElement[k] = std::sqrt(1./2*(u_Jump[edgeNumbers[0]]+u_Jump[edgeNumbers[1]]+u_Jump[edgeNumbers[2]])+divUElement+ h_T[k]*h_T[k]*resElement );
234 if(maxErrorElLoc < errorElement[k] )
235 maxErrorElLoc = errorElement[k];
238 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxErrorElLoc, outArg (maxErrorElLoc));
240 if( writeMeshQuality_ ){
242 double maxh_T, minh_T;
243 double maxC_T, minC_T;
244 double maxrho_T, minrho_T;
245 double maxArea_T, minArea_T;
247 auto it = max_element(h_T.begin(), h_T.end());
248 maxh_T = h_T[distance(h_T.begin(), it)];
249 it = min_element(h_T.begin(), h_T.end());
250 minh_T = h_T[distance(h_T.begin(), it)];
251 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxh_T, outArg (maxh_T));
252 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minh_T, outArg (minh_T));
254 it = max_element(rho_T.begin(), rho_T.end());
255 maxrho_T = rho_T[distance(rho_T.begin(), it)];
256 it = min_element(rho_T.begin(), rho_T.end());
257 minrho_T = rho_T[distance(rho_T.begin(), it)];
258 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxrho_T, outArg (maxrho_T));
259 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minrho_T, outArg (minrho_T));
261 it = max_element(areaTriangles.begin(), areaTriangles.end());
262 maxArea_T = areaTriangles[distance(areaTriangles.begin(), it)];
263 it = min_element(areaTriangles.begin(), areaTriangles.end());
264 minArea_T = areaTriangles[distance(areaTriangles.begin(), it)];
265 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxArea_T, outArg (maxArea_T));
266 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minArea_T, outArg (minArea_T));
269 it = max_element(C_T.begin(), C_T.end());
270 maxC_T = C_T[distance(C_T.begin(), it)];
271 it = min_element(C_T.begin(), C_T.end());
272 minC_T = C_T[distance(C_T.begin(), it)];
273 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxC_T, outArg (maxC_T));
274 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minC_T, outArg (minC_T));
276 if(inputMesh_->getComm()->getRank() == 0){
277 cout <<
"\tMesh Quality Assessment 2D of current mesh" << endl;
278 cout <<
"\t__________________________________________________________________________________________________________ " << endl;
280 cout <<
" \tCircumdiameter h_T: \t\t" <<
"max. = " << setprecision(5) << maxh_T <<
"\tmin. = " << setprecision(5) << minh_T << endl;
281 cout <<
" \tIncircumdiameter rho_T:\t\t" <<
"max. = " << setprecision(5) <<maxrho_T <<
"\tmin. = " <<setprecision(5) << minrho_T << endl;
282 cout <<
" \tArea of Triangles:\t \t" <<
"max. = " << setprecision(5) << maxArea_T <<
"\tmin. = " << setprecision(5) << minArea_T << endl;
283 cout <<
" \tShape parameter:\t \t" <<
"max. = " << setprecision(5) << maxC_T <<
"\tmin. = " << setprecision(5) <<minC_T << endl;
284 cout <<
" \tThe maximal Error of Elements is " << maxErrorElLoc << endl;
285 cout <<
"\t__________________________________________________________________________________________________________ " << endl;
293 else if(this->dim_ == 3){
297 this->surfaceElements_->matchSurfacesToElements(elementMap);
298 SurfaceElementsPtr_Type surfaceElements = this->surfaceElements_;
301 vec_dbl_Type errorSurfacesInterior(4);
303 vec_int_Type surfaceNumbers(4);
305 vec_dbl_Type u1(3),u2(3);
315 vec_dbl_Type areaTriangles(surfaceElements->numberElements());
316 vec_dbl_Type rho_Tri(surfaceElements->numberElements());
317 vec_dbl_Type C_Tri(surfaceElements->numberElements());
318 vec_dbl_Type h_Tri =
calcDiamTriangles3D(surfaceElements,points, areaTriangles, rho_Tri, C_Tri);
321 vec_dbl_Type rho_T =
calcRhoTetraeder(elements,surfaceElements, volTetraeder, areaTriangles);
324 vec_dbl_Type p1(3),p2(3);
336 double divUElement=0;
340 for(
int k=0; k< elements->numberElements();k++){
341 surfaceNumbers = surfaceElements->getSurfacesOfElement(k);
344 if(problemType_ ==
"Stokes" || problemType_ ==
"NavierStokes")
346 errorElement[k] = std::sqrt(1./2*(u_Jump[surfaceNumbers[0]]+u_Jump[surfaceNumbers[1]]+u_Jump[surfaceNumbers[2]]+u_Jump[surfaceNumbers[3]])+divUElement +h_T[k]*h_T[k]*resElement );
347 if(maxErrorElLoc < errorElement[k] )
348 maxErrorElLoc = errorElement[k];
351 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxErrorElLoc, outArg (maxErrorElLoc));
353 if( writeMeshQuality_ ){
354 double maxh_T, minh_T, maxh_Tri, minh_Tri;
355 double maxC_T, minC_T, maxC_Tri, minC_Tri;
356 double maxrho_T, minrho_T, maxrho_Tri, minrho_Tri;
357 double maxArea_T, minArea_T;
358 double maxVol_T, minVol_T;
361 auto it = max_element(h_Tri.begin(), h_Tri.end());
362 maxh_Tri = h_Tri[distance(h_Tri.begin(), it)];
363 it = min_element(h_Tri.begin(), h_Tri.end());
365 minh_Tri = h_Tri[distance(h_Tri.begin(), it)];
366 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxh_Tri, outArg (maxh_Tri));
367 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minh_Tri, outArg (minh_Tri));
370 it = max_element(h_T.begin(), h_T.end());
371 maxh_T = h_T[distance(h_T.begin(), it)];
372 it = min_element(h_T.begin(), h_T.end());
374 minh_T = h_T[distance(h_T.begin(), it)];
375 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxh_T, outArg (maxh_T));
376 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minh_T, outArg (minh_T));
379 it = max_element(rho_Tri.begin(), rho_Tri.end());
380 maxrho_Tri = rho_Tri[distance(rho_Tri.begin(), it)];
381 it = min_element(rho_Tri.begin(), rho_Tri.end());
382 minrho_Tri = rho_Tri[distance(rho_Tri.begin(), it)];
383 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxrho_Tri, outArg (maxrho_Tri));
384 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minrho_Tri, outArg (minrho_Tri));
387 it = max_element(rho_T.begin(), rho_T.end());
388 maxrho_T = rho_T[distance(rho_T.begin(), it)];
389 it = min_element(rho_T.begin(), rho_T.end());
390 minrho_T = rho_T[distance(rho_T.begin(), it)];
391 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxrho_T, outArg (maxrho_T));
392 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minrho_T, outArg (minrho_T));
395 it = max_element(areaTriangles.begin(), areaTriangles.end());
396 maxArea_T = areaTriangles[distance(areaTriangles.begin(), it)];
397 it = min_element(areaTriangles.begin(), areaTriangles.end());
398 minArea_T = areaTriangles[distance(areaTriangles.begin(), it)];
399 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxArea_T, outArg (maxArea_T));
400 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minArea_T, outArg (minArea_T));
403 it = max_element(volTetraeder.begin(), volTetraeder.end());
404 maxVol_T = volTetraeder[distance(volTetraeder.begin(), it)];
406 it = min_element(volTetraeder.begin(), volTetraeder.end());
407 minVol_T = volTetraeder[distance(volTetraeder.begin(), it)];
409 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxVol_T, outArg (maxVol_T));
410 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minVol_T, outArg (minVol_T));
413 it = max_element(C_Tri.begin(), C_Tri.end());
414 maxC_Tri = C_Tri[distance(C_Tri.begin(), it)];
416 it = min_element(C_Tri.begin(), C_Tri.end());
417 minC_Tri = C_Tri[distance(C_Tri.begin(), it)];
419 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxC_Tri, outArg (maxC_Tri));
420 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minC_Tri, outArg (minC_Tri));
423 vec_dbl_Type C_T(elements->numberElements());
424 for(
int i=0; i< h_T.size(); i++){
425 C_T[i] = h_T[i] / rho_T[i];
427 it = max_element(C_T.begin(), C_T.end());
428 maxC_T = C_T[distance(C_T.begin(), it)];
430 it = min_element(C_T.begin(), C_T.end());
431 minC_T = C_T[distance(C_T.begin(), it)];
433 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, maxC_T, outArg (maxC_T));
434 reduceAll<int, double> (*inputMesh_->getComm(), REDUCE_MAX, minC_T, outArg (minC_T));
437 if(inputMesh_->getComm()->getRank() == 0){
438 cout <<
" \t-- Mesh Quality Assessment 3D of current mesh level -- \t" << endl;
439 cout <<
"\t__________________________________________________________________________________________________________ " << endl;
441 cout <<
" \tCircumdiameter h_T:\t\t\t" <<
"max. = " << setprecision(5) << maxh_T <<
" min. = " << setprecision(5) <<minh_T << endl;
442 cout <<
" \tIncircumdiameter rho_T:\t\t\t" <<
"max. = " <<setprecision(5) << maxrho_T <<
" min. = " << setprecision(5) <<minrho_T << endl;
443 cout <<
" \tCircumdiameter h_Tri:\t\t\t" <<
"max. = " <<setprecision(5) << maxh_Tri <<
" min. = " << setprecision(5) <<minh_Tri << endl;
444 cout <<
" \tIncircumdiameter rho_Tri:\t\t" <<
"max. = " << setprecision(5) <<maxrho_Tri <<
" min. = " << setprecision(5) <<minrho_Tri << endl;
445 cout <<
" \tArea of Triangles: \t\t\t" <<
"max. = " << setprecision(5) <<maxArea_T <<
" min. = " << setprecision(5) <<minArea_T << endl;
446 cout <<
" \tVolume of Tetraeder: \t\t\t" <<
"max. = " << setprecision(5) <<maxVol_T <<
" min. = " << setprecision(5) <<minVol_T << endl;
447 cout <<
" \tShape parameter Tetraeder: \t\t" <<
"max. = " << setprecision(5) << maxC_T <<
" min. = " << setprecision(5) <<minC_T << endl;
448 cout <<
" \tShape parameter Triangles: \t\t" <<
"max. = " << setprecision(5) << maxC_Tri <<
" min. = " << setprecision(5) <<minC_Tri << endl;
449 cout <<
" \tThe maximal Error of Elements is \t" << maxErrorElLoc << endl;
450 cout <<
"\t__________________________________________________________________________________________________________ " << endl;
457 errorEstimation_ = errorElementMv;
459 MESH_TIMER_STOP(errorEstimation);
461 return errorElementMv;
784 int surfaceNumbers = dim_+1 ;
787 vec2D_dbl_ptr_Type points = inputMesh_->pointsRep_;
788 ElementsPtr_Type elements = inputMesh_->getElementsC();
789 EdgeElementsPtr_Type edgeElements = inputMesh_->getEdgeElements();
790 MapConstPtr_Type elementMap = inputMesh_->getElementMap();
791 SurfaceElementsPtr_Type surfaceTriangleElements = this->surfaceElements_;
792 vec_int_Type surfaceElementsIds(surfaceNumbers);
793 MapConstPtr_Type surfaceMap;
796 int numberSurfaceElements=0;
798 numberSurfaceElements = edgeElements->numberElements();
799 surfaceMap= inputMesh_->edgeMap_;
802 numberSurfaceElements = surfaceTriangleElements->numberElements();
803 surfaceMap= this->surfaceTriangleMap_;
808 int numNodes= dim_+1;
811 if(FEType2_ ==
"P2"){
823 vec3D_dbl_Type vec_El(numberSurfaceElements,vec2D_dbl_Type(quadPSize,vec_dbl_Type(dofsSol)));
824 vec3D_dbl_Type vec_El1(numberSurfaceElements,vec2D_dbl_Type(quadPSize,vec_dbl_Type(dofsSol)));
825 vec3D_dbl_Type vec_El2(numberSurfaceElements,vec2D_dbl_Type(quadPSize,vec_dbl_Type(dofsSol)));
827 vec3D_dbl_Type vec_El_Exp(numberSurfaceElements,vec2D_dbl_Type(quadPSize,vec_dbl_Type(dofsSol)));
830 vec_GO_Type elementImportIDs(0);
831 vec_GO_Type elementExportIDs(0);
832 vec_LO_Type surfaceIDsLocal(0);
835 vec_LO_Type kn1(numNodes);
843 edgeElements->matchEdgesToElements(elementMap);
846 vec2D_GO_Type elementsOfSurfaceGlobal;
847 vec2D_LO_Type elementsOfSurfaceLocal;
850 elementsOfSurfaceGlobal = edgeElements->getElementsOfEdgeGlobal();
851 elementsOfSurfaceLocal = edgeElements->getElementsOfEdgeLocal();
854 elementsOfSurfaceGlobal = surfaceTriangleElements->getElementsOfSurfaceGlobal();
855 elementsOfSurfaceLocal = surfaceTriangleElements->getElementsOfSurfaceLocal();
859 vec_dbl_Type v_E(dim_);
864 for(
int k=0; k< numberSurfaceElements;k++){
866 bool interiorElement=
false;
868 if((edgeElements->getElement(k).getFlag() == 10 || edgeElements->getElement(k).getFlag() == 0))
869 interiorElement=
true;
872 if((surfaceTriangleElements->getElement(k).getFlag() == 10 || surfaceTriangleElements->getElement(k).getFlag() == 0))
873 interiorElement=
true;
875 if(interiorElement ==
true && elementsOfSurfaceLocal.at(k).size() > 1){
877 vec_dbl_Type quadWeights(quadPSize);
878 vec2D_dbl_Type quadPoints;
881 quadPoints =
getQuadValues(dim_, FEType2_ ,
"Surface", quadWeights, edgeElements->getElement(k));
882 v_E.at(0) = points->at(edgeElements->getElement(k).getNode(0)).at(1) - points->at(edgeElements->getElement(k).getNode(1)).at(1);
883 v_E.at(1) = -(points->at(edgeElements->getElement(k).getNode(0)).at(0) - points->at(edgeElements->getElement(k).getNode(1)).at(0));
884 norm_v_E = std::sqrt(std::pow(v_E[0],2)+std::pow(v_E[1],2));
887 quadPoints =
getQuadValues(dim_, FEType2_ ,
"Surface", quadWeights, surfaceTriangleElements->getElement(k));
889 vec_dbl_Type p1(3),p2(3);
890 p1[0] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(0) - points->at(surfaceTriangleElements->getElement(k).getNode(1)).at(0);
891 p1[1] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(1) - points->at(surfaceTriangleElements->getElement(k).getNode(1)).at(1);
892 p1[2] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(2) - points->at(surfaceTriangleElements->getElement(k).getNode(1)).at(2);
894 p2[0] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(0) - points->at(surfaceTriangleElements->getElement(k).getNode(2)).at(0);
895 p2[1] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(1) - points->at(surfaceTriangleElements->getElement(k).getNode(2)).at(1);
896 p2[2] = points->at(surfaceTriangleElements->getElement(k).getNode(0)).at(2) - points->at(surfaceTriangleElements->getElement(k).getNode(2)).at(2);
898 v_E[0] = p1[1]*p2[2] - p1[2]*p2[1];
899 v_E[1] = p1[2]*p2[0] - p1[0]*p2[2];
900 v_E[2] = p1[0]*p2[1] - p1[1]*p2[0];
902 norm_v_E = std::sqrt(std::pow(v_E[0],2)+std::pow(v_E[1],2)+std::pow(v_E[2],2));
905 vec_LO_Type elementsIDs(0);
907 if(elementsOfSurfaceLocal.at(k).at(0) != -1){
908 elementsIDs.push_back(elementsOfSurfaceLocal.at(k).at(0));
910 if(elementsOfSurfaceLocal.at(k).at(1) != -1){
911 elementsIDs.push_back(elementsOfSurfaceLocal.at(k).at(1));
913 for(
int i=0; i<elementsIDs.size(); i++){
917 kn1= elements->getElement(elementsIDs[i]).getVectorNodeListNonConst();
922 for (
int s=0; s<dim_; s++) {
924 for (
int t=0; t<dim_; t++) {
925 B1[t][s] = points->at(index).at(t) -points->at(index0).at(t);
929 detB1 = B1.computeInverse(Binv1);
930 detB1 = std::fabs(detB1);
932 vec2D_dbl_Type quadPointsT1(quadPSize,vec_dbl_Type(dim_));
933 for(
int l=0; l< quadPSize; l++){
934 for(
int p=0; p< dim_ ; p++){
935 for(
int q=0; q< dim_; q++){
936 quadPointsT1[l][p] += Binv1[p][q]* (quadPoints[l][q] - points->at(elements->getElement(elementsIDs[i]).getNode(0)).at(q)) ;
942 for(
int l=0; l< quadPSize; l++){
943 if(phiDerivative ==
"Gradient"){
944 vec2D_dbl_Type deriPhi1 =
gradPhi(dim_, intFE, quadPointsT1[l]);
945 vec2D_dbl_Type deriPhiT1(numNodes,vec_dbl_Type(dim_));
946 for(
int q=0; q<dim_; q++){
947 for(
int p=0;p<numNodes; p++){
948 for(
int s=0; s< dim_ ; s++)
949 deriPhiT1[p][q] += (deriPhi1[p][s]*Binv1[s][q]);
952 vec2D_dbl_Type u1_Tmp(dofsSol, vec_dbl_Type(dim_));
953 Teuchos::ArrayRCP< SC > valuesSolRep;
954 for(
int d =0; d < dofsSol ; d++){
955 valuesSolRep = valuesSolutionRepVel_->getBlock(d)->getDataNonConst(0);
956 for(
int s=0; s<dim_; s++){
957 for(
int t=0; t< numNodes ; t++){
958 u1_Tmp[d][s] += valuesSolRep[kn1[t]]*deriPhiT1[t][s] ;
964 for(
int d =0; d < dofsSol ; d++){
965 for(
int s=0; s<dim_; s++){
966 vec_El1[k][l][d] += (u1_Tmp[d][s])*(v_E[s]/norm_v_E);
968 vec_El1[k][l][d] = std::sqrt(quadWeights[l])* vec_El1[k][l][d];
972 for(
int d =0; d < dofsSol ; d++){
973 for(
int s=0; s<dim_; s++){
974 vec_El2[k][l][d] += (u1_Tmp[d][s])*(v_E[s]/norm_v_E);
976 vec_El2[k][l][d] = std::sqrt(quadWeights[l])* vec_El2[k][l][d];
983 if(phiDerivative ==
"None"){
984 vec_dbl_Type phiV =
phi(dim_, intFE, quadPointsT1[l]);
985 vec_dbl_Type vec_Tmp(dofsSol);
986 Teuchos::ArrayRCP< SC > valuesSolRep;
987 for(
int d =0; d < dofsSol ; d++){
988 valuesSolRep = valuesSolutionRepPre_->getBlock(d)->getDataNonConst(0);
989 for(
int t=0; t< phiV.size() ; t++){
990 vec_Tmp[d] += valuesSolRep[kn1[t]]*phiV[t] ;
994 for(
int d =0; d < dofsSol ; d++){
995 for(
int s=0; s<dim_; s++){
996 vec_El1[k][l][d] += (vec_Tmp[d])*(v_E[s]/norm_v_E);
998 vec_El1[k][l][d] = std::sqrt(quadWeights[l])* vec_El1[k][l][d];
1002 for(
int d =0; d < dofsSol ; d++){
1003 for(
int s=0; s<dim_; s++){
1004 vec_El2[k][l][d] += (vec_Tmp[d])*(v_E[s]/norm_v_E);
1006 vec_El2[k][l][d] = std::sqrt(quadWeights[l])* vec_El2[k][l][d];
1015 if(elementsOfSurfaceLocal.at(k).at(0) == -1 || elementsOfSurfaceLocal.at(k).at(1) == -1){
1017 elementImportIDs.push_back(surfaceMap->getGlobalElement(k));
1019 for(
int l=0; l< vec_El1[k].size() ;l++){
1020 for(
int d =0; d < dofsSol ; d++)
1021 vec_El_Exp[k][l][d] = vec_El1[k][l][d];
1026 inputMesh_->getComm()->barrier();
1030 sort(elementImportIDs.begin(),elementImportIDs.end());
1032 vec_GO_Type::iterator ip = unique( elementImportIDs.begin(), elementImportIDs.end());
1034 elementImportIDs.resize(distance(elementImportIDs.begin(), ip));
1035 Teuchos::ArrayView<GO> globalElementArrayImp = Teuchos::arrayViewFromVector( elementImportIDs);
1038 MapPtr_Type mapElementImport =
1039 Teuchos::rcp(
new Map_Type( Teuchos::OrdinalTraits<GO>::invalid(), globalElementArrayImp, 0, inputMesh_->getComm()) );
1042 int maxRank = std::get<1>(inputMesh_->rankRange_);
1043 MapPtr_Type mapElementsUnique = mapElementImport;
1046 if(maxRank>0 && mapElementsUnique->getMaxAllGlobalIndex() > 0)
1047 mapElementsUnique = mapElementImport->buildUniqueMap( inputMesh_->rankRange_ );
1051 MultiVectorPtr_Type valuesU_x_expU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1052 MultiVectorPtr_Type valuesU_y_expU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1053 MultiVectorPtr_Type valuesU_z_expU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1055 MultiVectorPtr_Type valuesU_x_impU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1056 MultiVectorPtr_Type valuesU_y_impU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1057 MultiVectorPtr_Type valuesU_z_impU = Teuchos::rcp(
new MultiVector_Type( mapElementsUnique, 1 ) );
1060 MultiVectorPtr_Type valuesU_x_imp = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1061 MultiVectorPtr_Type valuesU_y_imp = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1062 MultiVectorPtr_Type valuesU_z_imp = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1064 MultiVectorPtr_Type valuesU_x_impF = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1065 MultiVectorPtr_Type valuesU_y_impF = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1066 MultiVectorPtr_Type valuesU_z_impF = Teuchos::rcp(
new MultiVector_Type( mapElementImport, 1 ) );
1069 Teuchos::ArrayRCP< SC > entriesU_x_imp = valuesU_x_imp->getDataNonConst(0);
1070 Teuchos::ArrayRCP< SC > entriesU_y_imp = valuesU_y_imp->getDataNonConst(0);
1071 Teuchos::ArrayRCP< SC > entriesU_z_imp = valuesU_z_imp->getDataNonConst(0);
1073 Teuchos::ArrayRCP< SC > entriesU_x_impF = valuesU_x_impF->getDataNonConst(0);
1074 Teuchos::ArrayRCP< SC > entriesU_y_impF = valuesU_y_impF->getDataNonConst(0);
1075 Teuchos::ArrayRCP< SC > entriesU_z_impF = valuesU_z_impF->getDataNonConst(0);
1078 for(
int i=0; i<quadPSize; i++){
1079 for(
int j=0; j<elementImportIDs.size(); j++){
1080 entriesU_x_imp[j] = vec_El_Exp[surfaceMap->getLocalElement(elementImportIDs[j])][i][0] ;
1082 entriesU_y_imp[j] = vec_El_Exp[surfaceMap->getLocalElement(elementImportIDs[j])][i][1] ;
1083 else if(dofsSol == 3)
1084 entriesU_z_imp[j] = vec_El_Exp[surfaceMap->getLocalElement(elementImportIDs[j])][i][2] ;
1087 valuesU_x_impU->importFromVector(valuesU_x_imp,
false,
"Insert");
1088 valuesU_y_impU->importFromVector(valuesU_y_imp,
false,
"Insert");
1089 valuesU_z_impU->importFromVector(valuesU_z_imp,
false,
"Insert");
1091 valuesU_x_expU->exportFromVector(valuesU_x_imp,
false,
"Insert");
1092 valuesU_y_expU->exportFromVector(valuesU_y_imp,
false,
"Insert");
1093 valuesU_z_expU->exportFromVector(valuesU_z_imp,
false,
"Insert");
1095 valuesU_x_impF->importFromVector(valuesU_x_impU,
false,
"Insert");
1096 valuesU_y_impF->importFromVector(valuesU_y_impU,
false,
"Insert");
1097 valuesU_z_impF->importFromVector(valuesU_z_impU,
false,
"Insert");
1099 valuesU_x_impF->exportFromVector(valuesU_x_expU,
false,
"Insert");
1100 valuesU_y_impF->exportFromVector(valuesU_y_expU,
false,
"Insert");
1101 valuesU_z_impF->exportFromVector(valuesU_z_expU,
false,
"Insert");
1103 for(
int j=0; j<elementImportIDs.size(); j++){
1104 vec_El2[surfaceMap->getLocalElement(elementImportIDs[j])][i][0] =entriesU_x_impF[j];
1106 vec_El2[surfaceMap->getLocalElement(elementImportIDs[j])][i][1] =entriesU_y_impF[j];
1107 else if(dofsSol ==3)
1108 vec_El2[surfaceMap->getLocalElement(elementImportIDs[j])][i][2] = entriesU_z_impF[j];
1111 for(
int i=0; i< numberSurfaceElements ; i++){
1112 for(
int j=0; j<quadPSize; j++){
1113 for(
int k=0; k< dofsSol ; k++){
1114 vec_El[i][j][k] = std::fabs(vec_El1[i][j][k]) - std::fabs(vec_El2[i][j][k]);
1323 vec_dbl_Type resElement(dofs_);
1325 int dim = this->dim_;
1334 vec_dbl_Type QuadW(t);
1335 vec2D_dbl_Type QuadPts =
getQuadValues(dim, FEType2_,
"Element", QuadW, element);
1338 if(this->FEType2_ ==
"P2")
1341 vec2D_dbl_ptr_Type points = inputMesh_->getPointsRepeated();
1345 vec_LO_Type nodeList = element.getVectorNodeListNonConst();
1352 int index0 = nodeList[0];
1353 for (
int s=0; s<dim; s++) {
1354 int index = nodeList[s+1];
1355 for (
int t=0; t<dim; t++) {
1356 B1[t][s] = points->at(index).at(t) - points->at(index0).at(t);
1361 detB1 = B1.computeInverse(Binv1);
1362 detB1 = std::fabs(detB1);
1364 vec_dbl_Type valueFunc(dofs_);
1366 vec2D_dbl_Type quadPointsTrans(QuadW.size(),vec_dbl_Type(dim));
1368 for(
int i=0; i< QuadW.size(); i++){
1369 for(
int j=0; j< dim; j++){
1370 for(
int k=0; k< dim; k++){
1371 quadPointsTrans[i][j] += B1[j][k]* QuadPts[i].at(k) ;
1373 quadPointsTrans[i][j] += points->at(element.getNode(0)).at(j);
1377 vec_dbl_Type nablaP(dim);
1378 if(problemType_ ==
"Stokes" || problemType_ ==
"NavierStokes"){
1379 Teuchos::ArrayRCP<SC> valuesSolutionRepPre = valuesSolutionRepPre_->getBlock(0)->getDataNonConst(0);
1380 vec2D_dbl_Type deriPhi =
gradPhi(dim, 1, QuadPts[0]);
1381 vec2D_dbl_Type deriPhiT(dim+1,vec_dbl_Type(dim));
1382 for(
int q=0; q<dim; q++){
1383 for(
int p=0;p<dim+1; p++){
1384 for(
int s=0; s< dim ; s++)
1385 deriPhiT[p][q] += (deriPhi[p][s]*Binv1[s][q]);
1389 for(
int s=0; s<dim; s++){
1390 for(
int t=0; t< dim+1 ; t++){
1391 nablaP[s] += valuesSolutionRepPre[nodeList[t]]*deriPhiT[t][s] ;
1396 vec2D_dbl_Type nablaU(dim,vec_dbl_Type(QuadW.size()));
1397 if(problemType_ ==
"NavierStokes"){
1398 for (UN w=0; w< QuadW.size(); w++){
1399 vec2D_dbl_Type deriPhi =
gradPhi(dim, intFE, QuadPts[w]);
1400 vec2D_dbl_Type deriPhiT(nodeList.size(),vec_dbl_Type(dim));
1401 for(
int q=0; q<dim; q++){
1402 for(
int p=0;p<nodeList.size(); p++){
1403 for(
int s=0; s< dim ; s++)
1404 deriPhiT[p][q] += (deriPhi[p][s]*Binv1[s][q]);
1408 Teuchos::ArrayRCP< SC > valuesSolRep;
1409 vec2D_dbl_Type vec_Tmp(nodeList.size(),vec_dbl_Type(dofs_));
1410 for(
int d =0; d < dofs_ ; d++){
1411 valuesSolRep = valuesSolutionRepVel_->getBlock(d)->getDataNonConst(0);
1412 for(
int t=0; t< nodeList.size() ; t++){
1413 vec_Tmp[t][d] = valuesSolRep[nodeList[t]];
1417 vec2D_dbl_Type u1_Tmp(dofs_, vec_dbl_Type(dim_));
1419 for(
int d =0; d < dofs_ ; d++){
1420 valuesSolRep = valuesSolutionRepVel_->getBlock(d)->getDataNonConst(0);
1421 for(
int s=0; s<dim; s++){
1422 for(
int t=0; t< nodeList.size() ; t++){
1423 u1_Tmp[d][s] += valuesSolRep[nodeList[t]]*deriPhiT[t][s] ;
1427 vec_dbl_Type phiV =
phi(dim, intFE, QuadPts[w]);
1428 for(
int d =0; d < dofs_ ; d++){
1429 for(
int t=0; t< nodeList.size() ; t++){
1430 for(
int s=0; s<dim; s++){
1431 nablaU[d][w] += vec_Tmp[t][s]*phiV[t]*u1_Tmp[s][d];
1439 vec_dbl_Type deltaU(dofs_);
1440 if(this->FEType2_ ==
"P2"){
1441 vec_dbl_Type deltaPhi(nodeList.size());
1442 if(this->dim_ == 2){
1443 deltaPhi={8, 4, 4, -8, 0, -8 };
1445 else if(this->dim_ == 3)
1446 deltaPhi={12, 4, 4, 4, -8, 0, -8, -8, 0, 0};
1448 for(
int j=0 ; j< dofs_; j++){
1449 Teuchos::ArrayRCP<SC> valuesSolutionRep = valuesSolutionRepVel_->getBlock(j)->getDataNonConst(0);
1450 for(
int i=0; i< nodeList.size() ; i++){
1451 deltaU[j] += deltaPhi[i]*valuesSolutionRep[nodeList[i]];
1455 for (UN w=0; w< QuadW.size(); w++){
1456 rhsFunc(&quadPointsTrans[w][0], &valueFunc[0] ,paras);
1457 for(
int j=0 ; j< dofs_; j++){
1458 resElement[j] += QuadW[w] * std::pow(valueFunc[j] + deltaU[j] - nablaU[j][w] - nablaP[j] ,2);
1461 double resElementValue =0.;
1462 for(
int j=0; j< dofs_ ; j++)
1463 resElementValue += resElement[j] *detB1;
1465 return resElementValue;
2034 int maxRank = std::get<1>(inputMesh_->rankRange_);
2035 const int myRank = inputMesh_->getComm()->getRank();
2037 vec_GO_Type globalProcs(0);
2038 for (
int i=0; i<= maxRank; i++)
2039 globalProcs.push_back(i);
2041 Teuchos::ArrayView<GO> globalProcArray = Teuchos::arrayViewFromVector( globalProcs);
2043 vec_GO_Type localProc(0);
2044 localProc.push_back(inputMesh_->getComm()->getRank());
2045 Teuchos::ArrayView<GO> localProcArray = Teuchos::arrayViewFromVector( localProc);
2047 MapPtr_Type mapGlobalProc =
2048 Teuchos::rcp(
new Map_Type( Teuchos::OrdinalTraits<GO>::invalid(), globalProcArray, 0, inputMesh_->getComm()) );
2050 MapPtr_Type mapProc =
2051 Teuchos::rcp(
new Map_Type( Teuchos::OrdinalTraits<GO>::invalid(), localProcArray, 0, inputMesh_->getComm()) );
2055 vec2D_int_Type interfaceSurfacesLocalId(1,vec_int_Type(1));
2058 MultiVectorLOPtr_Type exportLocalEntry = Teuchos::rcp(
new MultiVectorLO_Type( mapProc, 1 ) );
2062 int numSurfaces= surfaceElements_->numberElements();
2063 vec2D_GO_Type inzidenzIndices(0,vec_GO_Type(2));
2064 vec_LO_Type localSurfaceIndex(0);
2066 int surfacesUnique=0;
2068 vec2D_dbl_ptr_Type points = inputMesh_->getPointsRepeated();
2070 vec2D_GO_Type elementsOfSurfaceGlobal = surfaceElements_->getElementsOfSurfaceGlobal();
2072 vec_GO_Type elementRep(0);
2075 for(
int i=0; i<numSurfaces; i++ ){
2076 if(surfaceElements_->getElement(i).isInterfaceElement()){
2078 id[0] = elementsOfSurfaceGlobal[i][0];
2079 id[1] = elementsOfSurfaceGlobal[i][1];
2083 sort(
id.begin(),
id.end());
2084 inzidenzIndices.push_back(
id);
2086 localSurfaceIndex.push_back(i);
2095 for(
int j=0; j < elementsOfSurfaceGlobal[i].size() ; j++)
2096 elementRep.push_back(elementsOfSurfaceGlobal[i][j]);
2100 sort(elementRep.begin(),elementRep.end());
2101 vec_GO_Type::iterator ip = unique( elementRep.begin(), elementRep.end());
2102 elementRep.resize(distance(elementRep.begin(), ip));
2104 Teuchos::ArrayView<GO> elementRepArray = Teuchos::arrayViewFromVector( elementRep);
2106 MapPtr_Type elementMapRep =
2107 Teuchos::rcp(
new Map_Type( Teuchos::OrdinalTraits<GO>::invalid(), elementRepArray, 0, inputMesh_->getComm()) );
2113 MatrixPtr_Type inzidenzMatrix = Teuchos::rcp(
new Matrix_Type(inputMesh_->getElementMap(), 40 ) );
2114 Teuchos::Array<GO> index(1);
2115 Teuchos::Array<GO> col(1);
2116 Teuchos::Array<SC> value(1, Teuchos::ScalarTraits<SC>::one() );
2118 for(
int i=0; i<inzidenzIndices.size(); i++ ){
2119 index[0] = inzidenzIndices[i][0];
2120 col[0] = inzidenzIndices[i][1];
2121 inzidenzMatrix->insertGlobalValues(index[0], col(), value());
2123 inzidenzMatrix->fillComplete();
2131 exportLocalEntry->putScalar( (LO) surfacesUnique );
2133 MultiVectorLOPtr_Type newSurfacesUniqueGlobal= Teuchos::rcp(
new MultiVectorLO_Type( mapGlobalProc, 1 ) );
2134 newSurfacesUniqueGlobal->putScalar( (LO) 0 );
2135 newSurfacesUniqueGlobal->importFromVector( exportLocalEntry,
false,
"Insert");
2138 Teuchos::ArrayRCP< const LO > newSurfacesList = newSurfacesUniqueGlobal->getData(0);
2140 GO procOffsetSurface=0;
2141 for(
int i=0; i< myRank; i++)
2142 procOffsetSurface= procOffsetSurface + newSurfacesList[i];
2145 vec_GO_Type vecGlobalIDsSurfaces(numSurfaces);
2149 for(
int i=0; i< numSurfaces; i++){
2150 if(!surfaceElements_->getElement(i).isInterfaceElement()){
2151 vecGlobalIDsSurfaces.at(i) = procOffsetSurface+count;
2158 GO offsetInterface=0;
2159 for(
int i=0; i< maxRank+1; i++)
2160 offsetInterface= offsetInterface + newSurfacesList[i];
2164 Teuchos::ArrayView<const LO> indices;
2165 Teuchos::ArrayView<const SC> values;
2166 vec2D_GO_Type inzidenzIndicesUnique(0,vec_GO_Type(2));
2167 MapConstPtr_Type colMap = inzidenzMatrix->getMap(
"col");
2168 MapConstPtr_Type rowMap = inzidenzMatrix->getMap(
"row");
2169 int numRows = rowMap->getNodeNumElements();
2170 int uniqueSurfaces =0;
2171 for(
int i=0; i<numRows; i++ ){
2172 inzidenzMatrix->getLocalRowView(i, indices,values);
2173 uniqueSurfaces = uniqueSurfaces+indices.size();
2174 vec_GO_Type surfaceTmp(2);
2175 for(
int j=0; j<indices.size(); j++){
2176 surfaceTmp[0] = rowMap->getGlobalElement(i);
2177 surfaceTmp[1] = colMap->getGlobalElement(indices[j]);
2178 inzidenzIndicesUnique.push_back(surfaceTmp);
2182 exportLocalEntry->putScalar( uniqueSurfaces);
2183 MultiVectorLOPtr_Type newSurfaceInterfaceGlobal= Teuchos::rcp(
new MultiVectorLO_Type( mapGlobalProc, 1 ) );
2184 newSurfaceInterfaceGlobal->putScalar( (LO) 0 );
2185 newSurfaceInterfaceGlobal->importFromVector( exportLocalEntry,
true,
"Insert");
2188 Teuchos::ArrayRCP< const LO > numUniqueInterface = newSurfaceInterfaceGlobal->getData(0);
2190 procOffsetSurface=0;
2191 for(
int i=0; i< myRank; i++)
2192 procOffsetSurface= procOffsetSurface + numUniqueInterface[i];
2194 int numInterfaceSurface=0;
2196 vec_GO_Type uniqueInterfaceIDsList_(inzidenzIndicesUnique.size());
2197 for(
int i=0; i< uniqueInterfaceIDsList_.size(); i++)
2198 uniqueInterfaceIDsList_[i] = procOffsetSurface + i;
2200 MatrixPtr_Type indMatrix = Teuchos::rcp(
new Matrix_Type(inputMesh_->getElementMap(), 40 ) );
2202 for(
int i=0; i<inzidenzIndicesUnique.size(); i++ ){
2203 index[0] = inzidenzIndicesUnique[i][0];
2204 col[0] = inzidenzIndicesUnique[i][1];
2205 Teuchos::Array<SC> value2(1,uniqueInterfaceIDsList_[i]);
2206 indMatrix->insertGlobalValues(index[0], col(), value2());
2208 indMatrix->fillComplete();
2210 MatrixPtr_Type importMatrix = Teuchos::rcp(
new Matrix_Type(elementMapRep, 40 ) );
2212 importMatrix->importFromVector(indMatrix,
false,
"Insert");
2213 importMatrix->fillComplete();
2217 colMap = importMatrix->getMap(
"col");
2218 rowMap = importMatrix->getMap(
"row");
2222 for(
int i=0; i<inzidenzIndices.size(); i++ ){
2224 importMatrix->getLocalRowView(rowMap->getLocalElement(inzidenzIndices[i][0]), indices,values);
2228 vec2D_GO_Type indicesTmp(indices.size(),vec_GO_Type(2));
2229 vec_GO_Type indTmp(2);
2230 for(
int j=0; j<indices.size(); j++){
2231 indTmp[0] = colMap->getGlobalElement(indices[j]);
2232 indTmp[1] = values[j];
2233 indicesTmp.push_back(indTmp);
2237 for(
int k=0; k<indicesTmp.size();k++){
2238 if(inzidenzIndices[i][1] == indicesTmp[k][0]){
2240 k = indicesTmp.size();
2241 surfaceID = indicesTmp[entry][1];
2242 vecGlobalIDsSurfaces.at(localSurfaceIndex[i]) = offsetInterface + surfaceID;
2247 cout <<
" Asking for row " << rowMap->getLocalElement(inzidenzIndices[i][0]) <<
" for Edge [" << inzidenzIndices[i][0] <<
", " << inzidenzIndices[i][1] <<
"], on Proc " << myRank <<
" but no Value found " <<endl;
2251 Teuchos::RCP<std::vector<GO>> surfacesGlobMapping = Teuchos::rcp(
new std::vector<GO>( vecGlobalIDsSurfaces ) );
2252 Teuchos::ArrayView<GO> surfacesGlobMappingArray = Teuchos::arrayViewFromVector( *surfacesGlobMapping);
2254 this->surfaceTriangleMap_.reset(
new Map<LO,GO,NO>(Teuchos::OrdinalTraits<GO>::invalid(), surfacesGlobMappingArray, 0, inputMesh_->getComm()) );