[cig-commits] commit: Add NearestNeighbor_FindNeighbor
Mercurial
hg at geodynamics.org
Sun Oct 16 05:46:59 PDT 2011
changeset: 431:d772b0a9c881
user: Walter Landry <wlandry at caltech.edu>
date: Sun Oct 16 05:42:57 2011 -0700
files: MaterialPoints/src/NearestNeighborMapper.cxx MaterialPoints/src/NearestNeighborMapper.h
description:
Add NearestNeighbor_FindNeighbor
diff -r ca263445fe73 -r d772b0a9c881 MaterialPoints/src/NearestNeighborMapper.cxx
--- a/MaterialPoints/src/NearestNeighborMapper.cxx Sun Oct 16 05:42:05 2011 -0700
+++ b/MaterialPoints/src/NearestNeighborMapper.cxx Sun Oct 16 05:42:57 2011 -0700
@@ -52,6 +52,7 @@
#include <assert.h>
#include <string.h>
#include <math.h>
+#include <limits>
#include "MaterialPoints.h"
@@ -208,3 +209,38 @@ double _NearestNeighborMapper_GetDoubleF
abort();
return 0;
}
+
+/* This does a search over all of the particles in the swarm in the
+ element to find the one that is closest to the gauss point. There
+ may be more efficient ways of doing this, but this works for
+ now. */
+int NearestNeighbor_FindNeighbor(void* mapper, const Element_LocalIndex &lElement_I,
+ const int &cell_I, double *xi, const int &dim)
+{
+ NearestNeighborMapper* self = (NearestNeighborMapper*)mapper;
+ IntegrationPointsSwarm* swarm=self->swarm;
+
+ int cellParticleCount(swarm->cellParticleCountTbl[cell_I]);
+
+ Journal_Firewall(cellParticleCount!=0,
+ Journal_Register(Error_Type,(Name)NearestNeighborMapper_Type),
+ "In func %s: cellParticleCount is 0.\n",__func__);
+
+ double min_dist(std::numeric_limits<double>::max());
+ int nearest_particle(-1);
+
+ for(int cParticle_I=0; cParticle_I<cellParticleCount; cParticle_I++)
+ {
+ IntegrationPoint* particle=
+ (IntegrationPoint*)Swarm_ParticleInCellAt(swarm,cell_I,cParticle_I);
+
+ double dist=
+ StGermain_DistanceBetweenPoints(xi,particle->xi,dim);
+ if(dist<min_dist)
+ {
+ nearest_particle=cParticle_I;
+ min_dist=dist;
+ }
+ }
+ return nearest_particle;
+}
diff -r ca263445fe73 -r d772b0a9c881 MaterialPoints/src/NearestNeighborMapper.h
--- a/MaterialPoints/src/NearestNeighborMapper.h Sun Oct 16 05:42:05 2011 -0700
+++ b/MaterialPoints/src/NearestNeighborMapper.h Sun Oct 16 05:42:57 2011 -0700
@@ -116,4 +116,9 @@ void _NearestNeighborMapper_Init( void*
ExtensionInfo_Index extHandle,
int offs);
+ int NearestNeighbor_FindNeighbor(void* mapper,
+ const Element_LocalIndex &lElement_I,
+ const int &cell_I,
+ double *xi, const int &dim);
+
#endif
More information about the CIG-COMMITS
mailing list