InputFld.cpp 8.66 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
////////////////////////////////////////////////////////////////////////////////
//
//  File: InputFld.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.
//
32
//  Description: Reads a Nektar++ FLD file.
33 34 35 36
//
////////////////////////////////////////////////////////////////////////////////

#include <iostream>
37
#include <string>
38 39 40
using namespace std;

#include "InputFld.h"
41
using namespace Nektar;
42 43

static std::string npts = LibUtilities::SessionReader::RegisterCmdLineArgument(
44
    "NumberOfPoints", "n", "Define number of points to dump output");
45

46 47
namespace Nektar
{
Douglas Serson's avatar
Douglas Serson committed
48
namespace FieldUtils
Chris Cantwell's avatar
Chris Cantwell committed
49 50
{

51
ModuleKey InputFld::m_className[4] = {
Chris Cantwell's avatar
Chris Cantwell committed
52
    GetModuleFactory().RegisterCreatorFunction(
53 54 55 56 57 58 59
        ModuleKey(eInputModule, "fld"), InputFld::create, "Reads Fld file."),
    GetModuleFactory().RegisterCreatorFunction(ModuleKey(eInputModule, "chk"),
                                               InputFld::create,
                                               "Reads checkpoint file."),
    GetModuleFactory().RegisterCreatorFunction(ModuleKey(eInputModule, "rst"),
                                               InputFld::create,
                                               "Reads restart file."),
Chris Cantwell's avatar
Chris Cantwell committed
60
    GetModuleFactory().RegisterCreatorFunction(
61 62 63
        ModuleKey(eInputModule, "bse"),
        InputFld::create,
        "Reads stability base-flow file.")};
Chris Cantwell's avatar
Chris Cantwell committed
64 65 66 67 68 69 70 71 72 73

/**
 * @brief Set up InputFld object.
 *
 */
InputFld::InputFld(FieldSharedPtr f) : InputModule(f)
{
    m_allowedFiles.insert("fld");
    m_allowedFiles.insert("chk");
    m_allowedFiles.insert("rst");
74
    m_allowedFiles.insert("bse");
Chris Cantwell's avatar
Chris Cantwell committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88
}

/**
 *
 */
InputFld::~InputFld()
{
}

/**
 *
 */
void InputFld::Process(po::variables_map &vm)
{
89

90
    if (m_f->m_verbose)
Chris Cantwell's avatar
Chris Cantwell committed
91
    {
92
        if (m_f->m_comm->TreatAsRankZero())
93 94 95
        {
            cout << "Processing input fld file" << endl;
        }
Chris Cantwell's avatar
Chris Cantwell committed
96 97
    }

98
    int i, j;
Chris Cantwell's avatar
Chris Cantwell committed
99
    string fldending;
100 101
    // Determine appropriate field input
    if (m_f->m_inputfiles.count("fld") != 0)
Chris Cantwell's avatar
Chris Cantwell committed
102 103 104
    {
        fldending = "fld";
    }
105
    else if (m_f->m_inputfiles.count("chk") != 0)
Chris Cantwell's avatar
Chris Cantwell committed
106 107 108 109 110 111 112
    {
        fldending = "chk";
    }
    else if (m_f->m_inputfiles.count("rst") != 0)
    {
        fldending = "rst";
    }
113 114 115 116
    else if (m_f->m_inputfiles.count("bse") != 0)
    {
        fldending = "bse";
    }
Chris Cantwell's avatar
Chris Cantwell committed
117 118
    else
    {
119
        ASSERTL0(false, "no input file found");
Chris Cantwell's avatar
Chris Cantwell committed
120 121
    }

122
    if (!m_f->m_fld)
123
    {
124
        if (m_f->m_session)
125
        {
126 127 128
            m_f->m_fld =
                MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(
                    m_f->m_session->GetComm());
129
        }
Chris Cantwell's avatar
Chris Cantwell committed
130
        else // serial communicator
131
        {
132 133 134 135
            LibUtilities::CommSharedPtr c =
                LibUtilities::GetCommFactory().CreateInstance("Serial", 0, 0);
            m_f->m_fld =
                MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(c);
136
        }
Chris Cantwell's avatar
Chris Cantwell committed
137
    }
138

139
    if (m_f->m_graph)
Chris Cantwell's avatar
Chris Cantwell committed
140
    {
Douglas Serson's avatar
Douglas Serson committed
141
        if (m_f->m_data.size() == 0)
142 143 144
        {
            // currently load all field (possibly could read data from
            //  expansion list but it is re-arranged in expansion)
Chris Cantwell's avatar
Chris Cantwell committed
145

146
            const SpatialDomains::ExpansionMap &expansions =
147
                m_f->m_graph->GetExpansions();
Chris Cantwell's avatar
Chris Cantwell committed
148

149 150 151
            // if Range has been speficied it is possible to have a
            // partition which is empty so check this and return if
            // no elements present.
152

153
            if (!expansions.size())
154 155 156
            {
                return;
            }
157

158
            m_f->m_exp.resize(1);
Chris Cantwell's avatar
Chris Cantwell committed
159

160
            Array<OneD, int> ElementGIDs(expansions.size());
161
            SpatialDomains::ExpansionMap::const_iterator expIt;
Chris Cantwell's avatar
Chris Cantwell committed
162

163 164 165 166 167
            i = 0;
            for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
            {
                ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
            }
Chris Cantwell's avatar
Chris Cantwell committed
168

169 170
            m_f->m_fielddef.clear();
            m_f->m_data.clear();
Chris Cantwell's avatar
Chris Cantwell committed
171

172 173
            m_f->m_fld->Import(m_f->m_inputfiles[fldending][0], m_f->m_fielddef,
                               m_f->m_data, m_f->m_fieldMetaDataMap,
174 175
                               ElementGIDs);
        }
Chris Cantwell's avatar
Chris Cantwell committed
176 177 178
    }
    else // load all data.
    {
179 180
        m_f->m_fld->Import(m_f->m_inputfiles[fldending][0], m_f->m_fielddef,
                           m_f->m_data, m_f->m_fieldMetaDataMap);
Chris Cantwell's avatar
Chris Cantwell committed
181
    }
Chris Cantwell's avatar
Chris Cantwell committed
182

Chris Cantwell's avatar
Chris Cantwell committed
183
    // if m_exp defined presume we want to load all field  into expansions
184
    if (m_f->m_exp.size())
Chris Cantwell's avatar
Chris Cantwell committed
185
    {
186
        int nfields, nstrips;
187

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

190
        if (vm.count("useSessionVariables"))
Chris Cantwell's avatar
Chris Cantwell committed
191 192 193 194 195 196 197
        {
            nfields = m_f->m_session->GetVariables().size();
        }
        else
        {
            nfields = m_f->m_fielddef[0]->m_fields.size();
        }
198 199

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

Chris Cantwell's avatar
Chris Cantwell committed
201 202 203
        vector<string> vars = m_f->m_session->GetVariables();

        // declare other fields;
204
        for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
Chris Cantwell's avatar
Chris Cantwell committed
205 206 207
        {
            for (i = 0; i < nfields; ++i)
            {
208
                if (i < vars.size())
209
                {
210 211
                    // check to see if field already defined
                    if (!m_f->m_exp[s * nfields + i])
212
                    {
213 214
                        m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
                            m_f->m_fielddef[0]->m_numHomogeneousDir, vars[i]);
215
                    }
216 217 218
                }
                else
                {
219
                    if (vars.size())
220
                    {
221 222
                        m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
                            m_f->m_fielddef[0]->m_numHomogeneousDir, vars[0]);
223
                    }
Chris Cantwell's avatar
Chris Cantwell committed
224
                    else
225
                    {
226 227
                        m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
                            m_f->m_fielddef[0]->m_numHomogeneousDir);
Chris Cantwell's avatar
Chris Cantwell committed
228
                    }
229
                }
Chris Cantwell's avatar
Chris Cantwell committed
230 231 232
            }
        }

233
        // Extract data to coeffs and bwd transform
234
        for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
Chris Cantwell's avatar
Chris Cantwell committed
235 236 237
        {
            for (j = 0; j < nfields; ++j)
            {
238
                for (i = 0; i < m_f->m_data.size() / nstrips; ++i)
239
                {
240 241 242 243 244
                    m_f->m_exp[s * nfields + j]->ExtractDataToCoeffs(
                        m_f->m_fielddef[i * nstrips + s],
                        m_f->m_data[i * nstrips + s],
                        m_f->m_fielddef[i * nstrips + s]->m_fields[j],
                        m_f->m_exp[s * nfields + j]->UpdateCoeffs());
Chris Cantwell's avatar
Chris Cantwell committed
245
                }
246 247 248
                m_f->m_exp[s * nfields + j]->BwdTrans(
                    m_f->m_exp[s * nfields + j]->GetCoeffs(),
                    m_f->m_exp[s * nfields + j]->UpdatePhys());
Chris Cantwell's avatar
Chris Cantwell committed
249 250
            }
        }
Chris Cantwell's avatar
Chris Cantwell committed
251

252 253
        // reset output field in case Import loaded elements that are not
        // in the expansion (because of range option of partitioning)
254 255
        std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
            m_f->m_exp[0]->GetFieldDefinitions();
256
        std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
Chris Cantwell's avatar
Chris Cantwell committed
257

258 259 260
        for (j = 0; j < nfields; ++j)
        {
            for (i = 0; i < FieldDef.size(); ++i)
Chris Cantwell's avatar
Chris Cantwell committed
261
            {
262 263
                FieldDef[i]->m_fields.push_back(
                    m_f->m_fielddef[0]->m_fields[j]);
264
                m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
265
            }
266
        }
267 268
        m_f->m_fielddef = FieldDef;
        m_f->m_data     = FieldData;
269
    }
270
}
Chris Cantwell's avatar
Chris Cantwell committed
271 272
}
}