1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library 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. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // ICoCo file common to several codes
22 // version 1.2 10/05/2010
24 #include <ICoCoTrioField.hxx>
29 using namespace ICoCo;
32 // Default constructor
33 TrioField::TrioField() :
45 _nb_field_components(0),
47 _has_field_ownership(false) { }
50 TrioField::TrioField(const TrioField& OtherField):_connectivity(0),_coords(0),_field(0) {
55 TrioField::~TrioField() {
59 // After the call to clear(), all pointers are null and field ownership is false.
60 // Arrays are deleted if necessary
61 void TrioField::clear() {
63 delete[] _connectivity;
66 if (_field && _has_field_ownership)
71 _has_field_ownership=false;
74 // Returns the number of value locations
75 // The size of field is nb_values()*_nb_field_components
76 int TrioField::nb_values() const {
85 // Save field to a .field file (loadable by visit!)
86 void TrioField::save(ostream& os) const{
88 os << setprecision(12);
89 os << getName() << endl;
91 os << _mesh_dim << endl;
92 os << _space_dim << endl;
93 os << _nbnodes << endl;
94 os << _nodes_per_elem << endl;
95 os << _nb_elems << endl;
98 for (int i=0;i<_nb_elems;i++) {
99 for (int j=0;j<_nodes_per_elem;j++)
100 os << " " << _connectivity[i*_nodes_per_elem+j];
104 for (int i=0;i<_nbnodes;i++) {
105 for (int j=0;j<_space_dim;j++)
106 os << " " << _coords[i*_space_dim+j] ;
110 os << _time1 << endl;
111 os << _time2 << endl;
112 os << _nb_field_components << endl;
116 for (int i=0;i<nb_values();i++) {
117 for (int j=0;j<_nb_field_components;j++)
118 os << " " << _field[i*_nb_field_components+j];
125 os << _has_field_ownership << endl;
129 // Restore field from a .field file
130 void TrioField::restore(istream& in) {
139 in >> _nodes_per_elem;
144 delete [] _connectivity;
145 _connectivity=new int[_nodes_per_elem*_nb_elems];
146 for (int i=0;i<_nb_elems;i++) {
147 for (int j=0;j<_nodes_per_elem;j++)
148 in >> _connectivity[i*_nodes_per_elem+j];
152 _coords=new double[_nbnodes*_space_dim];
153 for (int i=0;i<_nbnodes;i++) {
154 for (int j=0;j<_space_dim;j++)
155 in >> _coords[i*_space_dim+j];
160 in >> _nb_field_components;
166 _field=new double[_nb_field_components*nb_values()];
167 for (int i=0;i<nb_values();i++) {
168 for (int j=0;j<_nb_field_components;j++)
169 in>> _field[i*_nb_field_components+j];
175 in >> _has_field_ownership;
179 // After the call to set_standalone(), field ownership is true and field is allocated
180 // to the size _nb_field_components*nb_values().
181 // The values of the field have been copied if necessary.
182 void TrioField::set_standalone() {
184 _field=new double[_nb_field_components*nb_values()];
185 _has_field_ownership=true;
188 else if (!_has_field_ownership) {
189 double *tmp_field=new double[_nb_field_components*nb_values()];
190 memcpy(tmp_field,_field,_nb_field_components*nb_values()*sizeof(double));
192 _has_field_ownership=true;
196 // Used to simulate a 0D geometry (Cathare/Trio for example).
197 void TrioField::dummy_geom() {
206 delete[] _connectivity;
207 _connectivity=new int[3];
213 _coords=new double[6];
222 _nb_field_components=1;
223 if (_field && _has_field_ownership)
225 _has_field_ownership=false;
229 // Overloading operator = for TrioField
230 // This becomes an exact copy of NewField.
231 // If NewField._has_field_ownership is false, they point to the same values.
232 // Otherwise the values are copied.
233 TrioField& TrioField::operator=(const TrioField& NewField){
237 _type=NewField._type;
238 _mesh_dim=NewField._mesh_dim;
239 _space_dim=NewField._space_dim;
240 _nbnodes=NewField._nbnodes;
241 _nodes_per_elem=NewField._nodes_per_elem;
242 _nb_elems=NewField._nb_elems;
243 _itnumber=NewField._itnumber;
244 _time1=NewField._time1;
245 _time2=NewField._time2;
246 _nb_field_components=NewField._nb_field_components;
248 if (!NewField._connectivity)
251 _connectivity=new int[_nodes_per_elem*_nb_elems];
252 memcpy( _connectivity,NewField._connectivity,_nodes_per_elem*_nb_elems*sizeof(int));
255 if (!NewField._coords)
258 _coords=new double[_nbnodes*_space_dim];
259 memcpy( _coords,NewField._coords,_nbnodes*_space_dim*sizeof(double));
262 //Copie des valeurs du champ
263 _has_field_ownership=NewField._has_field_ownership;
264 if (_has_field_ownership) {
265 _field=new double[nb_values()*_nb_field_components];
266 memcpy(_field,NewField._field,nb_values()*_nb_field_components*sizeof(double));
269 _field=NewField._field;