LifeV
ZeroDimensionalData.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief File containing a class for 0D model data handling.
30  *
31  * @date 16-11-2011
32  * @author Mahmoud Jafargholi
33  *
34  * @contributors Cristiano Malossi <cristiano.malossi@epfl.ch>
35  * @mantainer Cristiano Malossi <cristiano.malossi@epfl.ch>
36  */
37 
38 #include <lifev/zero_dimensional/solver/ZeroDimensionalData.hpp>
39 
40 namespace LifeV
41 {
42 
43 // ===================================================
44 // Constructors
45 // ===================================================
48  "12",
49  " ",
51 {
52 }
53 
55 {
56  M_voltageFileStream.close();
57  M_currentFileStream.close();
58  M_balanceFileStream.close();
59 }
60 
61 // ===================================================
62 // Methods
63 // ===================================================
64 void ZeroDimensionalData::setup ( const GetPot& dataFile,
65  bcPtr_Type bc,
66  const std::string& section )
67 {
68  if ( !M_time.get() )
69  M_time.reset ( new time_Type ( dataFile,
70  section + "/time_discretization" ) );
71 
72  std::string circuirDataFile = dataFile ( ( section + "/CircuitDataFile" ).data(),
73  "./inputFilexx.dat" );
74  GetPot dataFileCircuit ( circuirDataFile );
75  std::string circuitFile = dataFileCircuit ( "Files/InputFiles/CircuitFile",
76  "./circuitFilexx.dat" );
77  std::string folder = dataFileCircuit ( "Files/OutputFiles/Folder",
78  "outputxx" );//TODO create folder output
79 
80  std::string voltageFile = folder + "/" + dataFileCircuit ( "Files/OutputFiles/VoltageFile",
81  "voltagexx.txt" );
82  std::string currentFile = folder + "/" + dataFileCircuit ( "Files/OutputFiles/CurrentFile",
83  "currentxx.txt" );
84  std::string balanceFile = folder + "/" + dataFileCircuit ( "Files/OutputFiles/BalanceCurrentinNode",
85  "balancexx.txt" );
86  M_voltageFileStream.open ( voltageFile.c_str() );
87  M_currentFileStream.open ( currentFile.c_str() );
88  M_balanceFileStream.open ( balanceFile.c_str() );
89 
90  //Build the Circuit
91  M_circuitData->buildCircuit ( circuitFile.c_str(),
92  bc );
93 
94  //assign varible index
96 
97  M_solverData.method = dataFile ( ( section + "/Solver/method" ).data(), "IRK" );
98  M_solverData.numberTimeStep = dataFile ( ( section + "/Solver/numberTimeStep" ).data(), 1 );
99  M_solverData.maxError = dataFile ( ( section + "/Solver/maxError" ).data(), 1.0 );
100  M_solverData.reltol = dataFile ( ( section + "/Solver/reltol" ).data(), 0.1 );
101  M_solverData.abstol = dataFile ( ( section + "/Solver/abstol" ).data(), 1.0 );
102  M_solverData.maxOrder = dataFile ( ( section + "/Solver/maxOrder" ).data(), 1 );
103  M_solverData.verbose = dataFile ( ( section + "/Solver/verbose" ).data(), false );
104  M_solverData.verboseLevel = dataFile ( ( section + "/Solver/verboseLevel" ).data(), 0 );
105  M_solverData.useNOX = dataFile ( ( section + "/Solver/useNOX" ).data(), false );
106  M_solverData.fixTimeStep = dataFile ( ( section + "/Solver/fixTimeStep" ).data(), true );
107  M_solverData.extraLSParamsFile = dataFile ( ( section + "/Solver/extraLinearSolverParamsFile" ).data(), "./Extra_AztecOO_Params.xml" );
108  M_solverData.linearSolverParamsFile = dataFile ( ( section + "/Solver/linearSolverParamsUsedFile" ).data(), "./lowsf.aztecoo.used.xml" );
109 
110  //Set zero initial condition
111  // TODO: change to general initial condition
113 
114  //Wrire Header OutputFiles
116 }
117 
119 {
120  ptrVecZeroDimensionalElementPtr_Type elementList = M_circuitData->Elements() ->elementList();
121  for ( iterZeroDimensionalElement_Type theElement = elementList->begin(); theElement != elementList->end(); theElement++ )
122  {
123  ( *theElement )->setCurrent ( 0.0 );
124  ( *theElement )->setDeltaCurrent ( 0.0 );
125  }
126 
127  ptrVecZeroDimensionalNodePtr_Type nodeList = M_circuitData->Nodes() ->nodeList();
128  for ( iterZeroDimensionalNode_Type theNode = nodeList->begin(); theNode != nodeList->end(); theNode++ )
129  {
130  ( *theNode )->setVoltage ( 0.0 );
131  ( *theNode )->setDeltaVoltage ( 0.0 );
132  }
133 }
134 
135 //! update source elements
137 {
138  Real time = M_time->time();
139  ptrVecZeroDimensionalElementCurrentSourcePtr_Type currentElementList = M_circuitData->Elements()-> currentSourceList();
140 
141  for ( iterZeroDimensionalElementCurrentSource_Type theElement = currentElementList->begin(); theElement != currentElementList->end(); theElement++ )
142  {
143  ( *theElement )->setCurrentByTime ( time );
144  std::cout << ( *theElement )->current() << std::endl;
145  }
146 
147  ptrVecZeroDimensionalElementVoltageSourcePtr_Type voltageElementList = M_circuitData->Elements()-> voltageSourceList();
148  for ( iterZeroDimensionalElementVoltageSourcePtr_Type theElement = voltageElementList->begin(); theElement != voltageElementList->end(); theElement++ )
149  {
150  ( *theElement )->setVoltageByTime ( time );
151  std::cout << ( *theElement )->voltage() << std::endl;
152  }
153 }
154 
156 {
157  ptrVecZeroDimensionalElementPtr_Type elementList = M_circuitData->Elements() ->elementList();
158  M_outPutFormat.writeDataFormat ( M_time->time(),
159  M_currentFileStream,
160  M_outPutFormat.space );
161 
162  //write current
163  for ( iterZeroDimensionalElement_Type theElement = elementList->begin(); theElement != elementList->end(); theElement++ )
164  {
165  M_outPutFormat.writeDataFormat ( ( *theElement )->current(),
166  M_currentFileStream,
167  M_outPutFormat.space );
168  }
169 
170  //write voltage and current balance at each node
172  ptrVecZeroDimensionalNodePtr_Type nodeList = M_circuitData->Nodes() ->nodeList();
173  M_outPutFormat.writeDataFormat ( M_time->time(),
174  M_voltageFileStream,
175  M_outPutFormat.space );
176  M_outPutFormat.writeDataFormat ( M_time->time(),
177  M_balanceFileStream,
178  M_outPutFormat.space );
179 
180  for ( iterZeroDimensionalNode_Type theNode = nodeList->begin(); theNode != nodeList->end(); theNode++ )
181  {
182  M_outPutFormat.writeDataFormat ( ( *theNode )->voltage(),
183  M_voltageFileStream,
184  M_outPutFormat.space );
185  M_outPutFormat.writeDataFormat ( ( *theNode )->currentBalance(),
186  M_balanceFileStream,
187  M_outPutFormat.space );
188  }
189 
192 }
193 
194 
196 {
197  std::cout << "This MultiscaleModel0D::ShowVariables----------------------" << std::endl;
198  zeroDimensionalNodeSPtr_Type Nodes = M_circuitData->Nodes();
199  zeroDimensionalElementSPtr_Type Elements = M_circuitData->Elements();
200 
201  for ( iterZeroDimensionalNodeUnknown_Type theUnknownNode = Nodes->unknownNodeList()->begin(); theUnknownNode != Nodes->unknownNodeList()->end(); theUnknownNode++ )
202  {
203  ( *theUnknownNode )->showMe ( 1 );
204  }
205 
206  for ( iterZeroDimensionalElementPassiveInductor_Type theInductor = Elements->inductorList() ->begin(); theInductor
207  != Elements->inductorList() ->end(); theInductor++ )
208  {
209  ( *theInductor )->showMe ( 1 );
210  }
211 }
212 
214 {
215  zeroDimensionalNodeSPtr_Type Nodes = M_circuitData->Nodes();
216  ptrVecZeroDimensionalNodeUnknownPtr_Type unKnownList = Nodes->unknownNodeList();
217  zeroDimensionalElementSPtr_Type Elements = M_circuitData->Elements();
218  ptrVecZeroDimensionalElementPassiveInductorPtr_Type inductorList = Elements->inductorList();
219  M_unknownCounter = 0;
220 
221  //set variable index for unknown nodes
222  for ( iterZeroDimensionalNodeUnknown_Type theUnknownNode = unKnownList->begin(); theUnknownNode != unKnownList->end(); theUnknownNode++ )
223  {
224  ( *theUnknownNode )->assignVariableIndex ( M_unknownCounter );
225  M_unknownCounter++;
226  }
227 
228  //set variable index for inductor current
229  for ( iterZeroDimensionalElementPassiveInductor_Type theInductor = inductorList->begin(); theInductor != inductorList->end(); theInductor++ )
230  {
231  ( *theInductor )->assignVariableIndex ( M_unknownCounter );
232  M_unknownCounter++;
233  }
234 }
235 
237 {
238  //write header for current file
239  ptrVecZeroDimensionalElementPtr_Type elementList = M_circuitData->Elements() ->elementList();
240  M_outPutFormat.writeDataFormat ( "% time", M_currentFileStream, M_outPutFormat.space );
241  for ( iterZeroDimensionalElement_Type theElement = elementList->begin(); theElement != elementList->end(); theElement++ )
242  {
243  M_outPutFormat.writeDataFormat ( ( *theElement )->id(), M_currentFileStream, M_outPutFormat.space );
244  }
246 
247  //write header for voltage and current balance at each node (voltage file and balance file)
248  ptrVecZeroDimensionalNodePtr_Type nodeList = M_circuitData->Nodes() ->nodeList();
249  M_outPutFormat.writeDataFormat ( "% time", M_balanceFileStream, M_outPutFormat.space );
250  M_outPutFormat.writeDataFormat ( "% time", M_voltageFileStream, M_outPutFormat.space );
251  for ( iterZeroDimensionalNode_Type theNode = nodeList->begin(); theNode != nodeList->end(); theNode++ )
252  {
253  M_outPutFormat.writeDataFormat ( ( *theNode )->id(), M_voltageFileStream, M_outPutFormat.space );
254  M_outPutFormat.writeDataFormat ( ( *theNode )->id(), M_balanceFileStream, M_outPutFormat.space );
255  }
258 }
259 
260 } // LifeV namespace
virtual ~ZeroDimensionalData()
Destructor.
std::shared_ptr< vecZeroDimensionalElementCurrentSourcePtr_Type > ptrVecZeroDimensionalElementCurrentSourcePtr_Type
void updateBC()
update source elements
std::shared_ptr< ZeroDimensionalNodeS > zeroDimensionalNodeSPtr_Type
void saveSolution()
save solution
std::shared_ptr< ZeroDimensionalElementS > zeroDimensionalElementSPtr_Type
void updateInverseJacobian(const UInt &iQuadPt)
void writeNewLine(std::ofstream &stream)
std::shared_ptr< vecZeroDimensionalNodePtr_Type > ptrVecZeroDimensionalNodePtr_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
void initializeSolution()
initialize Solution
std::shared_ptr< vecZeroDimensionalElementPtr_Type > ptrVecZeroDimensionalElementPtr_Type
std::shared_ptr< vecZeroDimensionalElementVoltageSourcePtr_Type > ptrVecZeroDimensionalElementVoltageSourcePtr_Type
const std::string operator()(const char *VarName, const char *Default) const
Definition: GetPot.hpp:2045
std::shared_ptr< vecZeroDimensionalNodeUnknownPtr_Type > ptrVecZeroDimensionalNodeUnknownPtr_Type
GetPot(const STRING_VECTOR &FileNameList)
Definition: GetPot.hpp:645
void showMeVariables()
show variables
Data container for 0D model.
void setup(const GetPot &dataFile, bcPtr_Type bc, const std::string &section="0D_Model")
setup model
std::shared_ptr< vecZeroDimensionalElementPassiveInductorPtr_Type > ptrVecZeroDimensionalElementPassiveInductorPtr_Type