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>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
43 
44 #include "ProcessBoundaryExtract.h"
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey ProcessBoundaryExtract::className =
53  ModuleKey(eProcessModule, "extract"),
54  ProcessBoundaryExtract::create,
55  "Extract Boundary field");
56 
57 ProcessBoundaryExtract::ProcessBoundaryExtract(FieldSharedPtr f)
58  : ProcessModule(f)
59 {
60  // set up dafault values.
61  m_config["bnd"] = ConfigOption(false, "All", "Boundary to be processed");
62  m_config["addnormals"] =
63  ConfigOption(true, "0", "Add normals to output");
64 
65  f->m_writeBndFld = true;
66  f->m_declareExpansionAsContField = true;
67  f->m_requireBoundaryExpansion = true;
68 }
69 
71 {
72 }
73 
74 void ProcessBoundaryExtract::Process(po::variables_map &vm)
75 {
76  boost::ignore_unused(vm);
77 
78  m_f->m_addNormals = m_config["addnormals"].as<bool>();
79 
80  // Set up Field options to output boundary fld
81  string bvalues = m_config["bnd"].as<string>();
82 
83  vector<unsigned int> bndRegions;
84  if (boost::iequals(bvalues, "All"))
85  {
86  int numBndExp = 0;
87 
89  m_f->m_exp[0]->GetGraph());
91  bcs.GetBoundaryRegions();
92 
93  for (auto &breg_it : bregions)
94  {
95  numBndExp = max(numBndExp, breg_it.first);
96  }
97  // assuming all boundary regions are consecutive number if
98  // regions is one more than maximum id
99  numBndExp++;
100 
101  // not all partitions in parallel touch all boundaries so
102  // find maximum number of boundaries
103  m_f->m_comm->AllReduce(numBndExp, LibUtilities::ReduceMax);
104 
105  // THis presumes boundary regions are numbered consecutively
106  for (int i = 0; i < numBndExp; ++i)
107  {
108  bndRegions.push_back(i);
109  }
110  }
111  else
112  {
113  ASSERTL0(ParseUtils::GenerateVector(bvalues, bndRegions),
114  "Failed to interpret bnd values string");
115  }
116 
117  if(m_f->m_bndRegionsToWrite.size())
118  {
119  // This was already called. Just check if the bnd option is the same
120  ASSERTL0(m_f->m_bndRegionsToWrite == bndRegions,
121  "Incompatible bnd parameters.");
122  }
123  else
124  {
125  m_f->m_bndRegionsToWrite = bndRegions;
126 
127  if (m_f->m_exp[0]->GetNumElmts() != 0)
128  {
129  for (int i = 0; i < m_f->m_exp.size(); ++i)
130  {
131  m_f->m_exp[i]->FillBndCondFromField();
132  }
133  }
134  }
135 }
136 }
137 }
#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.
virtual void Process(po::variables_map &vm)
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
std::pair< ModuleType, std::string > ModuleKey
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition: Conditions.h:217
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
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.
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Definition: Conditions.h:238
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.