CEPS  24.01
Cardiac ElectroPhysiology Simulator
FunctionDictionary.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
32 
34 {
35  addEntry("dicofunc_time_selector",new DicoFuncTimeSelector());
36 }
37 
39 {
40  for (auto& e: m_scalars)
41  if (not m_doNotDelete.contains(e.first))
42  ceps::destroyObject(e.second);
43  for (auto& e: m_vectors)
44  if (not m_doNotDelete.contains(e.first))
45  ceps::destroyObject(e.second);
46  for (auto& e: m_tensors)
47  if (not m_doNotDelete.contains(e.first))
48  ceps::destroyObject(e.second);
49 }
50 
51 void
52 FunctionDictionary::add(const CepsString &label, const CepsString &options, Geometry* geom)
53 {
54 
56  CepsString fieldType = ceps::toUpper(splitted[0]);
57  CepsString params = splitted[1];
58 
59  if (fieldType == "CONSTANT")
60  return addConstant(label,params);
61  if (fieldType == "FILE")
62  return addFromFile(label,params,geom);
63  if (fieldType == "FUNCTION")
64  return addFunction(label,params);
65  if (fieldType == "CPIECEWISE")
66  return addCstPiecewise(label,params);
67  if (fieldType == "FPIECEWISE")
68  return addFctPiecewise(label,params);
69  if (fieldType == "OPERATOR")
70  return addOperator(label,params);
71  if (fieldType == "ALIAS")
72  return addAlias(label,params);
73 
74  CEPS_ABORT(
75  "When adding object with label " << label << std::endl <<
76  " unrecognized type: " << fieldType << std::endl <<
77  " Valid types are : CONSTANT, FILE, FUNCTION, CPIECEWISE, FPIECEWISE, OPERATOR, ALIAS.\n" <<
78  m_address
79  );
80 }
81 
82 void
84 {
85  const CepsVector<CepsString> &v = ceps::split(params);
86  switch (v.size())
87  {
88  case 1:
89  return addConstant(label,ceps::toMathScalar(v));
90  case 3:
91  return addConstant(label,ceps::toMathVertex(v));
92  case 9:
93  return addConstant(label,ceps::toMathTensor(v));
94  default: break;
95  }
96  CEPS_ABORT(
97  "When adding constant field "<< label <<" to the dictionary, incorrect number of values provided\n" <<
98  " Either 1, 3 or 9 values must be given, for scalars, vectors or tensors, respectively.\n" <<
99  m_address
100  );
101 }
102 
103 void
105 {
106  CepsVector<CepsString> attrValues = ceps::split(params,",");
107 
108  // Detect the dimensionality of the field
109  CepsVector<CepsString> av = ceps::split(attrValues[0]);
110  CEPS_ABORT_IF(av.size()!=2 and av.size()!=4 and av.size()!=10,
111  "When initializing piecewise constant field " << label << ",\n" <<
112  " wrong number of words in description <attribute> <value>.\n" << m_address
113  );
114  CepsUInt dim = av.size()-1;
115 
116  if (dim==1)
117  {
119  for (CepsString attrValue : attrValues)
120  {
122  CepsVector<CepsString> val = ceps::split(avv[1]);
123  map.insert(std::make_pair(ceps::toInt(avv[0]),ceps::toMathScalar(val)));
124  }
125  return addEntry(label,newCstPiecewiseSAFunc(map));
126  }
127  else if (dim==3)
128  {
130  for (CepsString attrValue : attrValues)
131  {
133  CepsVector<CepsString> val = ceps::split(avv[1]);
134  map.insert(std::make_pair(ceps::toInt(avv[0]),ceps::toMathVertex(val)));
135  }
136  return addEntry(label,newCstPiecewiseSAFunc(map));
137  }
138  // dim==9
139 
141  for (CepsString attrValue : attrValues)
142  {
144  CepsVector<CepsString> val = ceps::split(avv[1]);
145  map.insert(std::make_pair(ceps::toInt(avv[0]),ceps::toMathTensor(val)));
146  }
147  return addEntry(label,newCstPiecewiseSAFunc(map));
148 
149 }
150 
151 void
153 {
154  CepsVector<CepsString> attrValues = ceps::split(params,",");
158  for (CepsString attrValue : attrValues)
159  {
161  CEPS_ABORT_IF(av.size()<2,
162  "When adding piecewise function " << label << " to dictionary, not enough parameters\n" <<
163  " given after attribute " << attrValue
164  );
165 
166  // Check if function is already defined in dictionary, may be scalar, vector tensor
167  ScalarEntry fptrs = getScalar(av[1],nullptr);
168  VectorEntry fptrv = getVector(av[1],nullptr);
169  TensorEntry fptrt = getTensor(av[1],nullptr);
170  if (not ceps::isNullPtr(fptrs))
171  maps.insert(std::make_pair(ceps::toInt(av[0]),ceps::runtimeCast<SAFunc<CepsMathScalar>*>(fptrs)));
172  else if (not ceps::isNullPtr(fptrv))
173  mapv.insert(std::make_pair(ceps::toInt(av[0]),ceps::runtimeCast<SAFunc<CepsMathVertex>*>(fptrv)));
174  else if (not ceps::isNullPtr(fptrt))
175  mapt.insert(std::make_pair(ceps::toInt(av[0]),ceps::runtimeCast<SAFunc<CepsMathTensor>*>(fptrt)));
176  // If not, build from parameters, scalar only
177  else
178  {
179  fptrs = parseFunction(av[1]);
180  maps.insert(std::make_pair(ceps::toInt(av[0]),ceps::runtimeCast<SAFunc<CepsMathScalar>*>(fptrs)));
181  }
182  }
183 
184  if (not maps.empty())
185  return addEntry(label,newFctPiecewiseSAFunc(maps));
186  else if (not mapv.empty())
187  return addEntry(label,newFctPiecewiseSAFunc(mapv));
188  return addEntry(label,newFctPiecewiseSAFunc(mapt));
189 
190 }
191 
192 void
194  const CepsString& label,
195  const CepsString& params,
196  Geometry* geom,
197  CepsBool neverMind
198 )
199 {
200  const CepsVector<CepsString> &v = ceps::split(params);
201  CepsUInt nWords = v.size();
202 
203  CEPS_ABORT_IF(nWords<1,
204  "When initializing dictionary entry " << label << " with FILE labelword, \n" <<
205  " no file name was provided !"
206  );
207  // Check if file extension is compatible with coeff reader, if not, create interpolation
208  CepsString ext = ceps::getExtension(v[0]);
209 
210  if (ext=="vtk" or ext=="msh")
211  {
212  CEPS_ABORT_IF(nWords<4,
213  "When initializing dictionary entry " << label << " with FILE labelword, missing either\n" <<
214  " - fileName\n" <<
215  " - SCALAR, VECTOR, or TENSOR labelword\n" <<
216  " - name of data array in file\n" <<
217  " - CELL or NODE location labelword\n" <<
218  m_address
219  );
220 
221  CepsString locWord = ceps::toKey(v[3]);
222  CepsFunctionFlag loc = locWord == "NODE" ? CepsFunctionFlag::NodeIndex :
223  (locWord == "CELL" ? CepsFunctionFlag::CellIndex :
225 
227  "When initializing dictionary entry " << label << " with FILE labelword,\n" <<
228  " the last parameter should be either NODE or CELL.\n" <<
229  m_address
230  );
231 
232  CepsString arrayName = v[2];
233  CepsString dim = ceps::toKey(v[1]);
234 
235  if (neverMind)
236  {
237  CoeffReader reader(
239  );
240  if (not reader.hasArray(arrayName))
241  return;
242  }
243 
244  if (dim=="SCALAR")
245  return addEntry(label,new ArraySAFunc<CepsMathScalar>(v[0],arrayName,loc,geom));
246  else if (dim=="VECTOR")
247  return addEntry(label,new ArraySAFunc<CepsMathVertex>(v[0],arrayName,loc,geom));
248  else if (dim=="TENSOR")
249  return addEntry(label,new ArraySAFunc<CepsMathTensor>(v[0],arrayName,loc,geom));
250  else
251  CEPS_ABORT(
252  "When initializing dictionary entry " << label << " with FILE labelword,\n" <<
253  " the last parameter should be either NODE or CELL\n" <<
254  m_address
255  );
256 
257  }
258  else
259  {
260  std::ifstream ifs(v[0]);
261  CEPS_ABORT_IF(not ifs.good(),
262  "Impossible to open file " << v[0] << " to create interpolation table"
263  );
264 
265  CepsString line="";
266  while (line.empty())
267  std::getline(ifs,line);
268  // Determine which type we are reading
269  CepsUInt nElems = ceps::split(line).size()-1;
270  CepsBool time = v.size()>1 and ceps::toUpper(v[1])=="TIME";
271  if (nElems>8)
272  return addInterpolationTable<9,CepsMathTensor>(label,ifs,v[0],time);
273  else if (nElems>2)
274  return addInterpolationTable<3,CepsMathVertex>(label,ifs,v[0],time);
275  return addInterpolationTable<1,CepsMathScalar>(label,ifs,v[0],time);
276 
277  }
278 
279  return;
280 
281 }
282 
283 
284 void
286 {
287  return addEntry(label,parseFunction(ceps::toUpper(params)));
288 }
289 
290 void
292 {
293  auto v = ceps::split (params);
294  CEPS_ABORT_IF (v.size()!=3,
295  "When adding function " << label << " to the dictionary with keyword OPERATOR,\n" <<
296  " operator definition requires three arguments (func1 operator func2)\n" <<
297  m_address
298  );
299 
300  const CepsChar &op = v[1].at(0); // operator
301  CepsString str [2] = {ceps::toKey(v[0]), ceps::toKey(v[2])}; // left and right side of the operator
302  CepsString lr [2] = { "left", "right"};
303  ScalarEntry scalar[2] = {nullptr, nullptr};
304  VectorEntry vector[2] = {nullptr, nullptr};
305  TensorEntry tensor[2] = {nullptr, nullptr};
306 
307  // Loop on left and right
308  for (CepsUInt i = 0; i < 2; ++i)
309  {
310  // Check if operand is a real number
311  // If it is the case, a constant entry is added to the dictionary
312  if (not hasScalar(str[i]) and not hasVector(str[i]) and not hasTensor(str[i]))
313  {
314  CEPS_ABORT_IF(not ceps::isNumber(str[i]),
315  "When adding function " << label << " to the dictionary with keyword OPERATOR,\n" <<
316  " " << lr[i] << "operand is neither an existing function of the dictionary\n" <<
317  " or a real constant. Got: " << str[i] << "\n" << m_address
318  );
319  addConstant(label + "_" + lr[i], ceps::toReal(str[i]));
320  str[i] = label + "_" + lr[i];
321  }
322 
323  scalar[i] = getScalar(str[i], nullptr);
324  vector[i] = getVector(str[i], nullptr);
325  tensor[i] = getTensor(str[i], nullptr);
326  }
327 
328  auto tryToAdd = [&]<class _SharedPtr> (_SharedPtr obj) -> void {
329  if (ceps::isValidPtr(scalar[1]))
330  return addOperator(label,obj,op,scalar[1]);
331  if (ceps::isValidPtr(vector[1]))
332  return addOperator(label,obj,op,vector[1]);
333  return addOperator(label,obj,op,tensor[1]);
334  };
335 
336  if (ceps::isValidPtr(scalar[0])) // left = scalar
337  return tryToAdd(scalar[0]);
338  if (ceps::isValidPtr(vector[0])) // left = vector
339  return tryToAdd(vector[0]);
340  // if (ceps::isValidPtr(tensor[0])) // left = tensor
341  return tryToAdd(tensor[0]);
342 }
343 
344 void
346 {
347  CepsString LABEL = ceps::toKey(label);
348  CepsString PARAMS = ceps::toKey(params);
349  if (hasScalar(params))
350  m_scalars[LABEL] = m_scalars[PARAMS];
351  else if (hasVector(params))
352  m_vectors[LABEL] = m_vectors[PARAMS];
353  else if (hasTensor(params))
354  m_tensors[LABEL] = m_tensors[PARAMS];
355  else
356  CEPS_ABORT(
357  "Cannot create alias to function " << params << " that is not in the dictionary"
358  );
359 
360  m_doNotDelete.insert(LABEL);
361 
362  return;
363 }
364 
365 void
367 {
368  return addInternal(label,func,m_scalars,"Scalar");
369 }
370 
371 void
373 {
374  return addInternal(label,func,m_vectors,"Vector");
375 }
376 
377 void
379 {
380  return addInternal(label,func,m_tensors,"Tensor");
381 }
382 
383 // -------------------------------------------------------------------------
384 // Has, get
385 
386 CepsBool
388 {
389  return m_scalars.contains(ceps::toKey(label));
390 }
391 
392 CepsBool
394 {
395  return m_vectors.contains(ceps::toKey(label));
396 }
397 
398 CepsBool
400 {
401  return m_tensors.contains(ceps::toKey(label));
402 }
403 
404 // -----------------------------------------------------------------
405 // Get functions
406 // -----------------------------------------------------------------
407 
408 const typename FunctionDictionary::ScalarMap &
410 {
411  return m_scalars;
412 }
413 
414 const typename FunctionDictionary::VectorMap &
416 {
417  return m_vectors;
418 }
419 
420 const typename FunctionDictionary::TensorMap &
422 {
423  return m_tensors;
424 }
425 
426 const typename FunctionDictionary::ScalarEntry
428 {
429  CepsString LABEL = ceps::toKey(label);
430  CEPS_ABORT_IF(not hasScalar(LABEL),
431  "FunctionDictionary does not have any scalar entry " << std::quoted(LABEL)
432  );
433  return m_scalars.at(LABEL);
434 }
435 
436 const typename FunctionDictionary::VectorEntry
438 {
439  CepsString LABEL = ceps::toKey(label);
440  CEPS_ABORT_IF(not hasVector(LABEL),
441  "FunctionDictionary does not have any vector entry " << std::quoted(LABEL)
442  );
443  return m_vectors.at(LABEL);
444 }
445 
446 const typename FunctionDictionary::TensorEntry
448 {
449  CepsString LABEL = ceps::toKey(label);
450  CEPS_ABORT_IF(not hasTensor(LABEL),
451  "FunctionDictionary does not have any tensor entry " << std::quoted(LABEL)
452  );
453  return m_tensors.at(LABEL);
454 }
455 
456 const typename FunctionDictionary::ScalarEntry
457 FunctionDictionary::getScalar (const CepsString &label, const ScalarEntry def) const
458 {
459  CepsString LABEL = ceps::toKey(label);
460  if (hasScalar(LABEL))
461  return m_scalars.at(LABEL);
462  return def;
463 }
464 
465 const typename FunctionDictionary::VectorEntry
466 FunctionDictionary::getVector (const CepsString &label, const VectorEntry def) const
467 {
468  CepsString LABEL = ceps::toKey(label);
469  if (hasVector(LABEL))
470  return m_vectors.at(LABEL);
471  return def;
472 }
473 
474 const typename FunctionDictionary::TensorEntry
475 FunctionDictionary::getTensor (const CepsString &label, const TensorEntry def) const
476 {
477  CepsString LABEL = ceps::toKey(label);
478  if (hasTensor(LABEL))
479  return m_tensors.at(LABEL);
480  return def;
481 }
482 
483 // -----------------------------------------------------------------
484 // Delete functions
485 // -----------------------------------------------------------------
486 
487 void
489 {
490  CepsString LABEL = ceps::toKey(label);
492  m_scalars.erase(LABEL);
493 }
494 
495 void
497 {
498  CepsString LABEL = ceps::toKey(label);
500  m_vectors.erase(LABEL);
501 }
502 
503 void
505 {
506  CepsString LABEL = ceps::toKey(label);
508  m_tensors.erase(LABEL);
509 }
510 
511 // -----------------------------------------------------------------
512 // Private function
513 // -----------------------------------------------------------------
514 
515 
518 {
519  const CepsString &TIME = "TIME";
520  const CepsString &SPACE = "SPACE";
521  const CepsString &UFUNC = "UFUNC";
522 
523  CepsSet<CepsString> tags = {TIME, SPACE, UFUNC};
527 
528  // Detect which kind of function (TIME SPACE UFUNC) is being added
529  // Use previously defined functions of the dictionary if available
530  for (CepsString tag : tags)
531  {
532  is [tag] = ceps::argVector(ceps::split(ceps::toUpper(params)),tag)!=-1;
533  fun [tag] = nullptr;
534 
535  if (is[tag] and args[tag].size()>0)
536  fun[tag] = getScalar(args[tag][0],nullptr);
537  }
538 
539  CEPS_ABORT_IF(not is[TIME] and not is[SPACE] and not is[UFUNC],
540  "When adding function to the dictionary, no keyword TIME, SPACE or UFUNC found"
541  );
542 
543  // TIME : parse string arguments
544  if (is[TIME] and ceps::isNullPtr(fun[TIME]))
545  fun[TIME] = parseTimeFunction(args[TIME]);
546 
547  // SPACE : parse string arguments
548  if (is[SPACE] and ceps::isNullPtr(fun[SPACE]))
549  fun[SPACE] = parseSpatialFunction(args[SPACE]);
550 
551  // UFUNC : no parsing
552 
553  // In the case of 2 multiple valid functions, return the product
554  // if only 1 function is begin given, return it.
555  ScalarEntry res = nullptr;
556  for (auto [tag1,obj1]: fun)
557  if (ceps::isValidPtr(obj1))
558  {
559  for (auto [tag2,obj2] : fun)
560  if (tag1 != tag2 and ceps::isValidPtr(obj2))
561  {
562  auto res = newProductSAFunc(obj1,obj2);
563  res->setOwned(true,true);
564  return res;
565  }
566  res = obj1;
567  }
568  return res; // never reached
569 }
570 
573 {
574  checkParam(words,{"START","END","DURATION","PERIOD","AMPLITUDE"});
575 
576  CepsString profile = ceps::toUpper(ceps::readParams (words, "PROFILE", "CONSTANT", 1));
577  if (profile == "SRECT" or profile == "SMOOTH_RECTANGLE")
578  profile += " " + ceps::readParams (words, "PROFILE", "CONSTANT", 2);
579 
580  return ceps::getNew<ExcitationTimeFunction>(
581  profile, //
582  ceps::toReal(ceps::readParams(words,"START" , "0.0")), //
583  ceps::toReal(ceps::readParams(words,"END" , "5000.0")), //
584  ceps::toReal(ceps::readParams(words,"DURATION" , "1.0")), //
585  ceps::toReal(ceps::readParams(words,"PERIOD" , "-1.0")), //
586  ceps::toReal(ceps::readParams(words,"AMPLITUDE", "1.0")) //
587  );
588 }
589 
592 {
593  checkParam(words,{"CENTER","DIAMETER","AMPLITUDE"},{3,1,1});
594 
595  CepsString profile = ceps::toUpper(ceps::readParams (words, "PROFILE", "CONSTANT", 1));
596  if (profile == "SRECT" or profile == "SMOOTH_RECTANGLE")
597  profile += " " + ceps::readParams (words, "PROFILE", "CONSTANT", 2);
598 
599  return ceps::getNew<ExcitationSpatialFunction>(
600  profile, //
601  CepsReal3D({ //
602  ceps::toReal (ceps::readParams (words, "CENTER", "0.0", 1)), //
603  ceps::toReal (ceps::readParams (words, "CENTER", "0.0", 2)), //
604  ceps::toReal (ceps::readParams (words, "CENTER", "0.0", 3)) //
605  }), //
606  ceps::toReal (ceps::readParams (words, "DIAMETER", "1.0")), //
607  ceps::toReal (ceps::readParams (words, "AMPLITUDE","1.0")) //
608  );
609 }
610 
611 void
613  const CepsVector<CepsString>& keys,
614  const CepsVector<CepsUInt>& nToRead) const
615 {
616  for(CepsUInt i=0; i<keys.size(); i++)
617  {
618  CepsInt pos = ceps::argVector(words,keys[i]);
619  if (pos!=-1)
620  {
621  CepsUInt n = nToRead.size()!=0 ? nToRead[i] : 1;
622  CEPS_ABORT_IF(pos>=CepsInt(words.size()-n),
623  "When adding function into the dictionary, missing parameter(s)\n" <<
624  " after keyword " << keys[i] << "\n" << m_address
625  );
626  for(CepsUInt j=0;j<n;j++)
627  CEPS_ABORT_IF(not ceps::isNumber(words[pos+1+j]),
628  "When adding function into the dictionary, wrong parameter\n" <<
629  " after keyword " << keys[i] << ", got: " << words[pos+1+j] << "\n" << m_address
630  );
631  }
632  }
633 }
634 
635 CepsEnum
637 {
639 }
640 
641 CepsReal
643 {
644  return args.t;
645 }
@ Cell
Data is defined at cell centers.
@ Point
Data is defined on each point.
CepsFunctionFlag
Enum for CepsStandardArgs functions.
Definition: CepsEnums.hpp:137
@ CellIndex
Use cell index to determine position.
@ NodeIndex
Use node index to determine position.
@ None
No dependance, constant functions.
@ Time
Depends on time.
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
int CepsEnum
Enum type.
Definition: CepsTypes.hpp:216
char CepsChar
Char.
Definition: CepsTypes.hpp:125
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
CstPiecewiseSAFunc< _Result > * newCstPiecewiseSAFunc(const CepsMap< CepsAttribute, _Result > &map)
Direct way to build a CstPiecewiseSAFunc.
FctPiecewiseSAFunc< _Result > * newFctPiecewiseSAFunc(const CepsMap< CepsAttribute, SAFunc< _Result > * > &map)
Direct way to build a CstPiecewiseSAFunc.
OperatorSAFunc<' *', _Res1, _Res2 > * newProductSAFunc(SAFunc< _Res1 > *, SAFunc< _Res2 > *)
Get a new product object without having to look after return types of fn1 and fn2.
Functor that gets its result from an array.
Definition: ArraySAFunc.hpp:51
Reader used to import point or cell data from files.
Definition: CoeffReader.hpp:63
CepsBool hasArray(const CepsString &label, CepsInt dim=-1) const
Tells if file has data array, dim = 0 for scalars, 1 for vector, 2 for tensor.
A simple SA func that extracts time from arguments, will be added to the dictionary upon creation.
CepsReal eval(CepsStandardArgs) override
Returns args.t.
CepsEnum getFlags() const override
Time flags.
void addFromFile(const CepsString &label, const CepsString &params, Geometry *geom, CepsBool neverMind=false)
Add a function read from data file, requires geometry. If the extension is compatible with CoeffReade...
void addConstant(const CepsString &label, const CepsString &params)
Add a constant function through parameter string.
Map< CepsMathVertex > VectorMap
Typedef for the map of vector functions.
FunctionDictionary()
Constructor, adds some function by default.
CepsBool hasTensor(const CepsString &label) const
Tells if function "label" is registered.
void addFctPiecewise(const CepsString &label, const CepsString &params)
Add a piecewise function, function on eacg.
ScalarEntry parseSpatialFunction(const CepsVector< CepsString > &params)
Returns a pointer to a function deduced from the string parameters.
Map< CepsMathTensor > TensorMap
Typedef for the map of tensor functions.
void addOperator(const CepsString &label, const CepsString &params)
Add an operation between already registered functions and/or real constants.
void addCstPiecewise(const CepsString &label, const CepsString &params)
Add a piecewise function, constant on each region.
CepsSet< CepsString > m_doNotDelete
Functions that must not be deleted (created by alias)
~FunctionDictionary()
Destructor.
ScalarMap m_scalars
All scalar entries.
void deleteVector(const CepsString &label)
Delete a single vector entry. Be careful if the functor was created outside dictionary.
ScalarEntry parseTimeFunction(const CepsVector< CepsString > &params)
Returns a pointer to a function deduced from the string parameters.
VectorMap m_vectors
All vector entries.
CepsBool hasScalar(const CepsString &label) const
Tells if function "label" is registered.
void addAlias(const CepsString &label, const CepsString &params)
Adds a shortcut to an already existing function.
const TensorEntry getTensor(const CepsString &label) const
Get a single tensor entry, const version.
void checkParam(const CepsVector< CepsString > &words, const CepsVector< CepsString > &keys, const CepsVector< CepsUInt > &nToRead={}) const
Aborts if a function parameter is missing or not a number.
Map< CepsMathScalar > ScalarMap
Typedef for the map of scalar functions.
TensorMap m_tensors
All tensor entries.
void addInternal(const CepsString &label, Entry< _Result > func, Map< _Result > &map, const CepsString &name)
Internal adding method.
CepsBool hasVector(const CepsString &label) const
Tells if function "label" is registered.
const TensorMap & getTensors() const
Get all tensor entries, const version.
const VectorMap & getVectors() const
Get all vector entries, const version.
const VectorEntry getVector(const CepsString &label) const
Get a single vector entry, const version.
CepsString m_address
A string that is displayed in error messages.
const ScalarMap & getScalars() const
Get all scalar entries, const version.
void add(const CepsString &label, const CepsString &params, Geometry *geom=nullptr)
Add an object from parameters.
void addFunction(const CepsString &label, const CepsString &params)
Add a function deduced from tags only, works only with scalar return type.
void deleteScalar(const CepsString &label)
Delete a single scalar entry. Be careful if the functor was created outside dictionary.
const ScalarEntry getScalar(const CepsString &label) const
Get a single scalar entry, const version.
void addEntry(const CepsString &label, ScalarEntry func)
Ads an entry to the map of scalar functions.
void deleteTensor(const CepsString &label)
Delete a single tensor entry. Be careful if the functor was created outside dictionary.
ScalarEntry parseFunction(const CepsString &params)
Returns a pointer to a function deduced from the string parameters.
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
A SAFunc is a ceps::Function that uses CepsStandardArgs as argument of call operator (),...
Definition: SAFunc.hpp:100
CepsMathTensor toMathTensor(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathTensor.
Definition: CepsString.cpp:237
CepsString toKey(const CepsString &s)
Transform to key type a std::string, upper case and no spaces.
Definition: CepsString.cpp:157
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
Definition: CepsMemory.hpp:61
CepsMap< CepsString, CepsVector< CepsString > > splitByKeyword(const CepsString &s, const CepsSet< CepsString > &tags)
Extract parameters in the CepsString given by tags. Builds a map of keywords and parameter words acco...
Definition: CepsString.cpp:384
_Derived runtimeCast(_Base x)
Perform a runtime cast between base type and derived type if we can.
Definition: CepsMemory.hpp:94
CepsInt argVector(const CepsVector< _Type, _Alloc > &vec, const _Type &value)
Get position of element in vector, -1 if not found.
Definition: CepsVector.hpp:200
CepsMathScalar toMathScalar(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathScalar same effect as ceps::toReal(vec[0])
Definition: CepsString.cpp:219
CepsString readParams(const CepsVector< CepsString > &scope, const CepsString &tag, const CepsString &def="", const CepsUInt &pad=1)
Read parameters into a map.
Definition: CepsString.cpp:496
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
Definition: CepsMemory.hpp:45
CepsString getExtension(const CepsString &str)
Returns the extension of a file, if any.
Definition: CepsString.cpp:580
CepsVector< CepsString > splitAtNthDelimiter(const CepsString &s, CepsUInt n, CepsString delimiters=CepsString(" \t"))
Split a string a the n-th delimeter. This ignores the doubled delimiter (eg multiple spaces count as ...
Definition: CepsString.cpp:419
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsInt toInt(const CepsString &s)
Cast CepsString to CepsInt.
Definition: CepsString.cpp:270
CepsString toUpper(const CepsString &s)
Switches all characters to upper case.
Definition: CepsString.cpp:124
CepsBool isNumber(const CepsString &s)
Check if the string contains only digit numbers.
Definition: CepsString.cpp:322
CepsMathVertex toMathVertex(const CepsVector< CepsString > &vec)
Cast a CepsVector of CepsString to CepsMathVertex.
Definition: CepsString.cpp:227
CepsVector< CepsString > splitUntilNthDelimiter(const CepsString &s, const CepsUInt &n, CepsString delimiters=CepsString(" \t"))
Split a string for the first n delimeters.
Definition: CepsString.cpp:441
void destroyObject(_Type &)
Destroy[delete] any type.
Definition: CepsMemory.hpp:116
CepsReal toReal(const CepsString &s)
Cast CepsString to CepsReal.
Definition: CepsString.cpp:193
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
Definition: CepsTypes.hpp:239
CepsReal t
time
Definition: CepsTypes.hpp:240