Skip to content

Commit

Permalink
Update Outputter.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiyua-Ma authored Jun 20, 2024
1 parent 4d359af commit bb029e6
Showing 1 changed file with 82 additions and 81 deletions.
163 changes: 82 additions & 81 deletions src/h/Outputter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,96 @@

#pragma once

#include <fstream>
#include <iostream>
#include <iomanip>
#include "Node.h"
#include "Material.h"

using namespace std;

//! Outputer class is used to output results
class COutputter
{
private:

//! File stream for output
ofstream OutputFile;

//! Designed as a single instance class
static COutputter* _instance;

//! Constructor
COutputter(string FileName);

public:

//! Return pointer to the output file stream
inline ofstream* GetOutputFile() { return &OutputFile; }

//! Return the single instance of the class
static COutputter* GetInstance(string FileName = " ");

//! Output current time and date
void PrintTime(const struct tm * ptm, COutputter& output);

//! Output logo and heading
void OutputHeading();

//! Output nodal point data
void OutputNodeInfo();

//! Output equation numbers
void OutputEquationNumber();

//! Output element data
void OutputElementInfo();

//! Output bar element data
void OutputBarElements(unsigned int EleGrp);

//! Output load data
void OutputLoadInfo();

//! Output displacement data
void OutputNodalDisplacement();

//! Output element stresses
void OutputElementStress();

//! Print total system data
void OutputTotalSystemData();

//! Overload the operator <<
template <typename T>
COutputter& operator<<(const T& item)
{
std::cout << item;
OutputFile << item;
return *this;
}
using namespace std;

typedef std::basic_ostream<char, std::char_traits<char> > CharOstream;
COutputter& operator<<(CharOstream& (*op)(CharOstream&))
{
op(std::cout);
op(OutputFile);
return *this;
}
template <class type> void clear( type* a, unsigned int N ); // Clear an array

#ifdef _DEBUG_
//! Element base class
/*! All type of element classes should be derived from this base class */
class CElement
{
protected:

//! Print banded and full stiffness matrix for debuging
void PrintStiffnessMatrix();
//! Number of nodes per element
unsigned int NEN_;

//! Print address of diagonal elements for debuging
void PrintDiagonalAddress();
//! Nodes of the element
CNode** nodes_;

//! Print column heights for debuging
void PrintColumnHeights();
//! Material of the element
CMaterial* ElementMaterial_; //!< Pointer to an element of MaterialSetList[][]

//! Location Matrix of the element
unsigned int* LocationMatrix_;

//! Print displacement vector for debuging
void PrintDisplacement();
//! Dimension of the location matrix
unsigned int ND_;

#endif
public:

//! Constructor
CElement() : NEN_(0), nodes_(nullptr), ElementMaterial_(nullptr) {}

//! Virtual deconstructor
virtual ~CElement() {
if (nodes_)
delete [] nodes_;

if (ElementMaterial_)
delete [] ElementMaterial_;

if (LocationMatrix_)
delete [] LocationMatrix_;
}

//! Read element data from stream Input
virtual bool Read(ifstream& Input, CMaterial* MaterialSets, CNode* NodeList) = 0;

//! Write element data to stream
virtual void Write(COutputter& output) = 0;

//! Generate location matrix: the global equation number that corresponding to each DOF of the element
// Caution: Equation number is numbered from 1 !
virtual void GenerateLocationMatrix()
{
unsigned int i = 0;
for (unsigned int N = 0; N < NEN_; N++)
for (unsigned int D = 0; D < 3; D++)
LocationMatrix_[i++] = nodes_[N]->bcode[D];
}

//! Return the size of the element stiffness matrix (stored as an array column by column)
virtual unsigned int SizeOfStiffnessMatrix()
{
unsigned int size = 0;
for (int i=1; i<= ND_; i++)
size += i;

return size;
}

//! Calculate element stiffness matrix (Upper triangular matrix, stored as an array column by colum)
virtual void ElementStiffness(double* stiffness) = 0;

//! Calculate element stress
virtual void ElementStress(double* stress, double* Displacement) = 0;

//! Return number of nodes per element
inline unsigned int GetNEN() { return NEN_; }

//! Return nodes of the element
inline CNode** GetNodes() { return nodes_; }

//! Return material of the element
inline CMaterial* GetElementMaterial() { return ElementMaterial_; }

//! Return the Location Matrix of the element
inline unsigned int* GetLocationMatrix() { return LocationMatrix_; }

//! Return the dimension of the location matrix
inline unsigned int GetND() { return ND_; }
};

0 comments on commit bb029e6

Please sign in to comment.