This file is indexed.

/usr/include/trilinos/Galeri_FileGrid.h is in libtrilinos-galeri-dev 12.4.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 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
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
178
179
180
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
206
207
208
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
// @HEADER
// ************************************************************************
//
//           Galeri: Finite Element and Matrix Generation Package
//                 Copyright (2006) ETHZ/Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions about Galeri? Contact Marzio Sala (marzio.sala _AT_ gmail.com)
//
// ************************************************************************
// @HEADER

#ifndef GALERI_FILEGRID_H
#define GALERI_FILEGRID_H

#include "Epetra_Comm.h"
#include "Epetra_Map.h"
#include "Epetra_DistObject.h"
#include "Epetra_Import.h"
#include "Epetra_Export.h"
#include "Epetra_IntSerialDenseMatrix.h"
#include "Epetra_SerialDenseMatrix.h"
#include "Epetra_SerialDenseVector.h"
#include "Teuchos_RefCountPtr.hpp"
#include "Galeri_Utils.h"
#include "Galeri_Workspace.h"
#include "Galeri_AbstractGrid.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <fstream>

using namespace Teuchos;

namespace Galeri {
namespace FiniteElements {

/*!
 * \class Galeri_FileGrid
 *
 * \brief Reads a grid from file, in Galeri format.
 *
 * \author Marzio Sala, ETHZ/COLAB.
 *
 * \date Last updated on 15-Sep-05.
 */
class FileGrid : public AbstractGrid
{

public:

  //! Constructor.
  /*! 
   * \param Comm - (In) Communicator object.
   *
   * \param FileName - (In) Name of grid file.
   */
  FileGrid(const Epetra_Comm& Comm, const std::string FileName) :
    Comm_(Comm),
    FileName_(FileName),
    NumDimensions_(-1),
    NumVerticesPerElement_(-1),
    NumVerticesPerFace_(-1),
    NumFacesPerElement_(-1),
    NumMyVertices_(-1),
    NumGlobalVertices_(-1),
    NumMyElements_(-1),
    NumGlobalElements_(-1),
    NumMyBoundaryFaces_(-1),
    NumGlobalBoundaryFaces_(-1),
    ElementType_("NOT SET")
  {
    // works only in serial at this point
    if (Comm.NumProc() != 1)
      throw(Exception(__FILE__, __LINE__,
                      "FileGrid can be used only in serial"));

    // read the file. A description of the file format is reported above.

    std::ifstream GridFile;
    GridFile.open(FileName.c_str());
    if (!GridFile.good())
      throw(Exception(__FILE__, __LINE__,
                      "Error opening file `" + FileName + ")"));

    bool IsVertexCoordRead = false;
    bool IsElementVerticesRead = false;
    bool IsFaceVerticesRead = false;

    // STILL TO DO: ELEMENT TAG, VERTEX TAG, FACE TAG
    std::string what;
    while (!GridFile.eof())
    {
      GridFile >> what;
      if (what == "NumDimensions:") 
        GridFile >> NumDimensions_;
      else if (what == "NumVerticesPerElement:") 
        GridFile >> NumVerticesPerElement_;
      else if (what == "NumVerticesPerFace:") 
        GridFile >> NumVerticesPerFace_;
      else if (what == "NumFacesPerElement:") 
        GridFile >> NumFacesPerElement_;
      else if (what == "ElementType:") 
        GridFile >> ElementType_;
      else if (what == "NumMyElements:") 
        GridFile >> NumMyElements_;
      else if (what == "NumMyVertices:") 
        GridFile >> NumMyVertices_;
      else if (what == "NumMyBoundaryFaces:") 
        GridFile >> NumMyBoundaryFaces_;

      else if (what == "VertexCoord:")
      {
        if (NumMyVertices_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumMyVertices not set when reading VertexCoord"));
        if (NumDimensions_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumDimensions not set when reading VertexCoord"));

        // last entry is the tag
        VertexCoord_.Shape(NumMyVertices_, NumDimensions_ + 1);

        for (int i = 0 ; i < NumMyVertices_ ; ++i)
          for (int j = 0 ; j < NumDimensions_ + 1 ; ++j)
            GridFile >> VertexCoord_(i, j);

        IsVertexCoordRead = true;
      }
      else if (what == "ElementVertices:")
      {
        if (NumMyElements_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumMyElements not set when reading ElementVertices"));
        if (NumVerticesPerElement_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumVerticesPerElement not set when reading ElementVertices"));

        // last entry is the tag
        ElementVertices_.Shape(NumMyElements_, NumVerticesPerElement_ + 1);

        for (int i = 0 ; i < NumMyElements_ ; ++i)
          for (int j = 0 ; j < NumVerticesPerElement_ + 1 ; ++j)
            GridFile >> ElementVertices_(i, j);

        IsElementVerticesRead = true;
      }

      else if (what == "FaceVertices:")
      {
        if (NumMyBoundaryFaces_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumMyBoundaryFaces not set when reading FaceVertices"));
        if (NumVerticesPerFace_ == -1)
          throw(Exception(__FILE__, __LINE__,
                          "NumVerticesPerFace not set when reading FaceVertices"));

        // last entry is the tag
        FaceVertices_.Shape(NumMyBoundaryFaces_, NumVerticesPerFace_ + 1);

        for (int i = 0 ; i < NumMyBoundaryFaces_ ; ++i)
        {
          for (int j = 0 ; j < NumVerticesPerFace_ + 1 ; ++j)
            GridFile >> FaceVertices_(i, j);
        }

        IsFaceVerticesRead = true;
      }
    } // till file end

    if (!IsVertexCoordRead || !IsElementVerticesRead ||
        !IsFaceVerticesRead)
      throw(Exception(__FILE__, __LINE__,
                      "One among VertexCoord, ElementVertices and",
                      "FaceVertices has not been read"));

    if (NumDimensions_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumDimensions not read from file"));
    if (NumVerticesPerElement_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumVerticesPerElement not read from file"));
    if (NumVerticesPerFace_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumVerticesPerFace not read from file"));
    if (NumFacesPerElement_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumFacesPerElement not read from file"));
    if (NumMyVertices_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumMyVertices not read from file"));
    if (NumMyElements_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumMyElements not read from file"));
    if (NumMyBoundaryFaces_ == -1)
      throw(Exception(__FILE__, __LINE__, 
                      "NumMyBoundaryFaces not read from file"));
    if (ElementType_ == "NOT SET")
      throw(Exception(__FILE__, __LINE__, 
                      "ElementType not read from file"));
    
    NumGlobalVertices_ = NumMyVertices_;
    NumGlobalElements_ = NumMyElements_;
    NumGlobalBoundaryFaces_ = NumMyBoundaryFaces_;

    // This maps are all trivial here
    ElementMap_ = rcp(new Epetra_Map(-1, NumMyElements(), 0, Comm));
    VertexMap_ = rcp(new Epetra_Map(-1, NumMyVertices(), 0, Comm));
    RowMap_ = rcp(new Epetra_Map(-1, NumMyVertices(), 0, Comm));

    Importer_ = rcp(new Epetra_Import(VertexMap(), RowMap()));
    
    // computes the length and other element quantities

    ElementMaxLength_.Shape(NumMyElements_, 1);
    ElementMinLength_.Shape(NumMyElements_, 1);
    ElementVolume_.Shape(NumMyElements_, 1);

    if (ElementType_ == "GALERI_TRIANGLE")
    {
      int IDs[3];
      double x[3], y[3], z[3];
      z[0] = 0.0, z[1] = 0.0, z[2] = 0.0;

      for (int ie = 0 ; ie < NumMyElements_ ; ++ie)
      {
        ElementVertices(ie, IDs);

        for (int i = 0 ; i < 3 ; ++i)
        {
          x[i] = VertexCoord_(IDs[i], 0);
          y[i] = VertexCoord_(IDs[i], 1);
        }

        double l0 = Length(x[0], y[0], 0.0, x[1], y[1], 0.0);
        double l1 = Length(x[1], y[1], 0.0, x[2], y[2], 0.0);
        double l2 = Length(x[2], y[2], 0.0, x[0], y[0], 0.0);

        double max = l0;
        if (l1 > max) max = l1;
        if (l2 > max) max = l2;

        double min = l0;
        if (l1 < min) min = l1;
        if (l2 < min) min = l2;

        ElementMaxLength_[ie] = max;
        ElementMinLength_[ie] = min;
        ElementVolume_[ie] = AreaOfTriangle(x, y, z);
      }
    }
    else if (ElementType_ == "GALERI_QUAD")
    {
      int IDs[4];
      double x[4], y[4], z[4];
      z[0] = 0.0, z[1] = 0.0, z[2] = 0.0, z[3] = 0.0;

      for (int ie = 0 ; ie < NumMyElements_ ; ++ie)
      {
        ElementVertices(ie, IDs);

        for (int i = 0 ; i < 4 ; ++i)
        {
          x[i] = VertexCoord_(IDs[i], 0);
          y[i] = VertexCoord_(IDs[i], 1);
        }

        double l0 = Length(x[0], y[0], 0.0, x[1], y[1], 0.0);
        double l1 = Length(x[1], y[1], 0.0, x[2], y[2], 0.0);
        double l2 = Length(x[2], y[2], 0.0, x[3], y[3], 0.0);
        double l3 = Length(x[3], y[3], 0.0, x[0], y[0], 0.0);

        double max = l0;
        if (l1 > max) max = l1;
        if (l2 > max) max = l2;
        if (l3 > max) max = l3;

        double min = l0;
        if (l1 < min) min = l1;
        if (l2 < min) min = l2;
        if (l3 < max) max = l3;

        ElementMaxLength_[ie] = max;
        ElementMinLength_[ie] = min;
        ElementVolume_[ie] = AreaOfQuad(x, y, z);
      }
    }
    else if (ElementType_ == "GALERI_TET")
    {
      for (int ie = 0 ; ie < NumMyElements_ ; ++ie)
      {
        ElementMaxLength_[ie] = -1.;
        ElementMinLength_[ie] = -1.;
        ElementVolume_[ie] = -1;
      }
    }
    else if (ElementType_ == "GALERI_HEX")
    {
      for (int ie = 0 ; ie < NumMyElements_ ; ++ie)
      {
        ElementMaxLength_[ie] = -1.;
        ElementMinLength_[ie] = -1.;
        ElementVolume_[ie] = -1.;
      }
    }
  }

  virtual ~FileGrid() {}

  virtual int NumDimensions() const
  {
    return(NumDimensions_);
  }

  virtual int NumVerticesPerElement() const
  {
    return(NumVerticesPerElement_);
  }

  virtual int NumFacesPerElement() const
  {
    return(NumFacesPerElement_);
  }

  virtual int NumVerticesPerFace() const
  {
    return(NumVerticesPerFace_);
  }

  virtual std::string ElementType() const
  {
    return(ElementType_);
  }

  virtual const Epetra_Comm& Comm() const
  {
    return(Comm_);
  }

  virtual int NumMyElements() const
  {
    return(NumMyElements_);
  }

  virtual int NumGlobalElements() const
  {
    return(NumGlobalElements_);
  }

  virtual int NumMyVertices() const
  {
    return(NumMyVertices_);
  }

  virtual int NumGlobalVertices() const
  {
    return(NumGlobalVertices_);
  }

  virtual int NumMyBoundaryFaces() const
  {
    return(NumMyBoundaryFaces_);
  }

  virtual int NumGlobalBoundaryFaces() const
  {
    return(NumGlobalBoundaryFaces_);
  }

  virtual void VertexCoord(const int LocalID, double* coord) const
  {
    if (LocalID >= NumMyVertices_)
      throw(Exception(__FILE__, __LINE__, 
                      "LocalID = " + toString(LocalID) + ", " +
                      "NumMyVertices = " + toString(NumMyVertices_)));

    for (int i = 0 ; i < NumDimensions_ ; ++i)
      coord[i] = VertexCoord_(LocalID, i);
    if (NumDimensions_ == 2)
      coord[2] = 0.0;
  }

  virtual void VertexCoord(const int Length, const int* IDs, 
                           double* x, double* y, double* z) const
  {
    for (int i = 0 ; i < Length ; ++i)
    {
      if (IDs[i] >= NumMyVertices_)
        throw(Exception(__FILE__, __LINE__, 
                        "LocalID = " + toString(IDs[i]) + ", " +
                        "NumMyVertices = " + toString(NumMyVertices_)));

      x[i] = VertexCoord_(IDs[i], 0);
      y[i] = VertexCoord_(IDs[i], 1);
      if (NumDimensions_ == 3)
        z[i] = VertexCoord_(IDs[i], 2);
      else
        z[i] = 0.0;
    }
  }

  virtual void ElementVertices(const int LocalID, int* elements) const
  {
    for (int i = 0 ; i < NumVerticesPerElement_ ; ++i)
      elements[i] = ElementVertices_(LocalID, i);
  }

  virtual double ElementMinLength(const int LocalElement) const
  {
    return(ElementMinLength_[LocalElement]);
  }

  virtual double ElementMaxLength(const int LocalElement) const
  {
    return(ElementMaxLength_[LocalElement]);
  }

  virtual const RefCountPtr<Epetra_Map> RCPVertexMap() const
  {
    return(VertexMap_);
  }

  virtual const RefCountPtr<Epetra_Map> RCPElementMap() const
  {
    return(ElementMap_);
  }

  virtual const Epetra_Map& VertexMap() const
  {
    return(*(VertexMap_.get()));
  }

  virtual const Epetra_Map& ElementMap() const
  {
    return(*(ElementMap_.get()));
  }

  virtual const Epetra_Map& RowMap() const
  {
    return(*(RowMap_.get()));
  }

  virtual const Epetra_Import& Importer() const
  {
    return(*(Importer_.get()));
  }

  virtual int ElementTag(const int LocalID) const
  {
    return(ElementVertices_(LocalID, NumVerticesPerElement_));
  }

  virtual int VertexTag(const int LocalID) const
  {
    return((int)(VertexCoord_(LocalID, NumDimensions_)));
  }

  virtual double ElementVolume() const
  {
    throw(Exception(__FILE__, __LINE__, "Not implemented"));
  }

  virtual void FaceVertices(const int LocalFace, int& tag, int* IDs) const
  {
    for (int i = 0 ; i < NumVerticesPerFace_ ; ++i)
      IDs[i] = FaceVertices_(LocalFace, i);
    tag = FaceVertices_(LocalFace, NumVerticesPerFace_);
  }

  inline int FacePatch(const int LocalFace) const
  {
    return(FaceVertices_(LocalFace, NumVerticesPerFace_));
  }

  virtual double ElementVolume(const int LocalElement) const
  {
    return(ElementVolume_(LocalElement));
  }

  virtual double FaceArea(const int LocalFace) const
  {
    throw(Exception(__FILE__, __LINE__, "Not implemented"));
  }

  virtual double MyVolume() const
  {
    throw(Exception(__FILE__, __LINE__, "Not implemented"));
  }

  virtual double GlobalVolume() const
  {
    throw(Exception(__FILE__, __LINE__, "Not implemented"));
  }

  void ExportToVertexMap(const Epetra_DistObject& RowObject,
                         Epetra_DistObject& VertexObject) const
  {
    VertexObject.Import(RowObject, Importer(), Insert);
  }

  void ExportToRowMap(const Epetra_DistObject& VertexObject,
                            Epetra_DistObject& RowObject) const
  {
    RowObject.Export(VertexObject, Importer(), Insert);
  }

   int NumNeighborsPerElement() const
   {
     throw(Exception(__FILE__, __LINE__, "Not implemented"));
   }

   void ElementNeighbors(int, int*) const
   {
     throw(Exception(__FILE__, __LINE__, "Not implemented"));
   }

private:
  const Epetra_Comm& Comm_;
  std::string FileName_;

  int NumDimensions_;
  int NumVerticesPerElement_;
  int NumVerticesPerFace_;
  int NumFacesPerElement_;

  int NumMyVertices_;
  int NumGlobalVertices_;

  int NumMyElements_;
  int NumGlobalElements_;

  int NumMyBoundaryFaces_;
  int NumGlobalBoundaryFaces_;

  std::string ElementType_;

  Epetra_SerialDenseMatrix VertexCoord_;
  Epetra_IntSerialDenseMatrix ElementVertices_;
  Epetra_IntSerialDenseMatrix FaceVertices_;
  Epetra_SerialDenseVector ElementMaxLength_;
  Epetra_SerialDenseVector ElementMinLength_;
  Epetra_SerialDenseVector ElementVolume_;

  RefCountPtr<Epetra_Map> VertexMap_;
  RefCountPtr<Epetra_Map> ElementMap_;
  RefCountPtr<Epetra_Map> RowMap_;
  RefCountPtr<Epetra_Import> Importer_;
}; // class FileGrid

} // namespace FiniteElements
} // namespace Galeri
#endif