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>
36using namespace std;
37
38#include <boost/core/ignore_unused.hpp>
39
42
43#include "ProcessRemoveField.h"
44
45namespace Nektar
46{
47namespace FieldUtils
48{
49
53 "Remove one of the existing fields");
54
56{
57 m_config["fieldname"] =
58 ConfigOption(false, "NotSet", "Name for field to be removed, required");
59}
60
62{
63}
64
65void ProcessRemoveField::v_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 m_f->SetUpExp(vm);
77
78 // Remove fields specified
79 for (int i = 0; i < fieldName.size(); ++i)
80 {
81 // check if field exists
82 auto it = std::find(m_f->m_variables.begin(), m_f->m_variables.end(),
83 fieldName[i]);
84 ASSERTL0(it != m_f->m_variables.end(), "Field does not exist");
85
86 int fieldID = std::distance(m_f->m_variables.begin(), it);
87
88 m_f->m_variables.erase(it);
89 m_f->m_exp.erase(m_f->m_exp.begin() + fieldID);
90
91 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
92 {
93 cout << "Field " << fieldName[i] << " has been erased" << endl;
94 }
95 }
96}
97} // namespace FieldUtils
98} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
Abstract base class for processing modules.
Definition: Module.h:292
virtual void v_Process(po::variables_map &vm) override
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
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:131
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:453
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Represents a command-line configuration option.
Definition: Module.h:131