1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCalculatorDBSliceField.hxx"
22 #include "MEDCalculatorDBRangeSelection.hxx"
24 #include "MEDLoader.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
29 using namespace MEDCoupling;
31 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(int iter, int order):_iteration(iter),_order(order),_field(0),_work(0)
35 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(MEDCouplingFieldDouble *f):_field(f),_work(0)
39 std::size_t MEDCalculatorDBSliceField::getHeapMemorySizeWithoutChildren() const
44 std::vector<const BigMemoryObject *> MEDCalculatorDBSliceField::getDirectChildrenWithNull() const
46 return std::vector<const BigMemoryObject *>();
49 void MEDCalculatorDBSliceField::setField(MEDCouplingFieldDouble *f) const
59 void MEDCalculatorDBSliceField::setName(const char *name)
61 _field->setName(name);
64 void MEDCalculatorDBSliceField::setDescription(const char *descr)
66 _field->setDescription(descr);
69 void MEDCalculatorDBSliceField::write(const char *fName, const std::string& n, const std::string& d) const throw(INTERP_KERNEL::Exception)
71 std::string kn=_field->getName();
72 std::string kd=_field->getDescription();
73 MEDCouplingFieldDouble *myF=const_cast<MEDCouplingFieldDouble *>(_field);
74 myF->setName(n.c_str());
75 myF->setDescription(d.c_str());
76 WriteFieldUsingAlreadyWrittenMesh(fName,_field);
77 myF->setName(kn.c_str());
78 myF->setDescription(kd.c_str());
81 const MEDCouplingMesh *MEDCalculatorDBSliceField::getMesh(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
83 MEDCouplingFieldDouble *f=getField(type,fname,mname,fieldName);
87 MEDCalculatorDBSliceField::~MEDCalculatorDBSliceField()
95 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getField(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
99 MCAuto<MEDCouplingField> tmpp(ReadField(type,fname.c_str(),mname.c_str(),0,fieldName.c_str(),_iteration,_order));
100 MCAuto<MEDCouplingFieldDouble> tmp(DynamicCast<MEDCouplingField,MEDCouplingFieldDouble>(tmpp));
107 * _field is expected to be already loaded !
109 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getFieldWithoutQuestion(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const
111 std::vector<int> tIds=thisC.getIds(sizeCThis);
112 return _field->keepSelectedComponents(tIds);
115 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::buildCstFromThis(double val, int nbOfComp, const MEDCouplingFieldDouble *f) const
117 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(f->getTypeOfField(),ONE_TIME);
118 ret->setMesh(f->getMesh());
119 ret->applyFunc(nbOfComp,val);
120 ret->copyTinyAttrFrom(f);
124 void MEDCalculatorDBSliceField::assign(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
125 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC)
127 std::vector<int> tIds=thisC.getIds(sizeCThis);
128 std::vector<int> oIds=otherC.getIds(sizeCOther);
129 MCAuto<MEDCouplingFieldDouble> f1=other->_field->keepSelectedComponents(oIds);
130 _field->setSelectedComponents(f1,tIds);
133 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::add(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
134 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
135 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
138 throw INTERP_KERNEL::Exception("Slice::add : not implemented yet node/cell permutation !");
139 std::vector<int> tIds=thisC.getIds(sizeCThis);
140 std::vector<int> oIds=otherC.getIds(sizeCOther);
141 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
142 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
143 f2->setMesh(f1->getMesh());
144 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
145 return new MEDCalculatorDBSliceField(f3);
148 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::substract(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
149 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
150 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
153 throw INTERP_KERNEL::Exception("Slice::substract : not implemented yet node/cell permutation !");
154 std::vector<int> tIds=thisC.getIds(sizeCThis);
155 std::vector<int> oIds=otherC.getIds(sizeCOther);
156 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
157 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
158 f2->setMesh(f1->getMesh());
159 MEDCouplingFieldDouble *f3=(*f1)-(*f2);
160 return new MEDCalculatorDBSliceField(f3);
163 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::multiply(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
164 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
165 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
168 throw INTERP_KERNEL::Exception("Slice::multiply : not implemented yet node/cell permutation !");
169 std::vector<int> tIds=thisC.getIds(sizeCThis);
170 std::vector<int> oIds=otherC.getIds(sizeCOther);
171 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
172 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
173 f2->setMesh(f1->getMesh());
174 MEDCouplingFieldDouble *f3=(*f1)*(*f2);
175 return new MEDCalculatorDBSliceField(f3);
178 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::divide(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
179 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
180 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
183 throw INTERP_KERNEL::Exception("Slice::divide : not implemented yet node/cell permutation !");
184 std::vector<int> tIds=thisC.getIds(sizeCThis);
185 std::vector<int> oIds=otherC.getIds(sizeCOther);
186 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
187 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
188 f2->setMesh(f1->getMesh());
189 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
190 return new MEDCalculatorDBSliceField(f3);
193 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::dot(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
194 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
196 std::vector<int> tIds=thisC.getIds(sizeCThis);
197 std::vector<int> oIds=otherC.getIds(sizeCOther);
198 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
199 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
200 f2->setMesh(f1->getMesh());
201 MEDCouplingFieldDouble *f3=f1->dot(*f2);
202 return new MEDCalculatorDBSliceField(f3);
205 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::crossProduct(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
206 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
208 std::vector<int> tIds=thisC.getIds(sizeCThis);
209 std::vector<int> oIds=otherC.getIds(sizeCOther);
210 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
211 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
212 f2->setMesh(f1->getMesh());
213 MEDCouplingFieldDouble *f3=f1->crossProduct(*f2);
214 return new MEDCalculatorDBSliceField(f3);
217 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::doublyContractedProduct(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
219 std::vector<int> tIds=thisC.getIds(sizeCThis);
220 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
221 MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
222 return new MEDCalculatorDBSliceField(f2);
225 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::determinant(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
227 std::vector<int> tIds=thisC.getIds(sizeCThis);
228 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
229 MEDCouplingFieldDouble *f2=f1->determinant();
230 return new MEDCalculatorDBSliceField(f2);
233 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenValues(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
235 std::vector<int> tIds=thisC.getIds(sizeCThis);
236 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
237 MEDCouplingFieldDouble *f2=f1->eigenValues();
238 return new MEDCalculatorDBSliceField(f2);
241 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenVectors(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
243 std::vector<int> tIds=thisC.getIds(sizeCThis);
244 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
245 MEDCouplingFieldDouble *f2=f1->eigenVectors();
246 return new MEDCalculatorDBSliceField(f2);
249 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::inverse(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
251 std::vector<int> tIds=thisC.getIds(sizeCThis);
252 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
253 MEDCouplingFieldDouble *f2=f1->inverse();
254 return new MEDCalculatorDBSliceField(f2);
257 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::trace(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
259 std::vector<int> tIds=thisC.getIds(sizeCThis);
260 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
261 MEDCouplingFieldDouble *f2=f1->trace();
262 return new MEDCalculatorDBSliceField(f2);
265 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::deviator(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
267 std::vector<int> tIds=thisC.getIds(sizeCThis);
268 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
269 MEDCouplingFieldDouble *f2=f1->deviator();
270 return new MEDCalculatorDBSliceField(f2);
273 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::magnitude(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
275 std::vector<int> tIds=thisC.getIds(sizeCThis);
276 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
277 MEDCouplingFieldDouble *f2=f1->magnitude();
278 return new MEDCalculatorDBSliceField(f2);
281 void MEDCalculatorDBSliceField::applyFunc(const char *func, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC)
283 std::vector<int> tIds=thisC.getIds(sizeCThis);
284 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
286 _field->setSelectedComponents(f1,tIds);
289 bool MEDCalculatorDBSliceField::isEqual(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
290 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
291 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC, double prec) const
294 throw INTERP_KERNEL::Exception("Slice::isEqual : not implemented yet node/cell permutation !");
295 std::vector<int> tIds=thisC.getIds(sizeCThis);
296 std::vector<int> oIds=otherC.getIds(sizeCOther);
297 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
298 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
299 f2->setMesh(f1->getMesh());
300 return f1->isEqualWithoutConsideringStr(f2,0,prec);