/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * Geophysical Computational Tools & Library (GCTL)
 *
 * Copyright (c) 2022  Yi Zhang (yizhang-geo@zju.edu.cn)
 *
 * GCTL is distributed under a dual licensing scheme. 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 2 
 * of the License, or (at your option) any later version. You should have 
 * received a copy of the GNU Lesser General Public License along with this 
 * program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * If the terms and conditions of the LGPL v.2. would prevent you from using 
 * the GCTL, please consider the option to obtain a commercial license for a 
 * fee. These licenses are offered by the GCTL's original author. As a rule, 
 * licenses are provided "as-is", unlimited in time for a one time fee. Please 
 * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget 
 * to include some description of your company and the realm of its activities. 
 * Also add information on how to contact you by electronic and paper mail.
 ******************************************************/

#include "gctl/core.h"
#include "gctl/io.h"
#include "gctl/potential.h"

using namespace gctl;

int main(int argc, char const *argv[]) try
{
	// set up observation points
	array<point2dc> obs_loc;
	grid_points_1d(obs_loc, 0.0, 200.0, 2.0, 0.0);
	int obs_num = obs_loc.size();

	// set nodes locations
	array<vertex2dc> node_vert(3);
	node_vert[0].set(point2dc(90.0, -30.0));
	node_vert[1].set(point2dc(100.0, -60.0));
	node_vert[2].set(point2dc(110.0, -10.0));

	// set triangular elements
	array<double> rho(1, 1.0);
	array<triangle2d> tri(1);
	// anti-clock wise
	tri[0].set(node_vert[0], node_vert[1], node_vert[2]); // set triangle's vertex from existing vertex

	// forward modeling
	array<double> g(obs_num), gx(obs_num), gzx(obs_num), gzz(obs_num);
	gobser(g, tri, obs_loc, rho, gctl::Vz);
	gobser(gx, tri, obs_loc, rho, gctl::Vx);
	gobser(gzx, tri, obs_loc, rho, gctl::Tzx);
	gobser(gzz, tri, obs_loc, rho, gctl::Tzz);

	geodsv_io fio;
	fio.init_table(obs_num, 6);
	fio.set_column_names({"x", "y", "g", "gx", "gzx", "gzz"});
	fio.fill_column_point2dc(obs_loc, "x", "y");
	fio.fill_column(g, "g");
	fio.fill_column(gx, "gx");
	fio.fill_column(gzx, "gzx");
	fio.fill_column(gzz, "gzz");
	fio.save_text("gobser_tri2d_ex");
	return 0;
}
catch (std::exception &e)
{
	GCTL_ShowWhatError(e.what(), GCTL_ERROR_ERROR, 0, 0, 0);
}