📄 omega_h.cpp
字号:
#include "vs_h.h"
#include "dynamic_array.h"
#include "omega_h.h"
Nodal_Value::Nodal_Value(int nn, int ndim, double* a)
: the_node_no(nn), nd(ndim), the_tie_node_no(-1) { the_value = new double[nd]; if(a) for(int i = 0; i < nd; i++) the_value[i] = a[i]; // copy by value else for(int i = 0; i < nd; i++) the_value[i] = 0.0;}
Nodal_Value::Nodal_Value(const Nodal_Value& a)
: the_node_no(a.the_node_no), nd(a.nd), the_tie_node_no(a.the_tie_node_no) {
the_value = new double[nd];
for(int i = 0; i < nd; i++) the_value[i] = a.the_value[i];
}
Nodal_Value& Nodal_Value::operator=(const Nodal_Value& a) {
if(this != &a) { // if rhs and lhs are not the same object
if(nd != a.nd) { // if rhs and lhs do not have the same length
nd = a.nd;
if(the_value) delete [] the_value;
the_value = new double[nd];
}
for(int i = 0; i < nd; i++) the_value[i] = a.the_value[i];
the_node_no = a.the_node_no;
the_tie_node_no = a.the_tie_node_no;
}
return (*this);
}
ostream& operator<<(ostream& s, Nodal_Value& nv) {
s << "{";
if(nv.tie_node_no() == -1) s << nv.node_no() << " | (";
else s << nv.node_no() << "-" << (nv.tie_node_no()) << " | {"; // output tie node number to indicate been tied
for(int i = 0; i < nv.no_of_dim(); i++)
if(i != nv.no_of_dim()-1) s << (nv.value()[i]) << ", ";
else s << (nv.value()[i]) << ") } ";
return s;
}
Node::Node(const Node& node) :
Nodal_Value(node.the_node_no, node.nd, (double*)0) {
the_tie_node_no = node.the_tie_node_no;
for(int i = 0; i < nd; i++) the_value[i] = node.the_value[i];
}
Node& Node::operator=(const Node& node) {
if(this != &node) {
the_node_no = node.the_node_no;
nd = node.nd;
if(the_value) delete [] the_value;
the_value = new double[nd];
for(int i = 0; i < nd; i++) the_value[i] = node.the_value[i];
}
return (*this);
}
int Node::operator==(Node& a) { for(int i = 0; i < no_of_dim(); i++) if(fabs((*this)[i]-a[i]) > 1.e-12) return FALSE; return TRUE;
}
Omega_eh::Omega_eh(int en, int etn, int mtn, int nen, int* ena) :
the_element_no(en), the_element_type_no(etn), the_material_type_no(mtn), the_element_node_no(nen) { the_element_node_array = new int[the_element_node_no]; // copy by value if(ena) for(int i = 0; i < the_element_node_no; i++) the_element_node_array[i] = ena[i]; else for(int i = 0; i < the_element_node_no; i++) the_element_node_array[i] = -1; // an illeagal node number}
Omega_eh::Omega_eh(const Omega_eh& a)
: the_element_no(a.the_element_no), the_element_type_no(a.the_element_type_no),
the_material_type_no(a.the_material_type_no), the_element_node_no(a.the_element_node_no) {
the_element_node_array = new int[the_element_node_no];
for(int i = 0; i < the_element_node_no; i++) the_element_node_array[i] = a.the_element_node_array[i];
}
Omega_eh& Omega_eh::operator=(const Omega_eh& a) {
if(this != &a) {
if(the_element_node_no != a.the_element_node_no) {
the_element_node_no = a.the_element_node_no;
if(the_element_node_array) delete [] the_element_node_array;
the_element_node_array = new int[the_element_node_no];
}
for(int i = 0; i < a.the_element_node_no; i++)
the_element_node_array[i] = a.the_element_node_array[i];
the_element_type_no = a.the_element_type_no;
the_material_type_no = a.the_material_type_no;
the_element_node_no = a.the_element_node_no;
}
return (*this);
}
int Omega_eh::operator==(Omega_eh& a) { if(the_element_type_no != a.element_type_no()) return FALSE; if(the_material_type_no != a.material_type_no()) return FALSE; if(the_element_node_no != a.element_node_no()) return FALSE; for(int i = 0; i < the_element_node_no; i++) if(the_element_node_array[i] != a[i]) return FALSE; return TRUE;
}
Omega_h::Omega_h(const Omega_h& a) {
int total_node_no = a.total_node_no(),
total_element_no = a.total_element_no();
Node *node; Omega_eh *elem;
for(int i = 0; i < total_node_no; i++) {
node = new Node;
*node = a[i];
the_node_array.add(node);
}
for(i = 0; i < total_element_no; i++) {
elem = new Omega_eh;
*elem = a(i);
the_omega_eh_array.add(elem);
}
}
Node& Omega_h::operator[](int nn) { // node selector
Dynamic_Array_Iterator<Node> iter(the_node_array);
while(iter->node_no() != nn && iter.more()) iter++; // searching
return *(iter.current());
}
Node& Omega_h::operator[](int nn) const { // node selector
Dynamic_Array<Node> na = the_node_array;
Dynamic_Array_Iterator<Node> iter(na);
while(iter->node_no() != nn && iter.more()) iter++; // searching
return *(iter.current());
}
int Omega_h::node_order(int nn) const {
Dynamic_Array_Iterator<Node> iter((Dynamic_Array<Node>)the_node_array); while(iter->node_no() != nn && iter.more()) iter++; // searching return iter.index();}
int Omega_h::total_distinct_node_no() const { // total number of distinct nodes int node_count = 0; for(int i = 0; i < total_node_no(); i++) if(((Dynamic_Array<Node>)the_node_array)[i].tie_node_no() == -1) node_count++; return node_count;}
void Omega_h::set(Node *nd) { // define node with database integrity checking
Dynamic_Array_Iterator<Node> iter(the_node_array); while(iter.more() && iter->node_no() != nd->node_no()) iter++; // searching
if(iter.length() == 0) the_node_array.add(nd); // first record
else if(iter->node_no() == nd->node_no()) { // key exist; (with same node number)
delete nd; // skip adding to the database
} else {
iter.top();
while(iter.more() && *(iter.current()) != (*nd)) iter++; // search for same coordinates
if(*(iter.current()) == (*nd)) { // a tie node, different node number with the same coordinates
the_node_array.add(nd);
int nn = iter->node_no();
iter.end()->tie_node_no() = nn;
} else the_node_array.add(nd);
}
}
Omega_eh& Omega_h::operator()(int en) {// element selector Dynamic_Array_Iterator<Omega_eh> iter(the_omega_eh_array); while(iter->element_no() != en && iter.more()) iter++; // searching return *(iter.current());}
Omega_eh& Omega_h::operator()(int en) const {// element selector
Dynamic_Array<Omega_eh> oa = the_omega_eh_array;
Dynamic_Array_Iterator<Omega_eh> iter(oa);
while(iter->element_no() != en && iter.more()) iter++; // searching
return *(iter.current());
}
int Omega_h::element_order(int en) const { Dynamic_Array_Iterator<Omega_eh> iter((Dynamic_Array<Omega_eh>)the_omega_eh_array); while(iter->element_no() != en && iter.more()) iter++; // searching return iter.index();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -