Code_TYMPAN  4.4.0
Industrial site acoustic simulation
acoustic_problem_model.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
24 #include <iostream>
25 #include <iomanip>
26 
30 
31 // using namespace std;
32 
33 namespace tympan
34 {
35 
36 std::deque<triangle_idx> scene_volume_intersection(const triangle_pool_t& triangle_soup,
37  const nodes_pool_t& nodes, float w, float h,
38  OPoint3D source, OPoint3D receptor)
39 {
40  CGAL_Point3 _source = to_cgal(source);
41  CGAL_Point3 _receptor = to_cgal(receptor);
42  std::deque<CGAL_Point3> vertices = build_box(w, h, _source, _receptor);
43  // we just want to apply rotation on mesh triangles and no translation --> center the box system
44  // on (0, 0, 0)
45  CGAL_Vector3 vx = normalize(CGAL_Vector3(vertices[0], vertices[1]));
46  CGAL_Vector3 vy = normalize(CGAL_Vector3(vertices[0], vertices[2]));
47  CGAL_Vector3 vz = normalize(CGAL_Vector3(vertices[0], vertices[3]));
48  CGAL_Transform3 to_box_system(vx.x(), vx.y(), vx.z(), vy.x(), vy.y(), vy.z(), vz.x(), vz.y(), vz.z());
49  // Move triangles from the triangle soup of the scene to the volume reference systeme and
50  // build CGAL triangles out of them
51  std::deque<CGAL_Point3> cgal_nodes;
52  for (nodes_pool_t::const_iterator it = nodes.begin(); it != nodes.end(); it++)
53  {
54  cgal_nodes.push_back(CGAL_Point3(it->_x, it->_y, it->_z).transform(to_box_system));
55  }
56  CGAL_Triangles cgal_triangles;
57  for (triangle_pool_t::const_iterator it = triangle_soup.begin(); it != triangle_soup.end(); it++)
58  {
59  cgal_triangles.push_back(
60  CGAL_Triangle(cgal_nodes[it->n[0]], cgal_nodes[it->n[1]], cgal_nodes[it->n[2]]));
61  }
62  float l = (float)sqrt(CGAL_Vector3(_source, _receptor).squared_length());
63  // these 3 points delimit the bounds of the fresnel box (in other terms, the bounding
64  // box of this triangle should have the dimensions of the fresnel box). This will be checked
65  // anyway by intersected_triangles() thanks to the expected dimensions passed: l, w and h
66  std::deque<CGAL_Point3> box_triangle;
67  box_triangle.push_back(vertices[1].transform(to_box_system));
68  box_triangle.push_back(vertices[2].transform(to_box_system));
69  box_triangle.push_back(vertices[3].transform(to_box_system));
70  return intersected_triangles(cgal_triangles, box_triangle, l, w, h);
71 }
72 
74 {
75  all_nodes.push_back(p);
76  return all_nodes.size() - 1;
77 }
78 
80 {
81  n[0] = n1;
82  n[1] = n2;
83  n[2] = n3;
84 }
85 
87 {
88  all_triangles.push_back(AcousticTriangle(n1, n2, n3));
89  return all_triangles.size() - 1;
90 }
91 
92 material_ptr_t AcousticProblemModel::make_material(const string& name, double resistivity, double deviation,
93  double length, double factor_g)
94 {
95  material_ptr_t p_mat = nullptr;
96  shared_ptr<AcousticGroundMaterial> ptr = nullptr;
97  bool found = false;
98  // Search if an instance of AcousticGroundMaterial with same name and characteristics is already pushed
99  for (auto iter = all_materials.begin(); iter != all_materials.end(); ++iter)
100  {
101  ptr = tympan::dynamic_pointer_cast<AcousticGroundMaterial>(*iter);
102  // If it is not an AcousticGroundMaterial, continue
103  if (ptr == nullptr)
104  continue;
105  if (ptr->compare(name, resistivity, deviation, length, factor_g))
106  {
107  found = true;
108  break;
109  }
110  }
111  if (found)
112  {
113  p_mat = ptr;
114  }
115  else
116  {
117  // If no equivalent AcousticGroundMaterial is found, then create it and push it
118  p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
119  tympan::make_shared<AcousticGroundMaterial>(name, resistivity, deviation, length, factor_g));
120  all_materials.push_back(p_mat);
121  }
122  return p_mat;
123 }
124 
126 {
127  material_ptr_t p_mat = tympan::static_pointer_cast<AcousticMaterialBase>(
128  tympan::make_shared<AcousticBuildingMaterial>(name, spectrum));
129  all_materials.push_back(p_mat);
130  return p_mat;
131 }
132 
134  SourceDirectivityInterface* directivity)
135 {
136 
137  all_sources.push_back(AcousticSource(point, spectrum, directivity));
138  return all_sources.size() - 1;
139 }
140 
142 {
143  all_receptors.push_back(AcousticReceptor(position_));
144  return all_receptors.size() - 1;
145 }
146 
147 std::unique_ptr<AcousticProblemModel> make_AcousticProblemModel()
148 {
149  return std::unique_ptr<AcousticProblemModel>(new AcousticProblemModel());
150 }
151 
152 } // namespace tympan
const char * name
This file provides the top-level declaration for the acoustic problem model.
Utilities to ease (and wrap) use of CGAL.
The 3D point class.
Definition: 3d.h:487
Class to describe the acoustic problem.
source_pool_t all_sources
Array of all sources.
receptor_idx make_receptor(const Point &position_)
Push a new acoustic receptor into the model.
triangle_idx make_triangle(node_idx n1, node_idx n2, node_idx n3)
node_idx make_node(const Point &point)
Destructor.
material_ptr_t make_material(const string &name, double resistivity, double deviation, double length, double factor_g)
Push a representation of a ground material into the model. If an instance of a ground material with s...
material_pool_t all_materials
Array of all materials.
nodes_pool_t all_nodes
Array of all nodes.
receptor_pool_t all_receptors
Array of all receptors.
triangle_pool_t all_triangles
Array of all triangles.
source_idx make_source(const Point &point_, const Spectrum &spectrum_, SourceDirectivityInterface *directivity)
Push a new acoustic source into the model.
Describes an acoustic receptor.
Definition: entities.hpp:403
Describes an acoustic source.
Definition: entities.hpp:381
Describing a triangle.
Definition: entities.hpp:204
node_idx n[3]
Triangle vertexes.
Definition: entities.hpp:209
AcousticTriangle(node_idx n1, node_idx n2, node_idx n3)
Constructor with the 3 vertexes of the triangle.
Interface for source directivity classes (SphericalSourceDirectivity, CommonFaceDirectivity,...
Definition: entities.hpp:223
CGAL_Vector3 normalize(CGAL_Vector3 v)
normalize vector v
Definition: cgal_tools.cpp:41
size_t triangle_idx
Definition: entities.hpp:215
CGAL::Triangle_3< CGAL_Gt > CGAL_Triangle
Definition: cgal_tools.h:65
CGAL_Plane to_cgal(const OPlan &oplan)
Convert a OPlan to CGAL_Plane.
Definition: cgal_tools.cpp:34
size_t source_idx
Definition: entities.hpp:396
CGAL::Point_3< CGAL_Gt > CGAL_Point3
Definition: cgal_tools.h:60
CGAL::Vector_3< CGAL_Gt > CGAL_Vector3
Definition: cgal_tools.h:62
std::deque< CGAL_Triangle > CGAL_Triangles
Definition: cgal_tools.h:66
std::deque< triangle_idx > scene_volume_intersection(const triangle_pool_t &triangle_soup, const nodes_pool_t &nodes, float w, float h, OPoint3D source, OPoint3D receptor)
Find the intersection between some triangles (triangles, nodes) and a volume given by a width,...
std::deque< Point > nodes_pool_t
size_t receptor_idx
Definition: entities.hpp:413
std::unique_ptr< AcousticProblemModel > make_AcousticProblemModel()
std::deque< CGAL_Point3 > build_box(float w, float h, CGAL_Point3 pta, CGAL_Point3 ptb)
return 4 points defining a 3D parallelepiped
Definition: cgal_tools.cpp:46
CGAL::Aff_transformation_3< CGAL_Gt > CGAL_Transform3
Definition: cgal_tools.h:68
shared_ptr< AcousticMaterialBase > material_ptr_t
Definition: entities.hpp:55
std::deque< AcousticTriangle > triangle_pool_t
Array of AcousticTriangle.
Definition: entities.hpp:214
std::deque< size_t > intersected_triangles(CGAL_Triangles &triangle_soup, std::deque< CGAL_Point3 > query_box, float length, float width, float height)
Find the triangles from triangle_soup that are intersected by the 3D box including the points of quer...
Definition: cgal_tools.cpp:83
size_t node_idx