1 // Copyright (C) 2007-2012 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 #include "MEDCalculatorDBSliceField.hxx"
21 #include "MEDCalculatorDBRangeSelection.hxx"
23 #include "MEDLoader.hxx"
25 #include "MEDCouplingFieldDouble.hxx"
26 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
28 using namespace ParaMEDMEM;
30 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(int iter, int order):_iteration(iter),_order(order),_field(0),_work(0)
34 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(MEDCouplingFieldDouble *f):_field(f),_work(0)
38 void MEDCalculatorDBSliceField::setField(MEDCouplingFieldDouble *f) const
48 void MEDCalculatorDBSliceField::setName(const char *name)
50 _field->setName(name);
53 void MEDCalculatorDBSliceField::setDescription(const char *descr)
55 _field->setDescription(descr);
58 void MEDCalculatorDBSliceField::write(const char *fName, const std::string& n, const std::string& d) const throw(INTERP_KERNEL::Exception)
60 std::string kn=_field->getName();
61 std::string kd=_field->getDescription();
62 MEDCouplingFieldDouble *myF=const_cast<MEDCouplingFieldDouble *>(_field);
63 myF->setName(n.c_str());
64 myF->setDescription(d.c_str());
65 MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fName,_field);
66 myF->setName(kn.c_str());
67 myF->setDescription(kd.c_str());
70 const MEDCouplingMesh *MEDCalculatorDBSliceField::getMesh(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
72 MEDCouplingFieldDouble *f=getField(type,fname,mname,fieldName);
76 MEDCalculatorDBSliceField::~MEDCalculatorDBSliceField()
84 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getField(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
87 _field=MEDLoader::ReadField(type,fname.c_str(),mname.c_str(),0,fieldName.c_str(),_iteration,_order);
92 * _field is expected to be already loaded !
94 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getFieldWithoutQuestion(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const
96 std::vector<int> tIds=thisC.getIds(sizeCThis);
97 return _field->keepSelectedComponents(tIds);
100 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::buildCstFromThis(double val, int nbOfComp, const MEDCouplingFieldDouble *f) const
102 MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(f->getTypeOfField(),ONE_TIME);
103 ret->setMesh(f->getMesh());
104 ret->applyFunc(nbOfComp,val);
105 ret->copyTinyAttrFrom(f);
109 void MEDCalculatorDBSliceField::assign(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
110 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC)
112 std::vector<int> tIds=thisC.getIds(sizeCThis);
113 std::vector<int> oIds=otherC.getIds(sizeCOther);
114 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=other->_field->keepSelectedComponents(oIds);
115 _field->setSelectedComponents(f1,tIds);
118 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::add(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
119 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
120 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
123 throw INTERP_KERNEL::Exception("Slice::add : not implemented yet node/cell permutation !");
124 std::vector<int> tIds=thisC.getIds(sizeCThis);
125 std::vector<int> oIds=otherC.getIds(sizeCOther);
126 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
127 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
128 f2->setMesh(f1->getMesh());
129 MEDCouplingFieldDouble *f3=(*f1)+(*f2);
130 return new MEDCalculatorDBSliceField(f3);
133 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::substract(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::substract : not implemented yet node/cell permutation !");
139 std::vector<int> tIds=thisC.getIds(sizeCThis);
140 std::vector<int> oIds=otherC.getIds(sizeCOther);
141 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
142 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
143 f2->setMesh(f1->getMesh());
144 MEDCouplingFieldDouble *f3=(*f1)-(*f2);
145 return new MEDCalculatorDBSliceField(f3);
148 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::multiply(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::multiply : not implemented yet node/cell permutation !");
154 std::vector<int> tIds=thisC.getIds(sizeCThis);
155 std::vector<int> oIds=otherC.getIds(sizeCOther);
156 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
157 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
158 f2->setMesh(f1->getMesh());
159 MEDCouplingFieldDouble *f3=(*f1)*(*f2);
160 return new MEDCalculatorDBSliceField(f3);
163 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::divide(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::divide : not implemented yet node/cell permutation !");
169 std::vector<int> tIds=thisC.getIds(sizeCThis);
170 std::vector<int> oIds=otherC.getIds(sizeCOther);
171 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
172 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
173 f2->setMesh(f1->getMesh());
174 MEDCouplingFieldDouble *f3=(*f1)/(*f2);
175 return new MEDCalculatorDBSliceField(f3);
178 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::dot(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
179 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
181 std::vector<int> tIds=thisC.getIds(sizeCThis);
182 std::vector<int> oIds=otherC.getIds(sizeCOther);
183 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
184 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
185 f2->setMesh(f1->getMesh());
186 MEDCouplingFieldDouble *f3=f1->dot(*f2);
187 return new MEDCalculatorDBSliceField(f3);
190 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::crossProduct(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
191 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
193 std::vector<int> tIds=thisC.getIds(sizeCThis);
194 std::vector<int> oIds=otherC.getIds(sizeCOther);
195 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
196 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
197 f2->setMesh(f1->getMesh());
198 MEDCouplingFieldDouble *f3=f1->crossProduct(*f2);
199 return new MEDCalculatorDBSliceField(f3);
202 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::doublyContractedProduct(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
204 std::vector<int> tIds=thisC.getIds(sizeCThis);
205 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
206 MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
207 return new MEDCalculatorDBSliceField(f2);
210 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::determinant(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
212 std::vector<int> tIds=thisC.getIds(sizeCThis);
213 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
214 MEDCouplingFieldDouble *f2=f1->determinant();
215 return new MEDCalculatorDBSliceField(f2);
218 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenValues(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
220 std::vector<int> tIds=thisC.getIds(sizeCThis);
221 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
222 MEDCouplingFieldDouble *f2=f1->eigenValues();
223 return new MEDCalculatorDBSliceField(f2);
226 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenVectors(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
228 std::vector<int> tIds=thisC.getIds(sizeCThis);
229 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
230 MEDCouplingFieldDouble *f2=f1->eigenVectors();
231 return new MEDCalculatorDBSliceField(f2);
234 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::inverse(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
236 std::vector<int> tIds=thisC.getIds(sizeCThis);
237 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
238 MEDCouplingFieldDouble *f2=f1->inverse();
239 return new MEDCalculatorDBSliceField(f2);
242 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::trace(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
244 std::vector<int> tIds=thisC.getIds(sizeCThis);
245 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
246 MEDCouplingFieldDouble *f2=f1->trace();
247 return new MEDCalculatorDBSliceField(f2);
250 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::deviator(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
252 std::vector<int> tIds=thisC.getIds(sizeCThis);
253 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
254 MEDCouplingFieldDouble *f2=f1->deviator();
255 return new MEDCalculatorDBSliceField(f2);
258 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::magnitude(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
260 std::vector<int> tIds=thisC.getIds(sizeCThis);
261 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
262 MEDCouplingFieldDouble *f2=f1->magnitude();
263 return new MEDCalculatorDBSliceField(f2);
266 void MEDCalculatorDBSliceField::applyFunc(const char *func, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC)
268 std::vector<int> tIds=thisC.getIds(sizeCThis);
269 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
271 _field->setSelectedComponents(f1,tIds);
274 bool MEDCalculatorDBSliceField::isEqual(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
275 int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
276 int sizeCOther, const MEDCalculatorDBRangeSelection& otherC, double prec) const
279 throw INTERP_KERNEL::Exception("Slice::isEqual : not implemented yet node/cell permutation !");
280 std::vector<int> tIds=thisC.getIds(sizeCThis);
281 std::vector<int> oIds=otherC.getIds(sizeCOther);
282 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
283 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
284 f2->setMesh(f1->getMesh());
285 return f1->isEqualWithoutConsideringStr(f2,0,prec);