├── References ├── references.pdf └── citation.bib ├── src ├── sites_generation.cpp ├── Forward_polyhedron │ ├── Gravity.cpp │ ├── parameter.h │ ├── Modeling.h │ ├── Gravity.h │ ├── Integral.h │ ├── Modeling.cpp │ └── Integral.cpp ├── Geometry │ ├── Node.cpp │ ├── Node.h │ ├── Tetrahedron.h │ ├── Dyadic.h │ ├── Tetrahedron.cpp │ ├── Polyhedral.h │ ├── Polyhedral.cpp │ ├── Dyadic.cpp │ ├── Point.h │ └── Point.cpp ├── Forward_tetrahedron │ ├── Observation.cpp │ ├── Observation.h │ ├── tet_mesh.h │ ├── tet_model.h │ ├── tet_mesh.cpp │ └── tet_model.cpp ├── GraTet.cpp ├── GraPly.cpp └── timer.h ├── Examples ├── Tetrahedral_grid │ ├── calculate.sh │ ├── mesh_generating.sh │ ├── README.md │ ├── test.poly │ ├── test.poly~ │ ├── test.config │ └── plot.py └── Octahedron │ ├── vertex_edge_interior │ ├── octahedron_model │ ├── octahedron.sh │ ├── README.md │ ├── plot.py │ ├── profile2 │ └── profile1 ├── makefile ├── README.md └── LICENSE /References/references.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhong-yy/GraPly/HEAD/References/references.pdf -------------------------------------------------------------------------------- /src/sites_generation.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhong-yy/GraPly/HEAD/src/sites_generation.cpp -------------------------------------------------------------------------------- /src/Forward_polyhedron/Gravity.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhong-yy/GraPly/HEAD/src/Forward_polyhedron/Gravity.cpp -------------------------------------------------------------------------------- /Examples/Tetrahedral_grid/calculate.sh: -------------------------------------------------------------------------------- 1 | # calculate gravity field and gravity gradient tensor 2 | ./GraTet test.config 3 | 4 | # plot the results 5 | python plot.py -------------------------------------------------------------------------------- /Examples/Tetrahedral_grid/mesh_generating.sh: -------------------------------------------------------------------------------- 1 | ./Sites 0:0.5:10 0:0.5:10 -0.0002 obs_sites 2 | #./tetgen -pq1.5/20Aak test.poly 3 | ./tetgen -pqAak test.poly 4 | #./tetgen -pAk test.poly 5 | -------------------------------------------------------------------------------- /Examples/Octahedron/vertex_edge_interior: -------------------------------------------------------------------------------- 1 | # Comments are prefixed by character '#' 2 | 3 | 3 #3 points 4 | 0 0 0 0 # at a corner (0,0,0) 5 | 1 1 0 1 # on a edge (1,0,1) 6 | 2 0 0 1 # in the interior (0,0,1) 7 | -------------------------------------------------------------------------------- /src/Geometry/Node.cpp: -------------------------------------------------------------------------------- 1 | #include "Node.h" 2 | 3 | 4 | 5 | Node::Node() 6 | { 7 | } 8 | 9 | Node::Node(double x, double y, double z, unsigned int id, int marker):Point(x,y,z) 10 | { 11 | this->id = id; 12 | this->marker = marker; 13 | } 14 | 15 | 16 | 17 | Node::~Node() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /src/Geometry/Node.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Point.h" 3 | #include"parameter.h" 4 | class Node: public Point 5 | { 6 | public: 7 | Node(); 8 | Node(double x, double y, double z, unsigned int id=-1, int marker=-99); 9 | ~Node(); 10 | private: 11 | unsigned int id; 12 | int marker; 13 | //double rho; 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /src/Forward_polyhedron/parameter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | //threhold 5 | const double TOLERANCE = 1e-12; 6 | 7 | //pi 8 | const double PI = 3.1415926535897932384626433832795028841971693993751; 9 | 10 | //Gravitational constant 11 | const double G = 6.673e-11; 12 | static const unsigned int INVALID_UNIT = static_cast(-1); -------------------------------------------------------------------------------- /src/Geometry/Tetrahedron.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Node.h" 3 | #include"Polyhedral.h" 4 | #include 5 | class Tetrahedron:public Polyhedral 6 | { 7 | public: 8 | Tetrahedron(unsigned int id= INVALID_UNIT); 9 | void set_four_nodes(Node* n0, Node* n1, Node* n2, Node* n3); 10 | void set_id(unsigned int id) { this->id = id; } 11 | void set_marker(int marker) { this->marker = marker; } 12 | int get_marker() { return marker; } 13 | ~Tetrahedron(); 14 | 15 | private: 16 | unsigned int id; 17 | int marker; 18 | bool ini_state; 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /Examples/Tetrahedral_grid/README.md: -------------------------------------------------------------------------------- 1 | https://github.com/zhong-yy/GraPly/blob/master/Examples/Tetrahedral_grid/README.md 2 | 3 | 1. Copy 'GraPly' and 'Sites' to the current directory. 4 | 2. Download and install 3D mesh generator tetgen 5 | http://www.wias-berlin.de/software/index.jsp?id=TetGen&lang=1 6 | 3. Copy 'tetgen' to the current directory (or set environment variable) 7 | 4. Run script 'mesh_generating.sh' to generate tetrahedral mesh and measuring points 8 | ``` 9 | sh mesh_generating.sh 10 | ``` 11 | 5. Run script 'calculate.sh' to calculate the gravity field and gravity gradient tensor 12 | ``` 13 | sh calculate.sh 14 | ``` 15 | -------------------------------------------------------------------------------- /Examples/Octahedron/octahedron_model: -------------------------------------------------------------------------------- 1 | # Comments are prefixed by character '#' 2 | 3 | 1 #First line, number of polyhedrons 4 | 5 | #The 1th target body (numbered from 0), which has 6 nodes and 8 facets 6 | 0 6 8 7 | 8 | # Nodes, numbered from zero 9 | # 10 | 0 0 0 0 # 1st node, at (0,0,0) 11 | 1 -1 -1 1 12 | 2 1 -1 1 13 | 3 1 1 1 14 | 4 -1 1 1 15 | 5 0 0 2 16 | 17 | # Facets, numbered from zero 18 | # ... 19 | 0 3 0 1 2 # 1st facet, contains 3 corners (0-1-2) 20 | 1 3 0 1 4 21 | 2 3 0 2 3 22 | 3 3 0 4 3 23 | 4 3 5 1 2 24 | 5 3 5 1 4 25 | 6 3 5 2 3 26 | 7 3 5 4 3 27 | 28 | # Density contrast 29 | 100 30 | 10 5 2 31 | -50 -50 100 1 2 3 32 | 1 1 0.5 0.2 0.5 1 5 8 6 50 33 | -------------------------------------------------------------------------------- /Examples/Tetrahedral_grid/test.poly: -------------------------------------------------------------------------------- 1 | #nodes 2 | 16 3 0 0 3 | 0 0 0 0 4 | 1 10 0 0 5 | 2 10 10 0 6 | 3 0 10 0 7 | 4 0 10 5 8 | 5 10 10 5 9 | 6 10 0 5 10 | 7 0 0 5 11 | 8 3 3 1 12 | 9 7 3 1 13 | 10 7 7 1 14 | 11 3 7 1 15 | 12 3 7 3 16 | 13 7 7 3 17 | 14 7 3 3 18 | 15 3 3 3 19 | 20 | #facets 21 | 12 1 22 | 1 0 1 23 | 4 0 1 2 3 24 | 25 | 1 0 1 26 | 4 4 5 6 7 27 | 28 | 1 0 1 29 | 4 0 1 6 7 30 | 31 | 1 0 1 32 | 4 0 3 4 7 33 | 34 | 1 0 1 35 | 4 2 3 4 5 36 | 37 | 1 0 1 38 | 4 1 2 5 6 39 | 40 | 1 0 0 41 | 4 8 9 10 11 42 | 43 | 1 0 0 44 | 4 12 13 14 15 45 | 46 | 1 0 0 47 | 4 8 9 14 15 48 | 49 | 1 0 0 50 | 4 8 11 12 15 51 | 52 | 1 0 0 53 | 4 10 11 12 13 54 | 55 | 1 0 0 56 | 4 9 10 13 14 57 | 58 | #holes 59 | 0 60 | 61 | 2 62 | 0 5 5 0.2 -1 10 63 | 1 5 5 2 1 10 64 | -------------------------------------------------------------------------------- /Examples/Tetrahedral_grid/test.poly~: -------------------------------------------------------------------------------- 1 | #nodes 2 | 16 3 0 0 3 | 0 0 0 0 4 | 1 10 0 0 5 | 2 10 10 0 6 | 3 0 10 0 7 | 4 0 10 5 8 | 5 10 10 5 9 | 6 10 0 5 10 | 7 0 0 5 11 | 8 4 4 1 12 | 9 6 4 1 13 | 10 6 6 1 14 | 11 4 6 1 15 | 12 4 6 3 16 | 13 6 6 3 17 | 14 6 4 3 18 | 15 4 4 3 19 | 20 | #facets 21 | 12 1 22 | 1 0 1 23 | 4 0 1 2 3 24 | 25 | 1 0 1 26 | 4 4 5 6 7 27 | 28 | 1 0 1 29 | 4 0 1 6 7 30 | 31 | 1 0 1 32 | 4 0 3 4 7 33 | 34 | 1 0 1 35 | 4 2 3 4 5 36 | 37 | 1 0 1 38 | 4 1 2 5 6 39 | 40 | 1 0 0 41 | 4 8 9 10 11 42 | 43 | 1 0 0 44 | 4 12 13 14 15 45 | 46 | 1 0 0 47 | 4 8 9 14 15 48 | 49 | 1 0 0 50 | 4 8 11 12 15 51 | 52 | 1 0 0 53 | 4 10 11 12 13 54 | 55 | 1 0 0 56 | 4 9 10 13 14 57 | 58 | #holes 59 | 0 60 | 61 | 2 62 | 0 5 5 0.2 -1 1.5 63 | 1 5 5 2 1 1.5 64 | 65 | -------------------------------------------------------------------------------- /Examples/Octahedron/octahedron.sh: -------------------------------------------------------------------------------- 1 | # calculate the gravity fields of the octahedron at a vertex point (0,0,0), an edge point (1,0,1), 2 | # and a point inside the octahedron(0,0,1). Output results to file 'g_out_vertex_edge_interior' 3 | ./GraPly octahedron_model vertex_edge_interior g_out_vertex_edge_interior g 4 | 5 | 6 | # calculate gravity and gravity gradient on profile 1, which is outside the octahedron 7 | # output gravity field to file 'g_out_profile1', gravity gradient tensor field to file 'ggt_out_profile1' 8 | ./GraPly octahedron_model profile1 g_out_profile1 g 9 | ./GraPly octahedron_model profile1 ggt_out_profile1 ggt 10 | 11 | # calculate gravity and gravity gradient on profile 2, which is passing through the octahedron 12 | # output gravity field to file 'g_out_profile2', gravity gradient tensor field to file 'ggt_out_profile2' 13 | ./GraPly octahedron_model profile2 g_out_profile2 g 14 | ./GraPly octahedron_model profile2 ggt_out_profile2 ggt 15 | 16 | #plot results on profile1 and profile2 17 | python plot.py 18 | -------------------------------------------------------------------------------- /src/Forward_tetrahedron/Observation.cpp: -------------------------------------------------------------------------------- 1 | #include "Observation.h" 2 | 3 | Observation::Observation() 4 | { 5 | } 6 | 7 | Observation::~Observation() 8 | { 9 | } 10 | 11 | void Observation::read_site(const string &name) 12 | { 13 | ifstream in_stream; 14 | in_stream.open(name.c_str()); 15 | assert(in_stream.good()); 16 | string line; 17 | while (std::getline(in_stream, line)) 18 | { 19 | line_process(line, "#"); 20 | if (line.empty()) 21 | continue; 22 | std::istringstream iss(line); 23 | iss >> n_obs; 24 | break; 25 | } 26 | cout << "\nReading observation sites ...\nThe total number of sites is " << n_obs << ".\n"; 27 | unsigned lab; 28 | obs.resize(n_obs); 29 | double x, y, z; 30 | for (unsigned i = 0; i < n_obs; i++) 31 | { 32 | assert(in_stream.good()); 33 | while (std::getline(in_stream, line)) 34 | { 35 | line_process(line, "#"); 36 | if (line.empty()) 37 | continue; 38 | std::istringstream iss(line); 39 | iss >> lab>> x >> y >> z; 40 | break; 41 | } 42 | obs[i].setPoint(x, y, z); 43 | } 44 | cout << "Reading sites done!\n\n"; 45 | } 46 | -------------------------------------------------------------------------------- /src/GraTet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include"Point.h" 9 | #include"Dyadic.h" 10 | #include"Tetrahedron.h" 11 | #include"tet_model.h" 12 | 13 | using namespace std; 14 | 15 | int main(int argc, char* argv[]) { 16 | clock_t t_start = clock(); 17 | if (argc <2) { 18 | printf("Usage: %s input_paramters_filename\n", argv[0]); 19 | return 1; 20 | } 21 | /**************************command parameters*******************************************/ 22 | //the first input parameter specify the model file 23 | const char *config = argv[1]; 24 | tet_model model; 25 | const string out_g_file("g.dat"); 26 | const string out_ggt_file("ggt.dat"); 27 | 28 | model.read_config(config); 29 | model.compute_g(); 30 | model.out_g(out_g_file.c_str()); 31 | cout << "Calculated gravity data has been written into \"" << out_g_file <<"\""<< endl; 32 | 33 | 34 | 35 | model.compute_ggt(); 36 | model.out_T(out_ggt_file.c_str()); 37 | cout << "Calculated GGT data has been written into \"" << out_ggt_file << "\"" << endl; 38 | return 0; 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/Geometry/Dyadic.h: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | * Dyadic class is to represent a dyadic, in a form of 3 by 3 matrix 3 | * 4 | * Copyright 2017 5 | * Zhong, Yiyuan 6 | * Central South University 7 | ******************************************************************/ 8 | #pragma once 9 | #include"Point.h" 10 | #include 11 | class Dyadic 12 | { 13 | public: 14 | Dyadic(); 15 | Dyadic(Point a, Point b); 16 | Dyadic(double xx, double yx, double zx, double xy, double yy, double zy, double xz, double yz, double zz); 17 | 18 | ~Dyadic(); 19 | //operations of dyadics 20 | Dyadic operator+(const Dyadic& d); 21 | 22 | //subtract 23 | Dyadic operator - (const Dyadic& p)const; 24 | 25 | //plus 26 | Dyadic operator += (const Dyadic& d); 27 | 28 | //multiply 29 | Dyadic operator * (const double a)const; 30 | 31 | //multiply 32 | friend Dyadic operator*(double a, const Dyadic& d); 33 | 34 | //set to zero 35 | void set(); 36 | 37 | //show the values 38 | void display(); 39 | 40 | Point operator[](int i)const; 41 | //entries 42 | double xx, yx, zx; 43 | double xy, yy, zy; 44 | double xz, yz, zz; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /src/GraPly.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"Point.h" 3 | #include"Dyadic.h" 4 | #include 5 | #include 6 | #include"Modeling.h" 7 | #include 8 | #include"timer.h" 9 | #include 10 | using namespace std; 11 | 12 | int main(int argc, char* argv[]) { 13 | // clock_t t_start = clock(); 14 | Timer t; 15 | t.start(); 16 | if (argc <5) { 17 | printf("Usage: %s input_paramters_filename\n", argv[0]); 18 | return 1; 19 | } 20 | const char *model_file = argv[1]; 21 | const char *coor_file = argv[2]; 22 | const char *out_file = argv[3]; 23 | string specifier = argv[4]; 24 | Modeling m; 25 | 26 | m.read_model(model_file); 27 | m.read_site(coor_file); 28 | string field; 29 | if (specifier=="ggt") { 30 | field="gravity gradient tensor"; 31 | cout << "Computing " <id = id; 8 | this->node_number = 4; 9 | this->face_number = 4; 10 | this->node.resize(4); 11 | for (int i = 0; i < node_number; i++) { 12 | node[i] = NULL; 13 | } 14 | 15 | this->face_node_number.resize(4); 16 | this->face_node.resize(4); 17 | this->face_normal_vector.resize(4); 18 | this->faces.resize(4); 19 | 20 | for (int i = 0; i < face_number; i++) { 21 | face_node_number[i] = 3; 22 | face_node[i].resize(3); 23 | } 24 | //face 0 25 | face_node[0][0] = 0; 26 | face_node[0][1] = 1; 27 | face_node[0][2] = 2; 28 | 29 | //face 1 30 | face_node[1][0] = 1; 31 | face_node[1][1] = 2; 32 | face_node[1][2] = 3; 33 | 34 | //face 2 35 | face_node[2][0] = 0; 36 | face_node[2][1] = 1; 37 | face_node[2][2] = 3; 38 | 39 | //face 3 40 | face_node[3][0] = 0; 41 | face_node[3][1] = 2; 42 | face_node[3][2] = 3; 43 | ini_state = false; 44 | } 45 | Tetrahedron::~Tetrahedron() 46 | { 47 | } 48 | 49 | void Tetrahedron::set_four_nodes(Node * n0, Node * n1, Node * n2, Node * n3) 50 | { 51 | node[0] = n0; 52 | node[1] = n1; 53 | node[2] = n2; 54 | node[3] = n3; 55 | this->sort_and_compute_normal_vector(); 56 | this->set_faces_from_indices(); 57 | ini_state = true; 58 | } -------------------------------------------------------------------------------- /src/Forward_tetrahedron/Observation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | *Observation class is to represent a list of observation points and read observation points from ASCII file 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include"Point.h" 10 | class Observation 11 | { 12 | public: 13 | Observation(); 14 | ~Observation(); 15 | void read_site(const string& name); 16 | const Point & operator()(unsigned i) { 17 | assert(i < n_obs); 18 | return obs[i]; 19 | } 20 | void set_obs(unsigned i, double x,double y,double z) { 21 | assert(iobs[i].setPoint(x, y, z); 23 | } 24 | unsigned int get_n_obs() { return n_obs; } 25 | private: 26 | vector obs; 27 | unsigned int n_obs; 28 | 29 | //delete spaces at the begining and the end, and delete comments 30 | void line_process(string &line, const string comment_str = "#") 31 | { 32 | // if(line.size()==1&&(line[0]=='\n'||line[0]=='\r')){ 33 | // cout<<"23333"< 7 | class tet_mesh 8 | { 9 | public: 10 | tet_mesh(); 11 | ~tet_mesh(); 12 | 13 | void clear(); 14 | void read_mesh(string grid_name); 15 | 16 | void set_tet_density_0(int index, const double& rho_const) { 17 | (*tets[index]).const_density = rho_const; 18 | } 19 | void set_tet_density_1(int index, const vector& rho_lin) { 20 | assert(rho_lin.size() == 3); 21 | for (int i = 0; i < 3; i++) { 22 | (*tets[index]).lin[i] = rho_lin[i]; 23 | } 24 | } 25 | void set_tet_density_2(int index, const vector& rho_qua) { 26 | assert(rho_qua.size() == 6); 27 | for (int i = 0; i < 6; i++) { 28 | (*tets[index]).qua[i] = rho_qua[i]; 29 | } 30 | } 31 | void set_tet_density_3(int index, const vector& rho_cub) { 32 | assert(rho_cub.size() == 10); 33 | for (int i = 0; i < 10; i++) { 34 | (*tets[index]).cub[i] = rho_cub[i]; 35 | } 36 | } 37 | 38 | const unsigned int& get_n_nodes() { return n_nodes; } 39 | const unsigned int& get_n_tets() { return n_tets; } 40 | 41 | const vector& get_mesh_nodes() { return mesh_nodes; } 42 | const vector& get_tets() { return tets; } 43 | private: 44 | unsigned int n_nodes; 45 | unsigned int n_tets; 46 | vector mesh_nodes; 47 | vector tets; 48 | 49 | void nodes_in(std::istream& node_stream); 50 | void tets_in(std::istream& ele_stream); 51 | }; -------------------------------------------------------------------------------- /src/Forward_tetrahedron/tet_model.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include"tet_mesh.h" 8 | #include"Observation.h" 9 | #include"timer.h" 10 | class tet_model 11 | { 12 | public: 13 | tet_model(); 14 | ~tet_model(); 15 | 16 | //void read_site(const char * name); 17 | void compute_g(); 18 | void compute_ggt(); 19 | void out_g(const char * name); 20 | void out_T(const char* name); 21 | 22 | void read_config(string config_file); 23 | 24 | void set_density(); 25 | private: 26 | Observation observation; 27 | tet_mesh mesh; 28 | vector g; 29 | vector T; 30 | map region_table_0; 31 | map > region_table_1; 32 | map > region_table_2; 33 | map > region_table_3; 34 | int density_order;//0 or 1 or 2 or 3 35 | 36 | //delete spaces at the begining and the end, and delete comments 37 | void line_process(string &line, const string comment_str = "#") 38 | { 39 | // if(line.size()==1&&(line[0]=='\n'||line[0]=='\r')){ 40 | // cout<<"23333"< 10 | #include 11 | #include 12 | #include"Point.h" 13 | #include"Node.h" 14 | class Polyhedral 15 | { 16 | public: 17 | Polyhedral(); 18 | Polyhedral(int n); 19 | //Polyhedral(unsigned int node_num, unsigned int face_num); 20 | 21 | 22 | ~Polyhedral(); 23 | 24 | void init(); 25 | 26 | void sort_and_compute_normal_vector(); 27 | 28 | //this need to be called after calling "sort_and_compute_normal_vector()"; 29 | void set_faces_from_indices(); 30 | 31 | 32 | void set_node(unsigned int i, Node* node); 33 | 34 | 35 | public: 36 | /*********geometrical parameters************/ 37 | unsigned int node_number; 38 | unsigned int face_number; 39 | 40 | vector node; 41 | 42 | vector face_node_number;// number of nodes on each face 43 | vector > face_node;//indices for nodes on each face 44 | vector > faces; 45 | vector face_normal_vector; 46 | //Point center; 47 | 48 | 49 | 50 | /*********physical parameters************/ 51 | 52 | double const_density; 53 | double lin[3]; 54 | double qua[6]; 55 | double cub[10]; 56 | /* rho=const_density 57 | * +lin[0]*x+lin[1]*y+lin[2]*z 58 | * +qua[0]*x^2+qua[1]*y^2+qua[2]*z^2+qua[3]*xz+qua[4]*yz+qua[5]*xy 59 | * +(cub[0]*z^3+cub[1]*yz^2+cub[2]*y^2*z+cub[3]*y^3) 60 | * +(cub[4]x*z^2+cub[5]*xyz+cub[6]xy^2)+(cub[7]*x^2*z+cub[8]*x^2*y)+cub[9]*x^3 61 | */ 62 | protected: 63 | bool ini_state; 64 | 65 | }; 66 | 67 | -------------------------------------------------------------------------------- /Examples/Octahedron/README.md: -------------------------------------------------------------------------------- 1 | https://github.com/zhong-yy/GraPly/blob/master/Examples/Octahedron/README.md 2 | 3 | The file 'octahedron_model' describes the geometry and density contrast of a octahedral mass body. 4 | 5 | The file 'vertex_edge_interior' contains 3 observation points: a corner point (0, 0, 0), an edge point (1, 0, 1) and an interior point (0,0,1). 6 | 7 | The file 'profile1' contains observation points on a profile outside the octahedron, in a range of x=[-2,2] km, y=0.5 km, and z=-0.001 km. The file 'profile2' contains a measuring profile passing the octahedron, with x=[-2,2] km, y=0.5 km, and z=-0.001 km. The point interval is 0.1 km. 8 | 9 | Assuming you have built the program 'GraPly' using makefile in the '/GraPly' directory, first copy 'GraPly' to the current directory. 10 | 11 | 1. To calculate the gravity field at a corner point, a edge point and an interior point, type 12 | ``` 13 | ./GraPly octahedron_model vertex_edge_interior g_out_vertex_edge_interior g 14 | ``` 15 | The results are written to 'g_out_vertex_edge_interior'. 16 | 17 | 2. To calculate the gravity and gravity gradient tensor on profile 1 type 18 | ``` 19 | ./GraPly octahedron_model profile1 g_out_profile1 g 20 | ./GraPly octahedron_model profile1 ggt_out_profile1 ggt 21 | ``` 22 | The gravity fields are output to 'g_out_profile1', and the gravity gradient tensors are output to 'ggt_out_profile1'. 23 | 24 | 3. To calculate the gravity and gravity gradient tensor on profile 2, type 25 | ``` 26 | ./GraPly octahedron_model profile2 g_out_profile2 g 27 | ./GraPly octahedron_model profile2 ggt_out_profile2 ggt 28 | ``` 29 | The gravity fields are output to 'g_out_profile2', and the gravity gradient tensors are output to 'ggt_out_profile2'. 30 | 31 | 4. use python to plot results on profile1 and profile2 32 | ``` 33 | python plot.py 34 | ``` 35 | 36 | Altanatively, you can use the script octahedron.sh to do all the above things. 37 | -------------------------------------------------------------------------------- /src/Forward_polyhedron/Modeling.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /***************************************************************** 3 | * Modeling class is to read geometrical information of a collection of 4 | * polyhedrons from ASCII files, to read observation sites from files 5 | * and calculate gravity fields and GGTs of all polyhedrons at all 6 | * observation sites. 7 | * 8 | * Copyright 2017 9 | * Zhong, Yiyuan 10 | * Central South University 11 | ******************************************************************/ 12 | #include 13 | #include "Point.h" 14 | #include "Gravity.h" 15 | #include "Node.h" 16 | #include 17 | #include 18 | #include 19 | class Modeling 20 | { 21 | public: 22 | Modeling(); 23 | ~Modeling(); 24 | void read_model(const char *name); 25 | void read_site(const char *name); 26 | void out_g(const char *name); 27 | void out_T(const char *name); 28 | 29 | void analytic_g(); 30 | void analytic_T(); 31 | 32 | private: 33 | vector coor; //array of coordinates for observation sites 34 | vector po; // array of polyhedrons 35 | unsigned num_site; //number of observation sites 36 | unsigned num_po; //number of polyhedrons 37 | vector g; 38 | vector T; 39 | 40 | //delete spaces at the begining and the end, and delete comments 41 | void line_process(string &line, const string comment_str = "#") 42 | { 43 | // if(line.size()==1&&(line[0]=='\n'||line[0]=='\r')){ 44 | // cout<<"23333"<sort_and_compute_normal_vector(); 17 | this->set_faces_from_indices(); 18 | ini_state = true; 19 | } 20 | //compute unit normal vectors and sort 21 | void Polyhedral::sort_and_compute_normal_vector() 22 | { 23 | Point center(0, 0, 0); 24 | for (int i = 0; i < node_number; i++) 25 | { 26 | center += *node[i]; 27 | } 28 | center = center / node_number; 29 | 30 | Point a, b; //temporary variables 31 | 32 | for (int i = 0; i < face_number; i++) 33 | { 34 | //https://stackoverflow.com/questions/32274127/how-to-efficiently-determine-the-normal-to-a-polygon-in-3d-space 35 | //https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal 36 | Point *current, *next; 37 | Point sum_normal(0.0, 0.0, 0.0); 38 | int nodeN = face_node_number[i]; 39 | /*Newell method*/ 40 | for (int k = 0; k < nodeN; k++) 41 | { 42 | current = node[face_node[i][k]]; 43 | next = node[face_node[i][(k + 1) % nodeN]]; 44 | sum_normal.x += (current->y - next->y) * (current->z + next->z); 45 | sum_normal.y += (current->z - next->z) * (current->x + next->x); 46 | sum_normal.z += (current->x - next->x) * (current->y + next->y); 47 | } 48 | 49 | sum_normal.setUnit(); 50 | face_normal_vector[i] = sum_normal; 51 | 52 | // a = *node[face_node[i][1]] - *node[face_node[i][0]]; 53 | // b = *node[face_node[i][2]] - *node[face_node[i][0]]; 54 | // face_normal_vector[i] = unitCross(a, b); 55 | double flag = face_normal_vector[i] * (*node[face_node[i][0]] - center); 56 | if (flag < 0.0) 57 | { 58 | std::reverse(face_node[i].begin(), face_node[i].end()); 59 | face_normal_vector[i].reverse(); 60 | } 61 | } 62 | return; 63 | } 64 | 65 | void Polyhedral::set_faces_from_indices() 66 | { 67 | faces.resize(face_number); 68 | for (int i = 0; i < face_number; i++) 69 | { 70 | faces[i].resize(face_node_number[i]); 71 | 72 | for (int k = 0; k < face_node_number[i]; k++) 73 | { 74 | faces[i][k] = node[face_node[i][k]]; 75 | } 76 | } 77 | } 78 | 79 | void Polyhedral::set_node(unsigned int i, Node *node) 80 | { 81 | assert(i < node_number); 82 | assert(node != NULL); 83 | this->node[i] = node; 84 | } 85 | -------------------------------------------------------------------------------- /src/Geometry/Dyadic.cpp: -------------------------------------------------------------------------------- 1 | #include "Dyadic.h" 2 | 3 | 4 | 5 | Dyadic::Dyadic() 6 | { 7 | xx = 0; yx = 0; zx = 0; 8 | xy = 0; yy = 0; zy = 0; 9 | xz = 0; yz = 0; zz = 0; 10 | } 11 | 12 | Dyadic::Dyadic(Point a, Point b) 13 | { 14 | xx = a.x*b.x; yx = a.y*b.x; zx = a.z*b.x; 15 | xy = a.x*b.y; yy = a.y*b.y; zy = a.z*b.y; 16 | xz = a.x*b.z; yz = a.y*b.z; zz = a.z*b.z; 17 | } 18 | 19 | Dyadic::Dyadic(double xx, double yx, double zx, double xy, double yy, double zy, double xz, double yz, double zz) 20 | { 21 | this->xx = xx; this->yx = yx; this->zx = zx; 22 | this->xy = xy; this->yy = yy; this->zy = zy; 23 | this->xz = xz; this->yz = yz; this->zz = zz; 24 | } 25 | 26 | 27 | Dyadic::~Dyadic() 28 | { 29 | } 30 | 31 | Dyadic Dyadic::operator+(const Dyadic & d) 32 | { 33 | 34 | return Dyadic(this->xx+d.xx,this->yx+d.yx,this->zx+d.zx, 35 | this->xy+d.xy,this->yy+d.yy,this->zy+d.zy, 36 | this->xz+d.xz,this->yz+d.yz,this->zz+d.zz); 37 | } 38 | 39 | Dyadic Dyadic::operator-(const Dyadic & p) const 40 | { 41 | return Dyadic(xx-p.xx,yx-p.yx,zx-p.zx,xy-p.xy,yy-p.yy,zy-p.zy,xz-p.xz,yz-p.yz,zz-p.zz); 42 | } 43 | 44 | Dyadic Dyadic::operator+=(const Dyadic & d) 45 | { 46 | xx += d.xx; 47 | yx += d.yx; 48 | zx += d.zx; 49 | xy += d.xy; 50 | yy += d.yy; 51 | zy += d.zy; 52 | xz += d.xz; 53 | yz += d.yz; 54 | zz += d.zz; 55 | return Dyadic(xx,yx,zx,xy,yy,zy,xz,yz,zz); 56 | } 57 | 58 | Dyadic Dyadic::operator*(const double a) const 59 | { 60 | return Dyadic(xx*a,yx*a,zx*a,xy*a,yy*a,zy*a,xz*a,yz*a,zz*a); 61 | } 62 | 63 | // set to zero 64 | void Dyadic::set() 65 | { 66 | xx = 0; yx = 0; zx = 0; 67 | xy = 0; yy = 0; zy = 0; 68 | xz = 0; yz = 0; zz = 0; 69 | } 70 | 71 | //show 72 | void Dyadic::display() 73 | { 74 | cout << xx << "," << yx << "," << zx << '\n' 75 | << xy << "," << yy <<","<< zy << '\n' 76 | << xz << "," << yz << "," << zz << '\n'; 77 | } 78 | 79 | //get a line of elements 80 | Point Dyadic::operator[](int i)const 81 | { 82 | Point a; 83 | assert(i >= 0 && i <= 2); 84 | switch (i) { 85 | case 0: 86 | a.setPoint(xx, yx, zx); break; 87 | case 1: 88 | a.setPoint(xy, yy, zy); break; 89 | case 2: 90 | a.setPoint(xz, yz, zz); break; 91 | } 92 | return a; 93 | } 94 | 95 | 96 | 97 | Dyadic operator*(double a, const Dyadic & d) 98 | { 99 | return Dyadic(a*d.xx,a*d.yx,a*d.zx,a*d.xy,a*d.yy,a*d.zy,a*d.xz,a*d.yz,a*d.zz); 100 | } 101 | -------------------------------------------------------------------------------- /src/Geometry/Point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /*************************************************** 3 | *Point 4 | * by CSU,ZHONG YIYUAN 5 | * 2017,1,18 6 | **************************************************/ 7 | #include 8 | #include 9 | #include"parameter.h" 10 | using namespace std; 11 | class Point; 12 | Point operator*(double a, const Point & p); 13 | Point cross(const Point& v1, const Point& v2); 14 | Point unitCross(const Point& v1, const Point& v2); 15 | class Point 16 | { 17 | public: 18 | Point(); 19 | ~Point(); 20 | //constructer 21 | Point(double x1, double y1, double z1) :x(x1), y(y1), z(z1) {} 22 | 23 | 24 | //reset the point/vector value 25 | void setPoint(double x0, double y0, double z0); 26 | 27 | //distance from p1 28 | double distance(const Point& p1)const; 29 | 30 | /***********operator*****************/ 31 | //addition and subtraction 32 | Point operator + (const Point& v)const; 33 | Point operator - (const Point& v)const; 34 | 35 | //dot product and scalar multiplication 36 | Point operator * (const double a)const; 37 | friend Point operator*(double a,const Point& p); 38 | double operator * (const Point& v)const; 39 | 40 | Point operator -()const; 41 | void reverse(); 42 | 43 | //cross product 44 | friend Point cross(const Point& v1, const Point& v2); 45 | friend Point unitCross(const Point& v1, const Point& v2); 46 | 47 | //compound assignment 48 | bool operator ==(const Point& p); 49 | Point operator += (const Point& v); 50 | Point operator *= (double a); 51 | 52 | //divided by a real 53 | Point operator/(double a); 54 | Point operator/=(double a); 55 | 56 | // triple product 57 | friend double tripleProduct(const Point& v1, const Point& v2,const Point& v3); 58 | 59 | 60 | /*******other********/ 61 | //get the length of vector (x,y,z) 62 | double size()const; 63 | 64 | Point getUnit()const;//get the unit vector 65 | void setUnit();//to set itself to be a unit vector 66 | 67 | void zero();//reset 68 | 69 | //get the projection onto the plane defined by p1,p2 and p3 70 | Point projection(const Point& p1, const Point& p2, const Point& p3) const; 71 | 72 | //get the projection point on to the straight line passing through points p1 and p2 73 | Point projection_line(const Point& p1, const Point& p2)const; 74 | 75 | //displaying the coordinate of the vector or point, which is used to debug 76 | void display() const{ 77 | cout << "(" << x << "," << y << "," << z << ")\n"; 78 | } 79 | public: 80 | //components 81 | double x, y, z; 82 | }; -------------------------------------------------------------------------------- /Examples/Octahedron/profile2: -------------------------------------------------------------------------------- 1 | # Comments are prefixed by character '#' 2 | 3 | 41 4 | # This profile passes through the octahedron 5 | 1 -2 0.2 0.65 6 | 2 -1.9 0.2 0.65 7 | 3 -1.8 0.2 0.65 8 | 4 -1.7 0.2 0.65 9 | 5 -1.6 0.2 0.65 10 | 6 -1.5 0.2 0.65 11 | 7 -1.4 0.2 0.65 12 | 8 -1.3 0.2 0.65 13 | 9 -1.2 0.2 0.65 14 | 10 -1.1 0.2 0.65 15 | 11 -1 0.2 0.65 16 | 12 -0.9 0.2 0.65 17 | 13 -0.8 0.2 0.65 18 | 14 -0.7 0.2 0.65 19 | 15 -0.6 0.2 0.65 20 | 16 -0.5 0.2 0.65 21 | 17 -0.4 0.2 0.65 22 | 18 -0.3 0.2 0.65 23 | 19 -0.2 0.2 0.65 24 | 20 -0.1 0.2 0.65 25 | 21 0 0.2 0.65 26 | 22 0.1 0.2 0.65 27 | 23 0.2 0.2 0.65 28 | 24 0.3 0.2 0.65 29 | 25 0.4 0.2 0.65 30 | 26 0.5 0.2 0.65 31 | 27 0.6 0.2 0.65 32 | 28 0.7 0.2 0.65 33 | 29 0.8 0.2 0.65 34 | 30 0.9 0.2 0.65 35 | 31 1 0.2 0.65 36 | 32 1.1 0.2 0.65 37 | 33 1.2 0.2 0.65 38 | 34 1.3 0.2 0.65 39 | 35 1.4 0.2 0.65 40 | 36 1.5 0.2 0.65 41 | 37 1.6 0.2 0.65 42 | 38 1.7 0.2 0.65 43 | 39 1.8 0.2 0.65 44 | 40 1.9 0.2 0.65 45 | 41 2 0.2 0.65 46 | -------------------------------------------------------------------------------- /Examples/Octahedron/profile1: -------------------------------------------------------------------------------- 1 | # Comments are prefixed by character # 2 | 3 | 41 # profile 1 4 | # x=[-2, 2] km, y=0.5 km, z= -0.001 km, point inteval: 0.1 km 5 | 1 -2 0.5 -0.001 6 | 2 -1.9 0.5 -0.001 7 | 3 -1.8 0.5 -0.001 8 | 4 -1.7 0.5 -0.001 9 | 5 -1.6 0.5 -0.001 10 | 6 -1.5 0.5 -0.001 11 | 7 -1.4 0.5 -0.001 12 | 8 -1.3 0.5 -0.001 13 | 9 -1.2 0.5 -0.001 14 | 10 -1.1 0.5 -0.001 15 | 11 -1 0.5 -0.001 16 | 12 -0.9 0.5 -0.001 17 | 13 -0.8 0.5 -0.001 18 | 14 -0.7 0.5 -0.001 19 | 15 -0.6 0.5 -0.001 20 | 16 -0.5 0.5 -0.001 21 | 17 -0.4 0.5 -0.001 22 | 18 -0.3 0.5 -0.001 23 | 19 -0.2 0.5 -0.001 24 | 20 -0.1 0.5 -0.001 25 | 21 0 0.5 -0.001 26 | 22 0.1 0.5 -0.001 27 | 23 0.2 0.5 -0.001 28 | 24 0.3 0.5 -0.001 29 | 25 0.4 0.5 -0.001 30 | 26 0.5 0.5 -0.001 31 | 27 0.6 0.5 -0.001 32 | 28 0.7 0.5 -0.001 33 | 29 0.8 0.5 -0.001 34 | 30 0.9 0.5 -0.001 35 | 31 1 0.5 -0.001 36 | 32 1.1 0.5 -0.001 37 | 33 1.2 0.5 -0.001 38 | 34 1.3 0.5 -0.001 39 | 35 1.4 0.5 -0.001 40 | 36 1.5 0.5 -0.001 41 | 37 1.6 0.5 -0.001 42 | 38 1.7 0.5 -0.001 43 | 39 1.8 0.5 -0.001 44 | 40 1.9 0.5 -0.001 45 | 41 2 0.5 -0.001 46 | -------------------------------------------------------------------------------- /src/Geometry/Point.cpp: -------------------------------------------------------------------------------- 1 | #include "Point.h" 2 | Point::Point() 3 | { 4 | } 5 | 6 | Point::~Point() 7 | { 8 | } 9 | 10 | 11 | void Point::setPoint(double x0, double y0, double z0) 12 | { 13 | x = x0;y = y0;z = z0; 14 | } 15 | 16 | double Point::distance(const Point & p1)const 17 | { 18 | //double x0 = p1.x - x; 19 | //double y0 = p1.y - y; 20 | //double z0 = p1.z - z; 21 | return sqrt((p1.x - x )*(p1.x - x) +(p1.y - y)*(p1.y - y)+(p1.z - z)*(p1.z - z)); 22 | } 23 | 24 | Point Point::operator+(const Point & v)const 25 | { 26 | return Point(x+v.x,y+v.y,z+v.z); 27 | } 28 | 29 | Point Point::operator-(const Point & v)const 30 | { 31 | return Point(x-v.x,y-v.y,z-v.z); 32 | } 33 | 34 | Point Point::operator*(const double a)const 35 | { 36 | return Point(x*a,y*a,z*a); 37 | } 38 | 39 | double Point::operator*(const Point & v)const 40 | { 41 | return (x*v.x+y*v.y+z*v.z); 42 | } 43 | 44 | Point Point::operator-() const 45 | { 46 | return Point(-x,-y,-z); 47 | } 48 | 49 | void Point::reverse() 50 | { 51 | x = -x; 52 | y = -y; 53 | z = -z; 54 | 55 | } 56 | 57 | bool Point::operator==(const Point & p) 58 | { 59 | Point r = (*this) - p; 60 | return r.size()tets.clear(); 25 | 26 | for (unsigned int j = 0; j < n_nodes; j++) { 27 | if (mesh_nodes[j] != NULL) { 28 | delete mesh_nodes[j]; 29 | mesh_nodes[j] = NULL; 30 | } 31 | } 32 | this->mesh_nodes.clear(); 33 | } 34 | 35 | void tet_mesh::read_mesh(string grid_name) 36 | { 37 | string name_node, name_ele; 38 | string dummy = grid_name; 39 | name_node = dummy + string(".node"); 40 | name_ele = dummy + string(".ele"); 41 | 42 | ifstream node_stream(name_node.c_str()); 43 | ifstream ele_stream(name_ele.c_str()); 44 | assert(node_stream.good()); 45 | assert(ele_stream.good()); 46 | cout << "Reading mesh with tetrahedal elements ....\n"; 47 | nodes_in(node_stream); 48 | tets_in(ele_stream); 49 | 50 | return; 51 | 52 | } 53 | 54 | void tet_mesh::nodes_in(std::istream & node_stream) 55 | { 56 | assert(node_stream.good());// Check input buffer 57 | unsigned int dimension = 0, nAttributes = 0, BoundaryMarkers = 0; 58 | node_stream >> n_nodes // Read the number of nodes from the stream 59 | >> dimension // Read the dimension from the stream 60 | >> nAttributes // Read the number of attributes from stream 61 | >> BoundaryMarkers; // Read if or not boundary markers are included in *.node (0 or 1) 62 | cout << "Number of nodes: " << n_nodes<0); 65 | assert(nAttributes == 0); 66 | assert(BoundaryMarkers == 0);//boundary marker is currently not necessary 67 | this->mesh_nodes.clear(); 68 | this->mesh_nodes.resize(n_nodes); 69 | unsigned int node_lab = 0; 70 | double x, y, z; 71 | int marker; 72 | for (unsigned int i = 0; i> node_lab // node number 77 | >> x // x-coordinate value 78 | >> y // y-coordinate value 79 | >> z; // z-coordinate value 80 | Node* newnode = new Node(x, y, z); 81 | this->mesh_nodes[i] = newnode; 82 | } 83 | return; 84 | 85 | } 86 | 87 | void tet_mesh::tets_in(std::istream & ele_stream) 88 | { 89 | // Check input buffer 90 | assert(ele_stream.good()); 91 | unsigned int tet_lab = 0, n_nodes_tet = 0, nAttri = 0; 92 | //n_nodes_tet: number of nodes associated with each element 93 | this->n_tets = 0; 94 | int tet_marker = 0; 95 | ele_stream >> n_tets // Read the number of trirahedrons from the stream. 96 | >> n_nodes_tet // Linear or second Tet(4 or 10, defaults to 4). 97 | >> nAttri; // Read the number of region attributes from stream. 98 | cout << "Number of elements: " << n_tets<0); 100 | assert(n_nodes_tet == 4); 101 | assert(nAttri == 1); 102 | 103 | this->tets.clear(); 104 | this->tets.resize(n_tets); 105 | 106 | for (unsigned int i = 0; itets[i] = new Tetrahedron; 110 | // Read the label 111 | ele_stream >> tet_lab; 112 | this->tets[i]->set_id(tet_lab); 113 | // Read node labels 114 | for (unsigned int j = 0; j<4; j++) 115 | { 116 | unsigned long int node_label; 117 | ele_stream >> node_label; 118 | // Assign node to trient 119 | this->tets[i]->set_node(j, this->mesh_nodes[node_label]); 120 | } 121 | this->tets[i]->init();//sort the nodes, and compute normals, and set face nodes pointers 122 | 123 | // Read attributes from the stream. 124 | ele_stream >> tet_marker; 125 | this->tets[i]->set_marker(tet_marker);// Only 1 atrri. 126 | } 127 | return; 128 | 129 | 130 | 131 | } -------------------------------------------------------------------------------- /src/Forward_polyhedron/Gravity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /***************************************************************** 3 | *Gravity class is to calculate gravity and gravity gradient of a 4 | *single polyhedral mass body with (cubic) polynomial density contrast 5 | * 6 | *Copyright 2017 7 | *Zhong, Yiyuan 8 | *Central South University 9 | ******************************************************************/ 10 | #include"Integral.h" 11 | #include"Polyhedral.h" 12 | #include"Dyadic.h" 13 | class Gravity 14 | { 15 | public: 16 | Gravity(); 17 | ~Gravity(); 18 | 19 | /******Computation of gravity field due to a polyhedral body with polynomial density contrast*******/ 20 | Point g_const(const Polyhedral& phl, const Point& ob, const double& rho); 21 | //constant density, x-component of gravity field, unit:mGal 22 | double gx_const(const Polyhedral& phl, const Point& ob, const double& rho); 23 | //constant density, y-component of gravity field, unit:mGal 24 | double gy_const(const Polyhedral& phl, const Point& ob, const double& rho); 25 | //constant density, x-component of gravity field, unit:mGal 26 | double gz_const(const Polyhedral& phl, const Point& ob, const double& rho); 27 | 28 | //linearly varying density in x,y,z direction, unit:mGal 29 | Point g_1st(const Polyhedral& phl, const Point& ob, 30 | const double& a, const double& b, const double& c); 31 | 32 | double gx_1st(const Polyhedral& phl, const Point& ob, 33 | const double& a, const double& b, const double& c); 34 | 35 | double gy_1st(const Polyhedral& phl, const Point& ob, 36 | const double& a, const double& b, const double& c); 37 | double gz_1st(const Polyhedral& phl, const Point& ob, 38 | const double& a, const double& b, const double& c); 39 | 40 | 41 | 42 | //quadraticly varying density in x y z direction, unit:mGal 43 | //rho:a*x^2+by^2+c*z^2+d*xz+e*yz+f*xy 44 | Point g_2nd(const Polyhedral& poh, const Point& ob, 45 | const double& a, const double& b, const double& c, 46 | const double& d, const double& e, const double& f); 47 | double gx_2nd(const Polyhedral& poh, const Point& ob, 48 | const double& a, const double& b, const double& c, const double& d, const double& e, const double& f); 49 | double gy_2nd(const Polyhedral& poh, const Point& ob, 50 | const double& a, const double& b, const double& c, const double& d, const double& e, const double& f); 51 | double gz_2nd(const Polyhedral& poh, const Point& ob, 52 | double a, double b, double c, double d, double e, double f); 53 | 54 | Point g_3rd(const Polyhedral& po, const Point& ob, double a[10]); 55 | 56 | 57 | /************computation of gravity gradient tensor**************************************************/ 58 | 59 | //constant density contrast 60 | Dyadic tensor_const(const Polyhedral& phl, const Point& ob, const double& rho); 61 | 62 | //linear density contrast 63 | Dyadic tensor_1st(const Polyhedral& phl, const Point& ob, const double& a, const double &b, const double& c); 64 | 65 | //quadratic density contrast 66 | Dyadic tensor_2nd(const Polyhedral& phl, const Point& ob, double a, double b, double c, double d, double e, double f); 67 | 68 | //cubic density contrast 69 | Dyadic tensor_3rd(const Polyhedral& po, const Point& ob, double a[10]); 70 | 71 | 72 | 73 | private: 74 | //local coordinate system where ob is the origin 75 | //but the parameter "ob" is described by global coordinates 76 | Point g_1st0(const Polyhedral& phl, const Point& ob, double a, double b, double c); 77 | double gx_1st0(const Polyhedral& phl, const Point& ob, double a, double b, double c); 78 | double gy_1st0(const Polyhedral& phl, const Point& ob, double a, double b, double c); 79 | double gz_1st0(const Polyhedral& phl, const Point& ob,double a,double b,double c); 80 | 81 | Point g_2nd0(const Polyhedral& poh, const Point& ob, double a, double b, double c, double d, double e, double f); 82 | double gx_2nd0(const Polyhedral& poh, const Point& ob, double a, double b, double c, double d, double e, double f); 83 | double gy_2nd0(const Polyhedral& poh, const Point& ob, double a, double b, double c, double d, double e, double f); 84 | double gz_2nd0(const Polyhedral& poh, const Point& ob, double a,double b,double c,double d,double e,double f); 85 | 86 | Point g_3rd0(const Polyhedral& po, const Point& ob,double a[10]); 87 | 88 | //in local coordinate system 89 | Dyadic tensor_1st0(const Polyhedral& phl, const Point& ob, double a, double b, double c); 90 | Dyadic tensor_2nd0(const Polyhedral& phl, const Point& ob, double a, double b, double c, double d, double e, double f); 91 | Dyadic tensor_3rd0(const Polyhedral& po, const Point& ob, double a[10]); 92 | 93 | 94 | }; 95 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // Timer.h 3 | // ======= 4 | // High Resolution Timer. 5 | // This timer is able to measure the elapsed time with 1 micro-second accuracy 6 | // in both Windows, Linux and Unix system 7 | // 8 | // AUTHOR: Song Ho Ahn (song.ahn@gmail.com) 9 | // CREATED: 2003-01-13 10 | // UPDATED: 2006-01-13 11 | // 12 | // Copyright (c) 2003 Song Ho Ahn 13 | ////////////////////////////////////////////////////////////////////////////// 14 | 15 | #ifndef TIMER_H_DEF 16 | #define TIMER_H_DEF 17 | 18 | #ifdef WIN32 // Windows system specific 19 | #include 20 | #else // Unix based system specific 21 | #include 22 | #endif 23 | 24 | #include 25 | 26 | class Timer 27 | { 28 | public: 29 | Timer(); // default constructor 30 | ~Timer(); // default destructor 31 | 32 | void start(); // start timer 33 | void stop(); // stop the timer 34 | double getElapsedTime(); // get elapsed time in second 35 | double getElapsedTimeInSec(); // get elapsed time in second (same as getElapsedTime) 36 | double getElapsedTimeInMilliSec(); // get elapsed time in milli-second 37 | double getElapsedTimeInMicroSec(); // get elapsed time in micro-second 38 | 39 | 40 | protected: 41 | 42 | 43 | private: 44 | double startTimeInMicroSec; // starting time in micro-second 45 | double endTimeInMicroSec; // ending time in micro-second 46 | int stopped; // stop flag 47 | #ifdef WIN32 48 | LARGE_INTEGER frequency; // ticks per second 49 | LARGE_INTEGER startCount; // 50 | LARGE_INTEGER endCount; // 51 | #else 52 | timeval startCount; // 53 | timeval endCount; // 54 | #endif 55 | }; 56 | 57 | 58 | /////////////////////////////////////////////////////////////////////////////// 59 | // constructor 60 | /////////////////////////////////////////////////////////////////////////////// 61 | inline Timer::Timer() 62 | { 63 | #ifdef WIN32 64 | QueryPerformanceFrequency(&frequency); 65 | startCount.QuadPart = 0; 66 | endCount.QuadPart = 0; 67 | #else 68 | startCount.tv_sec = startCount.tv_usec = 0; 69 | endCount.tv_sec = endCount.tv_usec = 0; 70 | #endif 71 | 72 | stopped = 0; 73 | startTimeInMicroSec = 0; 74 | endTimeInMicroSec = 0; 75 | } 76 | 77 | 78 | 79 | /////////////////////////////////////////////////////////////////////////////// 80 | // distructor 81 | /////////////////////////////////////////////////////////////////////////////// 82 | inline Timer::~Timer() 83 | { 84 | } 85 | 86 | 87 | 88 | /////////////////////////////////////////////////////////////////////////////// 89 | // start timer. 90 | // startCount will be set at this point. 91 | /////////////////////////////////////////////////////////////////////////////// 92 | inline 93 | void Timer::start() 94 | { 95 | stopped = 0; // reset stop flag 96 | #ifdef WIN32 97 | QueryPerformanceCounter(&startCount); 98 | #else 99 | gettimeofday(&startCount, NULL); 100 | #endif 101 | } 102 | 103 | 104 | 105 | /////////////////////////////////////////////////////////////////////////////// 106 | // stop the timer. 107 | // endCount will be set at this point. 108 | /////////////////////////////////////////////////////////////////////////////// 109 | inline 110 | void Timer::stop() 111 | { 112 | stopped = 1; // set timer stopped flag 113 | 114 | #ifdef WIN32 115 | QueryPerformanceCounter(&endCount); 116 | #else 117 | gettimeofday(&endCount, NULL); 118 | #endif 119 | } 120 | 121 | 122 | 123 | /////////////////////////////////////////////////////////////////////////////// 124 | // compute elapsed time in micro-second resolution. 125 | // other getElapsedTime will call this first, then convert to correspond resolution. 126 | /////////////////////////////////////////////////////////////////////////////// 127 | inline 128 | double Timer::getElapsedTimeInMicroSec() 129 | { 130 | #ifdef WIN32 131 | if(!stopped) 132 | QueryPerformanceCounter(&endCount); 133 | 134 | startTimeInMicroSec = startCount.QuadPart * (1000000.0 / frequency.QuadPart); 135 | endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart); 136 | #else 137 | if(!stopped) 138 | gettimeofday(&endCount, NULL); 139 | 140 | startTimeInMicroSec = (startCount.tv_sec * 1000000.0) + startCount.tv_usec; 141 | endTimeInMicroSec = (endCount.tv_sec * 1000000.0) + endCount.tv_usec; 142 | #endif 143 | 144 | return endTimeInMicroSec - startTimeInMicroSec; 145 | } 146 | 147 | 148 | 149 | /////////////////////////////////////////////////////////////////////////////// 150 | // divide elapsedTimeInMicroSec by 1000 151 | /////////////////////////////////////////////////////////////////////////////// 152 | inline 153 | double Timer::getElapsedTimeInMilliSec() 154 | { 155 | return this->getElapsedTimeInMicroSec() * 0.001; 156 | } 157 | 158 | 159 | 160 | /////////////////////////////////////////////////////////////////////////////// 161 | // divide elapsedTimeInMicroSec by 1000000 162 | /////////////////////////////////////////////////////////////////////////////// 163 | inline 164 | double Timer::getElapsedTimeInSec() 165 | { 166 | return this->getElapsedTimeInMicroSec() * 0.000001; 167 | } 168 | 169 | 170 | 171 | /////////////////////////////////////////////////////////////////////////////// 172 | // same as getElapsedTimeInSec() 173 | /////////////////////////////////////////////////////////////////////////////// 174 | inline 175 | double Timer::getElapsedTime() 176 | { 177 | return this->getElapsedTimeInSec(); 178 | } 179 | 180 | #endif // TIMER_H_DEF 181 | 182 | -------------------------------------------------------------------------------- /src/Forward_polyhedron/Integral.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /***************************************************************** 4 | * Integral class is to calculte some useful line integrals and surface 5 | * integrals in terms of closed-form formulae. 6 | * 7 | * Copyright 2017 8 | * Zhong, Yiyuan 9 | * Central South University 10 | ******************************************************************/ 11 | #include 12 | #include 13 | #include 14 | #include"Point.h" 15 | #include"Node.h" 16 | #include 17 | 18 | using namespace std; 19 | class Integral 20 | { 21 | public: 22 | Integral(); 23 | ~Integral(); 24 | 25 | 26 | //caculate the solid angle of projection onto face from observation site 27 | static double getBeta(const Point& observation, const vector& face); 28 | 29 | 30 | 31 | /****************************************Line integrals*****************************************/ 32 | //line integral of R, v0 and v1 are the endpoints of the edge 33 | static double Line_R1(const Point& observation, const Point& v0, const Point& v1); 34 | 35 | //line integral of R^3 36 | static double Line_R3(const Point& observation, const Point& v0, const Point& v1); 37 | 38 | /*calculate the line integral of 1/R,observation site cannot locate on edge v0-v1, 39 | but it can locate on the extension of the edge*/ 40 | static double Line_R_1(const Point& observation, const Point& v0, const Point& v1); 41 | 42 | //Bj:mj*integral(R/(mj+s)^2)dl,see equation(51)-(52) Ren(2017) in "Survey in Geophysics" 43 | //normal is the unit vector normal to the plane, which is used to determine the plane 44 | static double Line_Bj1(const Point& observation,const Point& v0, const Point& v1, const Point& normal); 45 | static double Line_Bj3(const Point& observation,const Point& v0, const Point& v1, const Point& unit_normal); 46 | 47 | //calculate the line integral of rR,where r=(x,y,z) and r'=(0,0,0), 48 | //ob means observation point, v0 and v1 are the endpoints 49 | static Point Line_rR1(const Point& ob, const Point& v0, const Point& v1); 50 | 51 | //calculate the line integral of r/R,where r=(x,y,z) and r'=(0,0,0). 52 | //observation site cannot locate on edge v0-v1,though it can locate on the extension of the edge 53 | static Point Line_rR_1(const Point& ob, const Point& v0, const Point& v1); 54 | 55 | //calculate the line integral of x^2*R, y^2*R, z^2*R, xz*R,yz*R,xy*R 56 | static double Line_x2R(const Point& ob,const Point& v0,const Point& v1); 57 | static double Line_y2R(const Point& ob, const Point& v0, const Point& v1); 58 | static double Line_z2R(const Point& ob, const Point& v0, const Point& v1); 59 | static double Line_xzR(const Point& ob, const Point& v0, const Point& v1); 60 | static double Line_yzR(const Point& ob, const Point& v0, const Point& v1); 61 | static double Line_xyR(const Point& ob,const Point& v0, const Point& v1); 62 | 63 | //calculate the line integral of x^2/R, y^2/R, z^2/R, xz/R,yz/R,xy/R 64 | static double Line_x2R_1(const Point& ob, const Point& v0,const Point& v1); 65 | static double Line_y2R_1(const Point& ob, const Point& v0,const Point& v1); 66 | static double Line_z2R_1(const Point& ob, const Point& v0,const Point& v1); 67 | static double Line_xzR_1(const Point& ob, const Point& v0,const Point& v1); 68 | static double Line_yzR_1(const Point& ob, const Point& v0,const Point& v1); 69 | static double Line_xyR_1(const Point& ob, const Point& v0,const Point& v1); 70 | 71 | /*To calculate the line integral of xp*xq*xt/R^3, where xp, xq, xt can be x y or z. 72 | *The string s is used to specify the integrand. 73 | *Possible values of s are "x3","y3","z3","x2y","x2z","y2x","y2z","z2x","z2y","xyz" 74 | *For example, Line_f3R_1(ob, v0, v1,"xyz") mean the integrand is xyz/R 75 | **/ 76 | static double Line_f3R_1(const Point& ob, const Point& v0, const Point& v1,string s); 77 | 78 | 79 | 80 | 81 | 82 | /***************************************Surface integrals**************************************/ 83 | //calculate the surface integral of R*ds,face_node is the nodes on the face,n is the number of nodes 84 | static double Surface_R1(const Point& observation, const vector& face_node, int n); 85 | 86 | //calculate the surface integral of (1/R)*ds 87 | static double Surface_R_1(const Point& observation, const vector& face_node, int n); 88 | 89 | /*To calculate the surface integral of (rR)*ds. 90 | *Return value is a vector of (integral{xR}ds,integral{yR}ds,integral{zR}ds) 91 | */ 92 | static Point Surface_rR1(const Point& observation, const vector& face_node, int n); 93 | 94 | /*To compute the surface integra of (r/R)*ds 95 | *Return value is a vector of (integral{x/R}ds,integral{y/R}ds,integral{z/R}ds) 96 | */ 97 | static Point Surface_rR_1(const Point& observation, const vector& face_node, int n); 98 | 99 | /*To compute the surface integral of (f^2/R)*ds, where f=x, y or z. 100 | *Return value is a vector of (integral{x^2/R}ds,integral{y^2/R}ds,integral{z^2/R}ds) 101 | */ 102 | static Point Surface_r2R_1(const Point& observation, const vector& face_node, int n); 103 | 104 | /*To compute the surface integral of (xz/R)ds */ 105 | static double Surface_xzR_1(const Point& observation, const vector& face_node, int n); 106 | /*To compute the surface integral of (yz/R)ds */ 107 | static double Surface_yzR_1(const Point& observation, const vector& face_node, int n); 108 | /*To compute the surface integral of (xy/R)ds */ 109 | static double Surface_xyR_1(const Point& observation, const vector& face_node, int n); 110 | 111 | /*To compute the surface integral of (1/R^3)ds */ 112 | static double Surface_R_3(const Point& ob, const vector& face_node, int n); 113 | 114 | /*To compute the surface integral of (r/R^3)ds ,r=(x,y,z) 115 | return a vector of (integral{x/R^3}ds,integral{y/R^3}ds,integral{z/R^3}ds) 116 | */ 117 | static Point Surface_rR_3(const Point& ob, const vector& face_node, int n); 118 | 119 | //To compute the surface integral of x2/R^3 120 | static double Surface_x2R_3(const Point& ob, const vector& face_node, int n); 121 | 122 | //To compute the surface integral of y2/R^3 123 | static double Surface_y2R_3(const Point& ob, const vector& face_node, int n); 124 | 125 | //To compute the surface integral of z2/R^3 126 | static double Surface_z2R_3(const Point& ob, const vector& face_node, int n); 127 | 128 | //To compute the surface integral of xz/R^3 129 | static double Surface_xzR_3(const Point& ob, const vector& face_node, int n); 130 | 131 | //To compute the surface integral of yz/R^3 132 | static double Surface_yzR_3(const Point& ob, const vector& face_node, int n); 133 | 134 | //To compute the surface integral of xy/R^3 135 | static double Surface_xyR_3(const Point& ob, const vector& face_node, int n); 136 | 137 | //To compute the surface integral of (xp*xq*xt/R)ds, where xp, xq, xt can be x or y or z. 138 | static void Surface_r3R_1(const Point& ob, const vector& face, int n, 139 | double& x3R_1, double& y3R_1, double &z3R_1, 140 | double &x2yR_1, double& x2zR_1, 141 | double &y2xR_1, double& y2zR_1, 142 | double &z2xR_1, double& z2yR_1, 143 | double &xyzR_1); 144 | 145 | //To compute the surfae integral of (xp*xq*xt/R^3)ds 146 | static void Surface_f3R_3(const Point& ob, const vector& face, int n, 147 | double& x3R_3, double& y3R_3, double &z3R_3, 148 | double &x2yR_3, double& x2zR_3, 149 | double &y2xR_3, double& y2zR_3, 150 | double &z2xR_3, double& z2yR_3, 151 | double &xyzR_3); 152 | }; 153 | 154 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GraPly 2 | 3 | [![DOI](https://zenodo.org/badge/146179778.svg)](https://zenodo.org/badge/latestdoi/146179778) 4 | 5 | It's a C++ program for computing gravity fields and gravity gradient tensors (GGT) caused by polyhedrons with polynomial density contrasts (up to cubic order). Singularity-free analytical solutions are used in the calculation. For gravity, observation sites can be located inside, on, or outside the 3D mass bodies. For gravity gradient tensor, observation sites can be located everywhere except on the egdes or at the corners of polyhedrons (though on a facet the GGT values are evaluated as average of left-handed and righ-handed limits). 6 | 7 | 8 | ## 1 Building 9 | 'cd' to the 'GraPly' directory and type 'make' to compile. If everything goes well, you will get three executable programs: **GraPly**, **GraTet** and **Sites** 10 | 11 | - **GraPly** is a program to calculate the gravity and GGT of (convex) general polyhedrons using singularity-free closed-form solutions. 12 | - **GraTet** is a program for forward modelling of gravity fields and GGTs using tetrahedral unstructured grids. 13 | - **Sites** generates regular grid of measuring points in a ASCII file. 14 | 15 | To remove the program binaries and object files, just type 'make clean'. 16 | 17 | ## 2 How to use 18 | ### 2.1 GraPly 19 | The command to use '**GraPly**' is 20 | ``` 21 | GraPly model_file observation_file output_file field_flag 22 | ``` 23 | The 'field_flag' can be 'g' or 'ggt'. If 'g' is used, the gravity field will be calculated; if 'ggt' is used, the gravity gradient tensor field will be calculated. 24 | 25 | **Model file** 26 | The 'model_file' is a file containing descriptions about polyhedrons. The format for the model file is 27 | ``` 28 | ********************************************************************************* 29 | First line: 30 | Following lines: 31 | 32 | ... 33 | 34 | ********************************************************************************* 35 | ``` 36 | where the format for is 37 | ``` 38 | One line: 39 | Following lines list nodes: 40 | 41 | ... 42 | Following lines list facets: 43 | ... 44 | Folowing lines list polynomial coefficients of polynomial density contrast: 45 | a000 46 | a100 a010 a001 47 | a200 a020 a002 a101 a011 a110 48 | a003 a012 a021 a030 a102 a111 a120 a201 a210 a300 49 | ``` 50 | 51 | Given the polynomial coefficients in the model file, the polynomial density contrast is 52 | ``` 53 | a000 54 | + a100*x + a010*y + a001*z 55 | + a200*x^2 + a020*y^2 + a002*z^2 + a101*x*z + a011*y*z + a110*x*y 56 | + a003*z^3 + a012*y*z^2 + a021*y^2*z + a030*y^3 + a102*x*z^2+ a111*x*y*z+ a120*x*y^2+ a201*x^2*z+ a210*x^2*y+ a300x^3 57 | ``` 58 | i.e. 59 | 60 | ![](http://latex.codecogs.com/gif.latex?\\rho=a_{000}+a_{100}x+a_{010}y+a_{001}z+a_{200}x^2+a_{020}y^2+a_{002}z^2+a_{101}xz+a_{011}yz+a_{110}xy+a_{003}z^3+a_{012}yz^2+a_{021}y^2z+a_{030}y^3+a_{102}xz^2+a_{111}xyz+a_{120}xy^2+a_{201}x^2z+a_{210}x^2y+a_{300}x^3) 61 | 62 | In the model file, all polyhedrons, facets of a single polyhedron,and corners of a single facet are numbered from zero. The units for x, y, z are kilometer, and the unit for density contrast is kilogram per cubic meter. 63 | 64 | **Observation point file** 65 | The format for files containing observation points is given as 66 | ``` 67 | ********************************************************************************* 68 | First line: 69 | Following lines list coordinates of points: 70 | 71 | ... 72 | ********************************************************************************* 73 | ``` 74 | The obervation points can be numbered from zero or one. Comments in the files are prefixed by charactor '#'. 75 | 76 | An example is given in the folder '/Examples/Octahedron/' . 77 | 78 | ### 2.2 GraTet 79 | The command for '**GraTet**' is 80 | ``` 81 | GraTet configuration_file 82 | ``` 83 | The configuration file contains information about mesh files and density contrasts of different regions. The format is 84 | ``` 85 | ********************************************************************************* 86 | 87 | 88 | #0, 1, 2 or 3 89 | # agree with the number of regions specified in *.poly file 90 | #region marker 91 | 92 | ... # next region 93 | ********************************************************************************* 94 | ``` 95 | The polynomial coefficients given in the file as 96 | ``` 97 | a000 98 | a100 a010 a001 99 | a200 a020 a002 a101 a011 a110 100 | a003 a012 a021 a030 a102 a111 a120 a201 a210 a300 101 | ``` 102 | will define the following density contrast: 103 | ``` 104 | a000 105 | + a100*x + a010*y + a001*z 106 | + a200*x^2 + a020*y^2 + a002*z^2 + a101*x*z + a011*y*z + a110*x*y 107 | + a003*z^3 + a012*y*z^2 + a021*y^2*z + a030*y^3 + a102*x*z^2+ a111*x*y*z+ a120*x*y^2+ a201*x^2*z+ a210*x^2*y+ a300x^3 108 | ``` 109 | 110 | An example is given in the folder '/Examples/Tetrahedral_grid/' . 111 | 112 | ## 2.3 Sites 113 | **Sites** is a tool to generate regular grid of measuring points. 114 | 115 | The command is 116 | ``` 117 | Sites x_start:x_interval:x_end y_start:y_interval:y_end z output_file_name 118 | ``` 119 | 120 | To generate a measuring profile with x=[0,10], y=0, z=-0.001 and 0.5 point interval, and write results to file 'out', type 121 | ``` 122 | ./Sites 0:0.5:10 0 -0.001 out 123 | ``` 124 | 125 | To generate a grid with z=-0.001, x=[0,10], y=[0,10], point interval 0.5, and write results to file 'out', type 126 | ``` 127 | ./Sites 0:0.5:10 0:0.5:10 -0.001 out 128 | ``` 129 | 130 | To generate a grid with z=[-5,1], x=[-5,5], y=[0,10], point interval 0.5, and write results to file 'out', type 131 | ``` 132 | ./Sites -5:0.5:5 0:0.5:10 -5:0.5:1 out 133 | ``` 134 | 135 | ## 3 Citation 136 | Use the following citations to reference our codes: 137 | 138 | - Zhengyong Ren, Chaojian Chen, Kejia Pan, Thomas Kalscheuer, Hansruedi Maurer, and Jingtian Tang. Gravity Anomalies of Arbitrary 3D Polyhedral Bodies with Horizontal and Vertical Mass Contrasts. Surveys in Geophysics, 38(2):479–502, 2017. DOI: https://doi.org/10.1007/s10712-016-9395-x 139 | 140 | - Zhengyong Ren, Yiyuan Zhong, Chaojian Chen, Jingtian Tang, and Kejia Pan. Gravity anomalies of arbitrary 3D polyhedral bodies with horizontal and vertical mass contrasts up to cubic order. Geophysics, 83(1):G1–G13, 2018. DOI: https://doi.org/10.1190/geo2017-0219.1 141 | 142 | - Zhengyong Ren, Yiyuan Zhong, Chaojian Chen, Jingtian Tang, Thomas Kalscheuer, Hansruedi Maurer, and Yang Li. Gravity Gradient Tensor of Arbitrary 3D Polyhedral Bodies with up to Third-Order Polynomial Horizontal and Vertical Mass Contrasts. Surveys in Geophysics, 39(5):901–935, 2018. ([Open access](https://link.springer.com/article/10.1007/s10712-018-9467-1)) DOI: https://doi.org/10.1007/s10712-018-9467-1 143 | 144 | If you are a BibTex or BibLaTex user, see [citation.bib](https://github.com/zhong-yy/GraPly/blob/master/References/citation.bib). 145 | 146 | ## Notices / todos 147 | It may not work correctly when dealing with non-convex polyhedrons, because the automated calculation of facet normal vectors in the codes (Polyhedral.cpp, Integral.cpp) is invalid for non-convex polyhedron, but the closed-form formulae in the above cited papers are suitable for both convex and non-convex polyhedrons. An alternative is to decompose the non-convex polyhedron into a couple of convex polyhedrons. 148 | -------------------------------------------------------------------------------- /src/Forward_polyhedron/Modeling.cpp: -------------------------------------------------------------------------------- 1 | #include "Modeling.h" 2 | #include 3 | 4 | Modeling::Modeling() 5 | { 6 | } 7 | 8 | Modeling::~Modeling() 9 | { 10 | assert(num_po == po.size()); 11 | for (int i = 0; i < num_po; i++) 12 | { 13 | assert(po[i].node_number == po[i].node.size()); 14 | for (int k = 0; k < po[i].node_number; k++) 15 | { 16 | delete po[i].node[k]; 17 | } 18 | } 19 | } 20 | 21 | void Modeling::read_model(const char *name) 22 | { 23 | ifstream is; 24 | is.open(name); 25 | unsigned lab; 26 | assert(is.good()); 27 | std::string line; 28 | cout << "Reading model file: \"" << string(name) <<"\""<< endl; 29 | while (std::getline(is, line)) 30 | { 31 | line_process(line, "#"); 32 | if (line.empty()) 33 | continue; 34 | std::istringstream iss(line); 35 | iss >> num_po; 36 | break; 37 | } 38 | po.resize(num_po); 39 | cout << "\nNumber of polyhedrons: " << num_po << "\n\n"; 40 | 41 | for (unsigned i = 0; i < num_po; i++) 42 | { 43 | cout << "Polyhedral " << i << endl; 44 | // assert(is.good()); 45 | while (std::getline(is, line)) 46 | { 47 | line_process(line, "#"); 48 | if (line.empty()) 49 | continue; 50 | std::istringstream iss(line); 51 | iss >> lab; 52 | // cout<<"lab="<> po[i].node_number; //total number of vertices in the polyhedral 55 | po[i].node.resize(po[i].node_number); 56 | // cout << po[i].node.size() << endl; 57 | for (int kk = 0; kk < po[i].node_number; kk++) 58 | { 59 | po[i].node[kk] = NULL; 60 | } 61 | 62 | iss >> po[i].face_number; 63 | cout << " Number of nodes : " << po[i].node_number << "\n" 64 | << " Number of facets: " << po[i].face_number << "\n\n"; 65 | po[i].face_node_number.resize(po[i].face_number); 66 | po[i].face_node.resize(po[i].face_number); 67 | po[i].face_normal_vector.resize(po[i].face_number); 68 | break; 69 | } 70 | 71 | unsigned temp; 72 | 73 | for (int j = 0; j < po[i].node_number; j++) 74 | { 75 | assert(is.good()); 76 | while (std::getline(is, line)) 77 | { 78 | line_process(line, "#"); 79 | if (line.empty()) 80 | continue; 81 | 82 | std::istringstream iss(line); 83 | iss >> temp; 84 | //coordinate of each node 85 | double x, y, z; 86 | iss >> x >> y >> z; 87 | po[i].node[j] = new Node(x, y, z); 88 | break; 89 | } 90 | } 91 | // for (int j = 0; j < po[i].node_number; j++) { 92 | // cout << "node " << j << ": (x, y, z)=" << (*po[i].node[j]).x << 93 | // ", " << (*po[i].node[j]).y << ", " << (*po[i].node[j]).z << endl; 94 | // // (*po[i].node[j]).display(); 95 | // } 96 | 97 | for (int j = 0; j < po[i].face_number; j++) 98 | { 99 | assert(is.good()); 100 | while (std::getline(is, line)) 101 | { 102 | line_process(line, "#"); 103 | if (line.empty()) 104 | continue; 105 | std::istringstream iss(line); 106 | iss >> temp; 107 | iss >> po[i].face_node_number[j]; 108 | po[i].face_node[j].resize(po[i].face_node_number[j]); 109 | // cout << "Face " << j << ": " << "("; 110 | for (int k = 0; k < po[i].face_node_number[j]; k++) 111 | { 112 | iss >> po[i].face_node[j][k]; 113 | // cout << po[i].face_node[j][k] << ", "; 114 | } 115 | 116 | // cout << ")\n"; 117 | // for (int k = 0; k < po[i].face_node_number[j]; k++) { 118 | // cout << po[i].face_node[j][k] << ","; 119 | // (*po[i].node[po[i].face_node[j][k]]).display(); 120 | // } 121 | break; 122 | } 123 | } 124 | 125 | assert(is.good()); 126 | while (std::getline(is, line)) 127 | { 128 | line_process(line, "#"); 129 | if (line.empty()) 130 | continue; 131 | std::istringstream iss(line); 132 | iss >> po[i].const_density; 133 | break; 134 | } 135 | 136 | //cout << po[i].const_density<> po[i].lin[j]; 148 | //cout << po[i].lin[j]<<"\t"; 149 | } 150 | break; 151 | } 152 | 153 | //cout << endl; 154 | assert(is.good()); 155 | while (std::getline(is, line)) 156 | { 157 | line_process(line, "#"); 158 | if (line.empty()) 159 | continue; 160 | std::istringstream iss(line); 161 | for (int j = 0; j < 6; j++) 162 | { 163 | iss >> po[i].qua[j]; 164 | //cout << po[i].qua[j] << "\t"; 165 | } 166 | break; 167 | } 168 | //cout << endl; 169 | 170 | while (std::getline(is, line)) 171 | { 172 | line_process(line, "#"); 173 | if (line.empty()) 174 | continue; 175 | std::istringstream iss(line); 176 | for (int j = 0; j < 10; j++) 177 | { 178 | iss >> po[i].cub[j]; 179 | //cout << po[i].cub[j]<<"\t"; 180 | } 181 | break; 182 | } 183 | 184 | //cout << endl; 185 | 186 | po[i].init(); 187 | //po[i].sort_and_compute_normal_vector();//sort the order of face nodes 188 | 189 | // to check whether all vertice on a face are coplanar, if not, exit 190 | for (int j = 0; j < po[i].face_number; j++) 191 | { 192 | if (po[i].face_node_number[j] > 3) 193 | { 194 | for (int k = 3; k < po[i].face_node_number[j]; k++) 195 | { 196 | double flag = po[i].face_normal_vector[j] * (*po[i].node[po[i].face_node[j][k]] - *po[i].node[po[i].face_node[j][0]]); 197 | if (abs(flag) > TOLERANCE) 198 | { 199 | cerr << "The " << k << "-th vertex on the " << j << "-th facet of the " << i << "-th polyhedron is not coplanar with the first three point on face" << j << endl; 200 | exit(1); 201 | } 202 | } 203 | } 204 | } 205 | } 206 | } 207 | 208 | void Modeling::read_site(const char *name) 209 | { 210 | ifstream is; 211 | is.open(name); 212 | string line; 213 | assert(is.good()); 214 | cout << "Reading computation points in file: \"" << string(name) << "\"" << endl; 215 | while (std::getline(is, line)) 216 | { 217 | line_process(line, "#"); 218 | if (line.empty()) 219 | continue; 220 | std::istringstream iss(line); 221 | iss >> num_site; 222 | break; 223 | } 224 | 225 | cout << "Number of computation points: " << num_site << endl 226 | << endl; 227 | unsigned lab; 228 | coor.resize(num_site); 229 | g.resize(num_site); 230 | T.resize(num_site); 231 | //gx.resize(num_site); 232 | //gy.resize(num_site); 233 | //gz.resize(num_site); 234 | double x, y, z; 235 | for (unsigned i = 0; i < num_site; i++) 236 | { 237 | assert(is.good()); 238 | while (std::getline(is, line)) 239 | { 240 | line_process(line, "#"); 241 | if (line.empty()) 242 | continue; 243 | std::istringstream iss(line); 244 | iss >> lab; 245 | iss >> x >> y >> z; 246 | break; 247 | } 248 | coor[i].setPoint(x, y, z); 249 | } 250 | } 251 | 252 | void Modeling::out_g(const char *name) 253 | { 254 | ofstream os; 255 | os.open(name); 256 | assert(os.good()); 257 | 258 | os << setw(25) << left << "x(km)" 259 | << setw(25) << left << "y(km)" 260 | << setw(25) << left << "z(km)" 261 | << setw(25) << left << "gravity_x(mGal)" 262 | << setw(25) << left << "gravity_y(mGal)" 263 | << setw(25) << left << "gravity_z(mGal)"; 264 | os << '\n'; 265 | for (unsigned i = 0; i < num_site; i++) 266 | { 267 | assert(os.good()); 268 | os << setprecision(7); 269 | os << fixed; 270 | os << setw(25) << left << coor[i].x 271 | << setw(25) << left << coor[i].y 272 | << setw(25) << left << coor[i].z; 273 | os << setprecision(14); 274 | os << scientific; 275 | os << setw(25) << left << g[i].x; 276 | os << setw(25) << left << g[i].y; 277 | os << setw(25) << left << g[i].z << '\n'; 278 | } 279 | } 280 | 281 | void Modeling::out_T(const char *name) 282 | { 283 | ofstream os; 284 | os.open(name); 285 | assert(os.good()); 286 | 287 | os << setw(25) << left << "x(km)" 288 | << setw(25) << left << "y(km)" 289 | << setw(25) << left << "z(km)" 290 | << setw(25) << left << "Txx(1/s^2)" 291 | << setw(25) << left << "Tyx(1/s^2)" 292 | << setw(25) << left << "Tzx(1/s^2)" 293 | << setw(25) << left << "Txy(1/s^2)" 294 | << setw(25) << left << "Tyy(1/s^2)" 295 | << setw(25) << left << "Tzy(1/s^2)" 296 | << setw(25) << left << "Txz(1/s^2)" 297 | << setw(25) << left << "Tyz(1/s^2)" 298 | << setw(25) << left << "Tzz(1/s^2)"; 299 | os << '\n'; 300 | for (unsigned i = 0; i < num_site; i++) 301 | { 302 | assert(os.good()); 303 | os << setprecision(7); 304 | os << fixed; 305 | os << setw(25) << left << coor[i].x 306 | << setw(25) << left << coor[i].y 307 | << setw(25) << left << coor[i].z; 308 | os << setprecision(14); 309 | os << scientific; 310 | os << setw(25) << left << T[i].xx; 311 | os << setw(25) << left << T[i].yx; 312 | os << setw(25) << left << T[i].zx; 313 | os << setw(25) << left << T[i].xy; 314 | os << setw(25) << left << T[i].yy; 315 | os << setw(25) << left << T[i].zy; 316 | os << setw(25) << left << T[i].xz; 317 | os << setw(25) << left << T[i].yz; 318 | os << setw(25) << left << T[i].zz << '\n'; 319 | } 320 | } 321 | 322 | void Modeling::analytic_g() 323 | { 324 | vector gra; 325 | gra.resize(num_site); 326 | #pragma omp parallel for 327 | for (int i = 0; i < num_site; i++) 328 | { 329 | g[i].setPoint(0., 0., 0.); 330 | for (int j = 0; j < num_po; j++) 331 | { 332 | //clock_t t_start = clock(); 333 | g[i] += gra[i].g_const(po[j], coor[i], po[j].const_density); 334 | g[i] += gra[i].g_1st(po[j], coor[i], po[j].lin[0], po[j].lin[1], po[j].lin[2]); 335 | g[i] += gra[i].g_2nd(po[j], coor[i], po[j].qua[0], po[j].qua[1], po[j].qua[2], po[j].qua[3], po[j].qua[4], po[j].qua[5]); 336 | g[i] += gra[i].g_3rd(po[j], coor[i], po[j].cub); 337 | } 338 | } 339 | } 340 | void Modeling::analytic_T() 341 | { 342 | vector gra; 343 | gra.resize(num_site); 344 | #pragma omp parallel for 345 | for (int i = 0; i < num_site; i++) 346 | { 347 | T[i].set(); 348 | for (int j = 0; j < num_po; j++) 349 | { 350 | //clock_t t_start = clock(); 351 | T[i] = T[i] + gra[i].tensor_const(po[j], coor[i], po[j].const_density); 352 | T[i] = T[i] + gra[i].tensor_1st(po[j], coor[i], po[j].lin[0], po[j].lin[1], po[j].lin[2]); 353 | T[i] += gra[i].tensor_2nd(po[j], coor[i], po[j].qua[0], po[j].qua[1], po[j].qua[2], po[j].qua[3], po[j].qua[4], po[j].qua[5]); 354 | T[i] += gra[i].tensor_3rd(po[j], coor[i], po[j].cub); 355 | } 356 | } 357 | } 358 | -------------------------------------------------------------------------------- /src/Forward_tetrahedron/tet_model.cpp: -------------------------------------------------------------------------------- 1 | #include "tet_model.h" 2 | 3 | tet_model::tet_model() 4 | { 5 | } 6 | 7 | tet_model::~tet_model() 8 | { 9 | } 10 | 11 | void tet_model::compute_g() 12 | { 13 | vector gra; 14 | unsigned int num_site = observation.get_n_obs(); 15 | unsigned int num_tet = mesh.get_n_tets(); 16 | const vector &tetrahedrons = mesh.get_tets(); 17 | gra.resize(num_site); 18 | 19 | Timer ti; 20 | ti.start(); 21 | //cout << (*tetrahedrons[1]).lin[0] << (*tetrahedrons[1]).lin[1] << (*tetrahedrons[1]).lin[2] << endl; 22 | if (density_order == 0) 23 | { 24 | cout << "\nThe density contrast is constant.\n"; 25 | #pragma omp parallel for 26 | for (int i = 0; i < num_site; i++) 27 | { 28 | g[i].setPoint(0., 0., 0.); 29 | for (unsigned j = 0; j < num_tet; j++) 30 | { 31 | //clock_t t_start = clock(); 32 | g[i] += gra[i].g_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 33 | } 34 | } 35 | } 36 | else if (density_order == 1) 37 | { 38 | cout << "\nThe density contrast is linear.\n"; 39 | cout << "Computing gravity ..." << endl; 40 | #pragma omp parallel for 41 | for (int i = 0; i < num_site; i++) 42 | { 43 | g[i].setPoint(0., 0., 0.); 44 | for (unsigned j = 0; j < num_tet; j++) 45 | { 46 | //clock_t t_start = clock(); 47 | g[i] += gra[i].g_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 48 | g[i] += gra[i].g_1st(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).lin[0], 49 | (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 50 | } 51 | } 52 | } 53 | else if (density_order == 2) 54 | { 55 | cout << "\nThe density contrast is quadratic.\n"; 56 | cout << "Computing gravity ..." << endl; 57 | #pragma omp parallel for 58 | for (int i = 0; i < num_site; i++) 59 | { 60 | g[i].setPoint(0., 0., 0.); 61 | for (unsigned j = 0; j < num_tet; j++) 62 | { 63 | //clock_t t_start = clock(); 64 | g[i] += gra[i].g_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 65 | 66 | g[i] += gra[i].g_1st(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).lin[0], 67 | (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 68 | 69 | g[i] += gra[i].g_2nd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).qua[0], 70 | (*tetrahedrons[j]).qua[1], (*tetrahedrons[j]).qua[2], (*tetrahedrons[j]).qua[3], 71 | (*tetrahedrons[j]).qua[4], (*tetrahedrons[j]).qua[5]); 72 | } 73 | } 74 | } 75 | else if (density_order == 3) 76 | { 77 | cout << "\nThe density contrast is cubic.\n"; 78 | cout << "Computing gravity ..." << endl; 79 | #pragma omp parallel for 80 | for (int i = 0; i < num_site; i++) 81 | { 82 | g[i].setPoint(0., 0., 0.); 83 | for (unsigned j = 0; j < num_tet; j++) 84 | { 85 | //clock_t t_start = clock(); 86 | g[i] += gra[i].g_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 87 | 88 | g[i] += gra[i].g_1st(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).lin[0], 89 | (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 90 | 91 | g[i] += gra[i].g_2nd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).qua[0], 92 | (*tetrahedrons[j]).qua[1], (*tetrahedrons[j]).qua[2], (*tetrahedrons[j]).qua[3], 93 | (*tetrahedrons[j]).qua[4], (*tetrahedrons[j]).qua[5]); 94 | 95 | g[i] += gra[i].g_3rd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).cub); 96 | } 97 | } 98 | } 99 | ti.stop(); 100 | cout << "Computing gravity vectors done! "; 101 | cout << "Computation time for gravity vectors is " << ti.getElapsedTimeInSec() << " second(s).\n\n"; 102 | } 103 | 104 | void tet_model::compute_ggt() 105 | { 106 | vector gra; 107 | unsigned int num_site = observation.get_n_obs(); 108 | unsigned int num_tet = mesh.get_n_tets(); 109 | const vector &tetrahedrons = mesh.get_tets(); 110 | gra.resize(num_site); 111 | 112 | Timer ti; 113 | ti.start(); 114 | if (density_order == 0) 115 | { 116 | cout << "\nThe density contrast is constant.\n"; 117 | cout << "Computing gravity gradien tensor ..." << endl; 118 | #pragma omp parallel for 119 | for (int i = 0; i < num_site; i++) 120 | { 121 | T[i].set(); 122 | for (unsigned j = 0; j < num_tet; j++) 123 | { 124 | T[i] = T[i] + gra[i].tensor_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 125 | } 126 | } 127 | } 128 | else if (density_order == 1) 129 | { 130 | cout << "\nThe density contrast is linear.\n"; 131 | cout << "Computing gravity gradien tensor ..." << endl; 132 | #pragma omp parallel for 133 | for (int i = 0; i < num_site; i++) 134 | { 135 | T[i].set(); 136 | for (unsigned j = 0; j < num_tet; j++) 137 | { 138 | //clock_t t_start = clock(); 139 | T[i] = T[i] + gra[i].tensor_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 140 | T[i] = T[i] + gra[i].tensor_1st(*tetrahedrons[j], observation(i), 141 | (*tetrahedrons[j]).lin[0], (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 142 | } 143 | } 144 | } 145 | else if (density_order == 2) 146 | { 147 | cout << "\nThe density contrast is quadratic.\n"; 148 | cout << "Computing gravity gradien tensor ..." << endl; 149 | #pragma omp parallel for 150 | for (int i = 0; i < num_site; i++) 151 | { 152 | T[i].set(); 153 | for (unsigned j = 0; j < num_tet; j++) 154 | { 155 | //clock_t t_start = clock(); 156 | T[i] = T[i] + gra[i].tensor_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 157 | T[i] = T[i] + gra[i].tensor_1st(*tetrahedrons[j], observation(i), 158 | (*tetrahedrons[j]).lin[0], (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 159 | T[i] += gra[i].tensor_2nd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).qua[0], 160 | (*tetrahedrons[j]).qua[1], (*tetrahedrons[j]).qua[2], (*tetrahedrons[j]).qua[3], 161 | (*tetrahedrons[j]).qua[4], (*tetrahedrons[j]).qua[5]); 162 | } 163 | } 164 | } 165 | else if (density_order == 3) 166 | { 167 | cout << "\nThe density contrast is cubic.\n"; 168 | cout << "Computing gravity gradien tensor ..." << endl; 169 | #pragma omp parallel for 170 | for (int i = 0; i < num_site; i++) 171 | { 172 | T[i].set(); 173 | for (unsigned j = 0; j < num_tet; j++) 174 | { 175 | T[i] = T[i] + gra[i].tensor_const(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).const_density); 176 | T[i] = T[i] + gra[i].tensor_1st(*tetrahedrons[j], observation(i), 177 | (*tetrahedrons[j]).lin[0], (*tetrahedrons[j]).lin[1], (*tetrahedrons[j]).lin[2]); 178 | T[i] += gra[i].tensor_2nd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).qua[0], 179 | (*tetrahedrons[j]).qua[1], (*tetrahedrons[j]).qua[2], (*tetrahedrons[j]).qua[3], 180 | (*tetrahedrons[j]).qua[4], (*tetrahedrons[j]).qua[5]); 181 | T[i] += gra[i].tensor_3rd(*tetrahedrons[j], observation(i), (*tetrahedrons[j]).cub); 182 | } 183 | } 184 | } 185 | ti.stop(); 186 | cout << "Computing gravity gradient tensors done!\n"; 187 | cout << " Computaion time for GGTs is " << ti.getElapsedTimeInSec() << " second(s)\n\n"; 188 | } 189 | 190 | void tet_model::read_config(string config_file) 191 | { 192 | ifstream in_stream(config_file.c_str()); 193 | string model_mesh; 194 | 195 | std::string line; 196 | while (std::getline(in_stream, line)) 197 | { 198 | line_process(line, "#"); 199 | if (line.empty()) 200 | continue; 201 | std::istringstream iss(line); 202 | iss >> model_mesh; 203 | break; 204 | } 205 | std::cout << model_mesh << "\n"; 206 | 207 | string station_file; 208 | while (std::getline(in_stream, line)) 209 | { 210 | line_process(line, "#"); 211 | if (line.empty()) 212 | continue; 213 | std::istringstream iss(line); 214 | iss >> station_file; 215 | break; 216 | } 217 | std::cout << station_file << "\n"; 218 | 219 | while (std::getline(in_stream, line)) 220 | { 221 | line_process(line, "#"); 222 | if (line.empty()) 223 | continue; 224 | std::istringstream iss(line); 225 | iss >> density_order; 226 | break; 227 | } 228 | std::cout << density_order << "\n"; 229 | 230 | unsigned int n_regions; 231 | while (std::getline(in_stream, line)) 232 | { 233 | line_process(line, "#"); 234 | if (line.empty()) 235 | continue; 236 | std::istringstream iss(line); 237 | iss >> n_regions; 238 | break; 239 | } 240 | 241 | std::cout << n_regions << "\n"; 242 | for (unsigned i = 0; i < n_regions; i++) 243 | { 244 | std::vector temp; 245 | int marker; 246 | while (std::getline(in_stream, line)) 247 | { 248 | line_process(line, "#"); 249 | if (line.empty()) 250 | continue; 251 | std::istringstream iss(line); 252 | iss >> marker; 253 | break; 254 | } 255 | std::cout << marker << "\n"; 256 | 257 | double rho_const; 258 | while (std::getline(in_stream, line)) 259 | { 260 | line_process(line, "#"); 261 | if (line.empty()) 262 | continue; 263 | std::istringstream iss(line); 264 | iss >> rho_const; 265 | break; 266 | } 267 | std::cout << "\t" << rho_const << "\n"; 268 | region_table_0[marker] = rho_const; 269 | 270 | temp.resize(3); 271 | cout << "\t"; 272 | while (std::getline(in_stream, line)) 273 | { 274 | line_process(line, "#"); 275 | if (line.empty()) 276 | continue; 277 | std::istringstream iss(line); 278 | for (int j = 0; j < 3; j++) 279 | { 280 | iss >> temp[j]; 281 | std::cout << temp[j] << "\t"; 282 | } 283 | break; 284 | } 285 | std::cout << "\n"; 286 | region_table_1[marker] = temp; 287 | 288 | temp.resize(6); 289 | cout << "\t"; 290 | while (std::getline(in_stream, line)) 291 | { 292 | line_process(line, "#"); 293 | if (line.empty()) 294 | continue; 295 | std::istringstream iss(line); 296 | for (int j = 0; j < 6; j++) 297 | { 298 | iss >> temp[j]; 299 | std::cout << temp[j] << "\t"; 300 | } 301 | break; 302 | } 303 | std::cout << "\n"; 304 | region_table_2[marker] = temp; 305 | 306 | temp.resize(10); 307 | cout << "\t"; 308 | while (std::getline(in_stream, line)) 309 | { 310 | line_process(line, "#"); 311 | if (line.empty()) 312 | continue; 313 | std::istringstream iss(line); 314 | for (int j = 0; j < 10; j++) 315 | { 316 | iss >> temp[j]; 317 | std::cout << temp[j] << "\t"; 318 | } 319 | break; 320 | } 321 | std::cout << "\n"; 322 | region_table_3[marker] = temp; 323 | } 324 | 325 | mesh.read_mesh(model_mesh); 326 | this->set_density(); 327 | 328 | observation.read_site(station_file); 329 | int n_data = observation.get_n_obs(); 330 | this->g.resize(n_data); 331 | this->T.resize(n_data); 332 | } 333 | 334 | void tet_model::set_density() 335 | { 336 | typedef std::map::iterator IT0; 337 | typedef std::map>::iterator IT; 338 | const vector &tetrahedrons = mesh.get_tets(); 339 | for (int i = 0; i < mesh.get_n_tets(); i++) 340 | { 341 | int marker; 342 | marker = (*tetrahedrons[i]).get_marker(); 343 | IT0 it0 = region_table_0.find(marker); 344 | IT it1 = region_table_1.find(marker); 345 | IT it2 = region_table_2.find(marker); 346 | IT it3 = region_table_3.find(marker); 347 | mesh.set_tet_density_0(i, (*it0).second); 348 | mesh.set_tet_density_1(i, (*it1).second); 349 | mesh.set_tet_density_2(i, (*it2).second); 350 | mesh.set_tet_density_3(i, (*it3).second); 351 | } 352 | } 353 | 354 | void tet_model::out_g(const char *name) 355 | { 356 | unsigned num_site = observation.get_n_obs(); 357 | ofstream os; 358 | os.open(name); 359 | assert(os.good()); 360 | 361 | os << setw(25) << left << "x(km)" 362 | << setw(25) << left << "y(km)" 363 | << setw(25) << left << "z(km)" 364 | << setw(25) << left << "gravity_x(mGal)" 365 | << setw(25) << left << "gravity_y(mGal)" 366 | << setw(25) << left << "gravity_z(mGal)"; 367 | os << '\n'; 368 | for (unsigned i = 0; i < num_site; i++) 369 | { 370 | assert(os.good()); 371 | os << setprecision(7); 372 | os << fixed; 373 | os << setw(25) << left << observation(i).x 374 | << setw(25) << left << observation(i).y 375 | << setw(25) << left << observation(i).z; 376 | os << setprecision(14); 377 | os << scientific; 378 | os << setw(25) << left << g[i].x; 379 | os << setw(25) << left << g[i].y; 380 | os << setw(25) << left << g[i].z << '\n'; 381 | } 382 | } 383 | 384 | void tet_model::out_T(const char *name) 385 | { 386 | 387 | unsigned num_site = observation.get_n_obs(); 388 | ofstream os; 389 | os.open(name); 390 | assert(os.good()); 391 | 392 | os << setw(25) << left << "x(km)" 393 | << setw(25) << left << "y(km)" 394 | << setw(25) << left << "z(km)" 395 | << setw(25) << left << "Txx(1/s^2)" 396 | << setw(25) << left << "Tyx(1/s^2)" 397 | << setw(25) << left << "Tzx(1/s^2)" 398 | << setw(25) << left << "Txy(1/s^2)" 399 | << setw(25) << left << "Tyy(1/s^2)" 400 | << setw(25) << left << "Tzy(1/s^2)" 401 | << setw(25) << left << "Txz(1/s^2)" 402 | << setw(25) << left << "Tyz(1/s^2)" 403 | << setw(25) << left << "Tzz(1/s^2)"; 404 | os << '\n'; 405 | for (unsigned i = 0; i < num_site; i++) 406 | { 407 | assert(os.good()); 408 | os << setprecision(7); 409 | os << fixed; 410 | os << setw(25) << left << observation(i).x 411 | << setw(25) << left << observation(i).y 412 | << setw(25) << left << observation(i).z; 413 | os << setprecision(14); 414 | os << scientific; 415 | os << setw(25) << left << T[i].xx; 416 | os << setw(25) << left << T[i].yx; 417 | os << setw(25) << left << T[i].zx; 418 | os << setw(25) << left << T[i].xy; 419 | os << setw(25) << left << T[i].yy; 420 | os << setw(25) << left << T[i].zy; 421 | os << setw(25) << left << T[i].xz; 422 | os << setw(25) << left << T[i].yz; 423 | os << setw(25) << left << T[i].zz << '\n'; 424 | } 425 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/Forward_polyhedron/Integral.cpp: -------------------------------------------------------------------------------- 1 | #include "Integral.h" 2 | 3 | Integral::Integral() 4 | { 5 | } 6 | 7 | 8 | Integral::~Integral() 9 | { 10 | } 11 | 12 | double Integral::Line_R1(const Point& observation, const Point& v0, const Point& v1) 13 | { 14 | //projection onto the line v0-v1 from the observation point 15 | Point prj = observation.projection_line(v0, v1); 16 | Point t = (v1 - v0).getUnit();//unit tangent vector 17 | double D0 = observation.distance(prj); //distance from D0 to the line 18 | double s1, s0, R1, R0; 19 | s1 = t*(v1 - observation);//parameter 20 | s0 = t*(v0 - observation); 21 | R1 = observation.distance(v1); 22 | R0 = observation.distance(v0); 23 | double itg=0.0; 24 | //Table of integrals, series and products,equation(2.262.1),(Gradshteyn,1994) 25 | if (abs(s0 + R0)< TOLERANCE) { 26 | itg = 0.5*(s1*R1 - s0*R0); 27 | } 28 | else { 29 | itg=0.5*(D0*D0*log((s1+R1)/(s0+R0))+s1*R1 - s0*R0); 30 | } 31 | return itg; 32 | 33 | } 34 | 35 | double Integral::Line_R3(const Point& observation, const Point& v0, const Point& v1) 36 | { 37 | //projection onto the line v0-v1 from the observation point 38 | Point prj = observation.projection_line(v0, v1); 39 | Point t = (v1 - v0).getUnit();//unit tangent vector 40 | double D0 = observation.distance(prj);//distance from D0 to the line 41 | double s1, s0, R1, R0; 42 | s1 = t*(v1 - observation);//parameter s 43 | s0 = t*(v0 - observation); 44 | R1 = observation.distance(v1); 45 | R0 = observation.distance(v0); 46 | double itg = 0.0; 47 | //Table of integrals, series and products,equation(2.260.2),(Gradshteyn,1994) 48 | if (abs(s0 + R0) < TOLERANCE) { 49 | itg = 0.25*(s1*R1*R1*R1-s0*R0*R0*R0); 50 | } 51 | else { 52 | double itg_R1 = 0.5*(D0*D0*log((s1 + R1) / (s0 + R0)) + s1*R1 - s0*R0); 53 | itg = 0.25*(s1*R1*R1*R1 - s0*R0*R0*R0) 54 | +0.75*(D0*D0*itg_R1); 55 | } 56 | return itg; 57 | } 58 | 59 | double Integral::Line_R_1(const Point& observation, const Point& v0, const Point& v1) 60 | { 61 | Point t = (v1 - v0).getUnit(); 62 | Point prj = observation.projection_line(v0, v1); 63 | double L0 = observation.distance(prj); 64 | double s0, s1, R0, R1,result; 65 | s0 = (v0 - observation)*t; 66 | s1 = (v1 - observation)*t; 67 | R0 = v0.distance(observation); 68 | R1 = v1.distance(observation); 69 | 70 | if (abs(s0 + R0) < TOLERANCE) { 71 | result = abs(log(s1 / s0)); 72 | assert(s0*s1 > 0); 73 | } 74 | else { 75 | result = log((R1 + s1) / (R0 + s0)); 76 | } 77 | 78 | 79 | return result; 80 | } 81 | 82 | double Integral::Line_Bj1(const Point& observation, const Point& v0, const Point& v1, const Point& unit_normal) 83 | { 84 | Point t = (v1 - v0).getUnit(); 85 | Point mj = unitCross(t,unit_normal); 86 | double mj_value = (v0 - observation)*mj; 87 | if (abs(mj_value) < TOLERANCE) { 88 | return 0.0; 89 | } 90 | double h = (observation - v0)*unit_normal; 91 | double s0, s1, R0, R1; 92 | s1 = t*(v1 - observation);//parameter 93 | s0 = t*(v0 - observation); 94 | R1 = observation.distance(v1); 95 | R0 = observation.distance(v0); 96 | double bj1 = abs(h)*(atan((abs(h)*s1) / (mj_value*R1)) - atan((abs(h)*s0) / (mj_value*R0))) 97 | + mj_value*log((s1 + R1) / (s0 + R0)); 98 | //here,the case of mj_value=0 has been handled before 99 | return bj1; 100 | } 101 | 102 | double Integral::Line_Bj3(const Point& observation, const Point& v0, const Point& v1, const Point& unit_normal) 103 | { 104 | Point t = (v1 - v0).getUnit(); 105 | Point mj = cross(t, unit_normal); 106 | double mj_value = (v0 - observation)*mj; 107 | 108 | //judge if the mj_value is equal to zero 109 | if (abs(mj_value) < TOLERANCE) { 110 | return 0.0; 111 | } 112 | double s0, s1, R0, R1,h; 113 | 114 | //local coordinate s 115 | s1 = t*(v1 - observation); 116 | s0 = t*(v0 - observation); 117 | R1 = observation.distance(v1); 118 | //distance R 119 | R0 = observation.distance(v0); 120 | 121 | //height from observation point to the plane containing the face 122 | h = abs((observation - v0)*unit_normal); 123 | double bj3 = h*h*h*(atan((h*s1) / (mj_value*R1)) - atan((h*s0) / (mj_value*R0))) 124 | + 0.5*mj_value*(3.0 * h*h + mj_value*mj_value)*log((s1 + R1) / (s0 + R0)) 125 | + 0.5*mj_value*(s1*R1 - s0*R0); 126 | //here,the case of mj_value=0 has been handled before 127 | return bj3; 128 | } 129 | 130 | Point Integral::Line_rR1(const Point& ob, const Point& v0, const Point& v1) 131 | { 132 | Point t = (v1 - v0).getUnit(); 133 | Point prj = ob.projection_line(v0, v1);//projection on edge from point ob 134 | Point L = prj - ob; 135 | double D0 = L.size(); 136 | double s1, s0, R1, R0; 137 | s0 = (v0 - ob)*t; 138 | s1 = (v1 - ob)*t; 139 | R0 = ob.distance(v0); 140 | R1 = ob.distance(v1); 141 | double temp1, temp2; 142 | //cout << "here" << endl; 143 | if (abs(s0 + R0) < TOLERANCE) 144 | temp1 =0.5* (s1*R1 - s0*R0); 145 | else { 146 | temp1 = 0.5*(D0*D0 * log((s1 + R1) / (s0 + R0)) + s1*R1 - s0*R0); 147 | } 148 | temp2 = (R1*R1*R1 - R0*R0*R0) / 3.0; 149 | return (L*temp1+t*temp2); 150 | } 151 | 152 | Point Integral::Line_rR_1(const Point& ob, const Point& v0, const Point& v1) 153 | { 154 | Point t = (v1 - v0).getUnit(); 155 | Point prj = ob.projection_line(v0, v1); 156 | Point L = prj - ob; 157 | double L0 = L.size(); 158 | double s0, s1, R0, R1; 159 | Point result; 160 | s0 = (v0 - ob)*t; 161 | s1 = (v1 - ob)*t; 162 | R0 = v0.distance(ob); 163 | R1 = v1.distance(ob); 164 | if (abs(s0 + R0) < TOLERANCE) { 165 | result = L*abs(log(s1 / s0)) + t*(R1 - R0); 166 | } 167 | else { 168 | result = L*log((s1 + R1) / (s0 + R0)) + t*(R1 - R0); 169 | } 170 | return result; 171 | } 172 | 173 | double Integral::Line_x2R(const Point& ob, const Point& v0, const Point& v1) 174 | { 175 | Point t = (v1 - v0).getUnit(); 176 | Point prj = ob.projection_line(v0, v1); 177 | Point L = prj - ob; 178 | double L0 = L.size(); 179 | double s0, s1, R0, R1; 180 | s0 = (v0 - ob)*t; 181 | s1 = (v1 - ob)*t; 182 | R0 = v0.distance(ob); 183 | R1 = v1.distance(ob); 184 | double result = 0.0; 185 | if (abs(s0 + R0) < TOLERANCE) { 186 | result = (t.x)*(t.x)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 187 | + 2.0*(L.x)*(t.x)*(R1*R1*R1 - R0*R0*R0) / 3.0 188 | + 0.5*(L.x)*(L.x)*(s1*R1 - s0*R0); 189 | } 190 | else { 191 | result = (t.x)*(t.x)*0.125*(2*(s1*R1*R1*R1 - s0*R0*R0*R0) -L0*L0*(s1*R1-s0*R0)-L0*L0*L0*L0*log((s1+R1)/(s0+R0))) 192 | +2.0*(L.x)*(t.x)*(R1*R1*R1-R0*R0*R0)/3.0 193 | +0.5*(L.x)*(L.x)*(s1*R1-s0*R0+L0*L0*log((s1+R1)/(s0+R0))); 194 | } 195 | return result; 196 | } 197 | 198 | double Integral::Line_y2R(const Point& ob, const Point& v0, const Point& v1) 199 | { 200 | double result = 0.0; 201 | Point t = (v1 - v0).getUnit(); 202 | Point prj = ob.projection_line(v0, v1); 203 | Point L = prj - ob; 204 | double L0 = L.size(); 205 | double s0, s1, R0, R1; 206 | s0 = (v0 - ob)*t; 207 | s1 = (v1 - ob)*t; 208 | R0 = v0.distance(ob); 209 | R1 = v1.distance(ob); 210 | if (abs(s0 + R0) < TOLERANCE) { 211 | result = (t.y)*(t.y)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 212 | + 2.0*(L.y)*(t.y)*(R1*R1*R1 - R0*R0*R0) / 3.0 213 | + 0.5*(L.y)*(L.y)*(s1*R1 - s0*R0); 214 | } 215 | else { 216 | result = (t.y)*(t.y)*0.125*(2 * (s1*R1*R1*R1 - s0*R0*R0*R0) - L0*L0*(s1*R1 - s0*R0) - L0*L0*L0*L0*log((s1 + R1) / (s0 + R0))) 217 | + 2.0*(L.y)*(t.y)*(R1*R1*R1 - R0*R0*R0) / 3.0 218 | + 0.5*(L.y)*(L.y)*(s1*R1 - s0*R0 + L0*L0*log((s1 + R1) / (s0 + R0))); 219 | } 220 | return result; 221 | } 222 | 223 | double Integral::Line_z2R(const Point& ob, const Point& v0,const Point& v1) 224 | { 225 | double result = 0.0; 226 | Point t = (v1 - v0).getUnit(); 227 | Point prj = ob.projection_line(v0, v1); 228 | Point L = prj - ob; 229 | double L0 = L.size(); 230 | double s0, s1, R0, R1; 231 | s0 = (v0 - ob)*t; 232 | s1 = (v1 - ob)*t; 233 | R0 = v0.distance(ob); 234 | R1 = v1.distance(ob); 235 | if (abs(s0 + R0) < TOLERANCE) { 236 | result = (t.z)*(t.z)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 237 | + 2.0*(L.z)*(t.z)*(R1*R1*R1 - R0*R0*R0) / 3.0 238 | + 0.5*(L.z)*(L.z)*(s1*R1 - s0*R0); 239 | } 240 | else { 241 | result = (t.z)*(t.z)*0.125*(2 * (s1*R1*R1*R1 - s0*R0*R0*R0) - L0*L0*(s1*R1 - s0*R0) - L0*L0*L0*L0*log((s1 + R1) / (s0 + R0))) 242 | + 2.0*(L.z)*(t.z)*(R1*R1*R1 - R0*R0*R0) / 3.0 243 | + 0.5*(L.z)*(L.z)*(s1*R1 - s0*R0 + L0*L0*log((s1 + R1) / (s0 + R0))); 244 | } 245 | return result; 246 | } 247 | 248 | double Integral::Line_xzR(const Point& ob, const Point& v0, const Point& v1) 249 | { 250 | double result = 0.0; 251 | Point t = (v1 - v0).getUnit(); 252 | Point prj = ob.projection_line(v0, v1); 253 | Point L = prj - ob; 254 | double L0 = L.size(); 255 | double s0, s1, R0, R1; 256 | s0 = (v0 - ob)*t; 257 | s1 = (v1 - ob)*t; 258 | R0 = v0.distance(ob); 259 | R1 = v1.distance(ob); 260 | if (abs(s0 + R0) < TOLERANCE) { 261 | result = (t.x)*(t.z)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 262 | + ((L.x)*(t.z)+(L.z)*(t.x))*(R1*R1*R1 - R0*R0*R0) / 3.0 263 | + 0.5*(L.x)*(L.z)*(s1*R1 - s0*R0); 264 | } 265 | else { 266 | result = (t.x)*(t.z)*0.125*(2 * (s1*R1*R1*R1 - s0*R0*R0*R0) - L0*L0*(s1*R1 - s0*R0) - L0*L0*L0*L0*log((s1 + R1) / (s0 + R0))) 267 | + ((L.x)*(t.z)+ (L.z)*(t.x))*(R1*R1*R1 - R0*R0*R0) / 3.0 268 | + 0.5*(L.x)*(L.z)*(s1*R1 - s0*R0 + L0*L0*log((s1 + R1) / (s0 + R0))); 269 | } 270 | return result; 271 | } 272 | 273 | double Integral::Line_yzR(const Point& ob, const Point& v0, const Point& v1) 274 | { 275 | double result = 0.0; 276 | Point t = (v1 - v0).getUnit(); 277 | Point prj = ob.projection_line(v0, v1); 278 | Point L = prj - ob; 279 | double L0 = L.size(); 280 | double s0, s1, R0, R1; 281 | s0 = (v0 - ob)*t; 282 | s1 = (v1 - ob)*t; 283 | R0 = v0.distance(ob); 284 | R1 = v1.distance(ob); 285 | if (abs(s0 + R0) < TOLERANCE) { 286 | result = (t.y)*(t.z)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 287 | + ((L.y)*(t.z) + (L.z)*(t.y))*(R1*R1*R1 - R0*R0*R0) / 3.0 288 | + 0.5*(L.y)*(L.z)*(s1*R1 - s0*R0); 289 | } 290 | else { 291 | result = (t.y)*(t.z)*0.125*(2 * (s1*R1*R1*R1 - s0*R0*R0*R0) - L0*L0*(s1*R1 - s0*R0) - L0*L0*L0*L0*log((s1 + R1) / (s0 + R0))) 292 | + ((L.y)*(t.z) + (L.z)*(t.y))*(R1*R1*R1 - R0*R0*R0) / 3.0 293 | + 0.5*(L.y)*(L.z)*(s1*R1 - s0*R0 + L0*L0*log((s1 + R1) / (s0 + R0))); 294 | } 295 | return result; 296 | } 297 | 298 | double Integral::Line_xyR(const Point& ob, const Point& v0, const Point& v1) 299 | { 300 | double result = 0.0; 301 | Point t = (v1 - v0).getUnit(); 302 | Point prj = ob.projection_line(v0, v1); 303 | Point L = prj - ob; 304 | double L0 = L.size(); 305 | double s0, s1, R0, R1; 306 | s0 = (v0 - ob)*t; 307 | s1 = (v1 - ob)*t; 308 | R0 = v0.distance(ob); 309 | R1 = v1.distance(ob); 310 | if (abs(s0 + R0) < TOLERANCE) { 311 | result = (t.x)*(t.y)*0.25 * (s1*R1*R1*R1 - s0*R0*R0*R0) 312 | + ((L.x)*(t.y) + (L.y)*(t.x))*(R1*R1*R1 - R0*R0*R0) / 3.0 313 | + 0.5*(L.x)*(L.y)*(s1*R1 - s0*R0); 314 | } 315 | else { 316 | result = (t.x)*(t.y)*0.125*(2 * (s1*R1*R1*R1 - s0*R0*R0*R0) - L0*L0*(s1*R1 - s0*R0) - L0*L0*L0*L0*log((s1 + R1) / (s0 + R0))) 317 | + ((L.x)*(t.y) + (L.y)*(t.x))*(R1*R1*R1 - R0*R0*R0) / 3.0 318 | + 0.5*(L.x)*(L.y)*(s1*R1 - s0*R0 + L0*L0*log((s1 + R1) / (s0 + R0))); 319 | } 320 | return result; 321 | } 322 | 323 | double Integral::Line_x2R_1(const Point& ob, const Point& v0, const Point& v1) 324 | { 325 | double result = 0.0; 326 | Point e = (v1 - v0).getUnit(); 327 | Point prj = ob.projection_line(v0, v1); 328 | Point L = prj - ob; 329 | double L0 = L.size(); 330 | double s0, s1, R0, R1; 331 | s0 = (v0 - ob)*e; 332 | s1 = (v1 - ob)*e; 333 | R0 = v0.distance(ob); 334 | R1 = v1.distance(ob); 335 | double Lx = L.x; 336 | double ex = e.x; 337 | if (abs(s0 + R0) < TOLERANCE) { 338 | assert(s0*s1>0); 339 | result = ex*ex*0.5*(s1*R1 - s0*R0) + 2 * Lx*ex*(R1 - R0) + Lx*Lx*abs(log(s1 / s0)); 340 | } 341 | else { 342 | result = ex*ex*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + 2 * Lx*ex*(R1 - R0) + Lx*Lx*log((s1 + R1) / (s0 + R0)); 343 | } 344 | return result; 345 | } 346 | 347 | double Integral::Line_y2R_1(const Point& ob, const Point& v0, const Point& v1) 348 | { 349 | double result = 0.0; 350 | Point e = (v1 - v0).getUnit(); 351 | Point prj = ob.projection_line(v0, v1); 352 | Point L = prj - ob; 353 | double L0 = L.size(); 354 | double s0, s1, R0, R1; 355 | s0 = (v0 - ob)*e; 356 | s1 = (v1 - ob)*e; 357 | R0 = v0.distance(ob); 358 | R1 = v1.distance(ob); 359 | double Ly = L.y; 360 | double ey = e.y; 361 | if (abs(s0 + R0) < TOLERANCE) { 362 | assert(s0*s1>0); 363 | result = ey*ey*0.5*(s1*R1 - s0*R0) + 2 * Ly*ey*(R1 - R0) + Ly*Ly*abs(log(s1 / s0)); 364 | } 365 | else { 366 | result = ey*ey*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + 2 * Ly*ey*(R1 - R0) + Ly*Ly*log((s1 + R1) / (s0 + R0)); 367 | } 368 | return result; 369 | } 370 | 371 | double Integral::Line_z2R_1(const Point& ob, const Point& v0, const Point& v1) 372 | { 373 | double result = 0.0; 374 | Point e = (v1 - v0).getUnit(); 375 | Point prj = ob.projection_line(v0, v1); 376 | Point L = prj - ob; 377 | double L0 = L.size(); 378 | double s0, s1, R0, R1; 379 | s0 = (v0 - ob)*e; 380 | s1 = (v1 - ob)*e; 381 | R0 = v0.distance(ob); 382 | R1 = v1.distance(ob); 383 | double Lz = L.z; 384 | double ez = e.z; 385 | if (abs(s0 + R0) < TOLERANCE) { 386 | assert(s0*s1>0); 387 | result = ez*ez*0.5*(s1*R1 - s0*R0) + 2 * Lz*ez*(R1 - R0) + Lz*Lz*abs(log(s1 / s0)); 388 | } 389 | else { 390 | result = ez*ez*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + 2 * Lz*ez*(R1 - R0) + Lz*Lz*log((s1 + R1) / (s0 + R0)); 391 | } 392 | return result; 393 | } 394 | 395 | double Integral::Line_xzR_1(const Point& ob, const Point& v0,const Point& v1) 396 | { 397 | double result = 0.0; 398 | Point e = (v1 - v0).getUnit(); 399 | Point prj = ob.projection_line(v0, v1); 400 | Point L = prj - ob; 401 | double L0 = L.size(); 402 | double s0, s1, R0, R1; 403 | s0 = (v0 - ob)*e; 404 | s1 = (v1 - ob)*e; 405 | R0 = v0.distance(ob); 406 | R1 = v1.distance(ob); 407 | double Lx = L.x,Lz=L.z; 408 | double ex = e.x,ez=e.z; 409 | if (abs(s0 + R0) < TOLERANCE) { 410 | assert(s0*s1>0); 411 | result = ex*ez*0.5*(s1*R1 - s0*R0) + (Lx*ez + Lz*ex)*(R1 - R0) + Lx*Lz*abs(log(s1 / s0)); 412 | } 413 | else { 414 | result = ex*ez*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + (Lx*ez + Lz*ex)*(R1 - R0) + Lx*Lz*log((s1 + R1) / (s0 + R0)); 415 | } 416 | return result; 417 | } 418 | double Integral::Line_yzR_1(const Point& ob, const Point& v0, const Point& v1) 419 | { 420 | double result = 0.0; 421 | Point e = (v1 - v0).getUnit(); 422 | Point prj = ob.projection_line(v0, v1); 423 | Point L = prj - ob; 424 | double L0 = L.size(); 425 | double s0, s1, R0, R1; 426 | s0 = (v0 - ob)*e; 427 | s1 = (v1 - ob)*e; 428 | R0 = v0.distance(ob); 429 | R1 = v1.distance(ob); 430 | double Ly = L.y, Lz = L.z; 431 | double ey = e.y, ez = e.z; 432 | if (abs(s0 + R0) < TOLERANCE) { 433 | assert(s0*s1>0); 434 | result = ey*ez*0.5*(s1*R1 - s0*R0) + (Ly*ez + Lz*ey)*(R1 - R0) + Ly*Lz*abs(log(s1 / s0)); 435 | } 436 | else { 437 | result = ey*ez*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + (Ly*ez + Lz*ey)*(R1 - R0) + Ly*Lz*log((s1 + R1) / (s0 + R0)); 438 | } 439 | return result; 440 | } 441 | double Integral::Line_xyR_1(const Point& ob, const Point& v0, const Point& v1) 442 | { 443 | double result = 0.0; 444 | Point e = (v1 - v0).getUnit(); 445 | Point prj = ob.projection_line(v0, v1); 446 | Point L = prj - ob; 447 | double L0 = L.size(); 448 | double s0, s1, R0, R1; 449 | s0 = (v0 - ob)*e; 450 | s1 = (v1 - ob)*e; 451 | R0 = v0.distance(ob); 452 | R1 = v1.distance(ob); 453 | double Ly = L.y, Lx = L.x; 454 | double ey = e.y, ex = e.x; 455 | if (abs(s0 + R0) < TOLERANCE) { 456 | assert(s0*s1>0); 457 | result = ey*ex*0.5*(s1*R1 - s0*R0) + (Ly*ex + Lx*ey)*(R1 - R0) + Ly*Lx*abs(log(s1 / s0)); 458 | } 459 | else { 460 | result = ey*ex*0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))) + (Ly*ex + Lx*ey)*(R1 - R0) + Ly*Lx*log((s1 + R1) / (s0 + R0)); 461 | } 462 | return result; 463 | } 464 | double Integral::Line_f3R_1(const Point& ob, const Point& v0, const Point& v1,string s) 465 | { 466 | Point e = (v1 - v0).getUnit(); 467 | Point prj = ob.projection_line(v0, v1); 468 | Point L = prj - ob; 469 | double L0 = L.size(); 470 | double s0, s1, R0, R1; 471 | 472 | s0 = (v0 - ob)*e; 473 | s1 = (v1 - ob)*e; 474 | R0 = v0.distance(ob); 475 | R1 = v1.distance(ob); 476 | 477 | 478 | //double Lx = L.x, Ly = L.y, Lz = L.z; 479 | //double ex = e.x, ey = e.y, ez = e.z; 480 | double Li[3] = { L.x,L.y,L.z }; 481 | double ei[3] = { e.x,e.y,e.z }; 482 | double itg0 = 0.0, itg1 = 0.0, itg2 = 0.0,itg3=0.0; 483 | double result = 0.0; 484 | 485 | if (abs(s0 + R0) < TOLERANCE) { 486 | assert(s0*s1>0); 487 | itg0 = abs(log(s1 / s0)); 488 | itg2 = 0.5*(s1*R1 - s0*R0); 489 | } 490 | else { 491 | itg0 = log((s1 + R1) / (s0 + R0)); 492 | itg2 = 0.5*((s1*R1 - s0*R0) - L0*L0*log((s1 + R1) / (s0 + R0))); 493 | } 494 | itg1 = R1 - R0; 495 | itg3 = ((s1*s1 - 2.0*L0*L0)*R1 - (s0*s0 - 2.0*L0*L0)*R0) / 3.0; 496 | int p = 0, q = 0, t = 0; 497 | if (s == "x3") {} 498 | else if (s == "y3") { 499 | p = 1; q = 1; t = 1; 500 | } 501 | else if (s == "z3") { 502 | p = 2; q = 2; t = 2; 503 | } 504 | else if ((s == "xy2")||(s=="y2x")) { 505 | p = 0; q = 1; t = 1; 506 | } 507 | else if ((s == "x2y") || (s == "yx2")) { 508 | p = 0; q = 0; t = 1; 509 | } 510 | else if ((s == "xz2") || (s == "z2x")) { 511 | p = 0; q = 2; t = 2; 512 | } 513 | else if ((s == "x2z") ||(s == "zx2")) { 514 | p = 0; q = 0; t = 2; 515 | } 516 | else if ((s == "yz2") || (s == "z2y")) { 517 | p = 1; q = 2; t = 2; 518 | } 519 | else if ((s == "y2z" || (s == "zy2"))) { 520 | p = 1; q = 1; t = 2; 521 | } 522 | else if ((s == "xyz")) { 523 | p = 0; q = 1; t = 2; 524 | } 525 | else { 526 | cout << "error in argument s in Integral::Integral::Line_f3R_1(Point ob, Point v0, Point v1,string s)\n"; 527 | std::abort(); 528 | } 529 | result = Li[p] * Li[q] * Li[t] * itg0 530 | + (Li[p] * Li[q] * ei[t] + Li[p] * Li[t] * ei[q] + Li[q] * Li[t] * ei[p])*itg1 531 | + (Li[t] * ei[p] * ei[q] + Li[p] * ei[q] * ei[t] + Li[q] * ei[p] * ei[t])*itg2 532 | + ei[p] * ei[q] * ei[t] * itg3; 533 | return result; 534 | } 535 | double Integral::getBeta(const Point& observation, const vector& face) 536 | { 537 | int n = face.size();//node number of the face 538 | assert(n >= 3); 539 | Point mj,t; 540 | Point unit_normal = unitCross(*face[1] - *face[0], *face[2] - *face[1]); 541 | //unit_normal.display(); 542 | double beta = 0.0; 543 | double s1, s0, mj_value; 544 | //face.push_back(face[0]); 545 | int i_next = 0; 546 | for (int i = 0; i < n; i++) { 547 | i_next = (i + 1) % n; 548 | t=(*face[i_next] - *face[i]).getUnit(); 549 | s0 = (*face[i] - observation)*t; 550 | s1 = (*face[i_next] - observation)*t; 551 | mj = cross(t, unit_normal); 552 | mj_value = mj * (*face[i] - observation); 553 | double mp = mj *(*face[i_next] - observation); 554 | double tt = 0.; 555 | if (abs(mp)< TOLERANCE) { tt = 0.; } 556 | else if (mp>0) { tt = 1.; } 557 | else { tt = -1.; } 558 | if (abs(mj_value) < TOLERANCE) { beta += 0.0; } 559 | else { 560 | // cout <<(i+1)<<'\t'<< mj_value << endl; 561 | beta =beta+ tt*(atan(s1 / abs(mj_value)) - atan(s0 / abs(mj_value))); 562 | } 563 | } 564 | return beta; 565 | } 566 | 567 | 568 | 569 | double Integral::Surface_R1(const Point& observation, const vector& face_node, int n) 570 | { 571 | //assuming that face nodes have been arranged correctly 572 | int nn = face_node.size();//node number of the face 573 | assert(n ==nn); 574 | double beta = getBeta(observation, face_node);//solid angle 575 | double result = 0.0; 576 | //unit normal vector 577 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 578 | double h = (observation - *face_node[0])*unit_normal; 579 | //face_node.push_back(face_node[0]); 580 | for (int i = 0; i < n; i++) { 581 | result= result+1./3.*Line_Bj3(observation, *face_node[i], *face_node[(i + 1)%n], unit_normal); 582 | } 583 | 584 | result = result - beta/3.0*abs(h)*abs(h)*abs(h); 585 | return result; 586 | } 587 | 588 | double Integral::Surface_R_1(const Point& observation, const vector& face_node,int n) 589 | { 590 | int nn = face_node.size();//node number of the face 591 | assert(n == nn); 592 | 593 | double beta = getBeta(observation, face_node);//solid angle 594 | //unit normal vector 595 | Point unit_normal= unitCross(*face_node[1] - *face_node[0], *face_node[n-1] - *face_node[0]); 596 | double h = (observation - *face_node[0])*unit_normal; 597 | //cout<& face_node, int n) 628 | { 629 | Point i_rR1(0.0,0.0,0.0); 630 | Point prj = observation.projection(*face_node[0], *face_node[1], *face_node[2]); 631 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 632 | Point mj; 633 | double i_R1 = Surface_R1(observation, face_node, n); 634 | i_rR1 += (prj - observation)*i_R1; 635 | 636 | //face_node.push_back(face_node[0]); 637 | unsigned int next = 0; 638 | for (int i = 0; i < n ; i++) { 639 | next = (i + 1) % n; 640 | mj = unitCross(*face_node[next]-*face_node[i], unit_normal); 641 | i_rR1 +=1./3.* mj*Line_R3(observation, *face_node[i], *face_node[next]); 642 | } 643 | return i_rR1; 644 | } 645 | 646 | Point Integral::Surface_rR_1(const Point& observation, const vector& face_node, int n) 647 | { 648 | Point rR_1(0.0, 0.0, 0.0); 649 | Point prj = observation.projection(*face_node[0], *face_node[1], *face_node[2]); 650 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[0]); 651 | Point mj; 652 | double R_1 = Surface_R_1(observation, face_node, n); 653 | rR_1 = rR_1 + (prj - observation)*R_1; 654 | //face_node.push_back(face_node[0]); 655 | unsigned int next = 0; 656 | for (int i = 0; i < n; i++) { 657 | next = (i + 1) % n; 658 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 659 | rR_1 = rR_1 + mj*Line_R1(observation, *face_node[i], *face_node[next]); 660 | } 661 | return rR_1; 662 | 663 | } 664 | 665 | Point Integral::Surface_r2R_1(const Point& observation, const vector& face_node, int n) 666 | { 667 | double Rds = Surface_R1(observation, face_node, n); 668 | Point rR_1ds = Surface_rR_1(observation, face_node, n); 669 | 670 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[0]); 671 | 672 | Point rRdl(0,0,0),mj; 673 | Point r2R_1(0,0,0); 674 | for (int i = 0; i < n-1; i++) { 675 | rRdl = Line_rR1(observation, *face_node[i], *face_node[i+1]); 676 | //rRdl.display(); 677 | mj = unitCross(*face_node[i + 1] - *face_node[i],unit_normal); 678 | r2R_1.x = r2R_1.x + mj.x*rRdl.x; 679 | r2R_1.y = r2R_1.y + mj.y*rRdl.y; 680 | r2R_1.z = r2R_1.z + mj.z*rRdl.z; 681 | } 682 | //the last edge 683 | rRdl = Line_rR1(observation, *face_node[n-1], *face_node[0]); 684 | mj = unitCross(*face_node[0] - *face_node[n-1], unit_normal); 685 | r2R_1.x = r2R_1.x + mj.x*rRdl.x; 686 | r2R_1.y = r2R_1.y + mj.y*rRdl.y; 687 | r2R_1.z = r2R_1.z + mj.z*rRdl.z; 688 | double h = (observation - *face_node[0])*unit_normal; 689 | r2R_1.x = r2R_1.x - unit_normal.x*h*(rR_1ds.x) - (1 - (unit_normal.x)*(unit_normal.x))*Rds; 690 | r2R_1.y = r2R_1.y - unit_normal.y*h*(rR_1ds.y) - (1 - (unit_normal.y)*(unit_normal.y))*Rds; 691 | r2R_1.z = r2R_1.z - unit_normal.z*h*(rR_1ds.z) - (1 - (unit_normal.z)*(unit_normal.z))*Rds; 692 | 693 | return r2R_1; 694 | } 695 | 696 | double Integral::Surface_xzR_1(const Point& observation, const vector& face_node, int n) 697 | { 698 | double Rds = Surface_R1(observation, face_node, n); 699 | Point rR_1ds = Surface_rR_1(observation, face_node, n); 700 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 701 | double h = (observation - *face_node[0])*unit_normal; 702 | Point rRdl, mj; 703 | double xzR_1=0.0; 704 | for (int i = 0; i < n - 1; i++) { 705 | rRdl = Line_rR1(observation, *face_node[i], *face_node[i + 1]); 706 | mj = unitCross(*face_node[i+1]-*face_node[i],unit_normal); 707 | xzR_1 += mj.z*rRdl.x; 708 | } 709 | rRdl = Line_rR1(observation, *face_node[n-1], *face_node[0]); 710 | mj = unitCross(*face_node[0] - *face_node[n-1], unit_normal); 711 | xzR_1 += mj.z*rRdl.x; 712 | xzR_1 = xzR_1 - unit_normal.z*h*rR_1ds.x + unit_normal.z*unit_normal.x*Rds; 713 | return xzR_1; 714 | } 715 | 716 | double Integral::Surface_yzR_1(const Point& observation, const vector& face_node, int n) 717 | { 718 | double Rds = Surface_R1(observation, face_node, n); 719 | Point rR_1ds = Surface_rR_1(observation, face_node, n); 720 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 721 | double h = (observation - *face_node[0])*unit_normal; 722 | Point rRdl, mj; 723 | double yzR_1=0.0; 724 | for (int i = 0; i < n - 1; i++) { 725 | rRdl = Line_rR1(observation, *face_node[i], *face_node[i + 1]); 726 | mj = unitCross(*face_node[i + 1] - *face_node[i], unit_normal); 727 | yzR_1 += mj.z*rRdl.y; 728 | } 729 | rRdl = Line_rR1(observation, *face_node[n-1], *face_node[0]); 730 | mj = unitCross(*face_node[0] - *face_node[n-1], unit_normal); 731 | yzR_1 += mj.z*rRdl.y; 732 | yzR_1 = yzR_1 - unit_normal.z*h*rR_1ds.y + unit_normal.z*unit_normal.y*Rds; 733 | return yzR_1; 734 | } 735 | 736 | double Integral::Surface_xyR_1(const Point& observation, const vector &face_node, int n) 737 | { 738 | double Rds = Surface_R1(observation, face_node, n); 739 | Point rR_1ds = Surface_rR_1(observation, face_node, n); 740 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 741 | double h = (observation - *face_node[0])*unit_normal; 742 | Point rRdl, mj; 743 | double xyR_1 = 0.0; 744 | for (int i = 0; i < n - 1; i++) { 745 | rRdl = Line_rR1(observation, *face_node[i], *face_node[i + 1]); 746 | mj = unitCross(*face_node[i + 1] - *face_node[i], unit_normal); 747 | xyR_1 += mj.y*rRdl.x; 748 | } 749 | rRdl = Line_rR1(observation, *face_node[n-1], *face_node[0]); 750 | mj = unitCross(*face_node[0] - *face_node[n-1], unit_normal); 751 | xyR_1 += mj.y*rRdl.x; 752 | xyR_1 = xyR_1 - unit_normal.y*h*rR_1ds.x + unit_normal.x*unit_normal.y*Rds; 753 | return xyR_1; 754 | } 755 | 756 | double Integral::Surface_R_3(const Point& ob, const vector& face_node, int n) 757 | { 758 | //face_node.push_back(face_node[0]); 759 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 760 | double h = (ob - *face_node[0])*unit_normal; 761 | assert(!(abs(h) < TOLERANCE)); 762 | double R1 = 0.0, R0 = 0.0, s1 = 0.0, s0 = 0.0,m0=0.0; 763 | Point e,mj; 764 | double result = 0.0; 765 | //Point prj = ob.projection_line(v0, v1); 766 | //Point L = prj - ob; 767 | double L0 = 0.0; 768 | Point prj; 769 | unsigned next = 0; 770 | for (int i = 0; i < n; i++) { 771 | next = (i + 1) % n; 772 | e = (*face_node[next] - *face_node[i]).getUnit(); 773 | mj= unitCross(*face_node[next] - *face_node[i], unit_normal); 774 | prj = ob.projection_line(*face_node[next], *face_node[i]); 775 | L0 = (prj - ob).size(); 776 | s1 = (*face_node[next] - ob)*e; 777 | s0 = (*face_node[i] - ob)*e; 778 | R1 = ob.distance(*face_node[next]); 779 | R0 = ob.distance(*face_node[i]); 780 | m0 = (*face_node[i] - ob)*mj; 781 | result += atan((m0*s1)/(L0*L0+abs(h)*R1)) - atan((m0*s0)/(L0*L0+abs(h)*R0)); 782 | } 783 | result = result / abs(h); 784 | return result; 785 | } 786 | 787 | Point Integral::Surface_rR_3(const Point& ob, const vector& face_node, int n) 788 | { 789 | 790 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 791 | double h = (ob - *face_node[0])*unit_normal; 792 | //face_node.push_back(face_node[0]); 793 | Point result(0, 0, 0); 794 | Point mj; 795 | unsigned int next = 0; 796 | for (int i = 0; i < n; i++) { 797 | next = (i + 1) % n; 798 | mj=unitCross(*face_node[next] - *face_node[i], unit_normal); 799 | result = result - mj*Line_R_1(ob, *face_node[i], *face_node[next]); 800 | } 801 | if (abs(h) < TOLERANCE) {} 802 | else{ 803 | double sR_3 = Surface_R_3(ob, face_node, n); 804 | result = result - unit_normal*h*sR_3; 805 | } 806 | //if (abs(h) < TOLERANCE) { 807 | // cout << endl; 808 | // result.display(); 809 | // for (int i = 0; i < face_node.size(); i++) { 810 | // (*face_node[i]).display(); 811 | // } 812 | // cout << endl; 813 | //} 814 | return result; 815 | } 816 | 817 | double Integral::Surface_x2R_3(const Point& ob, const vector& face_node, int n) 818 | { 819 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 820 | double S_R_1 = Surface_R_1(ob, face_node, n); 821 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 822 | double h = (ob - *face_node[0])*unit_normal; 823 | //face_node.push_back(face_node[0]); 824 | Point mj(0,0,0); 825 | double result = 0.0; 826 | unsigned int next = 0; 827 | for (int i = 0; i < n; i++) { 828 | next = (i + 1) % n; 829 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 830 | result = result + (mj.x)*(Line_rR_1(ob, *face_node[i], *face_node[next]).x); 831 | } 832 | result = result + (unit_normal.x)*h*(S_rR_3.x) - (1 - (unit_normal.x)*(unit_normal.x))*S_R_1; 833 | result = -result; 834 | return result; 835 | } 836 | 837 | double Integral::Surface_y2R_3(const Point& ob, const vector& face_node, int n) 838 | { 839 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 840 | double S_R_1 = Surface_R_1(ob, face_node, n); 841 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 842 | double h = (ob - *face_node[0])*unit_normal; 843 | //face_node.push_back(face_node[0]); 844 | Point mj(0, 0, 0); 845 | double result = 0.0; 846 | unsigned int next = 0; 847 | for (int i = 0; i < n; i++) { 848 | next = (i + 1) % n; 849 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 850 | result = result + (mj.y)*(Line_rR_1(ob, *face_node[i], *face_node[next]).y); 851 | } 852 | result = result + (unit_normal.y)*h*(S_rR_3.y) - (1 - (unit_normal.y)*(unit_normal.y))*S_R_1; 853 | result = -result; 854 | return result; 855 | } 856 | 857 | double Integral::Surface_z2R_3(const Point& ob, const vector& face_node, int n) 858 | { 859 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 860 | double S_R_1 = Surface_R_1(ob, face_node, n); 861 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 862 | double h = (ob - *face_node[0])*unit_normal; 863 | //face_node.push_back(face_node[0]); 864 | Point mj(0, 0, 0); 865 | double result = 0.0; 866 | unsigned int next = 0; 867 | for (int i = 0; i < n; i++) { 868 | next = (i + 1) % n; 869 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 870 | result = result + (mj.z)*(Line_rR_1(ob, *face_node[i], *face_node[next]).z); 871 | } 872 | result = result + (unit_normal.z)*h*(S_rR_3.z) - (1 - (unit_normal.z)*(unit_normal.z))*S_R_1; 873 | result = -result; 874 | return result; 875 | } 876 | 877 | double Integral::Surface_xzR_3(const Point& ob, const vector& face_node, int n) 878 | { 879 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 880 | double S_R_1 = Surface_R_1(ob, face_node, n); 881 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 882 | double h = (ob - *face_node[0])*unit_normal; 883 | //face_node.push_back(face_node[0]); 884 | Point mj(0, 0, 0); 885 | double result = 0.0; 886 | unsigned next = 0; 887 | for (int i = 0; i < n; i++) { 888 | next = (i + 1) % n; 889 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 890 | result = result + (mj.z)*(Line_rR_1(ob, *face_node[i], *face_node[next]).x); 891 | } 892 | result = result + (unit_normal.z)*h*(S_rR_3.x) + (unit_normal.x)*(unit_normal.z)*S_R_1; 893 | result = -result; 894 | return result; 895 | } 896 | 897 | double Integral::Surface_yzR_3(const Point& ob, const vector& face_node, int n) 898 | { 899 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 900 | double S_R_1 = Surface_R_1(ob, face_node, n); 901 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 902 | double h = (ob - *face_node[0])*unit_normal; 903 | //face_node.push_back(face_node[0]); 904 | Point mj(0, 0, 0); 905 | double result = 0.0; 906 | unsigned next = 0; 907 | for (int i = 0; i < n; i++) { 908 | next = (i + 1) % n; 909 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 910 | result = result + (mj.z)*(Line_rR_1(ob, *face_node[i], *face_node[next]).y); 911 | } 912 | result = result + (unit_normal.z)*h*(S_rR_3.y) + (unit_normal.y)*(unit_normal.z)*S_R_1; 913 | result = -result; 914 | return result; 915 | } 916 | 917 | double Integral::Surface_xyR_3(const Point& ob, const vector& face_node, int n) 918 | { 919 | Point S_rR_3 = Surface_rR_3(ob, face_node, n); 920 | double S_R_1 = Surface_R_1(ob, face_node, n); 921 | Point unit_normal = unitCross(*face_node[1] - *face_node[0], *face_node[2] - *face_node[1]); 922 | double h = (ob - *face_node[0])*unit_normal; 923 | //face_node.push_back(face_node[0]); 924 | Point mj(0, 0, 0); 925 | double result = 0.0; 926 | unsigned int next = 0; 927 | for (int i = 0; i < n; i++) { 928 | next = (i + 1) % n; 929 | mj = unitCross(*face_node[next] - *face_node[i], unit_normal); 930 | result = result + (mj.x)*(Line_rR_1(ob, *face_node[i], *face_node[next]).y); 931 | } 932 | result = result + (unit_normal.x)*h*(S_rR_3.y) + (unit_normal.y)*(unit_normal.x)*S_R_1; 933 | result = -result; 934 | return result; 935 | } 936 | 937 | void Integral::Surface_r3R_1(const Point& ob, const vector& face, int n, 938 | double & x3R_1, double & y3R_1, double & z3R_1, 939 | double & x2yR_1, double & x2zR_1, double & y2xR_1, double & y2zR_1, double & z2xR_1, double & z2yR_1, 940 | double & xyzR_1) 941 | { 942 | int nn = face.size(); 943 | assert(n == nn); 944 | Point r2R_1 = Surface_r2R_1(ob, face, n); 945 | double xyR_1= Surface_xyR_1(ob, face, n); 946 | //double xzR_1 = Surface_xzR_1(ob, face, n); 947 | //double yzR_1 = Surface_yzR_1(ob, face, n); 948 | Point rR = Surface_rR1(ob, face, n); 949 | vector x2Rdl(n); 950 | vector y2Rdl(n); 951 | vector z2Rdl(n); 952 | vector xyRdl(n); 953 | vector mij; 954 | Point unit_normal = unitCross(*face[1] - *face[0], *face[2] - *face[0]); 955 | //cout << "BB" << face.size() << endl; 956 | //face.push_back(face[0]); 957 | //cout << "BB"<& face, int n, 998 | double & x3R_3, double & y3R_3, double & z3R_3, 999 | double & x2yR_3, double & x2zR_3, 1000 | double & y2xR_3, double & y2zR_3, 1001 | double & z2xR_3, double & z2yR_3, 1002 | double & xyzR_3) 1003 | { 1004 | int nn = face.size(); 1005 | assert(n == nn); 1006 | 1007 | double x2R_3 = Surface_x2R_3(ob, face, n); 1008 | double y2R_3 = Surface_y2R_3(ob, face, n); 1009 | double z2R_3 = Surface_z2R_3(ob, face, n); 1010 | double xyR_3 = Surface_xyR_3(ob, face, n); 1011 | 1012 | Point rR_1 = Surface_rR_1(ob, face, n); 1013 | 1014 | vector x2R_1(n); 1015 | vector y2R_1(n); 1016 | vector z2R_1(n); 1017 | vector xyR_1(n); 1018 | vector mij(n); 1019 | //face.push_back(face[0]); 1020 | Point unit_normal = unitCross(*face[1] - *face[0], *face[2] - *face[0]); 1021 | unsigned int next = 0; 1022 | for (int i = 0; i < n; i++) { 1023 | next = (i + 1) % n; 1024 | mij[i] = unitCross(*face[next] - *face[i], unit_normal); 1025 | x2R_1[i] = Line_x2R_1(ob, *face[i], *face[next]); 1026 | y2R_1[i] = Line_y2R_1(ob, *face[i], *face[next]); 1027 | z2R_1[i] = Line_z2R_1(ob, *face[i], *face[next]); 1028 | xyR_1[i] = Line_xyR_1(ob, *face[i], *face[next]); 1029 | } 1030 | double h = (ob - *face[0])*unit_normal; 1031 | 1032 | x3R_3 = unit_normal.x*h*x2R_3 - 2 * (1 - (unit_normal.x)*(unit_normal.x))*rR_1.x; 1033 | y3R_3 = unit_normal.y*h*y2R_3 - 2 * (1 - (unit_normal.y)*(unit_normal.y))*rR_1.y; 1034 | z3R_3 = unit_normal.z*h*z2R_3 - 2 * (1 - (unit_normal.z)*(unit_normal.z))*rR_1.z; 1035 | x2yR_3 = unit_normal.y*h*x2R_3 + 2 * (unit_normal.y)*(unit_normal.x)*rR_1.x; 1036 | x2zR_3 = unit_normal.z*h*x2R_3 + 2 * (unit_normal.z)*(unit_normal.x)*rR_1.x; 1037 | y2xR_3 = unit_normal.x*h*y2R_3 + 2 * (unit_normal.x)*(unit_normal.y)*rR_1.y; 1038 | y2zR_3 = unit_normal.z*h*y2R_3 + 2 * (unit_normal.z)*(unit_normal.y)*rR_1.y; 1039 | z2xR_3 = unit_normal.x*h*z2R_3 + 2 * (unit_normal.x)*(unit_normal.z)*rR_1.z; 1040 | z2yR_3 = unit_normal.y*h*z2R_3 + 2 * (unit_normal.y)*(unit_normal.z)*rR_1.z; 1041 | xyzR_3 = unit_normal.z*h*xyR_3 1042 | +unit_normal.z*unit_normal.y*rR_1.x+unit_normal.z*unit_normal.x*rR_1.y; 1043 | 1044 | for (int i = 0; i < n; i++) { 1045 | x3R_3 = x3R_3 + mij[i].x*x2R_1[i]; 1046 | y3R_3 = y3R_3 + mij[i].y*y2R_1[i]; 1047 | z3R_3 = z3R_3 + mij[i].z*z2R_1[i]; 1048 | x2yR_3 = x2yR_3 + mij[i].y*x2R_1[i]; 1049 | x2zR_3 = x2zR_3 + mij[i].z*x2R_1[i]; 1050 | y2xR_3 = y2xR_3 + mij[i].x*y2R_1[i]; 1051 | y2zR_3 = y2zR_3 + mij[i].z*y2R_1[i]; 1052 | z2xR_3 = z2xR_3 + mij[i].x*z2R_1[i]; 1053 | z2yR_3 = z2yR_3 + mij[i].y*z2R_1[i]; 1054 | xyzR_3 = xyzR_3 + mij[i].z*xyR_1[i]; 1055 | } 1056 | 1057 | x3R_3 = -x3R_3; 1058 | y3R_3 = -y3R_3; 1059 | z3R_3 = -z3R_3; 1060 | x2yR_3 = -x2yR_3; 1061 | x2zR_3 = -x2zR_3; 1062 | y2xR_3 = -y2xR_3; 1063 | y2zR_3 = -y2zR_3; 1064 | z2xR_3 = -z2xR_3; 1065 | z2yR_3 = -z2yR_3; 1066 | xyzR_3 = -xyzR_3; 1067 | return; 1068 | } 1069 | 1070 | 1071 | 1072 | --------------------------------------------------------------------------------