Nektar++
ProcessCreateExp.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessCreateExp.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: Dummy module to create m_exp.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include "ProcessCreateExp.h"
40
43
44namespace Nektar::FieldUtils
45{
46
50 "dummy module used to create m_exp.");
51
53{
54}
55
57{
58}
59
60void ProcessCreateExp::v_Process(po::variables_map &vm)
61{
62 if (m_f->m_graph)
63 {
64 LibUtilities::Timer timerpart;
65 if (m_f->m_verbose)
66 {
67 if (m_f->m_comm->TreatAsRankZero())
68 {
69 timerpart.Start();
70 }
71 }
72 // check to see if fld file defined so can use in
73 // expansion defintion if required
74 bool fldfilegiven = (m_f->m_fielddef.size() != 0);
75 bool expFromFld = fldfilegiven && !vm.count("use-session-expansion");
76
77 // load fielddef header if fld file is defined. This gives
78 // precedence to Homogeneous definition in fld file
79 m_f->m_numHomogeneousDir = 0;
80 if (expFromFld)
81 {
82 m_f->m_numHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
83
84 // Set up Expansion information to use mode order from field
85 m_f->m_graph->SetExpansionInfo(m_f->m_fielddef);
86 }
87 else
88 {
89 if (m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
90 {
91 std::string HomoStr =
92 m_f->m_session->GetSolverInfo("HOMOGENEOUS");
93
94 if ((HomoStr == "HOMOGENEOUS1D") ||
95 (HomoStr == "Homogeneous1D") || (HomoStr == "1D") ||
96 (HomoStr == "Homo1D"))
97 {
98 m_f->m_numHomogeneousDir = 1;
99 }
100 if ((HomoStr == "HOMOGENEOUS2D") ||
101 (HomoStr == "Homogeneous2D") || (HomoStr == "2D") ||
102 (HomoStr == "Homo2D"))
103 {
104 m_f->m_numHomogeneousDir = 2;
105 }
106 }
107 }
108
109 m_f->m_exp.resize(1);
110 // Check if there are any elements to process
111 vector<int> IDs;
112 auto domain = m_f->m_graph->GetDomain();
113 for (int d = 0; d < domain.size(); ++d)
114 {
115 for (auto &compIter : domain[d])
116 {
117 for (auto &x : compIter.second->m_geomVec)
118 {
119 IDs.push_back(x->GetGlobalID());
120 }
121 }
122 }
123 // if Range has been specified it is possible to have a
124 // partition which is empty so check this and return with empty
125 // expansion if no elements present.
126 if (!IDs.size())
127 {
128 m_f->m_exp[0] =
130 return;
131 }
132
133 // Adjust number of quadrature points
134 if (vm.count("output-points"))
135 {
136 int nPointsNew = vm["output-points"].as<int>();
137 m_f->m_graph->SetExpansionInfoToPointOrder(nPointsNew);
138 }
139
140 if (m_f->m_verbose)
141 {
142 if (m_f->m_comm->TreatAsRankZero())
143 {
144 timerpart.Stop();
145 NekDouble cpuTime = timerpart.TimePerTest(1);
146
147 stringstream ss;
148 ss << cpuTime << "s";
149 cout << "\t ProcessCreateExp setexpansion CPU Time: " << setw(8)
150 << left << ss.str() << endl;
151 timerpart.Start();
152 }
153 }
154 // Override number of planes with value from cmd line
155 if (m_f->m_numHomogeneousDir == 1 && vm.count("output-points-hom-z"))
156 {
157 int expdim = m_f->m_graph->GetMeshDimension();
158 m_f->m_fielddef[0]->m_numModes[expdim] =
159 vm["output-points-hom-z"].as<int>();
160 }
161 m_f->m_exp[0] =
162 m_f->SetUpFirstExpList(m_f->m_numHomogeneousDir, expFromFld);
163 if (m_f->m_verbose)
164 {
165 if (m_f->m_comm->TreatAsRankZero())
166 {
167 timerpart.Stop();
168 NekDouble cpuTime = timerpart.TimePerTest(1);
169
170 stringstream ss1;
171
172 ss1 << cpuTime << "s";
173 cout << "\t ProcessCreateExp set first exp CPU Time: "
174 << setw(8) << left << ss1.str() << endl;
175 }
176 }
177
178 if (fldfilegiven)
179 {
180 LoadFieldData(vm.count("use-session-variables"));
181 }
182 }
183}
184
185void ProcessCreateExp::LoadFieldData(bool useSessionVariables)
186{
187 int i, j;
188 int nfields, nstrips;
189 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
190 vector<string> vars = m_f->m_session->GetVariables();
191
192 if (useSessionVariables)
193 {
194 m_f->m_variables = vars;
195 }
196 nfields = m_f->m_variables.size();
197
198 m_f->m_exp.resize(nfields * nstrips);
199 // declare other fields;
200 for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
201 {
202 for (i = 0; i < nfields; ++i)
203 {
204 if (i < vars.size())
205 {
206 // check to see if field already defined
207 if (!m_f->m_exp[s * nfields + i])
208 {
209 m_f->m_exp[s * nfields + i] =
210 m_f->AppendExpList(m_f->m_numHomogeneousDir, vars[i]);
211 }
212 }
213 else
214 {
215 if (vars.size())
216 {
217 m_f->m_exp[s * nfields + i] =
218 m_f->AppendExpList(m_f->m_numHomogeneousDir, vars[0]);
219 }
220 else
221 {
222 m_f->m_exp[s * nfields + i] =
223 m_f->AppendExpList(m_f->m_numHomogeneousDir);
224 }
225 }
226 }
227 }
228
229 // Extract data to coeffs and bwd transform
230 for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
231 {
232 for (j = 0; j < nfields; ++j)
233 {
234 for (i = 0; i < m_f->m_data.size() / nstrips; ++i)
235 {
236 int n = i * nstrips + s;
237 // In case of multiple flds, we might not have a
238 // variable in this m_data[n] -> skip in this case
239 auto it = find(m_f->m_fielddef[n]->m_fields.begin(),
240 m_f->m_fielddef[n]->m_fields.end(),
241 m_f->m_variables[j]);
242 if (it != m_f->m_fielddef[n]->m_fields.end())
243 {
244 m_f->m_exp[s * nfields + j]->ExtractDataToCoeffs(
245 m_f->m_fielddef[n], m_f->m_data[n], m_f->m_variables[j],
246 m_f->m_exp[s * nfields + j]->UpdateCoeffs());
247 }
248 }
249 m_f->m_exp[s * nfields + j]->BwdTrans(
250 m_f->m_exp[s * nfields + j]->GetCoeffs(),
251 m_f->m_exp[s * nfields + j]->UpdatePhys());
252 }
253 }
254 // Clear fielddef and data (they should not be used after running this
255 // module)
256 m_f->m_fielddef = vector<LibUtilities::FieldDefinitionsSharedPtr>();
257 m_f->m_data = vector<std::vector<NekDouble>>();
258}
259
260} // namespace Nektar::FieldUtils
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
void v_Process(po::variables_map &vm) override
Write mesh to output file.
void LoadFieldData(bool useSessionVariables=false)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
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.
Definition: NekFactory.hpp:197
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:65
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:447
std::vector< double > d(NPUPPER *NPUPPER)
double NekDouble