@@ -348,3 +348,113 @@ TEST(CurvilinearGridUniform, DeleteInteriorNodesFailureTest)
348
348
EXPECT_THROW (curvilinearGrid->DeleteInterior ({1 , 1 }, {nx, ny}), meshkernel::ConstraintError);
349
349
EXPECT_THROW (curvilinearGrid->DeleteInterior ({nx, 1 }, {4 , 4 }), meshkernel::ConstraintError);
350
350
}
351
+
352
+ void TestDeleteExteriorNodes (std::shared_ptr<meshkernel::CurvilinearGrid> curvilinearGrid,
353
+ const meshkernel::CurvilinearGridNodeIndices first,
354
+ const meshkernel::CurvilinearGridNodeIndices second)
355
+ {
356
+ // Check first, that all nodes are valid
357
+ for (meshkernel::UInt i = 0 ; i < curvilinearGrid->m_numN ; ++i)
358
+ {
359
+ for (meshkernel::UInt j = 0 ; j < curvilinearGrid->m_numM ; ++j)
360
+ {
361
+ EXPECT_TRUE (curvilinearGrid->GetNode (i, j).IsValid ());
362
+ }
363
+ }
364
+
365
+ meshkernel::UInt lowerLimitI = std::min (first.m_n , second.m_n );
366
+ meshkernel::UInt upperLimitI = std::max (first.m_n , second.m_n );
367
+
368
+ meshkernel::UInt lowerLimitJ = std::min (first.m_m , second.m_m );
369
+ meshkernel::UInt upperLimitJ = std::max (first.m_m , second.m_m );
370
+
371
+ meshkernel::UInt expectedValid = (upperLimitI - lowerLimitI + 1 ) * (upperLimitJ - lowerLimitJ + 1 );
372
+
373
+ // Delete the nodes outside of a block
374
+ curvilinearGrid->DeleteExterior (first, second);
375
+
376
+ auto inRange = [](const meshkernel::UInt v, const meshkernel::UInt l, const meshkernel::UInt u)
377
+ { return l <= v && v <= u; };
378
+
379
+ EXPECT_EQ (expectedValid, CurvilinearGridCountValidNodes (curvilinearGrid));
380
+
381
+ // Check that these exterior nodes have been set to invalid.
382
+ for (meshkernel::UInt i = 0 ; i < curvilinearGrid->m_numN ; ++i)
383
+ {
384
+ for (meshkernel::UInt j = 0 ; j < curvilinearGrid->m_numM ; ++j)
385
+ {
386
+ if (inRange (i, lowerLimitI, upperLimitI) && inRange (j, lowerLimitJ, upperLimitJ))
387
+ {
388
+ EXPECT_TRUE (curvilinearGrid->GetNode (i, j).IsValid ()) << " node should be true: " << i << " " << j;
389
+ }
390
+ else
391
+ {
392
+ EXPECT_FALSE (curvilinearGrid->GetNode (i, j).IsValid ()) << " node should be false: " << i << " " << j;
393
+ }
394
+ }
395
+ }
396
+ }
397
+
398
+ TEST (CurvilinearGridUniform, DeleteExteriorNodesTest)
399
+ {
400
+ // Basic, testing of setting nodes inside a box to invalid
401
+ meshkernel::UInt nx = 10 ;
402
+ meshkernel::UInt ny = 10 ;
403
+ std::shared_ptr<meshkernel::CurvilinearGrid> curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
404
+ TestDeleteExteriorNodes (curvilinearGrid, {1 , 1 }, {4 , 4 });
405
+
406
+ // Reset the mesh
407
+ curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
408
+ TestDeleteExteriorNodes (curvilinearGrid, {2 , 1 }, {5 , 4 });
409
+
410
+ // Reset the mesh
411
+ curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
412
+ TestDeleteExteriorNodes (curvilinearGrid, {4 , 3 }, {7 , 8 });
413
+ }
414
+
415
+ TEST (CurvilinearGridUniform, DeleteExteriorNodesReverseTest)
416
+ {
417
+ // testing of setting nodes inside a box to invalid, with lower and upper reversed
418
+
419
+ meshkernel::UInt nx = 10 ;
420
+ meshkernel::UInt ny = 10 ;
421
+
422
+ // Prepare
423
+ std::shared_ptr<meshkernel::CurvilinearGrid> curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
424
+ TestDeleteExteriorNodes (curvilinearGrid, {5 , 6 }, {1 , 2 });
425
+
426
+ // Reset the mesh
427
+ curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
428
+ TestDeleteExteriorNodes (curvilinearGrid, {5 , 6 }, {0 , 4 });
429
+ }
430
+
431
+ TEST (CurvilinearGridUniform, DeleteExteriorNodesMixedTest)
432
+ {
433
+ // testing of setting nodes inside a box to invalid, with lower and upper reversed for any of i and j index
434
+
435
+ meshkernel::UInt nx = 100 ;
436
+ meshkernel::UInt ny = 100 ;
437
+
438
+ std::shared_ptr<meshkernel::CurvilinearGrid> curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
439
+ TestDeleteExteriorNodes (curvilinearGrid, {5 , 1 }, {1 , 6 });
440
+
441
+ // Reset grid
442
+ curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
443
+ TestDeleteExteriorNodes (curvilinearGrid, {1 , 6 }, {5 , 2 });
444
+ }
445
+
446
+ TEST (CurvilinearGridUniform, DeleteExteriorNodesFailureTest)
447
+ {
448
+ // testing of setting nodes inside a box to invalid with invalid or out of range indices.
449
+
450
+ meshkernel::UInt nx = 10 ;
451
+ meshkernel::UInt ny = 10 ;
452
+
453
+ // Prepare
454
+ std::shared_ptr<meshkernel::CurvilinearGrid> curvilinearGrid = MakeCurvilinearGrid (0.0 , 0.0 , 1.0 , 1.0 , nx, ny);
455
+
456
+ EXPECT_THROW (curvilinearGrid->DeleteExterior ({1 , meshkernel::constants::missing::uintValue}, {nx, ny}), meshkernel::ConstraintError);
457
+ EXPECT_THROW (curvilinearGrid->DeleteExterior ({1 , 1 }, {meshkernel::constants::missing::uintValue, ny}), meshkernel::ConstraintError);
458
+ EXPECT_THROW (curvilinearGrid->DeleteExterior ({1 , 1 }, {nx, ny}), meshkernel::ConstraintError);
459
+ EXPECT_THROW (curvilinearGrid->DeleteExterior ({nx, 1 }, {4 , 4 }), meshkernel::ConstraintError);
460
+ }
0 commit comments