MFEM v2.0
intrules.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
00003 // reserved. See file COPYRIGHT for details.
00004 //
00005 // This file is part of the MFEM library. For more information and source code
00006 // availability see http://mfem.googlecode.com.
00007 //
00008 // MFEM is free software; you can redistribute it and/or modify it under the
00009 // terms of the GNU Lesser General Public License (as published by the Free
00010 // Software Foundation) version 2.1 dated February 1999.
00011 
00012 #ifndef MFEM_INTRULES
00013 #define MFEM_INTRULES
00014 
00015 /* Classes for IntegrationPoint, IntegrationRule, and container class
00016    IntegrationRules.  Declares the global variable IntRules */
00017 
00019 class IntegrationPoint
00020 {
00021 public:
00022    double x, y, z, weight;
00023 
00024    void Set(const double x1, const double x2, const double x3, const double w)
00025    { x = x1; y = x2; z = x3; weight = w; }
00026 
00027    void Set3w(const double *p) { x = p[0]; y = p[1]; z = p[2]; weight = p[3]; }
00028 
00029    void Set3(const double x1, const double x2, const double x3)
00030    { x = x1; y = x2; z = x3; }
00031 
00032    void Set3(const double *p) { x = p[0]; y = p[1]; z = p[2]; }
00033 
00034    void Set2w(const double x1, const double x2, const double w)
00035    { x = x1; y = x2; weight = w; }
00036 
00037    void Set2w(const double *p) { x = p[0]; y = p[1]; weight = p[2]; }
00038 
00039    void Set2(const double x1, const double x2) { x = x1; y = x2; }
00040 
00041    void Set2(const double *p) { x = p[0]; y = p[1]; }
00042 
00043    void Set1w(const double x1, const double w) { x = x1; weight = w; }
00044 
00045    void Set1w(const double *p) { x = p[0]; weight = p[1]; }
00046 };
00047 
00049 class IntegrationRule
00050 {
00051 private:
00052    int NPoints;
00053    IntegrationPoint *IntPoints;
00054 
00055    friend class IntegrationRules;
00056 
00058    void GaussianRule();
00059 
00061    void UniformRule();
00062 
00064    void GrundmannMollerTetrahedronRule(int s);
00065 
00066    void AddTriMidPoint(const int off, const double weight)
00067    { IntPoints[off].Set2w(1./3., 1./3., weight); }
00068 
00069    void AddTriPoints3(const int off, const double a, const double b,
00070                       const double weight)
00071    {
00072       IntPoints[off + 0].Set2w(a, a, weight);
00073       IntPoints[off + 1].Set2w(a, b, weight);
00074       IntPoints[off + 2].Set2w(b, a, weight);
00075    }
00076 
00077    void AddTriPoints3(const int off, const double a, const double weight)
00078    { AddTriPoints3(off, a, 1. - 2.*a, weight); }
00079 
00080    void AddTriPoints3b(const int off, const double b, const double weight)
00081    { AddTriPoints3(off, (1. - b)/2., b, weight); }
00082 
00083    void AddTriPoints3R(const int off, const double a, const double b,
00084                        const double c, const double weight)
00085    {
00086       IntPoints[off + 0].Set2w(a, b, weight);
00087       IntPoints[off + 1].Set2w(c, a, weight);
00088       IntPoints[off + 2].Set2w(b, c, weight);
00089    }
00090 
00091    void AddTriPoints3R(const int off, const double a, const double b,
00092                        const double weight)
00093    { AddTriPoints3R(off, a, b, 1. - a - b, weight); }
00094 
00095    void AddTriPoints6(const int off, const double a, const double b,
00096                       const double c, const double weight)
00097    {
00098       IntPoints[off + 0].Set2w(a, b, weight);
00099       IntPoints[off + 1].Set2w(b, a, weight);
00100       IntPoints[off + 2].Set2w(a, c, weight);
00101       IntPoints[off + 3].Set2w(c, a, weight);
00102       IntPoints[off + 4].Set2w(b, c, weight);
00103       IntPoints[off + 5].Set2w(c, b, weight);
00104    }
00105 
00106    void AddTriPoints6(const int off, const double a, const double b,
00107                       const double weight)
00108    { AddTriPoints6(off, a, b, 1. - a - b, weight); }
00109 
00110    // add the permutations of (a,a,b)
00111    void AddTetPoints3(const int off, const double a, const double b,
00112                       const double weight)
00113    {
00114       IntPoints[off + 0].Set(a, a, b, weight);
00115       IntPoints[off + 1].Set(a, b, a, weight);
00116       IntPoints[off + 2].Set(b, a, a, weight);
00117    }
00118 
00119    // add the permutations of (a,b,c)
00120    void AddTetPoints6(const int off, const double a, const double b,
00121                       const double c, const double weight)
00122    {
00123       IntPoints[off + 0].Set(a, b, c, weight);
00124       IntPoints[off + 1].Set(a, c, b, weight);
00125       IntPoints[off + 2].Set(b, c, a, weight);
00126       IntPoints[off + 3].Set(b, a, c, weight);
00127       IntPoints[off + 4].Set(c, a, b, weight);
00128       IntPoints[off + 5].Set(c, b, a, weight);
00129    }
00130 
00131    void AddTetMidPoint(const int off, const double weight)
00132    { IntPoints[off].Set(0.25, 0.25, 0.25, weight); }
00133 
00134    // given a, add the permutations of (a,a,a,b), where 3*a + b = 1
00135    void AddTetPoints4(const int off, const double a, const double weight)
00136    {
00137       IntPoints[off].Set(a, a, a, weight);
00138       AddTetPoints3(off + 1, a, 1. - 3.*a, weight);
00139    }
00140 
00141    // given b, add the permutations of (a,a,a,b), where 3*a + b = 1
00142    void AddTetPoints4b(const int off, const double b, const double weight)
00143    {
00144       const double a = (1. - b)/3.;
00145       IntPoints[off].Set(a, a, a, weight);
00146       AddTetPoints3(off + 1, a, b, weight);
00147    }
00148 
00149    // add the permutations of (a,a,b,b), 2*(a + b) = 1
00150    void AddTetPoints6(const int off, const double a, const double weight)
00151    {
00152       const double b = 0.5 - a;
00153       AddTetPoints3(off,     a, b, weight);
00154       AddTetPoints3(off + 3, b, a, weight);
00155    }
00156 
00157    // given (a,b) or (a,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
00158    void AddTetPoints12(const int off, const double a, const double bc,
00159                        const double weight)
00160    {
00161       const double cb = 1. - 2*a - bc;
00162       AddTetPoints3(off,     a, bc, weight);
00163       AddTetPoints3(off + 3, a, cb, weight);
00164       AddTetPoints6(off + 6, a, bc, cb, weight);
00165    }
00166 
00167    // given (b,c), add the permutations of (a,a,b,c), 2*a + b + c = 1
00168    void AddTetPoints12bc(const int off, const double b, const double c,
00169                          const double weight)
00170    {
00171       const double a = (1. - b - c)/2.;
00172       AddTetPoints3(off,     a, b, weight);
00173       AddTetPoints3(off + 3, a, c, weight);
00174       AddTetPoints6(off + 6, a, b, c, weight);
00175    }
00176 
00177 public:
00178    IntegrationRule() { NPoints = 0; IntPoints = NULL; }
00179 
00181    explicit IntegrationRule(int NP);
00182 
00184    IntegrationRule(IntegrationRule &irx, IntegrationRule &iry);
00185 
00187    int GetNPoints() const { return NPoints; }
00188 
00190    IntegrationPoint &IntPoint(int i) { return IntPoints[i]; }
00191 
00193    const IntegrationPoint &IntPoint(int i) const { return IntPoints[i]; }
00194 
00196    ~IntegrationRule();
00197 };
00198 
00200 class IntegrationRules
00201 {
00202 private:
00203    int own_rules;
00204 
00205    Array<IntegrationRule *> PointIntRules;
00206    Array<IntegrationRule *> SegmentIntRules;
00207    Array<IntegrationRule *> TriangleIntRules;
00208    Array<IntegrationRule *> SquareIntRules;
00209    Array<IntegrationRule *> TetrahedronIntRules;
00210    Array<IntegrationRule *> CubeIntRules;
00211 
00212    void PointIntegrationRules();
00213    void SegmentIntegrationRules(int refined);
00214    void TriangleIntegrationRules(int refined);
00215    void SquareIntegrationRules();
00216    void TetrahedronIntegrationRules(int refined);
00217    void CubeIntegrationRules();
00218 
00219    void DeleteIntRuleArray(Array<IntegrationRule *> &ir_array);
00220 
00221 public:
00223    explicit IntegrationRules(int refined = 0);
00224 
00226    const IntegrationRule &Get(int GeomType, int Order);
00227 
00228    void Set(int GeomType, int Order, IntegrationRule &IntRule);
00229 
00230    void SetOwnRules(int o) { own_rules = o; }
00231 
00233    ~IntegrationRules();
00234 };
00235 
00237 extern IntegrationRules IntRules;
00238 
00240 extern IntegrationRules RefinedIntRules;
00241 
00242 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines