diff --git a/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.C b/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.C
new file mode 100644
index 0000000000..d5fdb11a0b
--- /dev/null
+++ b/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.C
@@ -0,0 +1,180 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+\*---------------------------------------------------------------------------*/
+
+#include "codedBasicSourceTemplate.H"
+#include "addToRunTimeSelectionTable.H"
+#include "fvPatchFieldMapper.H"
+#include "volFields.H"
+#include "surfaceFields.H"
+#include "unitConversion.H"
+//{{{ begin codeInclude
+${codeInclude}
+//}}} end codeInclude
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
+
+//{{{ begin localCode
+${localCode}
+//}}} end localCode
+
+
+// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
+
+extern "C"
+{
+ // dynamicCode:
+ // SHA1 = ${SHA1sum}
+ //
+ // unique function name that can be checked if the correct library version
+ // has been loaded
+ void ${typeName}_${SHA1sum}(bool load)
+ {
+ if (load)
+ {
+ // code that can be explicitly executed after loading
+ }
+ else
+ {
+ // code that can be explicitly executed before unloading
+ }
+ }
+}
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+//makeRemovablePatchTypeField
+//(
+// fvPatch${FieldType},
+// ${typeName}CodedBasic${SourceType}
+//);
+defineTypeNameAndDebug(${typeName}CodedBasic${SourceType}, 0);
+addRemovableToRunTimeSelectionTable
+(
+ basicSource,
+ ${typeName}CodedBasic${SourceType},
+ dictionary
+);
+
+
+const char* const ${typeName}CodedBasic${SourceType}::SHA1sum =
+ "${SHA1sum}";
+
+
+// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
+
+${typeName}CodedBasic${SourceType}::
+${typeName}CodedBasic${SourceType}
+(
+ const word& name,
+ const word& modelType,
+ const dictionary& dict,
+ const fvMesh& mesh
+)
+:
+ basicSource(name, modelType, dict, mesh)
+{
+ if (${verbose:-false})
+ {
+ Info<<"construct ${typeName} sha1: ${SHA1sum}"
+ " from components\n";
+ }
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
+
+${typeName}CodedBasic${SourceType}::
+~${typeName}CodedBasic${SourceType}()
+{
+ if (${verbose:-false})
+ {
+ Info<<"destroy ${typeName} sha1: ${SHA1sum}\n";
+ }
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
+
+void ${typeName}CodedBasic${SourceType}::correct
+(
+ GeometricField<${TemplateType}, fvPatchField, volMesh>& fld
+)
+{
+ if (${verbose:-false})
+ {
+ Info<<"${typeName}CodedBasic${SourceType}::correct()\n";
+ }
+
+//{{{ begin code
+ ${codeCorrect}
+//}}} end code
+}
+
+
+void ${typeName}CodedBasic${SourceType}::addSup
+(
+ fvMatrix<${TemplateType}>& eqn,
+ const label fieldI
+)
+{
+ if (${verbose:-false})
+ {
+ Info<<"${typeName}CodedBasic${SourceType}::addSup()\n";
+ }
+
+//{{{ begin code
+ ${codeAddSup}
+//}}} end code
+}
+
+
+void ${typeName}CodedBasic${SourceType}::setValue
+(
+ fvMatrix<${TemplateType}>& eqn,
+ const label fieldI
+)
+{
+ if (${verbose:-false})
+ {
+ Info<<"${typeName}CodedBasic${SourceType}::setValue()\n";
+ }
+
+//{{{ begin code
+ ${codeSetValue}
+//}}} end code
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.H b/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.H
new file mode 100644
index 0000000000..7f80510507
--- /dev/null
+++ b/etc/codeTemplates/dynamicCode/codedBasicSourceTemplate.H
@@ -0,0 +1,108 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+Description
+ Template for use with dynamic code generation of a basicSource
+
+ - without state
+
+SourceFiles
+ codedBasicSourceTemplate.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef codedBasicSourceTemplate_H
+#define codedBasicSourceTemplate_H
+
+#include "basicSource.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+ A templated CodedBasicSource
+\*---------------------------------------------------------------------------*/
+
+class ${typeName}CodedBasic${SourceType}
+:
+ public basicSource
+{
+public:
+
+ //- Information about the SHA1 of the code itself
+ static const char* const SHA1sum;
+
+ //- Runtime type information
+ TypeName("${typeName}");
+
+
+ // Constructors
+
+ //- Construct from patch and internal field
+ ${typeName}CodedBasic${SourceType}
+ (
+ const word& name,
+ const word& modelType,
+ const dictionary& dict,
+ const fvMesh& mesh
+ );
+
+ //- Destructor
+ virtual ~${typeName}CodedBasic${SourceType}();
+
+
+ // Member functions
+
+ //- Correct field
+ virtual void correct
+ (
+ GeometricField<${TemplateType}, fvPatchField, volMesh>&
+ );
+
+ //- Explicit and implicit matrix contributions
+ virtual void addSup
+ (
+ fvMatrix<${TemplateType}>& eqn,
+ const label fieldI
+ );
+
+ //- Set value
+ virtual void setValue
+ (
+ fvMatrix<${TemplateType}>& eqn,
+ const label fieldI
+ );
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/fieldSources/Make/files b/src/fieldSources/Make/files
index 1db2de4b5e..f642dd2b65 100644
--- a/src/fieldSources/Make/files
+++ b/src/fieldSources/Make/files
@@ -29,4 +29,6 @@ $(interRegion)/constantHeatTransfer/constantHeatTransfer.C
$(interRegion)/tabulatedHeatTransfer/tabulatedHeatTransfer.C
$(interRegion)/variableHeatTransfer/variableHeatTransfer.C
+basicSource/codedSource/codedSource.C
+
LIB = $(FOAM_LIBBIN)/libfieldSources
diff --git a/src/fieldSources/basicSource/codedSource/CodedSource.C b/src/fieldSources/basicSource/codedSource/CodedSource.C
new file mode 100644
index 0000000000..b379123e87
--- /dev/null
+++ b/src/fieldSources/basicSource/codedSource/CodedSource.C
@@ -0,0 +1,206 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+\*---------------------------------------------------------------------------*/
+
+#include "CodedSource.H"
+#include "fvMesh.H"
+#include "fvMatrices.H"
+#include "dynamicCode.H"
+#include "dynamicCodeContext.H"
+
+// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
+
+
+// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
+
+template
+void Foam::CodedSource::prepare
+(
+ dynamicCode& dynCode,
+ const dynamicCodeContext& context
+) const
+{
+ word sourceType(pTraits::typeName);
+
+ // Set additional rewrite rules
+ dynCode.setFilterVariable("typeName", redirectType_);
+ dynCode.setFilterVariable("TemplateType", sourceType);
+ dynCode.setFilterVariable("SourceType", sourceType + "Source");
+
+ //dynCode.removeFilterVariable("code");
+ dynCode.setFilterVariable("codeCorrect", codeCorrect_);
+ dynCode.setFilterVariable("codeAddSup", codeAddSup_);
+ dynCode.setFilterVariable("codeSetValue", codeSetValue_);
+
+ // compile filtered C template
+ dynCode.addCompileFile("codedBasicSourceTemplate.C");
+
+ // copy filtered H template
+ dynCode.addCopyFile("codedBasicSourceTemplate.H");
+
+ // debugging: make BC verbose
+ // dynCode.setFilterVariable("verbose", "true");
+ // Info<<"compile " << redirectType_ << " sha1: "
+ // << context.sha1() << endl;
+
+ // define Make/options
+ dynCode.setMakeOptions
+ (
+ "EXE_INC = -g \\\n"
+ "-I$(LIB_SRC)/fieldSources/lnInclude \\\n"
+ "-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
+ "-I$(LIB_SRC)/meshTools/lnInclude \\\n"
+ "-I$(LIB_SRC)/sampling/lnInclude \\\n"
+ + context.options()
+ + "\n\nLIB_LIBS = \\\n"
+ + " -lmeshTools \\\n"
+ + " -lfieldSources \\\n"
+ + " -lsampling \\\n"
+ + " -lfiniteVolume \\\n"
+ + context.libs()
+ );
+}
+
+
+template
+Foam::dlLibraryTable& Foam::CodedSource::libs() const
+{
+ return const_cast