Nektar++
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 // 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: Add composite ID as a variable to the field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <algorithm>
36 #include <iostream>
37 #include <string>
38 using namespace std;
39 
40 #include <boost/core/ignore_unused.hpp>
41 
43 
44 #include "ProcessAddCompositeID.h"
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey ProcessAddCompositeID::className =
53  ModuleKey(eProcessModule, "addcompositeid"),
54  ProcessAddCompositeID::create,
55  "Add a field which contains the composite ID of each element");
56 
57 ProcessAddCompositeID::ProcessAddCompositeID(FieldSharedPtr f)
58  : ProcessModule(f)
59 {
60 }
61 
63 {
64 }
65 
66 void ProcessAddCompositeID::Process(po::variables_map &vm)
67 {
68  m_f->SetUpExp(vm);
69 
70  int nfields = m_f->m_variables.size();
71  m_f->m_variables.push_back("compositeID");
72  // Skip in case of empty partition
73  if (m_f->m_exp[0]->GetNumElmts() == 0)
74  {
75  return;
76  }
77 
78  int NumHomogeneousDir = m_f->m_numHomogeneousDir;
80 
81  if (nfields)
82  {
83  m_f->m_exp.resize(nfields + 1);
84  exp = m_f->AppendExpList(NumHomogeneousDir);
85 
86  m_f->m_exp[nfields] = exp;
87  }
88  else
89  {
90  exp = m_f->m_exp[0];
91  }
92 
93  // Get Composites
95  m_f->m_graph->GetComposites();
96 
97  int compid = -1;
98 
99  // loop over elements
100  for (int n = 0; n < exp->GetNumElmts(); ++n)
101  {
102  LocalRegions::ExpansionSharedPtr elmt = exp->GetExp(n);
103 
104  // loop over composite list and search for geometry pointer in list
105  for (auto &it : CompositeMap)
106  {
107  if (find(it.second->m_geomVec.begin(),
108  it.second->m_geomVec.end(), elmt->GetGeom()) !=
109  it.second->m_geomVec.end())
110  {
111  compid = it.first;
112  break;
113  }
114  }
115 
116  WARNINGL0(compid != -1,
117  "Failed to find composite ID for element: " +
118  boost::lexical_cast<string>(n));
119 
120  // Fill element with the value of the index
121  int npts = elmt->GetTotPoints();
123  Vmath::Fill(npts, (NekDouble)compid,
124  tmp = exp->UpdatePhys() + exp->GetPhys_Offset(n), 1);
125  }
126 
127  // forward transform
128  exp->FwdTrans_IterPerExp(exp->GetPhys(), exp->UpdateCoeffs());
129 }
130 }
131 }
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:223
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:265
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:138
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:362
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45