View Issue Details

IDProjectCategoryView StatusLast Update
0003939OpenFOAMPatchpublic2022-12-05 13:52
Reportercgoessni Assigned Tohenry  
PrioritylowSeverityfeatureReproducibilityN/A
Status closedResolutionsuspended 
Product Versiondev 
Summary0003939: meshToMesh: Improved error messages due to missing patches in patchMap
DescriptionI saw some crashes with meshToMesh class, where patchToPatch would just segfault when I did not use -consistent flag for mapFieldsPar. After debugging the issue, it turned out that the error was on my side: I specified patches in the patchMap list which did not exist in one of the meshes (src/tgt). If you think this addition is worth it, I provided a simple patch to give a useful error message to the user. It might help users to easily identify and avoid such setup mistakes in the future.
TagsNo tags attached.

Activities

cgoessni

2022-11-30 07:00

reporter  

diff_meshToMesh_C.txt (1,365 bytes)   
diff --git a/src/meshTools/meshToMesh/meshToMesh.C b/src/meshTools/meshToMesh/meshToMesh.C
index dd2d6b1..cb38291 100644
--- a/src/meshTools/meshToMesh/meshToMesh.C
+++ b/src/meshTools/meshToMesh/meshToMesh.C
@@ -287,12 +287,32 @@ void Foam::meshToMesh::constructFromCuttingPatches
         const word& tgtPatchName = iter.key();
         const word& srcPatchName = iter();
 
-        srcToTgtPatchIDs_[i++] =
-            labelPair
-            (
-                srcMesh_.boundaryMesh().findPatchID(srcPatchName),
-                tgtMesh_.boundaryMesh().findPatchID(tgtPatchName)
-            );
+	const label tgtPatchi =
+            tgtMesh_.boundaryMesh().findPatchID(tgtPatchName);
+        const label srcPatchi =
+            srcMesh_.boundaryMesh().findPatchID(srcPatchName);
+
+	if (tgtPatchi == -1)
+	{
+	    FatalErrorInFunction
+		<< "Patch " << tgtPatchName
+		<< " not found in target mesh. "
+		<< "Available target patches are "
+		<< tgtMesh_.boundaryMesh().names()
+		<< exit(FatalError);
+	}
+
+	if (srcPatchi == -1)
+	{
+	    FatalErrorInFunction
+		<< "Patch " << srcPatchName
+		<< " not found in source mesh. "
+		<< "Available source patches are "
+		<< srcMesh_.boundaryMesh().names()
+		<< exit(FatalError);
+	}
+
+        srcToTgtPatchIDs_[i++] = labelPair(srcPatchi, tgtPatchi);
     }
 
     // calculate patch addressing and weights
diff_meshToMesh_C.txt (1,365 bytes)   

henry

2022-12-05 13:52

manager   ~0012907

Suspended pending contribution agreement.

Issue History

Date Modified Username Field Change
2022-11-30 07:00 cgoessni New Issue
2022-11-30 07:00 cgoessni File Added: diff_meshToMesh_C.txt
2022-12-05 13:52 henry Assigned To => henry
2022-12-05 13:52 henry Status new => closed
2022-12-05 13:52 henry Resolution open => suspended
2022-12-05 13:52 henry Note Added: 0012907