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// 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
40#include <boost/core/ignore_unused.hpp>
41
43
45
46namespace Nektar
47{
48namespace FieldUtils
49{
50
53 ModuleKey(eProcessModule, "addcompositeid"),
55 "Add a field which contains the composite ID of each element");
56
58 : ProcessModule(f)
59{
60}
61
63{
64}
65
66void ProcessAddCompositeID::v_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(), it.second->m_geomVec.end(),
108 elmt->GetGeom()) != it.second->m_geomVec.end())
109 {
110 compid = it.first;
111 break;
112 }
113 }
114
115 WARNINGL0(compid != -1, "Failed to find composite ID for element: " +
116 boost::lexical_cast<string>(n));
117
118 // Fill element with the value of the index
119 int npts = elmt->GetTotPoints();
121 Vmath::Fill(npts, (NekDouble)compid,
122 tmp = exp->UpdatePhys() + exp->GetPhys_Offset(n), 1);
123 }
124
125 // forward transform
126 exp->FwdTransLocalElmt(exp->GetPhys(), exp->UpdateCoeffs());
127}
128} // namespace FieldUtils
129} // namespace Nektar
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:222
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:292
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
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:453
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:43