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<MEDCouplingFieldDouble> tmp(ReadField(type,fname.c_str(),mname.c_str(),0,fieldName.c_str(),_iteration,_order));
106 * _field is expected to be already loaded !
108 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getFieldWithoutQuestion(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const
110 std::vector<int> tIds=thisC.getIds(sizeCThis);
111 return _field->keepSelectedComponents(tIds);
114 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::buildCstFromThis(double val, int nbOfComp, const MEDCouplingFieldDouble *f) const
116 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(f->getTypeOfField(),ONE_TIME);
117 ret->setMesh(f->getMesh());
118 ret->applyFunc(nbOfComp,val);
119 ret->copyTinyAttrFrom(f);
123 void MEDCalculatorDBSliceField::assign(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
124 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC)
126 std::vector<int> tIds=thisC.getIds(sizeCThis);
127 std::vector<int> oIds=otherC.getIds(sizeCOther);
128 MCAuto<MEDCouplingFieldDouble> f1=other->_field->keepSelectedComponents(oIds);
129 _field->setSelectedComponents(f1,tIds);
132 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::add(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
133 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
134 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
137 throw INTERP_KERNEL::Exception("Slice::add : not implemented yet node/cell permutation !");
138 std::vector<int> tIds=thisC.getIds(sizeCThis);
139 std::vector<int> oIds=otherC.getIds(sizeCOther);
140 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
141 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
142 f2->setMesh(f1->getMesh());
143 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
144 return new MEDCalculatorDBSliceField(f3);
147 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::substract(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
148 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
149 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
152 throw INTERP_KERNEL::Exception("Slice::substract : not implemented yet node/cell permutation !");
153 std::vector<int> tIds=thisC.getIds(sizeCThis);
154 std::vector<int> oIds=otherC.getIds(sizeCOther);
155 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
156 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
157 f2->setMesh(f1->getMesh());
158 MEDCouplingFieldDouble *f3=(*f1)-(*f2);
159 return new MEDCalculatorDBSliceField(f3);
162 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::multiply(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
163 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
164 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
167 throw INTERP_KERNEL::Exception("Slice::multiply : not implemented yet node/cell permutation !");
168 std::vector<int> tIds=thisC.getIds(sizeCThis);
169 std::vector<int> oIds=otherC.getIds(sizeCOther);
170 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
171 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
172 f2->setMesh(f1->getMesh());
173 MEDCouplingFieldDouble *f3=(*f1)*(*f2);
174 return new MEDCalculatorDBSliceField(f3);
177 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::divide(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
178 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
179 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
182 throw INTERP_KERNEL::Exception("Slice::divide : not implemented yet node/cell permutation !");
183 std::vector<int> tIds=thisC.getIds(sizeCThis);
184 std::vector<int> oIds=otherC.getIds(sizeCOther);
185 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
186 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
187 f2->setMesh(f1->getMesh());
188 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
189 return new MEDCalculatorDBSliceField(f3);
192 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::dot(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
193 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
195 std::vector<int> tIds=thisC.getIds(sizeCThis);
196 std::vector<int> oIds=otherC.getIds(sizeCOther);
197 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
198 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
199 f2->setMesh(f1->getMesh());
200 MEDCouplingFieldDouble *f3=f1->dot(*f2);
201 return new MEDCalculatorDBSliceField(f3);
204 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::crossProduct(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
205 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
207 std::vector<int> tIds=thisC.getIds(sizeCThis);
208 std::vector<int> oIds=otherC.getIds(sizeCOther);
209 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
210 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
211 f2->setMesh(f1->getMesh());
212 MEDCouplingFieldDouble *f3=f1->crossProduct(*f2);
213 return new MEDCalculatorDBSliceField(f3);
216 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::doublyContractedProduct(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
218 std::vector<int> tIds=thisC.getIds(sizeCThis);
219 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
220 MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
221 return new MEDCalculatorDBSliceField(f2);
224 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::determinant(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
226 std::vector<int> tIds=thisC.getIds(sizeCThis);
227 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
228 MEDCouplingFieldDouble *f2=f1->determinant();
229 return new MEDCalculatorDBSliceField(f2);
232 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenValues(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
234 std::vector<int> tIds=thisC.getIds(sizeCThis);
235 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
236 MEDCouplingFieldDouble *f2=f1->eigenValues();
237 return new MEDCalculatorDBSliceField(f2);
240 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenVectors(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
242 std::vector<int> tIds=thisC.getIds(sizeCThis);
243 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
244 MEDCouplingFieldDouble *f2=f1->eigenVectors();
245 return new MEDCalculatorDBSliceField(f2);
248 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::inverse(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
250 std::vector<int> tIds=thisC.getIds(sizeCThis);
251 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
252 MEDCouplingFieldDouble *f2=f1->inverse();
253 return new MEDCalculatorDBSliceField(f2);
256 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::trace(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
258 std::vector<int> tIds=thisC.getIds(sizeCThis);
259 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
260 MEDCouplingFieldDouble *f2=f1->trace();
261 return new MEDCalculatorDBSliceField(f2);
264 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::deviator(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
266 std::vector<int> tIds=thisC.getIds(sizeCThis);
267 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
268 MEDCouplingFieldDouble *f2=f1->deviator();
269 return new MEDCalculatorDBSliceField(f2);
272 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::magnitude(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
274 std::vector<int> tIds=thisC.getIds(sizeCThis);
275 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
276 MEDCouplingFieldDouble *f2=f1->magnitude();
277 return new MEDCalculatorDBSliceField(f2);
280 void MEDCalculatorDBSliceField::applyFunc(const char *func, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC)
282 std::vector<int> tIds=thisC.getIds(sizeCThis);
283 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
285 _field->setSelectedComponents(f1,tIds);
288 bool MEDCalculatorDBSliceField::isEqual(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
289 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
290 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC, double prec) const
293 throw INTERP_KERNEL::Exception("Slice::isEqual : not implemented yet node/cell permutation !");
294 std::vector<int> tIds=thisC.getIds(sizeCThis);
295 std::vector<int> oIds=otherC.getIds(sizeCOther);
296 MCAuto<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
297 MCAuto<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
298 f2->setMesh(f1->getMesh());
299 return f1->isEqualWithoutConsideringStr(f2,0,prec);