Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessAddCompositeID.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessAddCompositeID.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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Add composite ID as a variable to the field.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <algorithm>
37 #include <iostream>
38 #include <string>
39 
40 using namespace std;
41 
42 #include "ProcessAddCompositeID.h"
43 
46 
47 namespace Nektar
48 {
49 namespace FieldUtils
50 {
51 
52 ModuleKey ProcessAddCompositeID::className =
54  ModuleKey(eProcessModule, "addcompositeid"),
55  ProcessAddCompositeID::create,
56  "Add a field which contains the composite ID of each element");
57 
58 ProcessAddCompositeID::ProcessAddCompositeID(FieldSharedPtr f)
59  : ProcessModule(f)
60 {
61 }
62 
64 {
65 }
66 
67 void ProcessAddCompositeID::Process(po::variables_map &vm)
68 {
69  if (m_f->m_verbose)
70  {
71  if (m_f->m_comm->GetRank() == 0)
72  {
73  cout << "ProcessAddCompositeID: Adding composite ID as a new field"
74  << endl;
75  }
76  }
77 
78  int nfields = 0;
79  int NumHomogeneousDir = 0;
81 
82  if (m_f->m_fielddef.size())
83  {
84  nfields = m_f->m_fielddef[0]->m_fields.size();
85  NumHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
86 
87  m_f->m_exp.resize(nfields + 1);
88  exp = m_f->AppendExpList(NumHomogeneousDir, "Composite ID");
89 
90  m_f->m_exp[nfields] = exp;
91  }
92  else
93  {
94  exp = m_f->m_exp[0];
95  }
96 
97  // Get Composites
99  m_f->m_graph->GetComposites();
100 
102  NekDouble compid=0;
103 
104  // loop over elements
105  for (int n = 0; n < exp->GetNumElmts(); ++n)
106  {
107  LocalRegions::ExpansionSharedPtr elmt = exp->GetExp(n);
108 
109  // loop over composite list and search for geomtry pointer in list
110  for (it = CompositeMap.begin(); it != CompositeMap.end(); ++it)
111  {
112  if (find(it->second->begin(), it->second->end(), elmt->GetGeom()) !=
113  it->second->end())
114  {
115  compid = it->first;
116  break;
117  }
118  }
119 
120  WARNINGL0(it != CompositeMap.end(),
121  "Failed to find composite ID for element: " +
122  boost::lexical_cast<string>(n));
123 
124  // Fill element with the value of the index
125  int npts = elmt->GetTotPoints();
127  Vmath::Fill(npts, compid,
128  tmp = exp->UpdatePhys() + exp->GetPhys_Offset(n), 1);
129  }
130 
131  // forward transform
132  exp->FwdTrans_IterPerExp(exp->GetPhys(), exp->UpdateCoeffs());
133 
134  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
135  m_f->m_exp[0]->GetFieldDefinitions();
136  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
137 
138  // copy in previous fields if they exist.
139  for (int i = 0; i < nfields; ++i)
140  {
141  for (int j = 0; j < FieldDef.size(); ++j)
142  {
143  FieldDef[j]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[i]);
144  m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]);
145  }
146  }
147 
148  // append composite id field
149  for (int j = 0; j < FieldDef.size(); ++j)
150  {
151  FieldDef[j]->m_fields.push_back("compositeID");
152  m_f->m_exp[nfields]->AppendFieldData(FieldDef[j], FieldData[j]);
153  }
154 
155  m_f->m_fielddef = FieldDef;
156  m_f->m_data = FieldData;
157 }
158 }
159 }
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:46
STL namespace.
pair< ModuleType, string > ModuleKey
virtual void Process(po::variables_map &vm)
Write mesh to output file.
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:767
std::map< int, Composite >::const_iterator CompositeMapConstIter
Definition: MeshGraph.h:117
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:204
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static std::string npts
Definition: InputFld.cpp:43
double NekDouble
boost::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
std::map< int, Composite > CompositeMap
Definition: MeshGraph.h:115
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:316
Abstract base class for processing modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215