Nektar++
ProcessRemoveField.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessRemoveField.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Remove a variable
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 #include <iostream>
35 #include <string>
36 using namespace std;
37 
38 #include <boost/core/ignore_unused.hpp>
39 
42 
43 #include "ProcessRemoveField.h"
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
48 {
49 
50 ModuleKey ProcessRemoveField::className =
52  ModuleKey(eProcessModule, "removefield"), ProcessRemoveField::create,
53  "Remove one of the existing fields");
54 
55 ProcessRemoveField::ProcessRemoveField(FieldSharedPtr f) : ProcessModule(f)
56 {
57  m_config["fieldname"] =
58  ConfigOption(false, "NotSet", "Name for field to be removed, required");
59 }
60 
62 {
63 }
64 
65 void ProcessRemoveField::Process(po::variables_map &vm)
66 {
67  boost::ignore_unused(vm);
68 
69  // Obtain field names to be removed
70  string fieldNames = m_config["fieldname"].as<string>();
71  vector<string> fieldName;
72  ASSERTL0(fieldNames != "NotSet", "A fieldname is required");
73 
74  ASSERTL0(ParseUtils::GenerateVector(fieldNames, fieldName),
75  "Failed to interpret fields string");
76 
77  // Remove fields specified
78  for (int i = 0; i < fieldName.size(); ++i)
79  {
80  // check if field exists
81  auto it = std::find(m_f->m_variables.begin(), m_f->m_variables.end(),
82  fieldName[i]);
83  ASSERTL0(it != m_f->m_variables.end(), "Field does not exist");
84 
85  int fieldID = std::distance(m_f->m_variables.begin(), it);
86 
87  m_f->m_variables.erase(it);
88  m_f->m_exp.erase(m_f->m_exp.begin() + fieldID);
89 
90  if (m_f->m_comm->TreatAsRankZero())
91  {
92  cout << "Field " << fieldName[i] << " has been erased" << endl;
93  }
94  }
95 }
96 } // namespace FieldUtils
97 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::map< std::string, ConfigOption > m_config
List of configuration values.
Represents a command-line configuration option.
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
std::pair< ModuleType, std::string > ModuleKey
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
Abstract base class for processing modules.
virtual void Process(po::variables_map &vm)
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.