1 /* *****************************************************************
2 MESQUITE -- The Mesh Quality Improvement Toolkit
3
4 Copyright 2007 Sandia National Laboratories. Developed at the
5 University of Wisconsin--Madison under SNL contract number
6 624796. The U.S. Government and the University of Wisconsin
7 retain certain rights to this software.
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 (lgpl.txt) along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23 (2009) kraftche@cae.wisc.edu
24
25 ***************************************************************** */
26
27
28 /** \file Settings.cpp
29 * \brief
30 * \author Jason Kraftcheck
31 */
32
33 #include "Mesquite.hpp"
34 #include "Settings.hpp"
35 #include "TriLagrangeShape.hpp"
36 #include "QuadLagrangeShape.hpp"
37 #include "TetLagrangeShape.hpp"
38 #include "LinearPyramid.hpp"
39 #include "LinearPrism.hpp"
40 #include "LinearHexahedron.hpp"
41
42 namespace MBMesquite {
43
44 #ifdef MSQ_TRAP_FPE
45 const bool IQ_TRAP_FPE_DEFAULT = true;
46 #else
47 const bool IQ_TRAP_FPE_DEFAULT = false;
48 #endif
49
50 struct SettingData {
51 SettingData(); //!< Initialize to default settings.
52 SettingData( const SettingData& other );
53 SettingData& operator=( const SettingData& other );
54 bool trapFPE;
55 Settings::FixedVertexMode fixedMode;
56 Settings::HigherOrderSlaveMode slaveMode;
57 std::vector<const MappingFunction*> mapArray;
58 std::vector<const MappingFunction2D*> mapArray2D;
59 std::vector<const MappingFunction3D*> mapArray3D;
60
61 TriLagrangeShape defTriFunc;
62 QuadLagrangeShape defQuadFunc;
63 TetLagrangeShape defTetFunc;
64 LinearPyramid defPyrFunc;
65 LinearPrism defPriFunc;
66 LinearHexahedron defHexFunc;
67
68 private:
69 void fix_copy( const SettingData& other);
70 };
71
SettingData()72 SettingData::SettingData()
73 : trapFPE( IQ_TRAP_FPE_DEFAULT ),
74 fixedMode( Settings::FIXED_FLAG ),
75 slaveMode( Settings::SLAVE_ALL ),
76 mapArray( MIXED, 0 ),
77 mapArray2D( MIXED, 0 ),
78 mapArray3D( MIXED, 0 )
79 {
80 mapArray[TRIANGLE ] = &defTriFunc;
81 mapArray[QUADRILATERAL] = &defQuadFunc;
82 mapArray[TETRAHEDRON ] = &defTetFunc;
83 mapArray[PYRAMID ] = &defPyrFunc;
84 mapArray[PRISM ] = &defPriFunc;
85 mapArray[HEXAHEDRON ] = &defHexFunc;
86 mapArray2D[TRIANGLE ] = &defTriFunc;
87 mapArray2D[QUADRILATERAL] = &defQuadFunc;
88 mapArray3D[TETRAHEDRON ] = &defTetFunc;
89 mapArray3D[PYRAMID ] = &defPyrFunc;
90 mapArray3D[PRISM ] = &defPriFunc;
91 mapArray3D[HEXAHEDRON ] = &defHexFunc;
92 }
93
94
SettingData(const SettingData & other)95 SettingData::SettingData( const SettingData& other )
96 : trapFPE( other.trapFPE ),
97 fixedMode( other.fixedMode ),
98 slaveMode( other.slaveMode ),
99 mapArray( other.mapArray ),
100 mapArray2D( other.mapArray2D ),
101 mapArray3D( other.mapArray3D )
102 {
103 fix_copy( other );
104 }
105
operator =(const SettingData & other)106 SettingData& SettingData::operator=( const SettingData& other )
107 {
108 trapFPE = other.trapFPE;
109 fixedMode = other.fixedMode;
110 slaveMode = other.slaveMode;
111 mapArray = other.mapArray;
112 mapArray2D = other.mapArray2D;
113 mapArray3D = other.mapArray3D;
114 fix_copy( other );
115 return *this;
116 }
117
fix_copy(const SettingData & other)118 void SettingData::fix_copy( const SettingData& other )
119 {
120 if (mapArray[TRIANGLE] == &other.defTriFunc)
121 mapArray[TRIANGLE] = &defTriFunc;
122 if (mapArray[QUADRILATERAL] == &other.defQuadFunc)
123 mapArray[QUADRILATERAL] = &defQuadFunc;
124 if (mapArray[TETRAHEDRON] == &other.defTetFunc)
125 mapArray[TETRAHEDRON] = &defTetFunc;
126 if (mapArray[PYRAMID] == &other.defPyrFunc)
127 mapArray[PYRAMID] = &defPyrFunc;
128 if (mapArray[PRISM] == &other.defPriFunc)
129 mapArray[PRISM] = &defPriFunc;
130 if (mapArray[HEXAHEDRON] == &other.defHexFunc)
131 mapArray[HEXAHEDRON] = &defHexFunc;
132 if (mapArray2D[TRIANGLE] == &other.defTriFunc)
133 mapArray2D[TRIANGLE] = &defTriFunc;
134 if (mapArray2D[QUADRILATERAL] == &other.defQuadFunc)
135 mapArray2D[QUADRILATERAL] = &defQuadFunc;
136 if (mapArray3D[TETRAHEDRON] == &other.defTetFunc)
137 mapArray3D[TETRAHEDRON] = &defTetFunc;
138 if (mapArray3D[PYRAMID] == &other.defPyrFunc)
139 mapArray3D[PYRAMID] = &defPyrFunc;
140 if (mapArray3D[PRISM] == &other.defPriFunc)
141 mapArray3D[PRISM] = &defPriFunc;
142 if (mapArray3D[HEXAHEDRON] == &other.defHexFunc)
143 mapArray3D[HEXAHEDRON] = &defHexFunc;
144 }
145
Settings()146 Settings::Settings()
147 : mData( new SettingData )
148 { }
Settings(const Settings & other)149 Settings::Settings( const Settings& other )
150 : mData( new SettingData(*other.mData) )
151 { }
~Settings()152 Settings::~Settings()
153 { delete mData; }
operator =(const Settings & other)154 Settings& Settings::operator=( const Settings& other )
155 { *mData = *(other.mData); return *this; }
156
set_mapping_function(const MappingFunction * func)157 void Settings::set_mapping_function( const MappingFunction* func )
158 {
159 EntityTopology type = func->element_topology();
160 if (mData->mapArray.size() <= (size_t)type)
161 mData->mapArray.resize( type+1, 0 );
162 mData->mapArray[type] = func;
163 if (TopologyInfo::dimension(type) == 2 && mData->mapArray2D.size() > (size_t)type)
164 mData->mapArray2D[type] = 0;
165 else if (TopologyInfo::dimension(type) == 3 && mData->mapArray3D.size() > (size_t)type)
166 mData->mapArray3D[type] = 0;
167 }
168
set_mapping_function(const MappingFunction2D * func)169 void Settings::set_mapping_function( const MappingFunction2D* func )
170 {
171 unsigned type = func->element_topology();
172 if (mData->mapArray.size() <= type)
173 mData->mapArray.resize(type+1, 0);
174 mData->mapArray[type] = func;
175 if (mData->mapArray2D.size() <= type)
176 mData->mapArray2D.resize( type+1, 0 );
177 mData->mapArray2D[type] = func;
178 }
179
set_mapping_function(const MappingFunction3D * func)180 void Settings::set_mapping_function( const MappingFunction3D* func )
181 {
182 unsigned type = func->element_topology();
183 if (mData->mapArray.size() <= type)
184 mData->mapArray.resize(type+1, 0);
185 mData->mapArray[type] = func;
186 if (mData->mapArray3D.size() <= type)
187 mData->mapArray3D.resize( type+1, 0 );
188 mData->mapArray3D[type] = func;
189 }
190
set_mapping_functions(const MappingFunction * const * array,size_t array_len)191 void Settings::set_mapping_functions( const MappingFunction* const* array,
192 size_t array_len )
193 {
194 for (size_t i = 0; i < array_len; ++i)
195 set_mapping_function( array[i] );
196 }
set_mapping_functions(const MappingFunction2D * const * array,size_t array_len)197 void Settings::set_mapping_functions( const MappingFunction2D* const* array,
198 size_t array_len )
199 {
200 for (size_t i = 0; i < array_len; ++i)
201 set_mapping_function( array[i] );
202 }
set_mapping_functions(const MappingFunction3D * const * array,size_t array_len)203 void Settings::set_mapping_functions( const MappingFunction3D* const* array,
204 size_t array_len )
205 {
206 for (size_t i = 0; i < array_len; ++i)
207 set_mapping_function( array[i] );
208 }
209
get_mapping_function(EntityTopology type) const210 const MappingFunction* Settings::get_mapping_function( EntityTopology type ) const
211 { return (size_t)type < mData->mapArray.size() ? mData->mapArray[type] : 0; }
212
get_mapping_function_2D(EntityTopology type) const213 const MappingFunction2D* Settings::get_mapping_function_2D( EntityTopology type ) const
214 { return (size_t)type < mData->mapArray2D.size() ? mData->mapArray2D[type] : 0; }
215
get_mapping_function_3D(EntityTopology type) const216 const MappingFunction3D* Settings::get_mapping_function_3D( EntityTopology type ) const
217 { return (size_t)type < mData->mapArray3D.size() ? mData->mapArray3D[type] : 0; }
218
set_fixed_vertex_mode(Settings::FixedVertexMode mode)219 void Settings::set_fixed_vertex_mode( Settings::FixedVertexMode mode )
220 { mData->fixedMode = mode; }
221
get_fixed_vertex_mode() const222 Settings::FixedVertexMode Settings::get_fixed_vertex_mode() const
223 { return mData->fixedMode; }
224
set_slaved_ho_node_mode(Settings::HigherOrderSlaveMode mode)225 void Settings::set_slaved_ho_node_mode( Settings::HigherOrderSlaveMode mode )
226 { mData->slaveMode = mode; }
227
get_slaved_ho_node_mode() const228 Settings::HigherOrderSlaveMode Settings::get_slaved_ho_node_mode() const
229 { return mData->slaveMode; }
230
trap_floating_point_exception(bool enable)231 void Settings::trap_floating_point_exception( bool enable )
232 { mData->trapFPE = enable; }
trap_floating_point_exception() const233 bool Settings::trap_floating_point_exception() const
234 { return mData->trapFPE; }
235
236
237
238 } // namespace MBMesquite
239