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>
38using namespace std;
39
41
43
44namespace Nektar::FieldUtils
45{
46
49 ModuleKey(eProcessModule, "addcompositeid"),
51 "Add a field which contains the composite ID of each element");
52
54 : ProcessModule(f)
55{
56}
57
59{
60}
61
62void ProcessAddCompositeID::v_Process(po::variables_map &vm)
63{
64 m_f->SetUpExp(vm);
65
66 int nfields = m_f->m_variables.size();
67 m_f->m_variables.push_back("compositeID");
68 // Skip in case of empty partition
69 if (m_f->m_exp[0]->GetNumElmts() == 0)
70 {
71 return;
72 }
73
74 int NumHomogeneousDir = m_f->m_numHomogeneousDir;
76
77 if (nfields)
78 {
79 m_f->m_exp.resize(nfields + 1);
80 exp = m_f->AppendExpList(NumHomogeneousDir);
81
82 m_f->m_exp[nfields] = exp;
83 }
84 else
85 {
86 exp = m_f->m_exp[0];
87 }
88
89 // Get Composites
91 m_f->m_graph->GetComposites();
92
93 int compid = -1;
94
95 // loop over elements
96 for (int n = 0; n < exp->GetNumElmts(); ++n)
97 {
98 LocalRegions::ExpansionSharedPtr elmt = exp->GetExp(n);
99
100 // loop over composite list and search for geometry pointer in list
101 for (auto &it : CompositeMap)
102 {
103 if (find(it.second->m_geomVec.begin(), it.second->m_geomVec.end(),
104 elmt->GetGeom()) != it.second->m_geomVec.end())
105 {
106 compid = it.first;
107 break;
108 }
109 }
110
111 WARNINGL0(compid != -1, "Failed to find composite ID for element: " +
112 boost::lexical_cast<string>(n));
113
114 // Fill element with the value of the index
115 int npts = elmt->GetTotPoints();
117 Vmath::Fill(npts, (NekDouble)compid,
118 tmp = exp->UpdatePhys() + exp->GetPhys_Offset(n), 1);
119 }
120
121 // forward transform
122 exp->FwdTransLocalElmt(exp->GetPhys(), exp->UpdateCoeffs());
123}
124} // namespace Nektar::FieldUtils
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
void v_Process(po::variables_map &vm) override
Write mesh to output file.
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.
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
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:136
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
double NekDouble
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
STL namespace.