ExtractSurface2DCFS.cpp 29.6 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
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <iomanip>

#include <MultiRegions/ExpList.h>
#include <MultiRegions/ExpList1D.h>
#include <MultiRegions/ExpList2D.h>
#include <MultiRegions/ExpList2DHomogeneous1D.h>
#include <MultiRegions/ExpList3DHomogeneous1D.h>
#include <MultiRegions/ExpList3DHomogeneous2D.h>
#include <MultiRegions/AssemblyMap/AssemblyMapDG.h>

#include <MultiRegions/DisContField2D.h>
#include <LocalRegions/MatrixKey.h>
#include <LocalRegions/Expansion2D.h>
#include <LocalRegions/Expansion.h>

#include <LibUtilities/BasicUtils/FieldIO.h>
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/Communication/Comm.h>

#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <MultiRegions/ContField2D.h>
#include <SpatialDomains/MeshGraph2D.h>

#include <SolverUtils/SolverUtilsDeclspec.h>

using namespace Nektar;

int main(int argc, char *argv[])
{
    int cnt;
    int id1, id2;
38
39
    int i, j, n, e, b;
    Array<OneD, NekDouble> auxArray;
40
41
    
    int nBndEdgePts, nBndEdges, nBndRegions;
Daniele de Grazia's avatar
Daniele de Grazia committed
42
    
43
44
45
46
47
48
49
50
51
52
53
54
    if (argc < 3)
    {
        fprintf(stderr,
                "Usage: ExtractSurface2DCFS meshfile fieldFile\n");
        fprintf(stderr,
                "Extracts a surface from a 2D fld file" 
                "(only for CompressibleFlowSolver and purely 2D .fld files)\n");
        exit(1);
    }

    LibUtilities::SessionReaderSharedPtr vSession
            = LibUtilities::SessionReader::CreateInstance(3, argv);
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    
    std::string                         m_ViscosityType;
    
    NekDouble                           m_gamma;
    NekDouble                           m_pInf;
    NekDouble                           m_rhoInf;
    NekDouble                           m_uInf;
    NekDouble                           m_vInf;
    NekDouble                           m_wInf;
    NekDouble                           m_gasConstant;
    NekDouble                           m_Twall;
    NekDouble                           m_mu;
    NekDouble                           m_thermalConductivity;
    
    int m_spacedim = 2;
    int nDimensions = m_spacedim;
    int phys_offset;
    
    // Get gamma parameter from session file.
    ASSERTL0(vSession->DefinesParameter("Gamma"),
             "Compressible flow sessions must define a Gamma parameter.");
    vSession->LoadParameter("Gamma", m_gamma, 1.4);
    
    // Get E0 parameter from session file.
    ASSERTL0(vSession->DefinesParameter("pInf"),
             "Compressible flow sessions must define a pInf parameter.");
    vSession->LoadParameter("pInf", m_pInf, 101325);
    
    // Get rhoInf parameter from session file.
    ASSERTL0(vSession->DefinesParameter("rhoInf"),
             "Compressible flow sessions must define a rhoInf parameter.");
    vSession->LoadParameter("rhoInf", m_rhoInf, 1.225);
    
    // Get uInf parameter from session file.
    ASSERTL0(vSession->DefinesParameter("uInf"),
             "Compressible flow sessions must define a uInf parameter.");
    vSession->LoadParameter("uInf", m_uInf, 0.1);
    
    // Get vInf parameter from session file.
    if (m_spacedim == 2 || m_spacedim == 3)
    {
        ASSERTL0(vSession->DefinesParameter("vInf"),
                 "Compressible flow sessions must define a vInf parameter"
                 "for 2D/3D problems.");
        vSession->LoadParameter("vInf", m_vInf, 0.0);
    }
    
    // Get wInf parameter from session file.
    if (m_spacedim == 3)
    {
        ASSERTL0(vSession->DefinesParameter("wInf"),
                 "Compressible flow sessions must define a wInf parameter"
                 "for 3D problems.");
        vSession->LoadParameter("wInf", m_wInf, 0.0);
    }
    
    vSession->LoadParameter ("GasConstant",   m_gasConstant,   287.058);
    vSession->LoadParameter ("Twall",         m_Twall,         300.15);
    vSession->LoadSolverInfo("ViscosityType", m_ViscosityType, "Constant");
    vSession->LoadParameter ("mu",            m_mu,            1.78e-05);
    vSession->LoadParameter ("thermalConductivity",
                              m_thermalConductivity, 0.0257);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

    //--------------------------------------------------------------------------
    // Read in mesh from input file
    string meshfile(argv[1]);
    SpatialDomains::MeshGraphSharedPtr graphShPt = 
        SpatialDomains::MeshGraph::Read(vSession);
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    // Import field file
    string                                          fieldFile(argv[2]);
    vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
    vector<vector<NekDouble> >                      fieldData;
    
    LibUtilities::Import(fieldFile, fieldDef, fieldData);
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    // Set up Expansion information
    vector< vector<LibUtilities::PointsType> > pointsType;
    for (i = 0; i < fieldDef.size(); ++i)
    {
        vector<LibUtilities::PointsType> ptype;
        for (j = 0; j < 2; ++j)
        {
            ptype.push_back(LibUtilities::ePolyEvenlySpaced);
        }
        pointsType.push_back(ptype);
    }
    graphShPt->SetExpansions(fieldDef, pointsType);

    //--------------------------------------------------------------------------


    //--------------------------------------------------------------------------
    // Define Expansion
    int nfields = fieldDef[0]->m_fields.size();
    Array<OneD, MultiRegions::ExpListSharedPtr> Exp(nfields);
    Array<OneD, MultiRegions::ExpListSharedPtr> pFields(nfields);
        
    for(i = 0; i < pFields.num_elements(); i++)
    {
        pFields[i] = MemoryManager<MultiRegions
        ::DisContField2D>::AllocateSharedPtr(vSession, graphShPt, 
                                             vSession->GetVariable(i));
    }
    
    MultiRegions::ExpList2DSharedPtr Exp2D;
    Exp2D = MemoryManager<MultiRegions::ExpList2D>
        ::AllocateSharedPtr(vSession, graphShPt);
    
    Exp[0] = Exp2D;

    for (i = 1; i < nfields; ++i)
    {
        Exp[i] = MemoryManager<MultiRegions::ExpList2D>
            ::AllocateSharedPtr(*Exp2D);
    }
    
    int nSolutionPts = pFields[0]->GetNpoints();
    int nTracePts    = pFields[0]->GetTrace()->GetTotPoints();
178
179
180
    int nElements    = pFields[0]->GetExpSize();
    
    Array<OneD, NekDouble> tmp(nSolutionPts, 0.0);
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

    Array<OneD, NekDouble> x(nSolutionPts);
    Array<OneD, NekDouble> y(nSolutionPts); 
    Array<OneD, NekDouble> z(nSolutionPts);
    
    Array<OneD, NekDouble> traceX(nTracePts);
    Array<OneD, NekDouble> traceY(nTracePts); 
    Array<OneD, NekDouble> traceZ(nTracePts);
    
    Array<OneD, NekDouble> surfaceX(nTracePts);
    Array<OneD, NekDouble> surfaceY(nTracePts); 
    Array<OneD, NekDouble> surfaceZ(nTracePts);

    pFields[0]->GetCoords(x, y, z);
    
    pFields[0]->ExtractTracePhys(x, traceX);
    pFields[0]->ExtractTracePhys(y, traceY);
    pFields[0]->ExtractTracePhys(z, traceZ);
    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    // Copy data from field file
    Array<OneD, Array<OneD, NekDouble> > uFields(nfields);
    Array<OneD, Array<OneD, NekDouble> > traceFields(nfields);
    Array<OneD, Array<OneD, NekDouble> > surfaceFields(nfields);
206
    
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    // Extract the physical values of the solution at the boundaries
    for (j = 0; j < nfields; ++j)
    {
        uFields[j]       = Array<OneD, NekDouble>(nSolutionPts, 0.0);
        traceFields[j]   = Array<OneD, NekDouble>(nTracePts, 0.0);
        surfaceFields[j] = Array<OneD, NekDouble>(nTracePts, 0.0);


        for (i = 0; i < fieldData.size(); ++i)
        {
            Exp[j]->ExtractDataToCoeffs(fieldDef[i], fieldData[i],
                                        fieldDef[i]->m_fields[j],
                                        Exp[j]->UpdateCoeffs());
        }
        Exp[j]->BwdTrans(Exp[j]->GetCoeffs(), Exp[j]->UpdatePhys());
        Vmath::Vcopy(nSolutionPts, Exp[j]->GetPhys(), 1, uFields[j], 1);
        pFields[0]->ExtractTracePhys(uFields[j], traceFields[j]);
    }
225
226
227
    
    //Fields to add in the output file
    
228
    int nfieldsAdded = 19;
229
230
231
232
233
234
235
236
237
    Array<OneD, Array<OneD, NekDouble> > traceFieldsAdded(nfieldsAdded);
    Array<OneD, Array<OneD, NekDouble> > surfaceFieldsAdded(nfieldsAdded);
    
    for (j = 0; j < nfieldsAdded; ++j)
    {
        traceFieldsAdded[j] = Array<OneD, NekDouble>(nTracePts, 0.0);
        surfaceFieldsAdded[j] = Array<OneD, NekDouble>(nTracePts, 0.0);
    }
    
238
239
240
241
242
243
244
    /******** Evaluation of normals and tangents on the trace *****************
    * nx -> traceFieldsAdded[0];
    * ny -> traceFieldsAdded[1];
    * tx -> traceFieldsAdded[2];
    * ty -> traceFieldsAdded[3];
    ***************************************************************************/
    
245
246
247
248
249
250
251
252
253
254
255
256
257
    Array<OneD, Array<OneD, NekDouble> > m_traceNormals (nDimensions);
    for(i = 0; i < nDimensions; ++i)
    {
        m_traceNormals[i] = Array<OneD, NekDouble> (nTracePts, 0.0);
    }
    pFields[0]->GetTrace()->GetNormals(m_traceNormals);
    
    Array<OneD, Array<OneD, NekDouble> > m_traceTangents (nDimensions);
    for(i = 0; i < nDimensions; ++i)
    {
        m_traceTangents[i] = Array<OneD, NekDouble> (nTracePts, 0.0);
    }
    
258
259
260
261
262
263
264
265
266
267
268
    
    // nx
    Vmath::Vcopy(nTracePts,
                 &m_traceNormals[0][0], 1,
                 &traceFieldsAdded[0][0], 1);
    
    // ny
    Vmath::Vcopy(nTracePts,
                 &m_traceNormals[1][0], 1,
                 &traceFieldsAdded[1][0], 1);

269
270
271
272
273
274
    // t_x = - n_y
    Vmath::Vcopy(nTracePts,
                 &m_traceNormals[1][0], 1,
                 &m_traceTangents[0][0], 1);
    Vmath::Neg(nTracePts, &m_traceTangents[0][0], 1);
    
275
276
277
278
    Vmath::Vcopy(nTracePts,
                 &m_traceTangents[0][0], 1,
                 &traceFieldsAdded[2][0], 1);
    
279
280
281
282
    // t_y = n_x
    Vmath::Vcopy(nTracePts,
                 &m_traceNormals[0][0], 1,
                 &m_traceTangents[1][0], 1);
283
284
285
286
    
    Vmath::Vcopy(nTracePts,
                  &m_traceTangents[1][0], 1,
                  &traceFieldsAdded[3][0], 1);
287
288

    /******** Evaluation of the pressure ***************************************
Daniele de Grazia's avatar
Daniele de Grazia committed
289
     * P    = (E-1/2.*rho.*((rhou./rho).^2+(rhov./rho).^2))*(gamma - 1);
290
     * P -> traceFieldsAdded[4];
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
    ***************************************************************************/
    
    Array<OneD, NekDouble> pressure(nSolutionPts, 0.0);
    NekDouble gammaMinusOne    = m_gamma - 1.0;
    
    for (i = 0; i < m_spacedim; i++)
    {
        Vmath::Vmul(nSolutionPts,
                    &uFields[i][0], 1,
                    &uFields[i][0], 1,
                    &tmp[0],1);
        
        
        Vmath::Smul(nSolutionPts, 0.5,
                    &tmp[0], 1,
                    &tmp[0], 1);

        Vmath::Vadd(nSolutionPts,
                    &pressure[0], 1,
                    &tmp[0], 1,
                    &pressure[0], 1);
    }
    
    Vmath::Vdiv(nSolutionPts,
                &pressure[0], 1,
                &uFields[0][0], 1,
                &pressure[0],1);
    
    Vmath::Vsub(nSolutionPts,
                &uFields[nfields - 1][0], 1,
                &pressure[0], 1,
                &pressure[0],1);
    
    Vmath::Smul(nSolutionPts, gammaMinusOne,
                &pressure[0], 1,
                &pressure[0], 1);
    
    // Extract trace
329
    pFields[0]->ExtractTracePhys(pressure, traceFieldsAdded[4]);
330
331
    
    /******** Evaluation of the temperature ************************************
Daniele de Grazia's avatar
Daniele de Grazia committed
332
     * T = P/(R*rho);
333
     * T -> traceFieldsAdded[5];
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    ***************************************************************************/
    
    Array<OneD, NekDouble> temperature(nSolutionPts, 0.0);
    
    Vmath::Vdiv(nSolutionPts,
                &pressure[0], 1,
                &uFields[0][0], 1,
                &temperature[0],1);
    
    NekDouble GasConstantInv =  1.0/m_gasConstant;
    Vmath::Smul(nSolutionPts, GasConstantInv,
                &temperature[0], 1,
                &temperature[0], 1);
    
    // Extract trace
349
    pFields[0]->ExtractTracePhys(temperature, traceFieldsAdded[5]);
350
351
    
    /*** Evaluation of the temperature gradient in the normal direction ********
352
     * DT_n -> traceFieldsAdded[6]
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
    ***************************************************************************/

    Array<OneD, Array<OneD, NekDouble> > Dtemperature(nDimensions);
    Array<OneD, Array<OneD, NekDouble> > traceDtemperature(nDimensions);
    
    for (i = 0; i < nDimensions; ++ i)
    {
        Dtemperature[i]  = Array<OneD, NekDouble>(nSolutionPts, 0.0);
        traceDtemperature[i]  = Array<OneD, NekDouble>(nTracePts, 0.0);
    }

    for (i = 0; i < nDimensions; ++ i)
    {
        for (n = 0; n < nElements; n++)
        {
            phys_offset = pFields[0]->GetPhys_Offset(n);
        
            pFields[i]->GetExp(n)->PhysDeriv(
                                    i, temperature + phys_offset,
                                    auxArray = Dtemperature[i] + phys_offset);
        }
        // Extract trace
        pFields[0]->ExtractTracePhys(Dtemperature[i], traceDtemperature[i]);
    }
    
    for(i = 0; i < nDimensions; ++i)
    {
        Vmath::Vmul(nTracePts,
                    &m_traceNormals[i][0], 1,
                    &traceDtemperature[i][0], 1,
                    &tmp[0],1);
        
        Vmath::Vadd(nTracePts,
386
                    &traceFieldsAdded[6][0], 1,
387
                    &tmp[0], 1,
388
                    &traceFieldsAdded[6][0], 1);
389
390
    }
    
Daniele de Grazia's avatar
Daniele de Grazia committed
391
    /*** Evaluation of the pressure gradient ***********************************
392
393
394
     * DP_t -> traceFieldsAdded[7]   tangent direction
     * DP_x -> traceFieldsAdded[8]
     * DP_y -> traceFieldsAdded[9]
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
    ***************************************************************************/
    
    Array<OneD, Array<OneD, NekDouble> > Dpressure(nDimensions);
    Array<OneD, Array<OneD, NekDouble> > traceDpressure(nDimensions);
    
    for (i = 0; i < nDimensions; ++ i)
    {
        Dpressure[i]  = Array<OneD, NekDouble>(nSolutionPts, 0.0);
        traceDpressure[i]  = Array<OneD, NekDouble>(nTracePts, 0.0);
    }
    
    for (i = 0; i < nDimensions; ++ i)
    {
        for (n = 0; n < nElements; n++)
        {
            phys_offset = pFields[0]->GetPhys_Offset(n);
            
            pFields[i]->GetExp(n)->PhysDeriv(
Daniele de Grazia's avatar
Daniele de Grazia committed
413
414
                                        i, pressure + phys_offset,
                                        auxArray = Dpressure[i] + phys_offset);
415
416
417
418
419
        }
        // Extract trace
        pFields[0]->ExtractTracePhys(Dpressure[i], traceDpressure[i]);
    }
    
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
420
    // Dp_t
421
422
423
424
425
426
427
428
    for(i = 0; i < nDimensions; ++i)
    {
        Vmath::Vmul(nTracePts,
                    &m_traceTangents[i][0], 1,
                    &traceDpressure[i][0], 1,
                    &tmp[0],1);
        
        Vmath::Vadd(nTracePts,
429
                    &traceFieldsAdded[7][0], 1,
430
                    &tmp[0], 1,
431
                    &traceFieldsAdded[7][0], 1);
432
433
    }
    
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
434
435
436
    // Dp_x
    Vmath::Vcopy(nTracePts,
                 &traceDpressure[0][0], 1,
437
                 &traceFieldsAdded[8][0], 1);
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
438
439
440
441
    
    // Dp_y
    Vmath::Vcopy(nTracePts,
                 &traceDpressure[1][0], 1,
442
                 &traceFieldsAdded[9][0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
443
444
    
    /** Evaluation of the velocity gradient in the cartesian directions
445
446
447
448
     * Du_x:    traceFieldsAdded[10]
     * Du_y:    traceFieldsAdded[11]
     * Dv_x:    traceFieldsAdded[12]
     * Dv_y:    traceFieldsAdded[13]
Daniele de Grazia's avatar
Daniele de Grazia committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
     **/
    Array<OneD, Array<OneD, Array<OneD, NekDouble> > > Dvelocity(nDimensions);
    Array<OneD, Array<OneD, Array<OneD, NekDouble> > > traceDvelocity(nDimensions);
    Array<OneD, Array<OneD, NekDouble> > velocity(nDimensions);

    for (i = 0; i < nDimensions; ++ i)
    {
        Dvelocity[i]      = Array<OneD, Array<OneD, NekDouble> >(nDimensions);
        traceDvelocity[i] = Array<OneD, Array<OneD, NekDouble> >(nDimensions);
        velocity[i]       = Array<OneD, NekDouble>(nSolutionPts, 0.0);

        Vmath::Vdiv(nSolutionPts, uFields[i+1], 1, uFields[0], 1,
                    velocity[i], 1);
        
        for (j = 0; j < nDimensions; ++j)
        {
            Dvelocity[i][j]      = Array<OneD, NekDouble>(nSolutionPts, 0.0);
            traceDvelocity[i][j] = Array<OneD, NekDouble>(nTracePts, 0.0);
        }
    }
    
    for (i = 0; i < nDimensions; ++i)
    {
        for (j = 0; j < nDimensions; ++j)
        {
            for (n = 0; n < nElements; n++)
            {
                phys_offset = pFields[0]->GetPhys_Offset(n);
            
                pFields[i]->GetExp(n)->PhysDeriv(
                                    j, velocity[i] + phys_offset,
                                    auxArray = Dvelocity[i][j] + phys_offset);
            }
            
            // Extract trace
            pFields[0]->ExtractTracePhys(Dvelocity[i][j], traceDvelocity[i][j]);
        }
    }
    
    Vmath::Vcopy(nTracePts,
                 &traceDvelocity[0][0][0], 1,
490
                 &traceFieldsAdded[10][0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
491
492
    Vmath::Vcopy(nTracePts,
                 &traceDvelocity[0][1][0], 1,
493
                 &traceFieldsAdded[11][0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
494
495
    Vmath::Vcopy(nTracePts,
                 &traceDvelocity[1][0][0], 1,
496
                 &traceFieldsAdded[12][0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
497
498
    Vmath::Vcopy(nTracePts,
                 &traceDvelocity[1][1][0], 1,
499
                 &traceFieldsAdded[13][0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
500
501
502
    
    
    /*** Evaluation of shear stresses ******************************************
503
504
505
     * tau_xx -> traceFieldsAdded[14]
     * tau_yy -> traceFieldsAdded[15]
     * tau_xy -> traceFieldsAdded[16]
Daniele de Grazia's avatar
Daniele de Grazia committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
    ***************************************************************************/
    
    // Stokes hypotesis
    const NekDouble lambda = -2.0/3.0;
    
    // Auxiliary variables
    Array<OneD, NekDouble > mu    (nSolutionPts, 0.0);
    Array<OneD, NekDouble > mu2   (nSolutionPts, 0.0);
    Array<OneD, NekDouble > divVel(nSolutionPts, 0.0);
    
    // Variable viscosity through the Sutherland's law
    if (m_ViscosityType == "Variable")
    {
        NekDouble mu_star = m_mu;
        NekDouble T_star  = m_pInf / (m_rhoInf * m_gasConstant);
        NekDouble ratio;
        
        for (int i = 0; i < nSolutionPts; ++i)
        {
            ratio = temperature[i] / T_star;
            mu[i] = mu_star * pow(ratio, 1.50) *
            (T_star + 110.0) / (temperature[i] + 110.0);
        }
    }
    else
    {
        Vmath::Fill(nSolutionPts, m_mu, &mu[0], 1);
    }
    
    // Computing diagonal terms of viscous stress tensor
    Array<OneD, Array<OneD, NekDouble> > temp(m_spacedim);
    Array<OneD, Array<OneD, NekDouble> > Sgg(m_spacedim);
    
    // mu2 = 2 * mu
    Vmath::Smul(nSolutionPts, 2.0, &mu[0], 1, &mu2[0], 1);
    
    // Velocity divergence
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
543
544
545
546
    Vmath::Vadd(nSolutionPts, &divVel[0], 1, 
                &Dvelocity[0][0][0], 1, &divVel[0], 1);
    Vmath::Vadd(nSolutionPts, &divVel[0], 1, 
                &Dvelocity[1][1][0], 1, &divVel[0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

    // Velocity divergence scaled by lambda * mu
    Vmath::Smul(nSolutionPts, lambda, &divVel[0], 1, &divVel[0], 1);
    Vmath::Vmul(nSolutionPts, &mu[0], 1, &divVel[0], 1, &divVel[0], 1);
    
    // Diagonal terms of viscous stress tensor (Sxx, Syy)
    // Sjj = 2 * mu * du_j/dx_j - (2 / 3) * mu * sum_j(du_j/dx_j)
    for (j = 0; j < m_spacedim; ++j)
    {
        temp[j] = Array<OneD, NekDouble>(nSolutionPts, 0.0);
        Sgg[j] = Array<OneD, NekDouble>(nSolutionPts, 0.0);
        
        Vmath::Vmul(nSolutionPts, &mu2[0], 1, &Dvelocity[j][j][0], 1,
                    &temp[j][0], 1);
        
        Vmath::Vadd(nSolutionPts, &temp[j][0], 1, &divVel[0], 1, &Sgg[j][0], 1);
    }
    
565
    // Extra diagonal terms of viscous stress tensor (Sxy =  Syx)
Daniele de Grazia's avatar
Daniele de Grazia committed
566
567
568
569
570
571
572
573
574
    Array<OneD, NekDouble > Sxy(nSolutionPts, 0.0);
    
    // Sxy = (du/dy + dv/dx)
    Vmath::Vadd(nSolutionPts, &Dvelocity[0][1][0], 1,
                &Dvelocity[1][0][0], 1, &Sxy[0], 1);
        
    // Sxy = mu * (du/dy + dv/dx)
    Vmath::Vmul(nSolutionPts, &mu[0], 1, &Sxy[0], 1, &Sxy[0], 1);

575
576
577
    pFields[0]->ExtractTracePhys(Sgg[0], traceFieldsAdded[14]);
    pFields[0]->ExtractTracePhys(Sgg[1], traceFieldsAdded[15]);
    pFields[0]->ExtractTracePhys(Sxy,    traceFieldsAdded[16]);
Daniele de Grazia's avatar
Daniele de Grazia committed
578
    
Daniele de Grazia's avatar
Daniele de Grazia committed
579
    /*** Evaluation of the shear stress in tangent direction *******************
580
     * tau_t -> traceFieldsAdded[17]
581
    ***************************************************************************/
Daniele de Grazia's avatar
Daniele de Grazia committed
582
583
584
585
586
587
588
589
590
591
592
    Array<OneD, NekDouble > sigma_diff   (nTracePts, 0.0);
    Array<OneD, NekDouble > cosTeta      (nTracePts, 0.0);
    Array<OneD, NekDouble > sinTeta      (nTracePts, 0.0);
    Array<OneD, NekDouble > cos2Teta     (nTracePts, 0.0);
    Array<OneD, NekDouble > sin2Teta     (nTracePts, 0.0);
    Array<OneD, NekDouble > tau_t        (nTracePts, 0.0);
    
    Array<OneD, NekDouble > tmpTeta      (nTracePts, 0.0);
    
    // cos(teta) = nx
    Vmath::Vcopy(nTracePts, &m_traceNormals[0][0], 1, &cosTeta[0], 1);
593
    
Daniele de Grazia's avatar
Daniele de Grazia committed
594
595
    // sin(teta) = ny
    Vmath::Vcopy(nTracePts, &m_traceNormals[1][0], 1, &sinTeta[0], 1);
596
597
    
    // sigma_diff = sigma_x - sigma_y
Daniele de Grazia's avatar
Daniele de Grazia committed
598
599
    Vmath::Vsub(nTracePts, &traceFieldsAdded[10][0], 1,
                &traceFieldsAdded[11][0], 1, &sigma_diff[0], 1);
600
601
    
    // sin(2*teta)
Daniele de Grazia's avatar
Daniele de Grazia committed
602
603
    Vmath::Vmul(nTracePts, &cosTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
    Vmath::Smul(nTracePts, 2.0, &tmpTeta[0], 1, &sin2Teta[0], 1);
604
605
    
    // cos(2*teta)
Daniele de Grazia's avatar
Daniele de Grazia committed
606
607
608
    Vmath::Vmul(nTracePts, &cosTeta[0], 1, &cosTeta[0], 1, &cos2Teta[0], 1);
    Vmath::Vmul(nTracePts, &sinTeta[0], 1, &sinTeta[0], 1, &tmpTeta[0], 1);
    Vmath::Vsub(nTracePts, &cos2Teta[0], 1, &tmpTeta[0], 1, &cos2Teta[0], 1);
609
610
    
    // tau_t = -0.5*sigma_diff * sin(2*teta) + tau_xy * cos(2*teta)
Daniele de Grazia's avatar
Daniele de Grazia committed
611
612
    Vmath::Smul(nTracePts, -0.5, &sigma_diff[0], 1, &sigma_diff[0], 1);
    Vmath::Vmul(nTracePts, &sigma_diff[0], 1, &sin2Teta[0], 1, &tau_t[0], 1);
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
613
614
    Vmath::Vmul(nTracePts, &traceFieldsAdded[12][0], 1, &cos2Teta[0], 1, 
                &tmpTeta[0], 1);
Daniele de Grazia's avatar
Daniele de Grazia committed
615
    Vmath::Vadd(nTracePts, &tau_t[0], 1, &tmpTeta[0], 1, &tau_t[0], 1);
616
    
617
    Vmath::Vcopy(nTracePts, &tau_t[0], 1, &traceFieldsAdded[17][0], 1);
618
    
619
    /*** Evaluation of Mach number *********************************************
620
     * M -> traceFieldsAdded[18]
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
    ***************************************************************************/
    NekDouble gamma    = m_gamma;
    
    // Speed of sound
    Array<OneD, NekDouble> soundspeed(nSolutionPts, 0.0);
    
    Vmath::Vdiv (nSolutionPts, pressure, 1, uFields[0], 1, soundspeed, 1);
    Vmath::Smul (nSolutionPts, gamma, soundspeed, 1, soundspeed, 1);
    Vmath::Vsqrt(nSolutionPts, soundspeed, 1, soundspeed, 1);
    
    // Mach
    Array<OneD, NekDouble> mach(nSolutionPts, 0.0);
    
    for (int i = 0; i < m_spacedim; ++i)
    {
        Vmath::Vvtvp(nSolutionPts, uFields[i + 1], 1, uFields[i + 1], 1,
                     mach,           1, mach,           1);
    }
    
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
640
641
    Vmath::Vdiv(nSolutionPts,  mach, 1, uFields[0], 1, mach, 1);
    Vmath::Vdiv(nSolutionPts,  mach, 1, uFields[0], 1, mach, 1);
642
    Vmath::Vsqrt(nSolutionPts, mach, 1, mach, 1);
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
643
    Vmath::Vdiv(nSolutionPts,  mach, 1, soundspeed, 1, mach, 1);
644
    
645
    pFields[0]->ExtractTracePhys(mach, traceFieldsAdded[18]);
Daniele de Grazia's avatar
Daniele de Grazia committed
646
647
    
    /**************************************************************************/
648
    // Extract coordinates
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
    
    if (pFields[0]->GetBndCondExpansions().num_elements())
    {
        id1 = 0;
        cnt = 0;
        nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
        for (b = 0; b < nBndRegions; ++b)
        {
            nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
            for (e = 0; e < nBndEdges; ++e)
            {
                nBndEdgePts = pFields[0]->
                GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
                    
                id2 = pFields[0]->GetTrace()->
                GetPhys_Offset(pFields[0]->GetTraceMap()->
                    GetBndCondTraceToGlobalTraceMap(cnt++));
                    
                if (pFields[0]->GetBndConditions()[b]->
                    GetUserDefined() == SpatialDomains::eWallViscous || 
                    pFields[0]->GetBndConditions()[b]->
                    GetUserDefined() == SpatialDomains::eWall)
                {       
                    Vmath::Vcopy(nBndEdgePts, &traceX[id2], 1,
                                 &surfaceX[id1], 1);
                        
                    Vmath::Vcopy(nBndEdgePts, &traceY[id2], 1,
                                 &surfaceY[id1], 1);
                        
                    Vmath::Vcopy(nBndEdgePts, &traceZ[id2], 1,
                                 &surfaceZ[id1], 1);
                        
                    id1 += nBndEdgePts;
                }
            }
        }
    }
    
687
    // Extract fields
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
    if (pFields[0]->GetBndCondExpansions().num_elements())
    {
        for (j = 0; j < nfields; ++j)
        {
            id1 = 0;
            cnt = 0;
            nBndRegions = pFields[j]->GetBndCondExpansions().num_elements();
            for (b = 0; b < nBndRegions; ++b)
            {
                nBndEdges = pFields[j]->GetBndCondExpansions()[b]->GetExpSize();
                for (e = 0; e < nBndEdges; ++e)
                {
                    nBndEdgePts = pFields[j]->
                    GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
                                        
                    id2 = pFields[j]->GetTrace()->
                    GetPhys_Offset(pFields[j]->GetTraceMap()->
                                   GetBndCondTraceToGlobalTraceMap(cnt++));
                    
                    if (pFields[j]->GetBndConditions()[b]->
                        GetUserDefined() == SpatialDomains::eWallViscous || 
                        pFields[j]->GetBndConditions()[b]->
                        GetUserDefined() == SpatialDomains::eWall)
                    {
                        Vmath::Vcopy(nBndEdgePts, &traceFields[j][id2], 1,
                                     &surfaceFields[j][id1], 1);
                                                
                        id1 += nBndEdgePts;
                    }
                }
            }
        }
    }
    
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    // Extract fields added
    if (pFields[0]->GetBndCondExpansions().num_elements())
    {
        for (j = 0; j < nfieldsAdded; ++j)
        {
            id1 = 0;
            cnt = 0;
            nBndRegions = pFields[0]->GetBndCondExpansions().num_elements();
            for (b = 0; b < nBndRegions; ++b)
            {
                nBndEdges = pFields[0]->GetBndCondExpansions()[b]->GetExpSize();
                for (e = 0; e < nBndEdges; ++e)
                {
                    nBndEdgePts = pFields[0]->
                    GetBndCondExpansions()[b]->GetExp(e)->GetNumPoints(0);
                    
                    id2 = pFields[0]->GetTrace()->
                    GetPhys_Offset(pFields[0]->GetTraceMap()->
                                   GetBndCondTraceToGlobalTraceMap(cnt++));
                    
                    if (pFields[0]->GetBndConditions()[b]->
                        GetUserDefined() == SpatialDomains::eWallViscous ||
                        pFields[0]->GetBndConditions()[b]->
                        GetUserDefined() == SpatialDomains::eWall)
                    {
                        Vmath::Vcopy(nBndEdgePts, &traceFieldsAdded[j][id2], 1,
                                     &surfaceFieldsAdded[j][id1], 1);
                        
                        id1 += nBndEdgePts;
                    }
                }
            }
        }
    }
    
757
758
    // Print the surface coordinates and the surface solution in a .txt file
    ofstream outfile;
Daniele de Grazia's avatar
Daniele de Grazia committed
759
760
761
762
763
    
    string fname = strtok(argv[2],".");
    fname += ".txt";
    
    outfile.open(fname);
Daniele de Grazia's avatar
Daniele de Grazia committed
764
765
766
    outfile <<  "%  x[m] " << " \t"
    << "y[m] " << " \t"
    << "z[m] " << " \t"
767
768
769
770
    << "nx[]  " << " \t"
    << "ny[]  " << " \t"
    << "tx[]  " << " \t"
    << "ty[]  " << " \t"
Daniele de Grazia's avatar
Daniele de Grazia committed
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
    << "rho[kg/m^3] " << " \t"
    << "rhou[kg/(m^2 s)] " << " \t"
    << "rhov[kg/(m^2 s)] " << " \t"
    << "E[Pa] " << " \t"
    << "p[Pa] " << " \t"
    << "T[k]  " << " \t"
    << "dT/dn[k/m]  "  << " \t"
    << "dp/dT[Pa/m]  " << " \t"
    << "dp/dx[Pa/m]  " << " \t"
    << "dp/dy[Pa/m]  " << " \t"
    << "du/dx[s^-1]  " << " \t"
    << "du/dy[s^-1]  " << " \t"
    << "dv/dx[s^-1]  " << " \t"
    << "dv/dy[s^-1]  " << " \t"
    << "tau_xx[Pa]  " << " \t"
    << "tau_yy[Pa]  " << " \t"
    << "tau_xy[Pa]  " << " \t"
    << "tau_t[Pa]  " << " \t"
    << "M[] " << " \t"
    << endl;
791
792
    for (i = 0; i < id1; ++i)
    {
Daniele de Grazia's avatar
Daniele de Grazia committed
793
        outfile << scientific
794
795
796
797
        << setw (17) 
        << setprecision(16) 
        << surfaceX[i] << " \t " 
        << surfaceY[i] << " \t " 
Daniele de Grazia's avatar
Daniele de Grazia committed
798
        << surfaceZ[i] << " \t "
799
800
801
802
        << surfaceFieldsAdded[0][i] << " \t "
        << surfaceFieldsAdded[1][i] << " \t "
        << surfaceFieldsAdded[2][i] << " \t "
        << surfaceFieldsAdded[3][i] << " \t "
Daniele de Grazia's avatar
Daniele de Grazia committed
803
804
805
806
        << surfaceFields[0][i] << " \t "
        << surfaceFields[1][i] << " \t "
        << surfaceFields[2][i] << " \t "
        << surfaceFields[3][i] << " \t "
807
        << surfaceFieldsAdded[4][i] << " \t "
Daniele de Grazia's avatar
Daniele de Grazia committed
808
809
810
811
812
813
814
        << surfaceFieldsAdded[5][i] << " \t "
        << surfaceFieldsAdded[6][i] << " \t "
        << surfaceFieldsAdded[7][i] << " \t "
        << surfaceFieldsAdded[8][i] << " \t "
        << surfaceFieldsAdded[9][i] << " \t "
        << surfaceFieldsAdded[10][i] << " \t "
        << surfaceFieldsAdded[11][i] << " \t "
Gianmarco Mengaldo's avatar
Gianmarco Mengaldo committed
815
816
        << surfaceFieldsAdded[12][i] << " \t "
        << surfaceFieldsAdded[13][i] << " \t "
Daniele de Grazia's avatar
Daniele de Grazia committed
817
        << surfaceFieldsAdded[14][i] << " \t "
818
819
820
821
        << surfaceFieldsAdded[15][i] << " \t "
        << surfaceFieldsAdded[16][i] << " \t "
        << surfaceFieldsAdded[17][i] << " \t "
        << surfaceFieldsAdded[18][i] << " \t "
822
823
824
825
826
827
828
829
        << endl;
    }
    outfile << endl << endl;
    outfile.close();
    
    return 0;
}