InputCAD.cpp 8.54 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
#include <tinyxml.h>
39

Michael Turner's avatar
Michael Turner committed
40
41
#include "InputCAD.h"

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

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

50
ModuleKey InputCAD::className = GetModuleFactory().RegisterCreatorFunction(
Dave Moxey's avatar
Dave Moxey committed
51
    ModuleKey(eInputModule, "mcf"), InputCAD::create,
Michael Turner's avatar
Michael Turner committed
52
53
54
55
56
57
    "Reads CAD geometry and will generate the mesh file.");

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

Michael Turner's avatar
Michael Turner committed
61
62
63
InputCAD::~InputCAD()
{
}
Michael Turner's avatar
Michael Turner committed
64

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

Dave Moxey's avatar
Dave Moxey committed
72
73
74
75
76
    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");
77
78
79
80

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

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

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

    set<string> boolparameters;
105

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

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

Dave Moxey's avatar
Dave Moxey committed
120
    map<string, string>::iterator it;
121
122

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

126
    it = information.find("MeshType");
Dave Moxey's avatar
Dave Moxey committed
127
    ASSERTL0(it != information.end(), "no meshtype defined");
128
    m_makeBL = it->second == "BL";
Julian Marcon's avatar
Tidy    
Julian Marcon committed
129
    m_2D = it->second == "2D";
130
131
132
133
134
    if (it->second == "2DBL")
    {
        m_makeBL = true;
        m_2D = true;
    }
135

136
    it = information.find("UDSFile");
Dave Moxey's avatar
Dave Moxey committed
137
    if (it != information.end())
138
139
    {
        m_udsfile = it->second;
Dave Moxey's avatar
Dave Moxey committed
140
        m_uds     = true;
141
    }
142
143

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

147
    it = parameters.find("MaxDelta");
Dave Moxey's avatar
Dave Moxey committed
148
    ASSERTL0(it != parameters.end(), "no maxdelta defined");
149
    m_maxDelta = it->second;
Dave Moxey's avatar
Dave Moxey committed
150

151
    it = parameters.find("EPS");
Dave Moxey's avatar
Dave Moxey committed
152
    ASSERTL0(it != parameters.end(), "no eps defined");
153
    m_eps = it->second;
Dave Moxey's avatar
Dave Moxey committed
154

155
    it = parameters.find("Order");
Dave Moxey's avatar
Dave Moxey committed
156
    ASSERTL0(it != parameters.end(), "no order defined");
157
    m_order = it->second;
Dave Moxey's avatar
Dave Moxey committed
158
159

    if (m_makeBL)
Michael Turner's avatar
Michael Turner committed
160
161
162
163
    {
        it = parameters.find("BLSurfs");
        ASSERTL0(it != parameters.end(), "no blsurfs defined");
        m_blsurfs = it->second;
Dave Moxey's avatar
Dave Moxey committed
164

Michael Turner's avatar
Michael Turner committed
165
166
167
        it = parameters.find("BLThick");
        ASSERTL0(it != parameters.end(), "no blthick defined");
        m_blthick = it->second;
Dave Moxey's avatar
Dave Moxey committed
168

Michael Turner's avatar
Michael Turner committed
169
        it = parameters.find("BLLayers");
Michael Turner's avatar
Michael Turner committed
170
171
172
173
174
175
176
        m_splitBL = it != parameters.end();
        if(m_splitBL)
        {
            m_bllayers = it->second;
            it = parameters.find("BLProg");
            m_blprog = it != parameters.end() ? it->second : "2.0";
        }
Michael Turner's avatar
Michael Turner committed
177
    }
178
179

    set<string>::iterator sit;
Dave Moxey's avatar
Dave Moxey committed
180
    sit        = boolparameters.find("SurfOpti");
181
    m_surfopti = sit != boolparameters.end();
Dave Moxey's avatar
Dave Moxey committed
182
183
    sit        = boolparameters.find("WriteOctree");
    m_woct     = sit != boolparameters.end();
184
185
186
187
188
}

void InputCAD::Process()
{
    ParseFile(m_config["infile"].as<string>());
189

190
191
    m_mesh->m_expDim   = 3;
    m_mesh->m_spaceDim = 3;
Dave Moxey's avatar
Dave Moxey committed
192
    m_mesh->m_nummode  = boost::lexical_cast<int>(m_order) + 1;
193

194
    vector<ModuleSharedPtr> mods;
195

196
    ////**** CAD ****////
197
198
    mods.push_back(GetModuleFactory().CreateInstance(
        ModuleKey(eProcessModule, "loadcad"), m_mesh));
199
    mods.back()->RegisterConfig("filename", m_cadfile);
Michael Turner's avatar
Michael Turner committed
200

201
202
203
204
205
    if(m_2D)
    {
        mods.back()->RegisterConfig("2D","");
    }

206
    ////**** Octree ****////
207
208
    mods.push_back(GetModuleFactory().CreateInstance(
        ModuleKey(eProcessModule, "loadoctree"), m_mesh));
209
210
211
    mods.back()->RegisterConfig("mindel", m_minDelta);
    mods.back()->RegisterConfig("maxdel", m_maxDelta);
    mods.back()->RegisterConfig("eps", m_eps);
Dave Moxey's avatar
Dave Moxey committed
212
    if (m_uds)
213
    {
214
        mods.back()->RegisterConfig("udsfile", m_udsfile);
215
    }
Dave Moxey's avatar
Dave Moxey committed
216
    if (m_woct)
217
    {
218
219
        mods.back()->RegisterConfig("writeoctree", "");
    }
220

221
222
    if(m_2D)
    {
's avatar
committed
223
        m_mesh->m_expDim = 2;
Michael Turner's avatar
Michael Turner committed
224
        m_mesh->m_spaceDim = 2;
225
226
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "2dgenerator"), m_mesh));
227
228
229
230
231
        if (m_makeBL)
        {
            mods.back()->RegisterConfig("blcurves", m_blsurfs);
            mods.back()->RegisterConfig("blthick", m_blthick);
        }
232
233
    }
    else
Michael Turner's avatar
Michael Turner committed
234
    {
Michael Turner's avatar
Michael Turner committed
235
        ////**** SurfaceMesh ****////
236
237
238
        mods.push_back(GetModuleFactory().CreateInstance(
            ModuleKey(eProcessModule, "surfacemesh"), m_mesh));

Michael Turner's avatar
Michael Turner committed
239
        ////**** VolumeMesh ****////
240
241
242
243
244
245
246
247
248
        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
249
    }
Michael Turner's avatar
Michael Turner committed
250

251
    ////**** HOSurface ****////
252
    mods.push_back(GetModuleFactory().CreateInstance(
253
        ModuleKey(eProcessModule, "hosurface"), m_mesh));
Dave Moxey's avatar
Dave Moxey committed
254
    if (m_surfopti)
Michael Turner's avatar
Michael Turner committed
255
    {
Dave Moxey's avatar
Dave Moxey committed
256
        mods.back()->RegisterConfig("opti", "");
257
    }
Michael Turner's avatar
Michael Turner committed
258

Michael Turner's avatar
Michael Turner committed
259
<<<<<<< HEAD
Dave Moxey's avatar
Dave Moxey committed
260
    for (int i = 0; i < mods.size(); i++)
Michael Turner's avatar
Michael Turner committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
=======

    ////**** 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++)
>>>>>>> automatically split bl
Michael Turner's avatar
changes    
Michael Turner committed
276
    {
277
        mods[i]->Process();
Michael Turner's avatar
Michael Turner committed
278
    }
Michael Turner's avatar
Michael Turner committed
279
}
Michael Turner's avatar
Michael Turner committed
280
}
281
}