TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Quadrature_base.cpp
1/****************************************************************************
2 * Copyright (c) 2024, CEA
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 * 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.
8 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9 *
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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.
11 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 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;
12 * 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.
13 *
14 *****************************************************************************/
15
16#include <Quadrature_base.h>
17#include <Matrix_tools.h>
18#include <Array_tools.h>
19
20
21double Quadrature_base::compute_integral_on_elem(int num_elem, Parser_U& parser) const
22{
23 DoubleTab val_pts_integ(tab_nb_pts_integ_(num_elem));
24 for (int pts = 0; pts < tab_nb_pts_integ_(num_elem); pts++)
25 {
26 double x = integ_points_(ind_pts_integ_(num_elem) + pts, 0),
27 y = integ_points_(ind_pts_integ_(num_elem) + pts, 1);
28 parser.setVar("x", x);
29 parser.setVar("y", y);
30 val_pts_integ(pts) = parser.eval();
31 }
32 return compute_integral_on_elem(num_elem, val_pts_integ);
33}
34
35double Quadrature_base::compute_integral_on_elem(int num_elem, DoubleTab& val_pts_integ) const
36{
37 double volume = dom_->volumes()[num_elem];
38 double acc = 0.;
39 for (int pts = 0; pts < tab_nb_pts_integ_(num_elem); pts++)
40 {
41 acc += val_pts_integ(pts) * weights_(ind_pts_integ_(num_elem)+pts);
42 }
43 return acc * volume;
44}
45
46double Quadrature_base::compute_integral_on_facet(int num_facet, Parser_U& parser) const
47{
48 DoubleTab val_pts_integ(nb_pts_integ_facets_);
49 for (int pts = 0; pts < nb_pts_integ_facets_; pts++)
50 {
51 double x = integ_points_facets_(num_facet, pts, 0),
52 y = integ_points_facets_(num_facet, pts, 1);
53 parser.setVar("x", x);
54 parser.setVar("y", y);
55 val_pts_integ(pts) = parser.eval();
56 }
57 return compute_integral_on_facet(num_facet, val_pts_integ);
58}
59
60double Quadrature_base::compute_integral_on_facet(int num_facet, DoubleTab& val_pts_integ) const
61{
62 double surface = dom_->face_surfaces(num_facet);
63 double acc = 0.;
64 for (int pts = 0; pts < nb_pts_integ_facets_; pts++)
65 {
66 double val_on_pt = val_pts_integ(pts);
67 acc += val_on_pt * weights_facets_(pts);
68 }
69 return acc * surface;
70}
71
73{
74 int nb_elem = dom_->nb_elem();
75 double acc = 0.;
76 for (int e = 0; e < nb_elem; e++)
78 Process::mp_sum(acc);
79 return acc;
80}
81
82double Quadrature_base::compute_integral(DoubleTab& vals_pts_integ) const
83{
84 int nb_elem = dom_->nb_elem();
85 double acc = 0.;
86 double volume;
87 for (int e = 0; e < nb_elem; e++)
88 {
89 volume = dom_->volumes(e);
90 for (int pts = 0; pts < tab_nb_pts_integ_(e); pts++)
91 acc += vals_pts_integ(ind_pts_integ_(e)+pts)*weights_(ind_pts_integ_(e)+pts)*volume;
92 }
93 Process::mp_sum(acc);
94 return acc;
95}
96
97
98// Function to calculate the area of a triangle from the coordinates of its vertices
99double Quadrature_base::triangleArea(double x1, double y1, double x2, double y2, double x3, double y3)
100{
101 return 0.5 * fabs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
102}
103// Function to calculate the weight scaler for tesselation
104double Quadrature_base::calculateWeightScale(const IntTab& vert_elems, const DoubleTab& xs, DoubleVect& volumes, int e, int s1, int s2, int s3)
105{
106 return triangleArea(
107 xs(vert_elems(e, s1), 0), xs(vert_elems(e, s1), 1),
108 xs(vert_elems(e, s2), 0), xs(vert_elems(e, s2), 1),
109 xs(vert_elems(e, s3), 0), xs(vert_elems(e, s3), 1)
110 ) / volumes(e);
111}
112
113double Quadrature_base::calculateWeightScale(double ve, double s1x, double s1y, double s2x, double s2y, double s3x, double s3y)
114{
115 return triangleArea(
116 s1x, s1y,
117 s2x, s2y,
118 s3x, s3y
119 ) / ve;
120}
classe Parser_U Version de la classe Parser, derivant de Objet_U.
Definition Parser_U.h:32
void setVar(const char *sv, double val)
Definition Parser_U.h:149
double eval()
Definition Parser_U.h:125
static double mp_sum(double)
Calcule la somme de x sur tous les processeurs du groupe courant.
Definition Process.cpp:146
double triangleArea(double x1, double y1, double x2, double y2, double x3, double y3)
DoubleTab weights_facets_
DoubleTab integ_points_
double calculateWeightScale(const IntTab &vert_elems, const DoubleTab &xs, DoubleVect &volumes, int e, int s1, int s2, int s3)
double compute_integral_on_facet(int num_facet, Parser_U &parser) const
double compute_integral(Parser_U &parser) const
DoubleTab integ_points_facets_
double compute_integral_on_elem(int num_elem, Parser_U &parser) const