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
40
41#include "ProcessRemoveField.h"
42
43namespace Nektar::FieldUtils
44{
45
49 "Remove one of the existing fields");
50
52{
53 m_config["fieldname"] =
54 ConfigOption(false, "NotSet", "Name for field to be removed, required");
55}
56
58{
59}
60
61void ProcessRemoveField::v_Process([[maybe_unused]] po::variables_map &vm)
62{
63 // Obtain field names to be removed
64 string fieldNames = m_config["fieldname"].as<string>();
65 vector<string> fieldName;
66 ASSERTL0(fieldNames != "NotSet", "A fieldname is required");
67
68 ASSERTL0(ParseUtils::GenerateVector(fieldNames, fieldName),
69 "Failed to interpret fields string");
70 m_f->SetUpExp(vm);
71
72 // Remove fields specified
73 for (int i = 0; i < fieldName.size(); ++i)
74 {
75 // check if field exists
76 auto it = std::find(m_f->m_variables.begin(), m_f->m_variables.end(),
77 fieldName[i]);
78 ASSERTL0(it != m_f->m_variables.end(), "Field does not exist");
79
80 int fieldID = std::distance(m_f->m_variables.begin(), it);
81
82 m_f->m_variables.erase(it);
83 m_f->m_exp.erase(m_f->m_exp.begin() + fieldID);
84
85 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
86 {
87 cout << "Field " << fieldName[i] << " has been erased" << endl;
88 }
89 }
90}
91} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
Abstract base class for processing modules.
Definition: Module.h:301
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.
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:130
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
STL namespace.
Represents a command-line configuration option.
Definition: Module.h:129