From b3d4b836c81660c4349e98549eb5972332fb4a64 Mon Sep 17 00:00:00 2001
From: Andrew Heather <a.heather@opencfd.co.uk>
Date: Mon, 27 Mar 2017 09:10:01 +0100
Subject: [PATCH] ENH: readFields function object - added flag to read fields
 on construction

---
 src/functionObjects/field/readFields/readFields.C | 11 +++++++++--
 src/functionObjects/field/readFields/readFields.H |  6 +++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/functionObjects/field/readFields/readFields.C b/src/functionObjects/field/readFields/readFields.C
index 2ac396999f2..04fb569728e 100644
--- a/src/functionObjects/field/readFields/readFields.C
+++ b/src/functionObjects/field/readFields/readFields.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -50,9 +50,15 @@ Foam::functionObjects::readFields::readFields
 )
 :
     fvMeshFunctionObject(name, runTime, dict),
-    fieldSet_()
+    fieldSet_(),
+    readOnStart_(true)
 {
     read(dict);
+
+    if (readOnStart_)
+    {
+        execute();
+    }
 }
 
 
@@ -69,6 +75,7 @@ bool Foam::functionObjects::readFields::read(const dictionary& dict)
     fvMeshFunctionObject::read(dict);
 
     dict.lookup("fields") >> fieldSet_;
+    dict.readIfPresent("readOnStart", readOnStart_);
 
     return true;
 }
diff --git a/src/functionObjects/field/readFields/readFields.H b/src/functionObjects/field/readFields/readFields.H
index f026063e9f9..1dfb662d5d7 100644
--- a/src/functionObjects/field/readFields/readFields.H
+++ b/src/functionObjects/field/readFields/readFields.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2015-2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2015-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -48,6 +48,7 @@ Usage
         Property     | Description             | Required    | Default value
         type         | type name: readFields   | yes         |
         fields       | list of fields to read  |  no         |
+        readOnStart  | flag to start reading on start-up | no  | yes
         log          | Log to standard output  | no          | yes
     \endtable
 
@@ -88,6 +89,9 @@ protected:
         //- Fields to load
         wordList fieldSet_;
 
+        //- Flag to read on construction
+        bool readOnStart_;
+
 
     // Protected Member Functions
 
-- 
GitLab