Nektar++
ProcessC0Projection.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessC0Projection.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: Computes C0 projection.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessC0Projection.h"
41 
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey ProcessC0Projection::className =
52  ModuleKey(eProcessModule, "C0Projection"),
53  ProcessC0Projection::create, "Computes C0 projection.");
54 
55 ProcessC0Projection::ProcessC0Projection(FieldSharedPtr f) : ProcessModule(f)
56 {
57  m_config["fields"] = ConfigOption(false,"All","Start field to project");
58 }
59 
61 {
62 }
63 
64 void ProcessC0Projection::Process(po::variables_map &vm)
65 {
66  if (m_f->m_verbose)
67  {
68  cout << "ProcessC0Projection: Projecting field into C0 space..."
69  << endl;
70  }
71 
72  // ensure not using diagonal preconditioner since tends not to converge fo
73  // mass matrix
74  if(m_f->m_graph->GetMeshDimension() == 3)
75  {
76  if(boost::iequals(m_f->m_session->GetSolverInfo("GLOBALSYSSOLN"),
77  "IterativeStaticCond"))
78  {
79  if(boost::iequals(m_f->m_session->GetSolverInfo("PRECONDITIONER"),
80  "Diagonal"))
81  {
82  m_f->m_session->SetSolverInfo("PRECONDITIONER","LowEnergyBlock");
83  }
84  if(boost::iequals(m_f->m_session->GetSolverInfo("PRECONDITIONER"),
85  "FullLinearSpaceWithDiagonal"))
86  {
87  m_f->m_session->SetSolverInfo("PRECONDITIONER","FullLinearSpaceWithLowEnergyBlock");
88  }
89 
90  if(m_f->m_verbose)
91  {
92  cout << "Resetting diagonal precondition to low energy block " << endl;;
93  }
94  }
95  }
96 
97 
98  // generate an C0 expansion field with no boundary conditions.
99  bool savedef = m_f->m_declareExpansionAsContField;
100  m_f->m_declareExpansionAsContField = true;
101  MultiRegions::ExpListSharedPtr C0ProjectExp =
102  m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,
103  "DefaultVar",true);
104  m_f->m_declareExpansionAsContField = savedef;
105 
106  int nfields = m_f->m_exp.size();
107 
108  string fields = m_config["fields"].as<string>();
109  vector<unsigned int> processFields;
110 
111  if(fields.compare("All") == 0)
112  {
113  for(int i = 0; i < nfields; ++i)
114  {
115  processFields.push_back(i);
116  }
117  }
118  else
119  {
121  processFields),
122  "Failed to interpret field string in C0Projection");
123  }
124 
125  for (int i = 0; i < processFields.size(); ++i)
126  {
127  ASSERTL0(processFields[i] < nfields,
128  "Attempt to process field that is larger than then number of "
129  "fields available");
130 
131  if (m_f->m_verbose)
132  {
133  cout << "\t Processing field: " << processFields[i] << endl;
134  }
135  C0ProjectExp->BwdTrans(m_f->m_exp[processFields[i]]->GetCoeffs(),
136  m_f->m_exp[processFields[i]]->UpdatePhys());
137  C0ProjectExp->FwdTrans(m_f->m_exp[processFields[i]]->GetPhys(),
138  m_f->m_exp[processFields[i]]->UpdateCoeffs());
139  }
140 
141  // reset FieldDef in case of serial input and parallel output
142  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
143  = m_f->m_exp[0]->GetFieldDefinitions();
144  // reset up FieldData with new values before projecting
145  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
146 
147  for(int i = 0; i < nfields; ++i)
148  {
149  for (int j = 0; j < FieldDef.size(); ++j)
150  {
151  FieldDef[j]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[i]);
152  m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]);
153  }
154  }
155 
156  m_f->m_fielddef = FieldDef;
157  m_f->m_data = FieldData;
158 }
159 
160 }
161 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
pair< ModuleType, string > ModuleKey
static bool GenerateOrderedVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:96
virtual void Process()=0
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
Definition: ExpList.h:1340
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
Represents a command-line configuration option.
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215