From b8a1efa0fce35541d723d7cdf9bf4d430b509237 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Tue, 26 Jun 2012 17:50:07 +0100 Subject: [PATCH] ENH: patchSummary: -collate argument for patchGroups etc. --- .../miscellaneous/patchSummary/patchSummary.C | 90 +++++++++++++++++-- .../patchSummary/patchSummaryTemplates.C | 26 +++++- .../patchSummary/patchSummaryTemplates.H | 12 ++- 3 files changed, 116 insertions(+), 12 deletions(-) diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummary.C b/applications/utilities/miscellaneous/patchSummary/patchSummary.C index d344845fae2..9f35d900da2 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummary.C +++ b/applications/utilities/miscellaneous/patchSummary/patchSummary.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,11 +42,19 @@ int main(int argc, char *argv[]) timeSelector::addOptions(); # include "addRegionOption.H" + argList::addBoolOption + ( + "collate", + "Combine similar patches" + ); # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); + const bool collate = args.optionFound("collate"); + + # include "createNamedMesh.H" forAll(timeDirs, timeI) @@ -89,15 +97,81 @@ int main(int argc, char *argv[]) Info<< endl; const polyBoundaryMesh& bm = mesh.boundaryMesh(); + + DynamicList<HashTable<word> > fieldToTypes(bm.size()); + DynamicList<DynamicList<label> > groupToPatches(bm.size()); forAll(bm, patchI) { - Info<< bm[patchI].type() << ": " << bm[patchI].name() << nl; - outputFieldList<scalar>(vsf, patchI); - outputFieldList<vector>(vvf, patchI); - outputFieldList<sphericalTensor>(vsptf, patchI); - outputFieldList<symmTensor>(vsytf, patchI); - outputFieldList<tensor>(vtf, patchI); - Info<< endl; + if (collate) + { + HashTable<word> fieldToType; + collectFieldList<scalar>(vsf, patchI, fieldToType); + collectFieldList<vector>(vvf, patchI, fieldToType); + collectFieldList<sphericalTensor>(vsptf, patchI, fieldToType); + collectFieldList<symmTensor>(vsytf, patchI, fieldToType); + collectFieldList<tensor>(vtf, patchI, fieldToType); + + label groupI = findIndex(fieldToTypes, fieldToType); + if (groupI == -1) + { + DynamicList<label> group(1); + group.append(patchI); + groupToPatches.append(group); + fieldToTypes.append(fieldToType); + } + else + { + groupToPatches[groupI].append(patchI); + } + } + else + { + Info<< bm[patchI].type() << ": " << bm[patchI].name() << nl; + outputFieldList<scalar>(vsf, patchI); + outputFieldList<vector>(vvf, patchI); + outputFieldList<sphericalTensor>(vsptf, patchI); + outputFieldList<symmTensor>(vsytf, patchI); + outputFieldList<tensor>(vtf, patchI); + Info<< endl; + } + } + + + bool hasGroups = false; + forAll(groupToPatches, groupI) + { + const DynamicList<label>& patchIDs = groupToPatches[groupI]; + if (patchIDs.size() > 1) + { + hasGroups = true; + break; + } + } + + + if (hasGroups) + { + Info<< "Collated:" << endl; + forAll(groupToPatches, groupI) + { + const DynamicList<label>& patchIDs = groupToPatches[groupI]; + + if (patchIDs.size() > 1) + { + Info<< '(' << bm[patchIDs[0]].name(); + for (label i = 1; i < patchIDs.size(); i++) + { + Info<< ' ' << bm[patchIDs[i]].name(); + } + Info<< ')' << endl; + outputFieldList<scalar>(vsf, patchIDs[0]); + outputFieldList<vector>(vvf, patchIDs[0]); + outputFieldList<sphericalTensor>(vsptf, patchIDs[0]); + outputFieldList<symmTensor>(vsytf, patchIDs[0]); + outputFieldList<tensor>(vtf, patchIDs[0]); + Info<< endl; + } + } } } diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.C b/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.C index 7d03b999a4c..9c9842bd324 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.C +++ b/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,7 +55,7 @@ void Foam::addToFieldList template<class Type> void Foam::outputFieldList ( - PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, + const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, const label patchI ) { @@ -71,4 +71,26 @@ void Foam::outputFieldList } +template<class Type> +void Foam::collectFieldList +( + const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, + const label patchI, + HashTable<word>& fieldToType +) +{ + forAll(fieldList, fieldI) + { + if (fieldList.set(fieldI)) + { + fieldToType.insert + ( + fieldList[fieldI].name(), + fieldList[fieldI].boundaryField()[patchI].type() + ); + } + } +} + + // ************************************************************************* // diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.H b/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.H index 707c7d75179..d61a416a521 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.H +++ b/applications/utilities/miscellaneous/patchSummary/patchSummaryTemplates.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,9 +45,17 @@ namespace Foam template<class Type> void outputFieldList ( - PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, + const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, const label patchI ); + + template<class Type> + void collectFieldList + ( + const PtrList<GeometricField<Type, fvPatchField, volMesh> >& fieldList, + const label patchI, + HashTable<word>& fieldToType + ); } // End namespace Foam -- GitLab