From e89fa0665e5ddf58ae21266086532cc2d62be90a Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 12 Sep 2013 15:24:53 +0100
Subject: [PATCH] ENH:Field: added default values to mapping constructor

---
 src/OpenFOAM/fields/Fields/Field/Field.C | 56 ++++++++++++++++++++++++
 src/OpenFOAM/fields/Fields/Field/Field.H | 36 ++++++++++++++-
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C
index 334eba8e418..118de048b30 100644
--- a/src/OpenFOAM/fields/Fields/Field/Field.C
+++ b/src/OpenFOAM/fields/Fields/Field/Field.C
@@ -124,6 +124,34 @@ Foam::Field<Type>::Field
 }
 
 
+template<class Type>
+Foam::Field<Type>::Field
+(
+    const UList<Type>& mapF,
+    const FieldMapper& mapper,
+    const Type& defaultValue
+)
+:
+    List<Type>(mapper.size(), defaultValue)
+{
+    map(mapF, mapper);
+}
+
+
+template<class Type>
+Foam::Field<Type>::Field
+(
+    const UList<Type>& mapF,
+    const FieldMapper& mapper,
+    const UList<Type>& defaultValues
+)
+:
+    List<Type>(defaultValues)
+{
+    map(mapF, mapper);
+}
+
+
 template<class Type>
 Foam::Field<Type>::Field
 (
@@ -137,6 +165,34 @@ Foam::Field<Type>::Field
 }
 
 
+template<class Type>
+Foam::Field<Type>::Field
+(
+    const tmp<Field<Type> >& tmapF,
+    const FieldMapper& mapper,
+    const Type& defaultValue
+)
+:
+    List<Type>(mapper.size(), defaultValue)
+{
+    map(tmapF, mapper);
+}
+
+
+template<class Type>
+Foam::Field<Type>::Field
+(
+    const tmp<Field<Type> >& tmapF,
+    const FieldMapper& mapper,
+    const UList<Type>& defaultValues
+)
+:
+    List<Type>(defaultValues)
+{
+    map(tmapF, mapper);
+}
+
+
 template<class Type>
 Foam::Field<Type>::Field(const Field<Type>& f)
 :
diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H
index 9b4088a4ebc..dd3dbabeaef 100644
--- a/src/OpenFOAM/fields/Fields/Field/Field.H
+++ b/src/OpenFOAM/fields/Fields/Field/Field.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-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -160,6 +160,22 @@ public:
             const FieldMapper& map
         );
 
+        //- Construct by mapping from the given field
+        Field
+        (
+            const UList<Type>& mapF,
+            const FieldMapper& map,
+            const Type& defaultValue
+        );
+
+        //- Construct by mapping from the given field
+        Field
+        (
+            const UList<Type>& mapF,
+            const FieldMapper& map,
+            const UList<Type>& defaultValues
+        );
+
         //- Construct by mapping from the given tmp field
         Field
         (
@@ -167,6 +183,24 @@ public:
             const FieldMapper& map
         );
 
+        //- Construct by mapping from the given tmp field. Supplied uniform
+        //  value for unmapped items
+        Field
+        (
+            const tmp<Field<Type> >& tmapF,
+            const FieldMapper& map,
+            const Type& defaultValue
+        );
+
+        //- Construct by mapping from the given tmp field. Supplied values
+        //  for unmapped items
+        Field
+        (
+            const tmp<Field<Type> >& tmapF,
+            const FieldMapper& map,
+            const UList<Type>& defaultValues
+        );
+
         //- Construct as copy
         Field(const Field<Type>&);
 
-- 
GitLab