CEPS  24.01
Cardiac ElectroPhysiology Simulator
CoupledNodesReader.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #include "CoupledNodesReader.hpp"
32 
34  FileReader (fileName)
35 {
36  CEPS_ABORT_IF(not open(),"Unable to open file " << m_fileName);
37 }
38 
40 {}
41 
44 {
46  CEPS_ABORT_IF (meshes.size()<2,"Coupled nodes can be registered only between two meshes");
47 
48  this->reset ();
49 
50  CepsUInt n;
51  CepsString mesh;
52  CepsNodeGlobalIndex i1, i2;
53 
54  while (findNext ("COUPLING"))
55  {
56  NodeCoupling c;
57  for (CepsUInt i = 0u; i < 2; i++)
58  {
59  CEPS_ABORT_IF(not (m_file >> mesh),
60  "Impossible to read mesh names after CONNECTION keyword in file " << m_fileName
61  );
62  CEPS_ABORT_IF (not ceps::fileExists (mesh),
63  "Cannot find mesh given after CONNECTION keyword" << mesh
64  );
65  c.addMesh (mesh);
66  }
67 
68  // Is the connection valid ?
69  if (c.isValidIn (meshes))
70  {
71  n = ceps::readInt(m_file,"Impossible to read number of couples after COUPLING keyword in file " + m_fileName);
72  for (CepsUInt i = 0u; i < n; i++)
73  {
74  i1 = ceps::readInt(m_file,"Impossible to read node IDs after COUPLING keyword in file " + m_fileName);
75  i2 = ceps::readInt(m_file,"Impossible to read node IDs after COUPLING keyword in file " + m_fileName);
76  c.addCouple (i1, i2);
77  }
78  // Couples read, add them
79  res.push_back (c);
80  }
81  }
82 
83  return res;
84 }
#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::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
CepsGlobalIndex CepsNodeGlobalIndex
Indices of nodes.
Definition: CepsTypes.hpp:224
CoupledNodesReader(const CepsString &coupledNodesFile)
Constructor.
~CoupledNodesReader() override
Destructor.
CepsVector< NodeCoupling > getCoupledNodesBetween(const CepsVector< CepsString > &meshes)
Returns all given couples between current meshes,.
Base class that regroups common reader functionalities.
Definition: FileReader.hpp:43
void reset()
Set file stream to the beginning of the file.
Definition: FileReader.cpp:98
virtual CepsBool open()
Opens the designated file in read mode.
Definition: FileReader.cpp:70
CepsString m_fileName
file to open
Definition: FileReader.hpp:145
CepsBool findNext(const CepsString &pattern)
Advance stream until pattern is found.
Definition: FileReader.cpp:107
std::ifstream m_file
stream
Definition: FileReader.hpp:146
Meta-cell for connections between meshes.
void addCouple(const CepsNodeGlobalIndex &, const CepsNodeGlobalIndex &)
Adds an attribute.
void addMesh(const CepsString &mesh)
Adds a mesh.
CepsBool isValidIn(const CepsVector< CepsString > &meshes)
Determines if coupling can be used within the provided.
CepsInt readInt(std::istream &file, const CepsString &errorMessage="")
Reads an integral number from an istream, aborts if conversion fails advances the stream by 1 word.
Definition: CepsString.cpp:677
CepsBool fileExists(const CepsString &fileName, const CepsString &directory)
Definition: CepsString.cpp:595