Nektar++
ProcessBoundaryExtract.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessBoundaryExtract.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: Set up boundary to be extracted when writing fld file.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
41
43
44namespace Nektar::FieldUtils
45{
46
50 "Extract Boundary field");
51
53 : ProcessModule(f)
54{
55 // set up dafault values.
56 m_config["bnd"] = ConfigOption(false, "All", "Boundary to be processed");
57 m_config["addnormals"] = ConfigOption(true, "0", "Add normals to output");
58
59 f->m_writeBndFld = true;
60 f->m_declareExpansionAsContField = true;
61 f->m_requireBoundaryExpansion = true;
62}
63
65{
66}
67
68void ProcessBoundaryExtract::v_Process(po::variables_map &vm)
69{
70 m_f->SetUpExp(vm);
71
72 m_f->m_addNormals = m_config["addnormals"].as<bool>();
73
74 // Set up Field options to output boundary fld
75 string bvalues = m_config["bnd"].as<string>();
76
77 vector<unsigned int> bndRegions;
78 if (boost::iequals(bvalues, "All"))
79 {
80 int numBndExp = 0;
81
83 m_f->m_exp[0]->GetGraph());
86
87 for (auto &breg_it : bregions)
88 {
89 numBndExp = max(numBndExp, breg_it.first);
90 }
91 // assuming all boundary regions are consecutive number if
92 // regions is one more than maximum id
93 numBndExp++;
94
95 // not all partitions in parallel touch all boundaries so
96 // find maximum number of boundaries
97 m_f->m_comm->GetSpaceComm()->AllReduce(numBndExp,
99
100 // THis presumes boundary regions are numbered consecutively
101 for (int i = 0; i < numBndExp; ++i)
102 {
103 bndRegions.push_back(i);
104 }
105 }
106 else
107 {
108 ASSERTL0(ParseUtils::GenerateVector(bvalues, bndRegions),
109 "Failed to interpret bnd values string");
110 }
111
112 if (m_f->m_bndRegionsToWrite.size())
113 {
114 // This was already called. Just check if the bnd option is the same
115 ASSERTL0(m_f->m_bndRegionsToWrite == bndRegions,
116 "Incompatible bnd parameters.");
117 }
118 else
119 {
120 m_f->m_bndRegionsToWrite = bndRegions;
121
122 if (m_f->m_exp[0]->GetNumElmts() != 0)
123 {
124 for (int i = 0; i < m_f->m_exp.size(); ++i)
125 {
126 m_f->m_exp[i]->FillBndCondFromField(m_f->m_exp[i]->GetCoeffs());
127 }
128 }
129 }
130}
131} // 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
void v_Process(po::variables_map &vm) override
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Abstract base class for processing modules.
Definition: Module.h:301
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
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
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:234
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:210
Represents a command-line configuration option.
Definition: Module.h:129