ProcessInterpPointDataToFld.cpp 5.31 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
////////////////////////////////////////////////////////////////////////////////
//
//  File: ProcessInterpPointDataToFld.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: Interpolate, using finite different approximation,
//  given data to a fld file
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
37
#include <string>
Kilian Lackhove's avatar
Kilian Lackhove committed
38

39 40 41 42
using namespace std;

#include "ProcessInterpPointDataToFld.h"

43
#include <FieldUtils/Interpolator.h>
44
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
45
#include <LibUtilities/BasicUtils/PtsField.h>
46 47 48 49
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
namespace Nektar
{
Douglas Serson's avatar
Douglas Serson committed
50
namespace FieldUtils
51 52 53 54
{

ModuleKey ProcessInterpPointDataToFld::className =
    GetModuleFactory().RegisterCreatorFunction(
55 56 57 58
        ModuleKey(eProcessModule, "interppointdatatofld"),
        ProcessInterpPointDataToFld::create,
        "Interpolates given discrete data using a finite difference "
        "approximation to a fld file given a xml file");
59 60

ProcessInterpPointDataToFld::ProcessInterpPointDataToFld(FieldSharedPtr f)
61
    : ProcessModule(f)
62 63
{

64 65
    m_config["interpcoord"] =
        ConfigOption(false, "-1", "coordinate id to use for interpolation");
66 67 68 69 70 71 72 73
}

ProcessInterpPointDataToFld::~ProcessInterpPointDataToFld()
{
}

void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
{
74
    if (m_f->m_verbose)
75
    {
76
        if (m_f->m_comm->TreatAsRankZero())
77
        {
78 79 80
            cout
                << "ProcessInterpPointDataToFld: interpolating data to field..."
                << endl;
81 82 83
        }
    }

84
    int i, j;
85

86
    // Check for command line point specification if no .pts file specified
87
    ASSERTL0(m_f->m_fieldPts != LibUtilities::NullPtsField,
88
             "No input points found");
89

90
    int nFields = m_f->m_fieldPts->GetNFields();
91
    ASSERTL0(nFields > 0, "No field values provided in input");
92

93
    // assume one field is already defined from input file.
94
    m_f->m_exp.resize(nFields);
95
    for (i = 1; i < nFields; ++i)
96 97 98
    {
        m_f->m_exp[i] = m_f->AppendExpList(0);
    }
99

100
    int totpoints = m_f->m_exp[0]->GetTotPoints();
101 102 103
    Array<OneD, Array<OneD, NekDouble> > intFields(3 + nFields);
    for (int i = 0; i < 3 + nFields; ++i)
    {
104
        intFields[i] = Array<OneD, NekDouble>(totpoints);
105
    }
106
    m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
107
    LibUtilities::PtsFieldSharedPtr outPts =
108
        MemoryManager<LibUtilities::PtsField>::AllocateSharedPtr(3, intFields);
109 110

    int coord_id = m_config["interpcoord"].as<int>();
111
    ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
112
             "interpcoord is bigger than the Pts files dimension");
113

114
    Interpolator interp(eNoMethod, coord_id);
115 116

    if (m_f->m_comm->GetRank() == 0)
Kilian Lackhove's avatar
Kilian Lackhove committed
117
    {
118
        interp.SetProgressCallback(
119
            &ProcessInterpPointDataToFld::PrintProgressbar, this);
Kilian Lackhove's avatar
Kilian Lackhove committed
120
    }
121 122 123 124
    interp.Interpolate(m_f->m_fieldPts, outPts);
    if (m_f->m_comm->GetRank() == 0)
    {
        cout << endl;
Kilian Lackhove's avatar
Kilian Lackhove committed
125
    }
126

127
    for (i = 0; i < totpoints; ++i)
128
    {
129
        for (j = 0; j < nFields; ++j)
130
        {
131
            m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(3 + j, i));
132
        }
133 134 135
    }

    // forward transform fields
136
    for (i = 0; i < nFields; ++i)
137 138 139 140 141 142
    {
        m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
                                           m_f->m_exp[i]->UpdateCoeffs());
    }

    // set up output fld file.
143 144
    std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
        m_f->m_exp[0]->GetFieldDefinitions();
145 146
    std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());

147
    for (j = 0; j < nFields; ++j)
148 149
    {
        for (i = 0; i < FieldDef.size(); ++i)
150
        {
151
            FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
152

153
            m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
154 155
        }
    }
156 157 158 159 160

    m_f->m_fielddef = FieldDef;
    m_f->m_data     = FieldData;
}
}
161
}