Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cassiopee/Converter/Converter/Check.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def checkBCRanges(t, ntype):
zones = Internal.getZones(t)
for z in zones:
dim = Internal.getZoneDim(z)
if dim[0] != 'Structured': continue # pas de check en non structure
bcs = Internal.getNodesFromType1(z, ctype)
for bc in bcs:
nodes = Internal.getNodesFromType1(bc, ntype)
Expand Down Expand Up @@ -594,6 +595,7 @@ def checkDonorRanges(t, ntype):
if donors != []:
if all([Internal.getType(d) == 'Zone_t' for d in donors]):
dim = Internal.getZoneDim(donors[0])
if dim[0] != 'Structured': continue # pas de check en non structure
r = Internal.getElementRange(donors[0], type="NGON")
if r is not None: nfaces = r[1]-r[0]+1
else: nfaces = 0
Expand Down
53 changes: 23 additions & 30 deletions Cassiopee/Converter/Converter/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ def setFields(arrays, t, loc, writeDim=True):
# un array * ne peut pas etre mis en nodes
if loc == 'nodes' and len(a) == 4:
elt = a[3]
if elt[len(elt)-1] == '*':
if elt[-1] == '*':
print('Warning: setFields: %s array is not set.'%elt)
vars = []
p = 0
Expand Down Expand Up @@ -3189,7 +3189,7 @@ def _cpVars__(z1, var1, z2, var2):
z2[2].append([Internal.__FlowSolutionCenters__, None, [], 'FlowSolution_t'])
f = Internal.getNodeFromName1(z2, Internal.__FlowSolutionCenters__)
Internal._createUniqueChild(f, 'GridLocation', 'GridLocation_t', 'CellCenter')
h = z2[2][len(z2[2])-1]
h = z2[2][-1]
else:
h = place2
var2s = var2.split(':')
Expand Down Expand Up @@ -3754,7 +3754,7 @@ def _addFamilyOfStageGC__(z, bndName, bndType2, typeZone=0, faceList=None, eleme
zoneGC = Internal.getNodesFromType1(z, 'ZoneGridConnectivity_t')
if zoneGC == []:
z[2].append(['ZoneGridConnectivity', None, [], 'ZoneGridConnectivity_t'])
zoneGC = z[2][len(z[2])-1]
zoneGC = z[2][-1]
else:
zoneGC = zoneGC[0]
# Cree le noeud de GC
Expand All @@ -3772,7 +3772,7 @@ def _addFamilyOfStageGC__(z, bndName, bndType2, typeZone=0, faceList=None, eleme
if st == "": st = i[0]
else: st = st+","+i[0]
Internal._createChild(zoneGC, bndName, 'GridConnectivity_t', value=st)
info = zoneGC[2][len(zoneGC[2])-1]
info = zoneGC[2][-1]

if typeZone == 0: # STRUCTURED
if pointRange == []: raise ValueError("_addFamilyOfStageGC__: pointRange is empty.")
Expand Down Expand Up @@ -3853,14 +3853,13 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
zoneGC = Internal.getNodeFromType1(z, 'ZoneGridConnectivity_t')
if zoneGC is None:
z[2].append(['ZoneGridConnectivity', None, [], 'ZoneGridConnectivity_t'])
zoneGC = z[2][len(z[2])-1]
zoneGC = z[2][-1]
# Cree le noeud de GC1-1
if isinstance(zoneDonor, str): v = zoneDonor
else: v = zoneDonor[0]
Internal._createChild(zoneGC, bndName, 'GridConnectivity1to1_t', value=v)

l = len(zoneGC[2])
info = zoneGC[2][l-1]
info = zoneGC[2][-1]

if typeR == 0:
r = Internal.window2Range(wrange)
Expand Down Expand Up @@ -3898,16 +3897,14 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
zoneGC = Internal.getNodesFromType1(z, 'ZoneGridConnectivity_t')
if zoneGC == []:
Internal._createChild(z, 'ZoneGridConnectivity', 'ZoneGridConnectivity_t', value=None)
zoneGC = z[2][len(z[2])-1]
zoneGC = z[2][-1]
else:
zoneGC = zoneGC[0]
if isinstance(zoneDonor, str): v = zoneDonor
else: v = zoneDonor[0]
Internal._createChild(zoneGC, bndName, 'GridConnectivity_t', value=v)

l = len(zoneGC[2])

info = zoneGC[2][l-1]
info = zoneGC[2][-1]
r = Internal.window2Range(wrange)
info[2].append(['PointRange', r, [], 'IndexRange_t'])
Internal.createChild(info, 'GridConnectivityType', 'GridConnectivityType_t', 'Abutting')
Expand All @@ -3916,7 +3913,7 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],

# Nearmatch: rajoute les noeuds PointRangeDonor et Transform en UserDefinedData
info[2].append(['UserDefinedData', None, [], 'UserDefinedData_t'])
l = len(info[2])-1; info = info[2][l]
info = info[2][-1]
dd = Internal.window2Range(rangeDonor)
info[2].append(['PointRangeDonor', dd, [], 'DataArray_t'])
size = len(trirac); o = numpy.zeros((size), dtype=Internal.E_NpyInt)
Expand All @@ -3932,7 +3929,7 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
zoneGC = Internal.getNodesFromType1(z, 'ZoneGridConnectivity_t')
if zoneGC == []:
z[2].append(['ZoneGridConnectivity', None, [], 'ZoneGridConnectivity_t'])
zoneGC = z[2][len(z[2])-1]
zoneGC = z[2][-1]
else:
zoneGC = zoneGC[0]

Expand All @@ -3947,7 +3944,7 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
for i in zoneDonor:
if isinstance(i,str):
isp = i.split(":")
if len(isp)==1: dnrZoneNames.append(i)
if len(isp) == 1: dnrZoneNames.append(i)
else:
if isp[0]=='FamilySpecified': dnrZoneNames.append(isp[1])

Expand All @@ -3959,7 +3956,7 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],

Internal._createChild(zoneGC, bndName, 'GridConnectivity_t', value=v)

info = zoneGC[2][len(zoneGC[2])-1]
info = zoneGC[2][-1]
d = numpy.ones((3,1), dtype=Internal.E_NpyInt)
c = numpy.ones((3,1), dtype=numpy.float64)
r = Internal.window2Range(wrange)
Expand All @@ -3969,7 +3966,7 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
info[2].append(['InterpolantsDonor', c, [], 'DataArray_t'])
if rangeDonor == 'doubly_defined':
info[2].append(['UserDefinedData', None, [], 'UserDefinedData_t'])
l = len(info[2])-1; info = info[2][l]
info = info[2][-1]
dd = numpy.ones((1), dtype=Internal.E_NpyInt)
info[2].append(['doubly_defined', dd, [], 'DataArray_t'])

Expand All @@ -3981,12 +3978,11 @@ def _addBC2StructZone__(z, bndName, bndType, wrange=[], faceList=[],
zoneBC = Internal.getNodesFromType1(z, 'ZoneBC_t')
if zoneBC == []:
z[2].append(['ZoneBC', None, [], 'ZoneBC_t'])
zoneBC = z[2][len(z[2])-1]
zoneBC = z[2][-1]
else: zoneBC = zoneBC[0]
# Cree le noeud de BC
Internal._createChild(zoneBC, bndName, 'BC_t', value=bndType1)
l = len(zoneBC[2])
info = zoneBC[2][l-1]
info = zoneBC[2][-1]
r = Internal.window2Range(wrange)
info[2].append(['PointRange', r, [], 'IndexRange_t'])

Expand Down Expand Up @@ -4031,14 +4027,13 @@ def _addBC2NGonZone__(z, bndName, bndType, faceList, data, subzone,
zoneGC = Internal.getNodeFromType1(z, 'ZoneGridConnectivity_t')
if zoneGC is None:
z[2].append(['ZoneGridConnectivity', None, [], 'ZoneGridConnectivity_t'])
zoneGC = z[2][len(z[2])-1]
zoneGC = z[2][-1]

if isinstance(zoneDonor, str): v = zoneDonor
else: v = zoneDonor[0]
Internal._createChild(zoneGC, bndName, 'GridConnectivity_t', value=v)

l = len(zoneGC[2])
info = zoneGC[2][l-1]
info = zoneGC[2][-1]
Internal.createChild(info, 'GridLocation', 'GridLocation_t', 'FaceCenter')
if isinstance(faceList, numpy.ndarray): r = faceList
else: r = numpy.array(faceList, dtype=Internal.E_NpyInt)
Expand All @@ -4060,7 +4055,7 @@ def _addBC2NGonZone__(z, bndName, bndType, faceList, data, subzone,
# zoneGC = Internal.getNodesFromType1(z, 'ZoneGridConnectivity_t')
# if zoneGC == []:
# z[2].append(['ZoneGridConnectivity', None, [], 'ZoneGridConnectivity_t'])
# zoneGC = z[2][len(z[2])-1]
# zoneGC = z[2][-1]
# else:
# zoneGC = zoneGC[0]
# # Cree le noeud de GC
Expand All @@ -4081,8 +4076,7 @@ def _addBC2NGonZone__(z, bndName, bndType, faceList, data, subzone,
# v = numpy.fromstring(st, 'c')
# zoneGC[2].append([bndName, v, [], 'GridConnectivity_t'])

# l = len(zoneGC[2])
# info = zoneGC[2][l-1]
# info = zoneGC[2][-1]
# v = numpy.fromstring('FaceCenter', 'c')
# info[2].append(['GridLocation', v, [], 'GridLocation_t'])
# if isinstance(faceList, numpy.ndarray): r = faceList
Expand All @@ -4105,13 +4099,12 @@ def _addBC2NGonZone__(z, bndName, bndType, faceList, data, subzone,
zoneBC = Internal.getNodesFromType1(z, 'ZoneBC_t')
if zoneBC == []:
z[2].append(['ZoneBC', None, [], 'ZoneBC_t'])
zoneBC = z[2][len(z[2])-1]
zoneBC = z[2][-1]
else: zoneBC = zoneBC[0]

# Cree le noeud de BC
Internal._createChild(zoneBC, bndName, 'BC_t', value=bndType1)
l = len(zoneBC[2])
info = zoneBC[2][l-1]
info = zoneBC[2][-1]
Internal.createChild(info, 'GridLocation', 'GridLocation_t', 'FaceCenter')
if isinstance(faceList, numpy.ndarray): r = faceList
else: r = numpy.array(faceList, dtype=Internal.E_NpyInt)
Expand Down Expand Up @@ -6934,15 +6927,15 @@ def addState2Node__(a, state, value):

if H == []:
a[2].append(['FlowEquationSet', None, [], 'FlowEquationSet_t'])
H = a[2][len(a[2])-1]
H = a[2][-1]
else:
H = []
for n in a[2]:
if n[0] == 'ReferenceState': H = n; break

if H == []:
a[2].append(['ReferenceState', None, [], 'ReferenceState_t'])
H = a[2][len(a[2])-1]
H = a[2][-1]

# EquationDimension
if state == 'EquationDimension':
Expand Down
9 changes: 9 additions & 0 deletions Cassiopee/KCore/KCore/Connect/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ namespace K_CONNECT
E_Int connectEV2EENbrs(const char* eltType, E_Int nv, K_FLD::FldArrayI& cEV,
std::vector< std::vector<E_Int> >& cEEN,
std::vector< std::vector<E_Int> >& commonFace);
// Same as connectEV2EENbrs but only returns the number of neighbours
E_Int connectEV2NNbrs(const char* eltType, E_Int nv, FldArrayI& cEV,
std::vector<E_Int>& cENN);


/* Change un connectivite Elts-Vertex (basic elements) en une connectivite
Expand Down Expand Up @@ -514,5 +517,11 @@ namespace K_CONNECT
void build_face_neighbourhood(std::vector<E_Int> &, std::vector<E_Int> &,
std::vector<E_Int> &);
E_Int colorConnexParts(E_Int *, E_Int *, E_Int, E_Int *);

/* Miscellenous */
// Perform an exclusive prefix sum on an array that is a mask comprised solely
// of zeros and ones. Return the total number of ones, that is the total number
// of tagged elements.
E_Int prefixSum(std::vector<E_Int>& a);
}
#endif
94 changes: 94 additions & 0 deletions Cassiopee/KCore/KCore/Connect/connectEV2EENbrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,100 @@ E_Int K_CONNECT::connectEV2EENbrs(
return ierr;
}

//=============================================================================
// Same algo as in connectEV2EENbrs but only returns the number of neighbours
//=============================================================================
E_Int K_CONNECT::connectEV2NNbrs(
const char* eltType, E_Int nv,
FldArrayI& cEV,
vector<E_Int>& cENN
)
{
// Number of face per element for each connectivity
vector<E_Int> nfpe;
E_Int ierr = getNFPE(nfpe, eltType, true);
if (ierr != 0) return ierr;

E_Int nc = cEV.getNConnect();
vector<char*> eltTypes;
K_ARRAY::extractVars(eltType, eltTypes);

// Compute cumulative number of elements per connectivity (offsets)
std::vector<E_Int> cumnepc(nc+1); cumnepc[0] = 0;
for (E_Int ic = 0; ic < nc; ic++)
{
K_FLD::FldArrayI& cm = *(cEV.getConnect(ic));
E_Int nelts = cm.getSize();
cumnepc[ic+1] = cumnepc[ic] + nelts;
}

// Get vertex -> element connectivity
vector<vector<E_Int> > cVE(nv);
K_CONNECT::connectEV2VE(cEV, cVE);

// Boucle sur les connectivites pour remplir cENN
#pragma omp parallel default(shared) reduction(+:ierr)
{
E_Int nmatch, ind0, ind1, ind2, eidx, n, nidx, nneis, nvpf, nelts, nvpe;
vector<vector<E_Int> > facets;

for (E_Int ic = 0; ic < nc; ic++)
{
FldArrayI& cm = *(cEV.getConnect(ic));
nelts = cm.getSize();
nvpe = cm.getNfld();
ierr += getEVFacets(facets, eltTypes[ic], true);

#pragma omp for
for (E_Int i = 0; i < nelts; i++)
{
eidx = cumnepc[ic] + i;
cENN[eidx] = 0;

// Loop over each facet of element eidx
for (E_Int f = 0; f < nfpe[ic]; f++)
{
// Number of vertices per face
nvpf = facets[f].size();
// First vertex of that facet
ind0 = cm(i, facets[f][0]) - 1;

// Get all element indices sharing that vertex
const vector<E_Int>& cVE1 = cVE[ind0];
nneis = cVE1.size();

// Loop over all element sharing that vertex to determine the one
// with which this facet is shared
for (E_Int v = 0; v < nneis; v++)
{
nidx = cVE1[v];
// Skip elements belonging to another connectivity (shortcoming)
if (nidx < cumnepc[ic] || nidx >= cumnepc[ic] + nelts) continue;
if (nidx == eidx) continue;
n = nidx - cumnepc[ic]; // neighbour element index local to this conn.
nmatch = 0;
for (E_Int k = 0; k < nvpf; k++)
{
ind1 = cm(i, facets[f][k]);
for (E_Int j = 1; j <= nvpe; j++)
{
ind2 = cm(n, j);
if (ind1 == ind2) { nmatch++; break; }
}
}
if (nmatch == nvpf) { cENN[eidx]++; break; }
}
}
}
}
}

for (size_t ic = 0; ic < eltTypes.size(); ic++) delete [] eltTypes[ic];
if (ierr == 0) ierr = 1; // duct tape because success should be 0, not 1
else ierr = 0;
return ierr;
}

//=============================================================================
/* Recherche de l'element voisin (PENTA ou HEXA) contenant aussi la facette
QUAD ABCD dans cEEN */
Expand Down
Loading