From cd45f3c9c363aa0925ed88b9bd59641bfde6f544 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 24 Mar 2011 18:28:41 +0000 Subject: [PATCH 1/4] BUG: searchableSurfaceWithGaps: scale of perturb vectors --- .../searchableSurfaceWithGaps.C | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C index 80dc1cda45..e96d0a4c3d 100644 --- a/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C +++ b/src/meshTools/searchableSurface/searchableSurfaceWithGaps.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -72,14 +72,14 @@ Foam::Pair Foam::searchableSurfaceWithGaps::offsetVecs } offsets[0][minCmpt] = 1.0; - // Orthogonalise + // Orthonormalise offsets[0] -= n[minCmpt]*n; - // Scale - offsets[0] *= gap_/mag(offsets[0]); - - + offsets[0] /= mag(offsets[0]); // Do second offset vector perp to original edge and first offset vector offsets[1] = n ^ offsets[0]; + + // Scale + offsets[0] *= gap_; offsets[1] *= gap_; } @@ -240,7 +240,7 @@ void Foam::searchableSurfaceWithGaps::findLine // test in pairs: only if both perturbations hit something // do we accept the hit. - const vectorField smallVec(SMALL*(compactEnd-compactStart)); + const vectorField smallVec(1E-6*(compactEnd-compactStart)); List plusInfo; surface().findLine @@ -294,7 +294,7 @@ void Foam::searchableSurfaceWithGaps::findLine offset0.setSize(plusMissMap.size()); offset1.setSize(plusMissMap.size()); - const vectorField smallVec(SMALL*(compactEnd-compactStart)); + const vectorField smallVec(1E-6*(compactEnd-compactStart)); surface().findLine ( From 7c34b443e0ee1ea0f2397ae165780c7abda0222f Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 24 Mar 2011 21:18:56 +0000 Subject: [PATCH 2/4] BUG: sampledSurfaces: cleared out volPointInterpolation & pointMesh. --- .../sampledSurface/sampledSurfaces/sampledSurfaces.C | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index b3e2fc7394..4968f0a00f 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -277,6 +277,8 @@ void Foam::sampledSurfaces::read(const dictionary& dict) void Foam::sampledSurfaces::updateMesh(const mapPolyMesh&) { expire(); + + // pointMesh and interpolation will have been reset in mesh.update } @@ -327,10 +329,6 @@ bool Foam::sampledSurfaces::expire() } } - // reset interpolation - pointMesh::Delete(mesh_); - volPointInterpolation::Delete(mesh_); - // true if any surfaces just expired return justExpired; } From b5d6aee54f69a4dc2fef043ee18827f535de5fde Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 24 Mar 2011 21:21:07 +0000 Subject: [PATCH 3/4] ENH: triSurfaceMesh: added tolerance for edgeTree as well --- src/meshTools/searchableSurface/triSurfaceMesh.C | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/meshTools/searchableSurface/triSurfaceMesh.C b/src/meshTools/searchableSurface/triSurfaceMesh.C index deb92ee00f..c3c7c69b34 100644 --- a/src/meshTools/searchableSurface/triSurfaceMesh.C +++ b/src/meshTools/searchableSurface/triSurfaceMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -573,6 +573,9 @@ const Foam::indexedOctree& bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL); + scalar oldTol = indexedOctree::perturbTol(); + indexedOctree::perturbTol() = tolerance_; + edgeTree_.reset ( new indexedOctree @@ -590,6 +593,8 @@ const Foam::indexedOctree& 3.0 // duplicity ) ); + + indexedOctree::perturbTol() = oldTol; } return edgeTree_(); } From 20b1d49a8200d3705fce6d1ca2359c1a44ed25cb Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 25 Mar 2011 04:43:29 +0000 Subject: [PATCH 4/4] ENH: dynamicCode: display line numbers --- doc/changes/dynamicCode.org | 10 +++- .../dynamicLibrary/dynamicCode/dynamicCode.C | 2 +- .../dynamicCode/dynamicCodeContext.C | 56 +++++++++++++----- .../dynamicCode/dynamicCodeContext.H | 8 +++ .../codedFixedValueFvPatchField.C | 12 ++-- .../codedFunctionObject/codedFunctionObject.C | 59 ++++++++++++++++--- 6 files changed, 114 insertions(+), 33 deletions(-) diff --git a/doc/changes/dynamicCode.org b/doc/changes/dynamicCode.org index 16c0b39143..12217c6f6c 100644 --- a/doc/changes/dynamicCode.org +++ b/doc/changes/dynamicCode.org @@ -233,7 +233,11 @@ - codedFixedValue could be extended to provide local data however in terms of complexity this is not really worthwhile. - - all templates come from - =etc/codeTemplates/dynamicCode= - =~/.OpenFOAM/dev/codeTemplates/dynamicCode= + - all templates come from (in order of preference) =FOAM_TEMPLATE_DIR= + =~/.OpenFOAM/dev/codeTemplates/dynamicCode= + =etc/codeTemplates/dynamicCode= + + - any generated C++ code will display line numbers relative to the original + dictionary (using the '#line' directive) to ease finding compilation + errors. diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C index d28494463f..56402b28e5 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C @@ -522,7 +522,7 @@ bool Foam::dynamicCode::copyOrCreateFiles(const bool verbose) const bool Foam::dynamicCode::wmakeLibso() const { - const Foam::string wmakeCmd("wmake -s libso " + this->codeRelPath()); + const Foam::string wmakeCmd("wmake -s libso " + this->codePath()); Info<< "Invoking " << wmakeCmd << endl; if (Foam::system(wmakeCmd)) diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C index ef6231d9b3..81c1a50ceb 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.C @@ -34,44 +34,57 @@ License Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) : dict_(dict), - code_(stringOps::trim(dict["code"])), + code_(), localCode_(), include_(), options_(), libs_() { // expand dictionary entries - stringOps::inplaceExpand(code_, dict); + + { + const entry& codeEntry = dict.lookupEntry("code", false, false); + code_ = stringOps::trim(codeEntry.stream()); + stringOps::inplaceExpand(code_, dict); + addLineDirective(code_, codeEntry.startLineNumber(), dict.name()); + } // note: removes any leading/trailing whitespace // - necessary for compilation options, convenient for includes // and body. // optional - if (dict.found("localCode")) + const entry* includePtr = dict.lookupEntryPtr + ( + "codeInclude", + false, + false + ); + if (includePtr) { - localCode_ = stringOps::trim(dict["localCode"]); - stringOps::inplaceExpand(localCode_, dict); - } - - // optional - if (dict.found("codeInclude")) - { - include_ = stringOps::trim(dict["codeInclude"]); + include_ = stringOps::trim(includePtr->stream()); stringOps::inplaceExpand(include_, dict); + addLineDirective(include_, includePtr->startLineNumber(), dict.name()); } // optional - if (dict.found("codeOptions")) + const entry* optionsPtr = dict.lookupEntryPtr + ( + "codeOptions", + false, + false + ); + if (optionsPtr) { - options_ = stringOps::trim(dict["codeOptions"]); + options_ = stringOps::trim(optionsPtr->stream()); stringOps::inplaceExpand(options_, dict); } // optional - if (dict.found("codeLibs")) + const entry* libsPtr = dict.lookupEntryPtr("codeLibs", false, false); + if (libsPtr) { - libs_ = stringOps::trim(dict["codeLibs"]); + libs_ = stringOps::trim(libsPtr->stream()); stringOps::inplaceExpand(libs_, dict); } @@ -82,4 +95,17 @@ Foam::dynamicCodeContext::dynamicCodeContext(const dictionary& dict) } +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::dynamicCodeContext::addLineDirective +( + string& code, + const label lineNum, + const fileName& name +) +{ + code = "#line " + Foam::name(lineNum) + " \"" + name + "\"\n" + code; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H index f4a38695b7..8ff83b0724 100644 --- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H +++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCodeContext.H @@ -51,6 +51,7 @@ namespace Foam class dynamicCodeContext { // Private data + //- The parent dictionary context const dictionary& dict_; @@ -123,6 +124,13 @@ public: return sha1_; } + //- Helper: add #line directive + static void addLineDirective + ( + string&, + const label lineNum, + const fileName& name + ); }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C index 208077b262..8dd28c5e07 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/codedFixedValue/codedFixedValueFvPatchField.C @@ -241,10 +241,6 @@ void Foam::codedFixedValueFvPatchField::createLibrary // Write files for new library if (!dynCode.upToDate(context)) { - Info<< "Using dynamicCode for patch " << this->patch().name() - << " on field " << this->dimensionedInternalField().name() - << endl; - // filter with this context dynCode.reset(context); @@ -271,7 +267,7 @@ void Foam::codedFixedValueFvPatchField::createLibrary dynCode.setMakeOptions ( "EXE_INC = -g \\\n" - "-I$(LIB_SRC)/finiteVolume/lnInclude\\\n" + "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n" + context.options() + "\n\nLIB_LIBS = \\\n" + " -lOpenFOAM \\\n" @@ -343,6 +339,12 @@ void Foam::codedFixedValueFvPatchField::updateLibrary() const return; } + Info<< "Using dynamicCode for patch " << this->patch().name() + << " on field " << this->dimensionedInternalField().name() << nl + << "at line " << codeDict.startLineNumber() + << " in " << codeDict.name() << endl; + + // remove instantiation of fvPatchField provided by library redirectPatchFieldPtr_.clear(); diff --git a/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index 36da451a63..5dcdf627c7 100644 --- a/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/postProcessing/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -188,9 +188,6 @@ void Foam::codedFunctionObject::createLibrary // Write files for new library if (!dynCode.upToDate(context)) { - Info<< "Using dynamicCode for functionObject " << name() - << endl; - // filter with this context dynCode.reset(context); @@ -282,6 +279,11 @@ void Foam::codedFunctionObject::updateLibrary() const return; } + Info<< "Using dynamicCode for functionObject " << name() + << " at line " << dict_.startLineNumber() + << " in " << dict_.name() << endl; + + // remove instantiation of fvPatchField provided by library redirectFunctionObjectPtr_.clear(); @@ -375,21 +377,60 @@ bool Foam::codedFunctionObject::read(const dictionary& dict) { dict.lookup("redirectType") >> redirectType_; - if (dict.found("codeRead")) + const entry* readPtr = dict.lookupEntryPtr + ( + "codeRead", + false, + false + ); + if (readPtr) { - codeRead_ = stringOps::trim(dict["codeRead"]); + codeRead_ = stringOps::trim(readPtr->stream()); stringOps::inplaceExpand(codeRead_, dict); + dynamicCodeContext::addLineDirective + ( + codeRead_, + readPtr->startLineNumber(), + dict.name() + ); } - if (dict.found("codeExecute")) + + const entry* execPtr = dict.lookupEntryPtr + ( + "codeExecute", + false, + false + ); + if (execPtr) { - codeExecute_ = stringOps::trim(dict["codeExecute"]); + codeExecute_ = stringOps::trim(execPtr->stream()); stringOps::inplaceExpand(codeExecute_, dict); + dynamicCodeContext::addLineDirective + ( + codeExecute_, + execPtr->startLineNumber(), + dict.name() + ); } - if (dict.found("codeEnd")) + + const entry* endPtr = dict.lookupEntryPtr + ( + "codeEnd", + false, + false + ); + if (execPtr) { - codeEnd_ = stringOps::trim(dict["codeEnd"]); + codeEnd_ = stringOps::trim(endPtr->stream()); stringOps::inplaceExpand(codeEnd_, dict); + dynamicCodeContext::addLineDirective + ( + codeEnd_, + endPtr->startLineNumber(), + dict.name() + ); } + updateLibrary(); return redirectFunctionObject().read(dict); }