InputMCF.cpp 11.6 KB
Newer Older
Michael Turner's avatar
Michael Turner committed
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: InputCAD.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.
//
Michael Turner's avatar
Michael Turner committed
32
//  Description: create mesh from cad using mesh utils
Michael Turner's avatar
Michael Turner committed
33
34
35
//
////////////////////////////////////////////////////////////////////////////////

36
37
#include <LibUtilities/BasicUtils/SessionReader.h>

38
39
#include <boost/thread.hpp>

40
#include <tinyxml.h>
41

Michael Turner's avatar
Michael Turner committed
42
#include "InputMCF.h"
Michael Turner's avatar
Michael Turner committed
43

Michael Turner's avatar
Michael Turner committed
44
using namespace std;
45
using namespace Nektar::NekMeshUtils;
46
47
48
49
50

namespace Nektar
{
namespace Utilities
{
Michael Turner's avatar
Michael Turner committed
51

Michael Turner's avatar
Michael Turner committed
52
53
54
ModuleKey InputMCF::className = GetModuleFactory().RegisterCreatorFunction(
    ModuleKey(eInputModule, "mcf"), InputMCF::create,
    "Reads mesh configuration and will generate the mesh file.");
Michael Turner's avatar
Michael Turner committed
55
56
57
58

/**
 * @brief Set up InputCAD object.
 */
Michael Turner's avatar
Michael Turner committed
59
InputMCF::InputMCF(MeshSharedPtr m) : InputModule(m)
60
{
Michael Turner's avatar
Michael Turner committed
61
}
Michael Turner's avatar
Michael Turner committed
62

Michael Turner's avatar
Michael Turner committed
63
InputMCF::~InputMCF()
Michael Turner's avatar
Michael Turner committed
64
65
{
}
Michael Turner's avatar
Michael Turner committed
66

Michael Turner's avatar
Michael Turner committed
67
void InputMCF::ParseFile(string nm)
Michael Turner's avatar
Michael Turner committed
68
{
69
    vector<string> filename;
70
    filename.push_back(nm);
71
72
    LibUtilities::SessionReaderSharedPtr pSession =
        LibUtilities::SessionReader::CreateInstance(0, NULL, filename);
Michael Turner's avatar
Michael Turner committed
73

Dave Moxey's avatar
Dave Moxey committed
74
75
76
77
78
    ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING"), "no meshing tag");
    ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING/INFORMATION"),
             "no information tag");
    ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING/PARAMETERS"),
             "no parameters tag");
79
80
81
82

    TiXmlElement *mcf = pSession->GetElement("NEKTAR/MESHING");

    TiXmlElement *info = mcf->FirstChildElement("INFORMATION");
Dave Moxey's avatar
Dave Moxey committed
83
84
85
    TiXmlElement *I    = info->FirstChildElement("I");
    map<string, string> information;
    while (I)
86
    {
Dave Moxey's avatar
Dave Moxey committed
87
88
89
        string tmp1, tmp2;
        I->QueryStringAttribute("PROPERTY", &tmp1);
        I->QueryStringAttribute("VALUE", &tmp2);
90
        information[tmp1] = tmp2;
Dave Moxey's avatar
Dave Moxey committed
91
        I                 = I->NextSiblingElement("I");
92
93
94
    }

    TiXmlElement *param = mcf->FirstChildElement("PARAMETERS");
Dave Moxey's avatar
Dave Moxey committed
95
96
97
    TiXmlElement *P     = param->FirstChildElement("P");
    map<string, string> parameters;
    while (P)
98
    {
Dave Moxey's avatar
Dave Moxey committed
99
100
101
        string tmp1, tmp2;
        P->QueryStringAttribute("PARAM", &tmp1);
        P->QueryStringAttribute("VALUE", &tmp2);
102
        parameters[tmp1] = tmp2;
Dave Moxey's avatar
Dave Moxey committed
103
        P                = P->NextSiblingElement("P");
104
105
106
    }

    set<string> boolparameters;
107

Dave Moxey's avatar
Dave Moxey committed
108
    if (pSession->DefinesElement("NEKTAR/MESHING/BOOLPARAMETERS"))
109
    {
110
        TiXmlElement *bparam = mcf->FirstChildElement("BOOLPARAMETERS");
Dave Moxey's avatar
Dave Moxey committed
111
        TiXmlElement *BP     = bparam->FirstChildElement("P");
112

Dave Moxey's avatar
Dave Moxey committed
113
        while (BP)
114
115
        {
            string tmp;
Dave Moxey's avatar
Dave Moxey committed
116
            BP->QueryStringAttribute("VALUE", &tmp);
117
118
119
            boolparameters.insert(tmp);
            BP = BP->NextSiblingElement("P");
        }
120
121
    }

Michael Turner's avatar
Michael Turner committed
122
123
124
125
    set<string> refinement;
    if(pSession->DefinesElement("NEKTAR/MESHING/REFINEMENT"))
    {
        TiXmlElement *refine = mcf->FirstChildElement("REFINEMENT");
Michael Turner's avatar
Michael Turner committed
126
        TiXmlElement *L     = refine->FirstChildElement("LINE");
Michael Turner's avatar
Michael Turner committed
127
128
129

        while (L)
        {
Michael Turner's avatar
Michael Turner committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            stringstream ss;
            TiXmlElement *T = L->FirstChildElement("X1");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("Y1");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("Z1");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("X2");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("Y2");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("Z2");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("R");
            ss << T->GetText() << ",";
            T = L->FirstChildElement("D");
            ss << T->GetText();

            refinement.insert(ss.str());

            L = L->NextSiblingElement("LINE");
Michael Turner's avatar
Michael Turner committed
151
152
        }
    }
Michael Turner's avatar
Michael Turner committed
153
154

    map<string,string>::iterator it;
155
156

    it = information.find("CADFile");
Dave Moxey's avatar
Dave Moxey committed
157
    ASSERTL0(it != information.end(), "no cadfile defined");
158
    m_cadfile = it->second;
Dave Moxey's avatar
Dave Moxey committed
159

160
    it = information.find("MeshType");
Dave Moxey's avatar
Dave Moxey committed
161
    ASSERTL0(it != information.end(), "no meshtype defined");
Michael Turner's avatar
Michael Turner committed
162
    m_makeBL = it->second == "3DBndLayer";
Julian Marcon's avatar
Tidy    
Julian Marcon committed
163
    m_2D = it->second == "2D";
Michael Turner's avatar
Michael Turner committed
164
    if (it->second == "2DBndLayer")
165
166
167
168
    {
        m_makeBL = true;
        m_2D = true;
    }
Michael Turner's avatar
Michael Turner committed
169
170
171
172
    if(!m_makeBL && !m_2D)
    {
        ASSERTL0(it->second == "3D", "unsure on MeshType")
    }
173

174
175

    it = parameters.find("MinDelta");
Dave Moxey's avatar
Dave Moxey committed
176
    ASSERTL0(it != parameters.end(), "no mindelta defined");
177
    m_minDelta = it->second;
Dave Moxey's avatar
Dave Moxey committed
178

179
    it = parameters.find("MaxDelta");
Dave Moxey's avatar
Dave Moxey committed
180
    ASSERTL0(it != parameters.end(), "no maxdelta defined");
181
    m_maxDelta = it->second;
Dave Moxey's avatar
Dave Moxey committed
182

183
    it = parameters.find("EPS");
Dave Moxey's avatar
Dave Moxey committed
184
    ASSERTL0(it != parameters.end(), "no eps defined");
185
    m_eps = it->second;
Dave Moxey's avatar
Dave Moxey committed
186

187
    it = parameters.find("Order");
Dave Moxey's avatar
Dave Moxey committed
188
    ASSERTL0(it != parameters.end(), "no order defined");
189
    m_order = it->second;
Dave Moxey's avatar
Dave Moxey committed
190
191

    if (m_makeBL)
Michael Turner's avatar
Michael Turner committed
192
    {
Michael Turner's avatar
Michael Turner committed
193
194
        it = parameters.find("BndLayerSurfaces");
        ASSERTL0(it != parameters.end(), "no BndLayersurfs defined");
Michael Turner's avatar
Michael Turner committed
195
        m_blsurfs = it->second;
Dave Moxey's avatar
Dave Moxey committed
196

Michael Turner's avatar
Michael Turner committed
197
198
        it = parameters.find("BndLayerThickness");
        ASSERTL0(it != parameters.end(), "no BndLayerthick defined");
Michael Turner's avatar
Michael Turner committed
199
        m_blthick = it->second;
Dave Moxey's avatar
Dave Moxey committed
200

Michael Turner's avatar
Michael Turner committed
201
        it = parameters.find("BndLayerLayers");
Michael Turner's avatar
Michael Turner committed
202
203
204
205
        m_splitBL = it != parameters.end();
        if(m_splitBL)
        {
            m_bllayers = it->second;
Michael Turner's avatar
Michael Turner committed
206
            it = parameters.find("BndLayerProgression");
Michael Turner's avatar
Michael Turner committed
207
208
            m_blprog = it != parameters.end() ? it->second : "2.0";
        }
Michael Turner's avatar
Michael Turner committed
209
    }
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    m_naca = false;
    if(m_2D && m_cadfile.find('.') == std::string::npos)
    {
        m_naca = true;

        stringstream ss;
        it = parameters.find("Xmin");
        ASSERTL0(it != parameters.end(), "no xmin defined");
        ss << it->second << ",";
        it = parameters.find("Ymin");
        ASSERTL0(it != parameters.end(), "no ymin defined");
        ss << it->second << ",";
        it = parameters.find("Xmax");
        ASSERTL0(it != parameters.end(), "no xmax defined");
        ss << it->second << ",";
        it = parameters.find("Ymax");
        ASSERTL0(it != parameters.end(), "no zmax defined");
        ss << it->second << ",";
        it = parameters.find("AOA");
        ASSERTL0(it != parameters.end(), "no aoa defined");
        ss << it->second;

        m_nacadomain = ss.str();
    }

236
    set<string>::iterator sit;
Michael Turner's avatar
Michael Turner committed
237
    sit        = boolparameters.find("SurfaceOptimiser");
238
    m_surfopti = sit != boolparameters.end();
Dave Moxey's avatar
Dave Moxey committed
239
240
    sit        = boolparameters.find("WriteOctree");
    m_woct     = sit != boolparameters.end();
Michael Turner's avatar
Michael Turner committed
241
    sit        = boolparameters.find("VariationalOptimiser");
242
    m_varopti  = sit != boolparameters.end();
Michael Turner's avatar
Michael Turner committed
243
244
245
246
247
248
249
250
251
252
253
254
255

    m_refine = refinement.size() > 0;
    if(m_refine)
    {
        stringstream ss;
        for(sit = refinement.begin(); sit != refinement.end(); sit++)
        {
            ss << *sit;
            ss << ":";
        }
        m_refinement = ss.str();
        m_refinement.erase(m_refinement.end()-1);
    }
256
257
}

Michael Turner's avatar
Michael Turner committed
258
void InputMCF::Process()
259
260
{
    ParseFile(m_config["infile"].as<string>());
261

262
263
    m_mesh->m_expDim   = 3;
    m_mesh->m_spaceDim = 3;
Dave Moxey's avatar
Dave Moxey committed
264
    m_mesh->m_nummode  = boost::lexical_cast<int>(m_order) + 1;
265

266
    vector<ModuleSharedPtr> mods;
267

268
    ////**** CAD ****////
269
270
    mods.push_back(GetModuleFactory().CreateInstance(
        ModuleKey(eProcessModule, "loadcad"), m_mesh));
271
    mods.back()->RegisterConfig("filename", m_cadfile);
Michael Turner's avatar
Michael Turner committed
272

273
274
275
276
    if(m_2D)
    {
        mods.back()->RegisterConfig("2D","");
    }
277
278
279
280
    if(m_naca)
    {
        mods.back()->RegisterConfig("NACA",m_nacadomain);
    }
281

282
    ////**** Octree ****////
283
284
    mods.push_back(GetModuleFactory().CreateInstance(
        ModuleKey(eProcessModule, "loadoctree"), m_mesh));
285
286
287
    mods.back()->RegisterConfig("mindel", m_minDelta);
    mods.back()->RegisterConfig("maxdel", m_maxDelta);
    mods.back()->RegisterConfig("eps", m_eps);
Michael Turner's avatar
Michael Turner committed
288
    if (m_refine)
289
    {
Michael Turner's avatar
Michael Turner committed
290
        mods.back()->RegisterConfig("refinement", m_refinement);
291
    }
Dave Moxey's avatar
Dave Moxey committed
292
    if (m_woct)
293
    {
294
295
        mods.back()->RegisterConfig("writeoctree", "");
    }
296

297
298
    if(m_2D)
    {
's avatar
committed
299
        m_mesh->m_expDim = 2;
Michael Turner's avatar
Michael Turner committed
300
        m_mesh->m_spaceDim = 2;
301
302
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "2dgenerator"), m_mesh));
303
304
305
306
307
        if (m_makeBL)
        {
            mods.back()->RegisterConfig("blcurves", m_blsurfs);
            mods.back()->RegisterConfig("blthick", m_blthick);
        }
308
309
    }
    else
Michael Turner's avatar
Michael Turner committed
310
    {
Michael Turner's avatar
Michael Turner committed
311
        ////**** SurfaceMesh ****////
312
313
314
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "surfacemesh"), m_mesh));

Michael Turner's avatar
Michael Turner committed
315
        ////**** VolumeMesh ****////
316
317
318
319
320
321
322
323
324
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "volumemesh"), m_mesh));
        if(m_makeBL)
        {
            mods.back()->RegisterConfig("blsurfs",m_blsurfs);
            mods.back()->RegisterConfig("blthick",m_blthick);
            mods.back()->RegisterConfig("bllayers",m_bllayers);
            mods.back()->RegisterConfig("blprog",m_blprog);
        }
Michael Turner's avatar
Michael Turner committed
325
    }
Michael Turner's avatar
Michael Turner committed
326

327
    ////**** HOSurface ****////
328
    mods.push_back(GetModuleFactory().CreateInstance(
329
        ModuleKey(eProcessModule, "hosurface"), m_mesh));
Dave Moxey's avatar
Dave Moxey committed
330
    if (m_surfopti)
Michael Turner's avatar
Michael Turner committed
331
    {
Dave Moxey's avatar
Dave Moxey committed
332
        mods.back()->RegisterConfig("opti", "");
333
    }
Michael Turner's avatar
Michael Turner committed
334

335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
    ////*** VARIATIONAL OPTIMISATION ****////
    if(m_varopti)
    {
        unsigned int np = boost::thread::physical_concurrency();
        if(m_mesh->m_verbose)
        {
            cout << "Detecting 4 cores, will attempt to run in parrallel" << endl;
        }
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "varopti"), m_mesh));
        mods.back()->RegisterConfig("nq",boost::lexical_cast<string>(m_mesh->m_nummode));
        mods.back()->RegisterConfig("hyperelastic","");
        mods.back()->RegisterConfig("maxiter","10");
        mods.back()->RegisterConfig("restol","1e-6");
        mods.back()->RegisterConfig("overint","6");
        mods.back()->RegisterConfig("numthreads",boost::lexical_cast<string>(np));
    }

Michael Turner's avatar
Michael Turner committed
353
354
355
356
357
358
359
360
361
362
363
364
    ////**** SPLIT BL ****////
    if(m_splitBL)
    {
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "bl"), m_mesh));
        mods.back()->RegisterConfig("layers",m_bllayers);
        mods.back()->RegisterConfig("surf",m_blsurfs);
        mods.back()->RegisterConfig("nq",boost::lexical_cast<string>(m_mesh->m_nummode));
        mods.back()->RegisterConfig("r",m_blprog);
    }

    for(int i = 0; i < mods.size(); i++)
Michael Turner's avatar
changes    
Michael Turner committed
365
    {
366
        mods[i]->Process();
Michael Turner's avatar
Michael Turner committed
367
    }
Michael Turner's avatar
Michael Turner committed
368
}
Michael Turner's avatar
Michael Turner committed
369
}
370
}