ProcessCreateExp.cpp 9.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
////////////////////////////////////////////////////////////////////////////////
//
//  File: ProcessCreateExp.cpp
//
//  For more information, please see: http://www.nektar.info/
//
//  The MIT License
//
//  Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
//  Department of Aeronautics, Imperial College London (UK), and Scientific
//  Computing and Imaging Institute, University of Utah (USA).
//
//  License for the specific language governing rights and limitations under
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included
//  in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
//  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
//  Description: Dummy module to create m_exp.
//
////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <string>
using namespace std;

#include "ProcessCreateExp.h"

#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/Timer.h>

namespace Nektar
{
namespace FieldUtils
{

ModuleKey ProcessCreateExp::className =
    GetModuleFactory().RegisterCreatorFunction(
        ModuleKey(eProcessModule, "createExp"),
        ProcessCreateExp::create,
        "dummy module used to create m_exp.");

ProcessCreateExp::ProcessCreateExp(FieldSharedPtr f) : ProcessModule(f)
{
}

ProcessCreateExp::~ProcessCreateExp()
{
}

void ProcessCreateExp::Process(po::variables_map &vm)
{
    if(m_f->m_graph)
    {
        int i, j;
70
        LibUtilities::Timer timerpart;
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        if (m_f->m_verbose)
        {
            if (m_f->m_comm->TreatAsRankZero())
            {
                timerpart.Start();
            }
        }

        // check to see if fld file defined so can use in
        // expansion defintion if required
        bool fldfilegiven = (m_f->m_fielddef.size() != 0);

        // currently load all field (possibly could read data from
        // expansion list but it is re-arranged in expansion)
        const SpatialDomains::ExpansionMap &expansions =
            m_f->m_graph->GetExpansions();

        // load fielddef header if fld file is defined. This gives
        // precedence to Homogeneous definition in fld file
90
        m_f->m_numHomogeneousDir = 0;
91
92
        if (fldfilegiven)
        {
93
            m_f->m_numHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

            // Set up Expansion information to use mode order from field
            m_f->m_graph->SetExpansions(m_f->m_fielddef);
        }
        else
        {
            if (m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
            {
                std::string HomoStr = 
                        m_f->m_session->GetSolverInfo("HOMOGENEOUS");

                if ((HomoStr == "HOMOGENEOUS1D") ||
                    (HomoStr == "Homogeneous1D") ||
                    (HomoStr == "1D") || (HomoStr == "Homo1D"))
                {
109
                    m_f->m_numHomogeneousDir = 1;
110
111
112
113
114
                }
                if ((HomoStr == "HOMOGENEOUS2D") ||
                    (HomoStr == "Homogeneous2D") ||
                    (HomoStr == "2D") || (HomoStr == "Homo2D"))
                {
115
                    m_f->m_numHomogeneousDir = 2;
116
117
118
119
                }
            }
        }

120
121
        m_f->m_exp.resize(1);

122
        // if Range has been specified it is possible to have a
123
124
        // partition which is empty so check this and return with empty
        // expansion if no elements present.
125
126
        if (!expansions.size())
        {
127
128
            m_f->m_exp[0] = MemoryManager<MultiRegions::ExpList>::
                            AllocateSharedPtr();
129
130
131
132
133
134
135
136
137
            return;
        }

        if (fldfilegiven)
        {
            // Set up Expansion information to use mode order from field
            m_f->m_graph->SetExpansions(m_f->m_fielddef);
        }

138
139
        // Adjust number of quadrature points
        if (vm.count("output-points"))
140
        {
141
142
            int nPointsNew = vm["output-points"].as<int>();
            m_f->m_graph->SetExpansionsToPointOrder(nPointsNew);
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        }

        if (m_f->m_verbose)
        {
            if (m_f->m_comm->TreatAsRankZero())
            {
                timerpart.Stop();
                NekDouble cpuTime = timerpart.TimePerTest(1);

                stringstream ss;
                ss << cpuTime << "s";
                cout << "\t ProcessCreateExp setexpansion CPU Time: "
                     << setw(8) << left
                     << ss.str() << endl;
                timerpart.Start();
            }
        }

        // Override number of planes with value from cmd line
162
        if (m_f->m_numHomogeneousDir == 1 && vm.count("output-points-hom-z"))
163
164
165
166
167
168
        {
            int expdim = m_f->m_graph->GetMeshDimension();
            m_f->m_fielddef[0]->m_numModes[expdim] =
                vm["output-points-hom-z"].as<int>();
        }

169
170
        m_f->m_exp[0] = m_f->SetUpFirstExpList(m_f->m_numHomogeneousDir,
                                                fldfilegiven);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

        if (m_f->m_verbose)
        {
            if (m_f->m_comm->TreatAsRankZero())
            {
                timerpart.Stop();
                NekDouble cpuTime = timerpart.TimePerTest(1);

                stringstream ss1;

                ss1 << cpuTime << "s";
                cout << "\t ProcessCreateExp set first exp CPU Time: "
                     << setw(8)   << left
                     << ss1.str() << endl;
            }
        }

        if (fldfilegiven)
        {
            int nfields, nstrips;

            m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);

194
            vector<string> vars = m_f->m_session->GetVariables();
195
196
            if (vm.count("useSessionVariables"))
            {
197
                m_f->m_variables = vars;
198
            }
Douglas Serson's avatar
Douglas Serson committed
199
            nfields = m_f->m_variables.size();
200
201
202
203
204
205
206
207
208
209
210
211
212
213

            m_f->m_exp.resize(nfields * nstrips);

            // declare other fields;
            for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
            {
                for (i = 0; i < nfields; ++i)
                {
                    if (i < vars.size())
                    {
                        // check to see if field already defined
                        if (!m_f->m_exp[s * nfields + i])
                        {
                            m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
214
                              m_f->m_numHomogeneousDir, vars[i]);
215
216
217
218
219
220
221
                        }
                    }
                    else
                    {
                        if (vars.size())
                        {
                            m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
222
                              m_f->m_numHomogeneousDir, vars[0]);
223
224
225
226
                        }
                        else
                        {
                            m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
227
                                m_f->m_numHomogeneousDir);
228
229
230
231
232
233
234
235
236
237
238
239
                        }
                    }
                }
            }

            // Extract data to coeffs and bwd transform
            for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
            {
                for (j = 0; j < nfields; ++j)
                {
                    for (i = 0; i < m_f->m_data.size() / nstrips; ++i)
                    {
Douglas Serson's avatar
Douglas Serson committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
                        int n = i * nstrips + s;
                        // In case of multiple flds, we might not have a
                        //   variable in this m_data[n] -> skip in this case
                        vector<string>::iterator it =
                            find (m_f->m_fielddef[n]->m_fields.begin(),
                                  m_f->m_fielddef[n]->m_fields.end(),
                                  m_f->m_variables[j]);
                        if(it !=m_f->m_fielddef[n]->m_fields.end())
                        {
                            m_f->m_exp[s * nfields + j]->ExtractDataToCoeffs(
                                m_f->m_fielddef[n],
                                m_f->m_data[n],
                                m_f->m_variables[j],
                                m_f->m_exp[s * nfields + j]->UpdateCoeffs());
                        }
255
256
257
258
259
260
                    }
                    m_f->m_exp[s * nfields + j]->BwdTrans(
                        m_f->m_exp[s * nfields + j]->GetCoeffs(),
                        m_f->m_exp[s * nfields + j]->UpdatePhys());
                }
            }
261
262
263
264
            // Clear fielddef and data
            //    (they should not be used after running this module)
            m_f->m_fielddef = vector<LibUtilities::FieldDefinitionsSharedPtr>();
            m_f->m_data     = vector<std::vector<NekDouble> >();
265
266
267
268
269
270
        }
    }

}
}
}