<commit_before>/*
 * Assembler.cc
 *
 *  Created on: Oct 9, 2014
 *      Author: lurker
 */
#include "Assembler.h"

Assembler::Assembler(){


}

Assembler::~Assembler() {
#ifdef DEBUG
	mexPrintf("Assembler detached\n");
#endif
}


/*
 * Extract information of basis on Reference Triangle
 */
void Assembler::Reference(MatlabPtr &F, MatlabPtr &DX, MatlabPtr &DY,
		MatlabPtr Points, MatlabPtr QPoints){

	auto _numberofpoints = mxGetN(Points);
	auto _numberofqpoints = mxGetN(QPoints);


	/*
	 *  Temporary Arrays, will be destroyed later.
	 */
	auto Vander = mxCreateNumericMatrix(_numberofpoints,_numberofpoints,mxDOUBLE_CLASS, mxREAL);
	auto VanderF = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderX = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderY = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);


	int deg = round((sqrt(8*_numberofpoints + 1) - 3)/2);

	if ((deg + 1) * (deg + 2)/2 != _numberofpoints){
		mexErrMsgTxt("Invalid length of input nodes\n");
	}

	// extract all nodes from promoted nodes.
	auto Vander_ptr  = mxGetPr(Vander);
	auto VanderF_ptr = mxGetPr(VanderF);
	auto VanderX_ptr = mxGetPr(VanderX);
	auto VanderY_ptr = mxGetPr(VanderY);

	auto nodes_ptr   = mxGetPr(Points);
	auto qnodes_ptr  = mxGetPr(QPoints);

	// basis on all nodes

	for (size_t col = 0; col < _numberofpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++){
				*Vander_ptr++ = pow(nodes_ptr[2*col], i - j)*pow(nodes_ptr[2*col + 1], j);
			}
		}
	}



	// basis on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++){
				*VanderF_ptr++ = pow(qnodes_ptr[2*col], i - j)*pow(qnodes_ptr[2*col + 1], j);
			}
		}
	}

	// partial x on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++) {
				if (j == i){
					*VanderX_ptr++ = 0.;
				}
				else{
					*VanderX_ptr++ = (i - j) * pow(qnodes_ptr[2*col], i - j - 1)*pow(qnodes_ptr[2*col + 1], j);
				}
			}
		}
	}

	// partial y on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++) {
				if (j == 0){
					*VanderY_ptr++ = 0.;
				}
				else{
					*VanderY_ptr++ = j* pow(qnodes_ptr[2*col], i - j)*pow(qnodes_ptr[2*col + 1], j - 1);
				}
			}
		}
	}



	mxArray* RHS_f[] = {Vander, VanderF};
	mexCallMATLAB(1, &F, 2, RHS_f, "mldivide");

	mxArray* RHS_x[] = {Vander, VanderX};
	mexCallMATLAB(1, &DX, 2, RHS_x, "mldivide");

	mxArray* RHS_y[] = {Vander, VanderY};
	mexCallMATLAB(1, &DY, 2, RHS_y, "mldivide");


	mxDestroyArray(Vander);
	mxDestroyArray(VanderF);
	mxDestroyArray(VanderX);
	mxDestroyArray(VanderY);


}

/*
 * 1D reference
 */
void Assembler::Reference(MatlabPtr& F, MatlabPtr& DX, MatlabPtr Degree, MatlabPtr QPoints){
	// Reference segment [-1 , 1],
	// with (Degree - 1) equal-spaced points in between.

	auto _numberofpoints = static_cast<int32_t>(*Matlab_Cast<Real_t>(Degree) + 1);

	vector<Real_t> Points(_numberofpoints);
	Points[0] = -1.;
	Points[1] = 1. ;
	for (size_t i = 2; i < _numberofpoints; i++) {
		Points[i] = (-1.) + 2.0*(i - 1)/static_cast<Real_t>(_numberofpoints - 1);
	}

	// 1D vector-row-majored
	auto _numberofqpoints = mxGetN(QPoints);
	auto qnodes_ptr       = mxGetPr(QPoints);

	/*
	 *  Temporary Arrays, will be destroyed later.
	 */
	auto Vander = mxCreateNumericMatrix(_numberofpoints, _numberofpoints ,mxDOUBLE_CLASS, mxREAL);
	auto VanderF = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderX = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);


	// extract all nodes from promoted nodes.
	auto Vander_ptr  = mxGetPr(Vander);
	auto VanderF_ptr = mxGetPr(VanderF);
	auto VanderX_ptr = mxGetPr(VanderX);

	for (size_t col = 0; col < _numberofpoints; col++){
		for (size_t i = 0; i < _numberofpoints; i++){
			*Vander_ptr++ = pow(Points[col], i);
		}
	}

	for (size_t col = 0; col < _numberofqpoints; col++) {
		for (size_t i = 0; i < _numberofpoints; i++) {
			*VanderF_ptr++ = pow(qnodes_ptr[col], i);
		}
	}

	for (size_t col = 0; col < _numberofqpoints; col++) {
		for (size_t i = 0 ; i < _numberofpoints ; i++) {
			if (i == 0) {
				*VanderX_ptr++ = 0.;
			}
			else{
				*VanderX_ptr++ = pow(qnodes_ptr[col], i - 1);
			}
		}
	}

	mxArray* RHS_f[] = {Vander, VanderF};
	mexCallMATLAB(1, &F, 2, RHS_f, "mldivide");

	mxArray* RHS_x[] = {Vander, VanderX};
	mexCallMATLAB(1, &DX, 2, RHS_x, "mldivide");

	Points.clear();
	mxDestroyArray(Vander);
	mxDestroyArray(VanderF);<commit_msg>typo in reference<commit_after>/*
 * Assembler.cc
 *
 *  Created on: Oct 9, 2014
 *      Author: lurker
 */
#include "Assembler.h"

Assembler::Assembler(){


}

Assembler::~Assembler() {
#ifdef DEBUG
	mexPrintf("Assembler detached\n");
#endif
}


/*
 * Extract information of basis on Reference Triangle
 */
void Assembler::Reference(MatlabPtr &F, MatlabPtr &DX, MatlabPtr &DY,
		MatlabPtr Points, MatlabPtr QPoints){

	auto _numberofpoints = mxGetN(Points);
	auto _numberofqpoints = mxGetN(QPoints);


	/*
	 *  Temporary Arrays, will be destroyed later.
	 */
	auto Vander = mxCreateNumericMatrix(_numberofpoints,_numberofpoints,mxDOUBLE_CLASS, mxREAL);
	auto VanderF = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderX = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderY = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);


	int deg = round((sqrt(8*_numberofpoints + 1) - 3)/2);

	if ((deg + 1) * (deg + 2)/2 != _numberofpoints){
		mexErrMsgTxt("Invalid length of input nodes\n");
	}

	// extract all nodes from promoted nodes.
	auto Vander_ptr  = mxGetPr(Vander);
	auto VanderF_ptr = mxGetPr(VanderF);
	auto VanderX_ptr = mxGetPr(VanderX);
	auto VanderY_ptr = mxGetPr(VanderY);

	auto nodes_ptr   = mxGetPr(Points);
	auto qnodes_ptr  = mxGetPr(QPoints);

	// basis on all nodes

	for (size_t col = 0; col < _numberofpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++){
				*Vander_ptr++ = pow(nodes_ptr[2*col], i - j)*pow(nodes_ptr[2*col + 1], j);
			}
		}
	}



	// basis on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++){
				*VanderF_ptr++ = pow(qnodes_ptr[2*col], i - j)*pow(qnodes_ptr[2*col + 1], j);
			}
		}
	}

	// partial x on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++) {
				if (j == i){
					*VanderX_ptr++ = 0.;
				}
				else{
					*VanderX_ptr++ = (i - j) * pow(qnodes_ptr[2*col], i - j - 1)*pow(qnodes_ptr[2*col + 1], j);
				}
			}
		}
	}

	// partial y on qnodes
	for (size_t col = 0; col < _numberofqpoints; col++){
		for (size_t i = 0; i < deg + 1; i++){
			for (size_t j = 0; j < i + 1; j++) {
				if (j == 0){
					*VanderY_ptr++ = 0.;
				}
				else{
					*VanderY_ptr++ = j* pow(qnodes_ptr[2*col], i - j)*pow(qnodes_ptr[2*col + 1], j - 1);
				}
			}
		}
	}



	mxArray* RHS_f[] = {Vander, VanderF};
	mexCallMATLAB(1, &F, 2, RHS_f, "mldivide");

	mxArray* RHS_x[] = {Vander, VanderX};
	mexCallMATLAB(1, &DX, 2, RHS_x, "mldivide");

	mxArray* RHS_y[] = {Vander, VanderY};
	mexCallMATLAB(1, &DY, 2, RHS_y, "mldivide");


	mxDestroyArray(Vander);
	mxDestroyArray(VanderF);
	mxDestroyArray(VanderX);
	mxDestroyArray(VanderY);


}

/*
 * 1D reference
 */
void Assembler::Reference(MatlabPtr& F, MatlabPtr& DX, MatlabPtr Degree, MatlabPtr QPoints){
	// Reference segment [-1 , 1],
	// with (Degree - 1) equal-spaced points in between.

	auto _numberofpoints = static_cast<int32_t>(*Matlab_Cast<Real_t>(Degree) + 1);

	vector<Real_t> Points(_numberofpoints);
	Points[0] = -1.;
	Points[1] = 1. ;
	for (size_t i = 2; i < _numberofpoints; i++) {
		Points[i] = (-1.) + 2.0*(i - 1)/static_cast<Real_t>(_numberofpoints - 1);
	}

	// 1D vector-row-majored
	auto _numberofqpoints = mxGetN(QPoints);
	auto qnodes_ptr       = mxGetPr(QPoints);

	/*
	 *  Temporary Arrays, will be destroyed later.
	 */
	auto Vander = mxCreateNumericMatrix(_numberofpoints, _numberofpoints ,mxDOUBLE_CLASS, mxREAL);
	auto VanderF = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);
	auto VanderX = mxCreateNumericMatrix(_numberofpoints, _numberofqpoints, mxDOUBLE_CLASS, mxREAL);


	// extract all nodes from promoted nodes.
	auto Vander_ptr  = mxGetPr(Vander);
	auto VanderF_ptr = mxGetPr(VanderF);
	auto VanderX_ptr = mxGetPr(VanderX);

	for (size_t col = 0; col < _numberofpoints; col++){
		for (size_t i = 0; i < _numberofpoints; i++){
			*Vander_ptr++ = pow(Points[col], i);
		}
	}

	for (size_t col = 0; col < _numberofqpoints; col++) {
		for (size_t i = 0; i < _numberofpoints; i++) {
			*VanderF_ptr++ = pow(qnodes_ptr[col], i);
		}
	}

	for (size_t col = 0; col < _numberofqpoints; col++) {
		for (size_t i = 0 ; i < _numberofpoints ; i++) {
			if (i == 0) {
				*VanderX_ptr++ = 0.;
			}
			else{
				*VanderX_ptr++ = i * pow(qnodes_ptr[col], i - 1);
			}
		}
	}

	mxArray* RHS_f[] = {Vander, VanderF};
	mexCallMATLAB(1, &F, 2, RHS_f, "mldivide");

	mxArray* RHS_x[] = {Vander, VanderX};
	mexCallMATLAB(1, &DX, 2, RHS_x, "mldivide");

	Points.clear();
	mxDestroyArray(Vander);
	mxDestroyArray(VanderF);
{'fraction_non_alphanumeric': 0.16102403343782654, 'fraction_numerical': 0.017972831765935213, 'mean_word_length': 3.77356608478803, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1538468', 'n_tokens_mistral': 4352, 'n_tokens_neox': 3961, 'n_words': 920}