and node_0,node_1,and node_2 are coming from the connectivity matrix which is n_element*4 and
1 2 3 4 5 6 7
for (int i=0;i<n_element;i++)
{
int node_0=((connectivity[i].Node_0 - 1));
int node_1=((connectivity[i].Node_1 - 1));
int node_2=((connectivity[i].Node_2 - 1));
}
I've already defined the summation operator (matrix+ scalar) and summation operator (matrix+matrix) but in does not work properly in this case and I'm not sure how to define the proper overloading operator for this. I would be grateful if you could help me with this.
I've already said what you need to show us so that we can help you. How can we help you define overloaded operators when you haven't shown the classes involved?
@dhayden I'm attaching the class for the operation which does the summation between a matrix and a scalar. In this case every element of this matrix is being added with a scalar and it is not a problem.
for the present case the problem is we need to do something like this NN[node_0][node_0] += NN_e[0][0] and at the end the NN matrix will be for example 100 by 100 but my NN_e matrix will be 3 by 3 all the time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template <class T>
Matrix2D<T> operator+ (const Matrix2D<T>& lhs, const T& rhs)
{
int numRows = lhs.m_nRows;
int numCols = lhs.m_nCols;
int numElements = numRows * numCols;
T *tempResult = new T[numElements];
for (int i = 0; i < numElements; ++i)
tempResult[i] = lhs.m_matrixData[i] + rhs;
Matrix2D<T> result(numRows, numCols, tempResult);
delete[] tempResult;
return result;
}
I can not use also the operator for matrix + matrix because they are not in the same dimension
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template <class T>
Matrix2D<T> operator+ (const Matrix2D<T>& lhs, const Matrix2D<T>& rhs)
{
int numRows = lhs.m_nRows;
int numCols = lhs.m_nCols;
int numElements = numRows * numCols;
T *tempResult = new T[numElements];
for (int i = 0; i < numElements; i++)
tempResult[i] = lhs.m_matrixData[i] + rhs.m_matrixData[i];
Matrix2D<T> result(numRows, numCols, tempResult);
delete[] tempResult;
return result;
}
so for now I don't know how I can define a operator which can do this for me.
I wish you would provide all the information I requested.
It appears that you can't use an overloaded operator because the operation you're trying to do is pretty non-standard. At the very least, it has 5 arguments instead of 2: NN, NN_e, node_0, node_1, and node_2. Perhaps you should create a member function to do this: const Matrix2D<T> &Matrix2D<T>::func(const Matrix2D<T> &rhs, int node_0, int node_1, int node_2);
Anytime you find yourself writing variables ending in _0, _1, _2 etc., you should consider whether they should be an array or vector instead. So maybe it should be: const Matrix2D<T> &Matrix2D<T>::func(const Matrix2D<T> &rhs, int nodes[3]);
NodeID and ElemID, they are different value,one is the number of node and the other is the number of element.
About the second part I expect to get the gx1,gy1,gx2,gy2,gx3 and gy3, it was my mistake,I missed some of them in the return value.