ZeroDimensionalCircuitData.hpp 35.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@HEADER
/*
*******************************************************************************

    Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
    Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University

    This file is part of LifeV.

    LifeV is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    LifeV is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with LifeV.  If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************
*/
//@HEADER

/*!
 *  @file
Cristiano Malossi's avatar
Cristiano Malossi committed
29
 *  @brief File containing a class for 0D model circuit data handling.
30
 *  @version alpha (experimental)
31
32
33
34
35
36
37
38
39
40
41
42
 *
 *  @date 26-09-2011
 *  @author Mahmoud Jafargholi <mahmoud.jafargholi@epfl.ch>
 *
 *  @contributors Cristiano Malossi <cristiano.malossi@epfl.ch>
 *  @mantainer    Cristiano Malossi <cristiano.malossi@epfl.ch>
 */

#ifndef ZeroDimensionalCircuitData_H
#define ZeroDimensionalCircuitData_H 1

// LIFEV
43
#include <lifev/core/array/MatrixEpetra.hpp>
44
45

// MATHCARD
46
#include <lifev/core/fem/BCInterface0D.hpp>
47
48
#include <lifev/zero_dimensional/solver/ZeroDimensionalDefinitions.hpp>
#include <lifev/zero_dimensional/fem/ZeroDimensionalBC.hpp>
49
50
51
52

namespace LifeV
{

53
54
// TODO Move forward declarations in ZeroDimensionalDefinitions
// TODO Move type definitions inside classes
55
56
57
58
59
60
61

//! A container class for all node objects
class ZeroDimensionalNodeS;

  //! A container class for all element obkects
class ZeroDimensionalElementS;

62
63
64
65
66
67
68
69
70
71
72
73
74
75
typedef boost::shared_ptr< ZeroDimensionalElementS >                    zeroDimensionalElementSPtr_Type;
typedef boost::shared_ptr< ZeroDimensionalNodeS >                       zeroDimensionalNodeSPtr_Type;
typedef std::vector<Int>                                                vecInt_Type;
typedef vecInt_Type::iterator                                           iterVecInt_Type;
typedef ZeroDimensionalBCHandler                                        bc_Type;
typedef boost::shared_ptr< bc_Type >                                    bcPtr_Type;
typedef MatrixEpetra<Real>                                              matrix_Type;
typedef VectorEpetra                                                    vector_Type;
typedef Epetra_Vector                                                   vectorEpetra_Type;
typedef boost::shared_ptr< matrix_Type >                                matrixPtr_Type;
typedef boost::shared_ptr< vector_Type >                                vectorPtr_Type;
typedef boost::shared_ptr<vectorEpetra_Type >                           vectorEpetraPtr_Type;

//! ZeroDimensionalElement - The base element class.
76
/*!
77
 *  @authors Mahmoud Jafargholi
78
79
80
81
 */
class ZeroDimensionalElement
{
public:
82

83
84
85
86
    //! @name Constructors & Destructor
    //@{

    //! Constructor
87
    explicit ZeroDimensionalElement() {}
88

89
90
91
92
    //! Destructor
    virtual ~ZeroDimensionalElement() {}

    //@}
93

94
95
96
97

    //! @name Methods
    //@{

98
    //! Display some information.
99
100
    virtual void showMe( const Int& flag = 0 );

101
    const std::string enum2string( const ZeroDimensionalElementType & type );
102
103
104
105
106

    //! Connect elements to the nodes.
    /*!
     * After all emenets and nodes are created, each element will call this
     * method to connect itse;f to the nodes.
107
     */
108
    virtual void connectElement( zeroDimensionalNodeSPtr_Type& nodes ) = 0;
109

110
111
    //! Contribution of the element of matrix \bf{A} and \bf{B} and vector \bf{C}.
    /*!
112
     * After updating the BCs ( or Terminal nodes ) this each element will invoke
113
114
     * this method to compute it's contribution on matrices.
     */
115
116
117
118
119
120
121
    virtual void buildABC( matrix_Type& /*A*/, matrix_Type& /*B*/, vector_Type& /*C*/, const zeroDimensionalNodeSPtr_Type& /*Nodes*/ ) {}

    //! Compute outputs (currents and voltages) from the solution vector after each succesful iteration.
    /*!
     * After each time step, when Rythmos solver is succesfully finishes, this method will compute
     * finial outputs ( for exmple currents) from the finial solution vector.
     */
122
    virtual void extractSolution( const ZeroDimensionalNodeS& /*nodes*/ ) {}
123
124
125
126
127
128
129
130
131

    //! This method specifies the convention of current direction in an element.
    /*!
     * @param A node index connected to the element.
     * @return +1 if the current convention is toward the iniput node and -1 otherwise.
     */
    virtual Real direction( const Int & nodeId ) const = 0;

    //@}
132
133


134
135
    //! @name Set Methods
    //@{
136

137
    void setId(const Int& id ) { M_id = id; }
138

139
    void setCurrent(const Real& current ) { M_current = current; }
140

141
    //! Set derivative of current respect to time.
142
    void setDeltaCurrent(const Real& deltaCurrent ) { M_deltaCurrent= deltaCurrent; }
143

144
    //@}
145
146


147
148
    //! @name Get Methods
    //@{
149

150
    const Int& id() const { return M_id; }
151

152
    const ZeroDimensionalElementType& type() const { return M_type; }
153
154
155
156
157
158
159

    const Real& current() const { return M_current; }

    //! Get derivative of current respect to time.
    const Real& deltaCurrent() const { return M_deltaCurrent; }

    //@}
160
161
162

protected:

163
    Int                             M_id;
164
    ZeroDimensionalElementType      M_type; //= 'Resistor';%'Capacitor' ,'Inductor','Voltage Source','Current Source' 'Diode'
165
166
    Real                            M_current;
    Real                            M_deltaCurrent;
167
168
};

169
170

// TODO Move type definitions inside classes
171
172
173
174
typedef boost::shared_ptr<ZeroDimensionalElement>                              zeroDimensionalElementPtr_Type;
typedef std::vector<zeroDimensionalElementPtr_Type>                            vecZeroDimensionalElementPtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementPtr_Type>                   ptrVecZeroDimensionalElementPtr_Type;
typedef vecZeroDimensionalElementPtr_Type::iterator                            iterZeroDimensionalElement_Type;
175
176
177
178
179

//! ZeroDimensionalElementPassive - A class for passive elements.
/*!
 *  @authors Mahmoud Jafargholi
 */
180
181
182
183
class ZeroDimensionalElementPassive: public ZeroDimensionalElement
{
public:

184
185
186
187
    //! @name Constructors & Destructor
    //@{

    //! Constructor
188
189
190
191
192
    explicit ZeroDimensionalElementPassive();

    //! Destructor
    virtual ~ZeroDimensionalElementPassive() {}

193
    //@}
194
195


196
197
    //! @name Methods
    //@{
198

199
200
    //! Show some information.
    void showMe( const Int& flag = 0 );
201

202
203
    //! Impleaments the abstarct class for passive elements.
    void connectElement( zeroDimensionalNodeSPtr_Type & nodes );
204

205
206
207
208
209
210
211
    //@}


    //! @name Set Methods
    //@{

    //! set parameter (1/R, 1/L, C, 1/R_{eff})
212
    void setParameter( const Real & parameter ) { M_parameter = parameter; }
213
214
215
216
217

    //! add the node to the list.
    /*!
     * @param node index.
     */
218
    void setNodeIndex( const Int& index ) { M_nodeIndex.push_back(index); }
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238

    //@}


    //! @name Get Methods
    //@{

    //! get the parameter (1/R, 1/L, C, 1/R_{eff})
    const Real& parameter() const { return M_parameter; }

    //! get the node index connected to the node.
    /*!
     * @param \it{i}th node connected to the elelemt.
     * @return  Index of \it{i}th node connected to the element.
     */
    const Int& nodeIndex( const Int& position ) const { return M_nodeIndex.at(position); }

    Real direction( const Int& nodeId )const;

    //@}
239
240
241
242
243

protected:

    //parameter= 'Resistor';%'Capacitor' ,'Inductor','Diode'
    //parameter=  1/R      ;%C            ,1/L      , 1/R_{eff}
244
245
246

    Real        M_parameter;
    vecInt_Type M_nodeIndex; //Index of connected nodes
247
};
248
249
250
251




252
//! ZeroDimensionalElementPassiveResistor - Resistor.
253
254
255
/*!
 *  @authors Mahmoud Jafargholi
 */
256
257
258
259
class ZeroDimensionalElementPassiveResistor: public ZeroDimensionalElementPassive
{
public:

260
261
262
263
    //! @name Constructors & Destructor
    //@{

    //! Contructor.
264
265
266
267
268
    explicit ZeroDimensionalElementPassiveResistor();

    //! Destructor
    virtual ~ZeroDimensionalElementPassiveResistor() {}

269
270
    //@}

271

272
273
274
275
276
277
    //! @name Methods
    //@{

    void showMe( const Int& flag = 0 );

    void buildABC( matrix_Type& A, matrix_Type& B, vector_Type& C, const zeroDimensionalNodeSPtr_Type& Nodes );
278

279
    void extractSolution( const ZeroDimensionalNodeS& nodes );
280

281
    //@}
282
283
};

284
285
286
287
288
289


//! ZerodimentionalElementPassiveDiode - Diode.
/*!
 *  @authors Mahmoud Jafargholi
 */
290
291
292
class ZeroDimensionalElementPassiveDiode: public ZeroDimensionalElementPassiveResistor
{
public:
293

294
295
296
    //! @name Constructors & Destructor
    //@{

297
298
299
300
301
302
    //! Constructor
    explicit ZeroDimensionalElementPassiveDiode();

    //! Destructor
    virtual ~ZeroDimensionalElementPassiveDiode() {}

303
304
305
306
307
308
309
310
    //@}


    //! @name Methods
    //@{

    void showMe( const Int& flag = 0 );

311
    void extractSolution( const ZeroDimensionalNodeS& nodes );
312
313
314
315
316
317
318
319

    void buildABC( matrix_Type& A, matrix_Type& B, vector_Type& C, const zeroDimensionalNodeSPtr_Type& Nodes );

    //@}


    //! @name Set Methods
    //@{
320
321

    //!current = beta * exp(alpha * (voltage - forwardBias )) - (beta * exp(alpha * ( - forwardBias )))
322
323
324
    void setalpha(const Real& alpha ) { M_alpha = alpha; }

    void setbeta(const Real& beta ) { M_beta = beta; }
325

326
327
328
    void setforwardBias(const Real& forwardBias ) { M_forwardBias = forwardBias; }

    //@}
329
330


331
332
    //! @name Get Methods
    //@{
333

334
    const Real& alpha() const { return M_alpha; }
335

336
    const Real& beta() const { return M_beta; }
337

338
    const Real& forwardBias() const { return M_forwardBias; }
339

340
    //@}
341
342
343

protected:

344
345
346
347
348
349
    //! calculate the effective resistance.
    /*!
     * @param voltage difference
     * @return effective ressitance
     */
    void calculateEffectiveResistance(const Real& voltage);
350

351
352
353
    Real            M_alpha; //current = beta * exp(alpha * (voltage - forwardBias )) - (beta * exp(alpha * ( - forwardBias )))
    Real            M_beta;
    Real            M_forwardBias;
354
355
};

356
357
358
359
360
361


//! ZerodimentionalElementPassiveCapacitor - Capacitor.
/*!
 *  @authors Mahmoud Jafargholi
 */
362
363
364
365
class ZeroDimensionalElementPassiveCapacitor: public ZeroDimensionalElementPassive
{
public:

366
367
368
369
    //! @name Constructors & Destructor
    //@{

    //! Constructor
370
371
372
373
374
    explicit ZeroDimensionalElementPassiveCapacitor();

    //! Destructor
    virtual ~ZeroDimensionalElementPassiveCapacitor() {}

375
    //@}
376
377


378
379
    //! @name Methods
    //@{
380

381
382
    void showMe( const Int& flag = 0 );

383
    void extractSolution( const ZeroDimensionalNodeS& nodes );
384
385
386
387

    void buildABC( matrix_Type& A, matrix_Type& B, vector_Type& C, const zeroDimensionalNodeSPtr_Type& Nodes );

    //@}
388
389
390
};


391
//! ZeroDimensionalElementPassiveInductor - Inductor.
392
393
394
/*!
 *  @authors Mahmoud Jafargholi
 */
395
396
397
398
class ZeroDimensionalElementPassiveInductor: public ZeroDimensionalElementPassive
{
public:

399
400
401
402
    //! @name Constructors & Destructor
    //@{

    //! Constructor
403
404
405
406
407
    explicit ZeroDimensionalElementPassiveInductor();

    //! Destructor
    virtual ~ZeroDimensionalElementPassiveInductor() {}

408
409
410
411
412
    //@}


    //! @name Methods
    //@{
413

414
415
416
417
418
    //! Set the variable index and equation row index for Inductor.
    /*!
     *Current in Inductor is an unknown.
     */
    virtual void assignVariableIndex( const Int& index );
419

420
    void showMe( const Int& flag = 0 );
421

422
423
424
425
426
427
428
    void buildABC( matrix_Type& A, matrix_Type& B, vector_Type& C, const zeroDimensionalNodeSPtr_Type& Nodes );

    //@}


    //! @name Get Methods
    //@{
429

430
431
432
433
434
435
436
    //! get equation row for in matrix A,B and C.
    const Int& equationRow() const { return M_equationRow; }

    //! get variable index in solution vector  x  and \dot{x}
    const Int& variableIndex() const { return M_variableIndex; }

    //@}
437
438

protected:
439
440
    Int            M_equationRow;
    Int            M_variableIndex;
441
442
};

443
444


445
//! ZeroDimensionalElementSource - Base class for source elements.
446
447
448
/*!
 *  @authors Mahmoud Jafargholi
 */
449
450
451
452
453
class ZeroDimensionalElementSource: public ZeroDimensionalElement
{

public:

454
455
456
457
    //! @name Constructors & Destructor
    //@{

    //!Constructor
458
459
460
461
462
    explicit ZeroDimensionalElementSource();

    //! Destructor
    virtual ~ZeroDimensionalElementSource() {}

463
464
465
466
467
468
469
470
471
472
473
474
475
    //@}


    //! @name Methods
    //@{

    void showMe( const Int& flag = 0 );

    //@}


    //! @name Set Methods
    //@{
476

477
    void setNodeIndex(const Real & index ) { M_nodeIndex = index; }
478

479
    //! Set BC handler.
480
    void setBC( const bcPtr_Type& bc) { M_bc = bc; }
481

482
483
484
485
486
487
488
    //@}


    //! @name Get Methods
    //@{

    Int nodeIndex() const { return M_nodeIndex; }
489

490
491
492
    Real direction( const Int& /*nodeId*/ ) const { return -1.0; }

    //@}
493
494
495

protected:

496
497
    Int            M_nodeIndex; //Index of connected node
    bcPtr_Type     M_bc;
498
499
};

500
501


502
//! ZeroDimensionalElementVoltageSource - Voltage Source.
503
504
505
/*!
 *  @authors Mahmoud Jafargholi
 */
506
507
508
509
510
class ZeroDimensionalElementVoltageSource: public ZeroDimensionalElementSource
{

public:

511
512
513
514
    //! @name Constructors & Destructor
    //@{

    //! Constructor
515
516
517
518
519
    explicit ZeroDimensionalElementVoltageSource();

    //! Destructor
    virtual ~ZeroDimensionalElementVoltageSource() {}

520
521
522
523
524
525
526
527
528
529
    //@}


    //! @name Get Methods
    //@{

    void connectElement(zeroDimensionalNodeSPtr_Type & Nodes);

    //! calculate current passing outward in voltage source.
    /*!
530
     *  This method can be called after all elements invoked extractSolution method.
531
532
533
534
535
536
537
538
539
540
     */
    void calculateCurrent( const ZeroDimensionalNodeS& Nodes,const ZeroDimensionalElementS& Elements );

    //@}


    //! @name Set Methods
    //@{

    //! Update voltage source by time.
541
    void setVoltageByTime( const Real& time ) { M_voltage = M_bc->bc( M_nodeIndex ).evaluate(time); }
542
543

    //! Update \frac{\partial voltage}{\partial t} by time.
544
    void setDeltaVoltageByTime( const Real& time ) { M_deltaVoltage = M_bc->bc( M_nodeIndex + BC_CONSTANT ).evaluate(time); }
545
546
547

    //@}

548

549
550
    //! @name Get Methods
    //@{
551

552
    const Real& voltage() const { return M_voltage; }
553

554
    Real deltaVoltage() const { return M_deltaVoltage; }
555

556
    Real voltageByTime(const Real & time) const { return M_bc->bc( M_nodeIndex ).evaluate(time); }
557

558
    Real deltaVoltageByTime(const Real & time) const { return M_bc->bc( M_nodeIndex + BC_CONSTANT ).evaluate(time); }
559

560
    //@}
561
562
563
564
565
566
567
568

protected:

    Real    M_voltage                     ; //voltage at time t_{n}
    Real    M_deltaVoltage                ; //\frac{\mathrm{d \text{ voltage}} }{\mathrm{d} t}
};


569

570
//! ZeroDimensionalElementCurrentSource - Current Source.
571
572
573
/*!
 *  @authors Mahmoud Jafargholi
 */
574
575
576
577
578
class ZeroDimensionalElementCurrentSource: public ZeroDimensionalElementSource
{

public:

579
580
581
582
    //! @name Constructors & Destructor
    //@{

    //! Constructor.
583
584
585
586
587
    explicit ZeroDimensionalElementCurrentSource();

    //! Destructor
    virtual ~ZeroDimensionalElementCurrentSource() {}

588
    //@}
589
590


591
592
    //! @name Methods
    //@{
593

594
    void connectElement( zeroDimensionalNodeSPtr_Type & Nodes );
595

596
597
598
599
600
601
602
603
    void buildABC( matrix_Type& A, matrix_Type& B, vector_Type& C, const zeroDimensionalNodeSPtr_Type& Nodes );

    //@}


    //! @name set Methods
    //@{

604
    void setCurrentByTime(const Real& time ) { M_current = M_bc->bc( M_nodeIndex ).evaluate(time); }
605
606
607
608
609
610
611
612
613
614
615
616

    //@}


    //! @name Get Methods
    //@{

    Real currentByTime(const Real& time ) const { return M_bc->bc( M_nodeIndex ).evaluate(time); }

    Real current() const { return M_current; }

    //@}
617
618
619

};

620
621
622
623
624
625
626
627
628
629
630
631
632












// TODO Move type definitions inside classes
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
typedef boost::shared_ptr<ZeroDimensionalElementPassiveResistor>        zeroDimensionalElementPassiveResistorPtr_Type;
typedef boost::shared_ptr<ZeroDimensionalElementPassiveCapacitor>       zeroDimensionalElementPassiveCapacitorPtr_Type;
typedef boost::shared_ptr<ZeroDimensionalElementPassiveInductor>        zeroDimensionalElementPassiveInductorPtr_Type;
typedef boost::shared_ptr<ZeroDimensionalElementPassiveDiode>           zeroDimensionalElementPassiveDiodePtr_Type;
typedef boost::shared_ptr<ZeroDimensionalElementCurrentSource>          zeroDimensionalElementCurrentSourcePtr_Type;
typedef boost::shared_ptr<ZeroDimensionalElementVoltageSource>          zeroDimensionalElementVoltageSourcePtr_Type;


typedef std::vector<zeroDimensionalElementPassiveResistorPtr_Type>      vecZeroDimensionalElementPassiveResistorPtr_Type;
typedef std::vector<zeroDimensionalElementPassiveCapacitorPtr_Type>     vecZeroDimensionalElementPassiveCapacitorPtr_Type;
typedef std::vector<zeroDimensionalElementPassiveInductorPtr_Type>      vecZeroDimensionalElementPassiveInductorPtr_Type;
typedef std::vector<zeroDimensionalElementPassiveDiodePtr_Type>         vecZeroDimensionalElementPassiveDiodePtr_Type;
typedef std::vector<zeroDimensionalElementCurrentSourcePtr_Type>        vecZeroDimensionalElementCurrentSourcePtr_Type;
typedef std::vector<zeroDimensionalElementVoltageSourcePtr_Type>        vecZeroDimensionalElementVoltageSourcePtr_Type;


typedef boost::shared_ptr<vecZeroDimensionalElementPassiveResistorPtr_Type>     ptrVecZeroDimensionalElementPassiveResistorPtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementPassiveCapacitorPtr_Type>    ptrVecZeroDimensionalElementPassiveCapacitorPtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementPassiveInductorPtr_Type>     ptrVecZeroDimensionalElementPassiveInductorPtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementPassiveDiodePtr_Type>        ptrVecZeroDimensionalElementPassiveDiodePtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementCurrentSourcePtr_Type>       ptrVecZeroDimensionalElementCurrentSourcePtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalElementVoltageSourcePtr_Type>       ptrVecZeroDimensionalElementVoltageSourcePtr_Type;

typedef vecZeroDimensionalElementPassiveResistorPtr_Type::iterator              iterZeroDimensionalElementPassiveResistor_Type;
typedef vecZeroDimensionalElementPassiveCapacitorPtr_Type::iterator             iterZeroDimensionalElementPassiveCapacitor_Type;
typedef vecZeroDimensionalElementPassiveInductorPtr_Type::iterator              iterZeroDimensionalElementPassiveInductor_Type;
typedef vecZeroDimensionalElementPassiveDiodePtr_Type::iterator                 iterZeroDimensionalElementPassiveDiode_Type;
typedef vecZeroDimensionalElementCurrentSourcePtr_Type::iterator                iterZeroDimensionalElementCurrentSource_Type;
typedef vecZeroDimensionalElementVoltageSourcePtr_Type::iterator                iterZeroDimensionalElementVoltageSourcePtr_Type;

663
664

//! ZeroDimensionalNode - The base node class.
665
/*!
666
 *  @authors Mahmoud Jafargholi
667
668
669
670
671
 */
class ZeroDimensionalNode
{
public:

672
673
674
675
    //! @name Constructors & Destructor
    //@{

    //! Constructor
676
677
678
679
680
    explicit ZeroDimensionalNode();

    //! Destructor
    virtual ~ZeroDimensionalNode() {}

681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
    //@}


    //! @name Methods
    //@{

    //! Calculate current balance at node.
    /*!
     * After updating current in all elements, we can verify the balance of current flow at each node.
     */
    void calculateCurrentBalance( const ZeroDimensionalElementS& Elements );

    virtual void showMe( const Int& flag = 0 );

    //@}


    //! @name Set Methods
    //@{
700

701
    const std::string enum2string( const ZeroDimensionalNodeType & type ) const;
702

703
    void setId( const Int& id ) { M_id = id; }
704

705
    //! add an element index to the elelemt list.
706
    void setElementListIndex( const Int& index ) { M_elementListIndex.push_back(index); }
707

708
709
710
711
712
    //! add an node index which is connected by an element in element list.
    /*!
     * Each elelemnt in element list, coonects this node to another node ( except source elementt). nodeList is a container for conecting nodes.
     * If the element connected to this node has only one terminal ( like voltage source and current source), the connecting index would be -1.
     */
713
    void setNodeListIndex(const Int& index ) { M_nodeListIndex.push_back(index); }
714

715
    virtual void setVoltage(const Real& voltage ) { M_voltage = voltage; }
716

717
    virtual void setDeltaVoltage(const Real& deltaVoltage ) { M_deltaVoltage = deltaVoltage; }
718

719
    //@}
720

721

722
723
    //! @name Get Methods
    //@{
724

725
    const Int& id() const { return M_id; }
726

727
    const ZeroDimensionalNodeType& type() const { return M_type; }
728

729
    const Int& elementListIndexAt( const Int& position ) const { return M_elementListIndex.at(position); }
730

731
    const vecInt_Type& elementListIndex() const { return M_elementListIndex; }
732

733
    const Int& nodeListIndexAt( const Int& position ) const { return M_nodeListIndex.at(position); }
734

735
736
737
738
739
740
741
    virtual const Real& voltage() const { return M_voltage; }

    virtual Real deltaVoltage() const { return M_deltaVoltage;}

    const Real& currentBalance() const{ return M_currentBalance; }

    //@}
742
743
744

protected:

745
    Int                             M_id;
746
    ZeroDimensionalNodeType         M_type;             //= 'Known';%'Unknown'
747
748
749
750
751
    Real                            M_currentBalance;   //sum of currents over all branches
    vecInt_Type                     M_elementListIndex; // List of id(s) of connected Elements to this Node
    vecInt_Type                     M_nodeListIndex;    // List of id(s) of connected Nodes to this Node
    Real                            M_voltage;
    Real                            M_deltaVoltage;
752
753
};

754
755

//! ZeroDimensionalNodeUnknown - This class defines the unknown node class.
756
/*!
757
 *  @authors Mahmoud Jafargholi
758
759
760
761
762
 */
class ZeroDimensionalNodeUnknown: public ZeroDimensionalNode
{
public:

763
764
765
766
    //! @name Constructors & Destructor
    //@{

    //! Constructor
767
768
769
770
771
    explicit ZeroDimensionalNodeUnknown();

    //! Destructor
    virtual ~ZeroDimensionalNodeUnknown() {}

772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
    //@}


    //! @name Methods
    //@{

    void showMe( const Int& flag = 0 );

    //@}


    //! @name Set Methods
    //@{

    //! assign the index of the unknown voltage.
787
788
    void assignVariableIndex(const Int & index) ;

789
    //@}
790
791


792
793
794
795
    //! @name Get Methods
    //@{

    const Int& variableIndex() const { return M_variableIndex; }
796

797
798
799
    const Int& equationRow() const { return M_equationRow; }

    //@}
800
801

protected:
802
803
    Int                 M_variableIndex; // Index of the variable
    Int                 M_equationRow;   // #Row(equation) in the Matrix
804
805
};

806
807
808


//! ZeroDimensionalNodeKnown - This class defines the known node class. A Voltage Source element is connected to this class.
809
/*!
810
 *  @authors Mahmoud Jafargholi
811
812
813
814
815
 */
class ZeroDimensionalNodeKnown: public ZeroDimensionalNode
{
public:

816
817
818
819
    //! @name Constructors & Destructor
    //@{

    //! Contructor
820
821
    explicit ZeroDimensionalNodeKnown();

822
823
824
825
    //! Contructor.
    /*!
     *@param Voltage Source connected to the knwn node.
     */
826
827
828
829
830
831
    ZeroDimensionalNodeKnown( const zeroDimensionalElementVoltageSourcePtr_Type & theElement );


    //! Destructor
    virtual ~ZeroDimensionalNodeKnown() {}

832
833
834
835
836
837
838
    //@}


    //! @name Set Methods
    //@{

    //!Set the VoltageSource Element which is connected to the Node
839
    void setElement( const zeroDimensionalElementVoltageSourcePtr_Type &element ) { M_element=element; }
840

841
    void setVoltageByTime(const Real& time ) { M_voltage = M_element->voltageByTime(time); M_element->setVoltageByTime(time); }
842

843
    void setDeltaVoltageByTime(const Real& time ) { M_deltaVoltage = M_element->deltaVoltageByTime(time); M_element->setDeltaVoltageByTime(time); }
844

845
    const Real& voltage() const { return M_element->voltage(); }
846

847
    Real  voltageByTime(Real& time) const { return M_element->voltageByTime(time); }
848

849
    Real  deltaVoltageByTime(Real& time) const { return M_element->deltaVoltageByTime(time); }
850

851
    //@}
852
853
854
855
856
857

protected:

    zeroDimensionalElementVoltageSourcePtr_Type M_element;
};

858
859
860
861



// TODO Move type definitions inside classes
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
typedef boost::shared_ptr<ZeroDimensionalNode>              zeroDimensionalNodePtr_Type;
typedef std::vector<zeroDimensionalNodePtr_Type>            vecZeroDimensionalNodePtr_Type;
typedef boost::shared_ptr< vecZeroDimensionalNodePtr_Type > ptrVecZeroDimensionalNodePtr_Type;
typedef vecZeroDimensionalNodePtr_Type::iterator            iterZeroDimensionalNode_Type;

typedef boost::shared_ptr<ZeroDimensionalNodeUnknown>             zeroDimensionalNodeUnknownPtr_Type;
typedef std::vector< zeroDimensionalNodeUnknownPtr_Type >         vecZeroDimensionalNodeUnknownPtr_Type;
typedef boost::shared_ptr<vecZeroDimensionalNodeUnknownPtr_Type>  ptrVecZeroDimensionalNodeUnknownPtr_Type;
typedef vecZeroDimensionalNodeUnknownPtr_Type::iterator           iterZeroDimensionalNodeUnknown_Type;

typedef boost::shared_ptr<ZeroDimensionalNodeKnown>               zeroDimensionalNodeKnownPtr_Type;
typedef std::vector< zeroDimensionalNodeKnownPtr_Type >           vecZeroDimensionalNodeKnownPtr_Type;
typedef boost::shared_ptr< vecZeroDimensionalNodeKnownPtr_Type >  ptrVecZeroDimensionalNodeKnownPtr_Type;
typedef vecZeroDimensionalNodeKnownPtr_Type::iterator             iterZeroDimensionalNodeKnown_Type;

877
878
879
typedef std::map <Int, zeroDimensionalElementVoltageSourcePtr_Type>  mapVoltageSource_Type;
typedef boost::shared_ptr < mapVoltageSource_Type>                   mapVoltageSourcePtr_Type;

880

881
882
883
884
//! ZeroDimensionalElementS - Container of elements
/*!
 *  @authors Mahmoud Jafargholi
 */
885
886
887
888
class ZeroDimensionalElementS
{
public:

889
    //! constructor
890
891
892
893
894
    explicit ZeroDimensionalElementS();

    //! Destructor
    virtual ~ZeroDimensionalElementS() {}

895
    void showMe( const Int& flag = 0 );
896

897
898
    //! add element to the list.
    void setelementList(const zeroDimensionalElementPtr_Type& theElement ) { M_elementList->push_back(theElement);}
899

900
901
902
903
904
905
    //! get element.
    /*!
     *@param element index
     *@return element
     */
    const zeroDimensionalElementPtr_Type& elementListAt( const Int & index ) const { return M_elementList->at(index); }
906

907
    const ptrVecZeroDimensionalElementPtr_Type& elementList() const { return M_elementList; }
908

909
    const ptrVecZeroDimensionalElementPassiveResistorPtr_Type& resistorList() const { return M_resistorList; }
910

911
    const ptrVecZeroDimensionalElementPassiveCapacitorPtr_Type& capacitorList() const { return M_capacitorList; }
912

913
    const ptrVecZeroDimensionalElementPassiveInductorPtr_Type& inductorList() const { return M_inductorList; }
914

915
    const ptrVecZeroDimensionalElementPassiveDiodePtr_Type& diodeList() const { return M_diodeList; }
916

917
    const ptrVecZeroDimensionalElementVoltageSourcePtr_Type& voltageSourceList() const { return M_voltageSourceList; }
918

919
    const ptrVecZeroDimensionalElementCurrentSourcePtr_Type& currentSourceList() const { return M_currentSourceList; }
920

921
922
    //! total number of elements including sources.
   Int elementCounter() const { return M_elementList->size(); }//TODO Why when I use CONST I get a warning??
923

924
   Int resistorCounter() const { return M_resistorList->size(); }
925

926
   Int capacitorCounter() const { return M_capacitorList->size(); }
927

928
   Int inductorCounter() const { return M_inductorList->size(); }
929

930
   Int diodeCounter() const { return M_diodeList->size(); }
931

932
   Int voltageSourceCounter() const { return M_voltageSourceList->size(); }
933

934
   Int currentSourceCounter() const { return M_currentSourceList->size(); }
935

936
   //! add resistor to the resistor list.
937
    void  setResistorList(const zeroDimensionalElementPassiveResistorPtr_Type & resistorPtr ) { M_resistorList->push_back(resistorPtr); }
938

939
    //! add capacitor to the capacitor list.
940
    void  setCapacitorList(const zeroDimensionalElementPassiveCapacitorPtr_Type & capacitorPtr ) { M_capacitorList->push_back(capacitorPtr); }
941

942
    //! add inductor to the inductor list.
943
    void  setInductorList(const zeroDimensionalElementPassiveInductorPtr_Type& inductorPtr ) { M_inductorList->push_back(inductorPtr); }
944

945
    //! add diode to the diode list.
946
    void  setDiodeList(const zeroDimensionalElementPassiveDiodePtr_Type& diodePtr ) { M_diodeList->push_back(diodePtr); }
947

948
    //! add currentSource to the current Source list.
949
    void  setCurrentSourceList(const zeroDimensionalElementCurrentSourcePtr_Type& currentSourcePtr ) { M_currentSourceList->push_back(currentSourcePtr); }
950

951
    //! add voltgeSource to the voltage source list.
952
    void  setVoltageSourceList(const zeroDimensionalElementVoltageSourcePtr_Type& voltageSourcePtr ) { M_voltageSourceList->push_back(voltageSourcePtr); }
953

954
    //! add object to the map from voltage source index to the voltage source object.
955
    void setVoltageSourceMap(const Int & id, const zeroDimensionalElementVoltageSourcePtr_Type & voltageSource) {(*M_voltageSourceMap)[id]= voltageSource;}
956

957
    const zeroDimensionalElementVoltageSourcePtr_Type voltageSourceMap(Int& id) const {return (*M_voltageSourceMap)[id] ;}
958
959
960

protected:

961
962
963
964
965
966
967
968
969
    //!List of Elements Ptr
    ptrVecZeroDimensionalElementPtr_Type                    M_elementList;
    ptrVecZeroDimensionalElementPassiveResistorPtr_Type     M_resistorList;
    ptrVecZeroDimensionalElementPassiveCapacitorPtr_Type    M_capacitorList;
    ptrVecZeroDimensionalElementPassiveInductorPtr_Type     M_inductorList;
    ptrVecZeroDimensionalElementPassiveDiodePtr_Type        M_diodeList;
    ptrVecZeroDimensionalElementCurrentSourcePtr_Type       M_currentSourceList;
    ptrVecZeroDimensionalElementVoltageSourcePtr_Type       M_voltageSourceList;
    mapVoltageSourcePtr_Type                                M_voltageSourceMap;
970
971
};

972
973
974
// TODO Move type definitions inside classes
typedef std::map <Int, zeroDimensionalNodeUnknownPtr_Type>                          mapNodeUnknown_Type;
typedef std::map <Int, zeroDimensionalNodeKnownPtr_Type>                            mapNodeKnown_Type;
975
976
977
typedef boost::shared_ptr < mapNodeKnown_Type>                                      mapNodeKnownPtr_Type;
typedef boost::shared_ptr < mapNodeUnknown_Type  >                                  mapNodeUnknownPtr_Type;

978
979
980
981
982
983


//! ZeroDimensionalNodeS - Container of nodes
/*!
 *  @authors Mahmoud Jafargholi
 */
984
985
986
987
class ZeroDimensionalNodeS
{
public:

988
989
990
991
    //! @name Constructors & Destructor
    //@{

    //! Constructor
992
993
994
995
996
    explicit ZeroDimensionalNodeS();

    //! Destructor
    virtual ~ZeroDimensionalNodeS() {}

997
    virtual void showMe( const Int& flag = 0 );
998

999
    const zeroDimensionalNodePtr_Type& nodeListAt( const Int & index ) const { return M_nodeList->at(index); }
1000