geom_object_element.cc
Go to the documentation of this file.
1//LIC// ====================================================================
2//LIC// This file forms part of oomph-lib, the object-oriented,
3//LIC// multi-physics finite-element library, available
4//LIC// at http://www.oomph-lib.org.
5//LIC//
6//LIC// Copyright (C) 2006-2025 Matthias Heil and Andrew Hazel
7//LIC//
8//LIC// This library is free software; you can redistribute it and/or
9//LIC// modify it under the terms of the GNU Lesser General Public
10//LIC// License as published by the Free Software Foundation; either
11//LIC// version 2.1 of the License, or (at your option) any later version.
12//LIC//
13//LIC// This library is distributed in the hope that it will be useful,
14//LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15//LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16//LIC// Lesser General Public License for more details.
17//LIC//
18//LIC// You should have received a copy of the GNU Lesser General Public
19//LIC// License along with this library; if not, write to the Free Software
20//LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21//LIC// 02110-1301 USA.
22//LIC//
23//LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24//LIC//
25//LIC//====================================================================
26// Demonstrate use of geometric object as GeneralisedElement
27
28
29// Generic oomph-lib headers
30#include "generic.h"
31
32// Circle as generalised element:
34
35using namespace std;
36
37using namespace oomph;
38
39///////////////////////////////////////////////////////////////////////
40///////////////////////////////////////////////////////////////////////
41///////////////////////////////////////////////////////////////////////
42
43
44//======start_of_problem==============================================
45/// Problem to demonstrate the use of a GeomObject as a
46/// GeneralisedElement: A geometric object (a Circle) is "upgraded"
47/// to a GeneralisedElement. The position of the Circle is
48/// determined by a balance of forces, assuming that the
49/// Circle is mounted on an elastic spring of specified
50/// stiffness and loaded by a vertical "load".
51//====================================================================
53{
54
55public:
56
57 /// Constructor
59
60 /// Update the problem specs after solve (empty)
62
63 /// Update the problem specs before solve (empty)
65
66 /// Doc the solution
67 void doc_solution();
68
69 /// Return value of the "load" on the elastically supported ring
70 double& load()
71 {
72 return *Load_pt->value_pt(0);
73 }
74
75 /// Access to DocInfo object
77
78private:
79
80 /// Trace file
82
83 /// Pointer to data item that stores the "load" on the ring
85
86 /// Doc info object
88
89};
90
91
92
93
94
95//=============================start_of_problem_constructor===============
96/// Constructor
97//========================================================================
99{
100
101 // Set coordinates and radius for the circle
102 double x_c=0.5;
103 double y_c=0.0;
104 double R=1.0;
105
106 // Build GeomObject that's been upgraded to a GeneralisedElement
107 // GeneralisedElement*
109 new ElasticallySupportedRingElement(x_c,y_c,R);
110
111 // Set the stiffness of the elastic support
112 geom_object_element_pt->k_stiff()=0.3;
113
114 // Build mesh
115 mesh_pt()=new Mesh;
116
117 // So far, the mesh is completely empty. Let's add the
118 // one (and only!) GeneralisedElement to it:
119 mesh_pt()->add_element_pt(geom_object_element_pt);
120
121 // Create the load (a Data object with a single value)
122 Load_pt=new Data(1);
123
124 // The load is prescribed so its one-and-only value is pinned
125 Load_pt->pin(0);
126
127 // Set the pointer to the Data object that specifies the
128 // load on the ring
129 geom_object_element_pt->set_load_pt(Load_pt);
130
131 // Setup equation numbering scheme.
132 cout <<"Number of equations: " << assign_eqn_numbers() << std::endl;
133
134 // Set output directory
135 Doc_info.set_directory("RESLT");
136
137 // Open trace file
138 char filename[100];
139 snprintf(filename, sizeof(filename), "%s/trace.dat",Doc_info.directory().c_str());
140 Trace_file.open(filename);
141 Trace_file << "VARIABLES=\"load\",\"y<sub>circle</sub>\"" << std::endl;
142
143} // end of constructor
144
145
146
147
148//===========================start_of_doc_solution========================
149/// Doc the solution in tecplot format.
150//========================================================================
152{
153
155 char filename[100];
156
157 // Number of plot points
158 unsigned npts=100;
159
160 // Lagrangian coordinate and position vector (both as vectors)
162 Vector<double> r(2);
163
164 // Output solution
165 snprintf(filename, sizeof(filename), "%s/soln%i.dat",Doc_info.directory().c_str(),
166 Doc_info.number());
167 some_file.open(filename);
168 for (unsigned i=0;i<npts;i++)
169 {
170 zeta[0]=2.0*MathematicalConstants::Pi*double(i)/double(npts-1);
171 static_cast<ElasticallySupportedRingElement*>(mesh_pt()->element_pt(0))->
172 position(zeta,r);
173 some_file << r[0] << " " << r[1] << std::endl;
174 }
175 some_file.close();
176
177
178 // Write "load" and vertical position of the ring's centre
180 << static_cast<ElasticallySupportedRingElement*>(
181 mesh_pt()->element_pt(0))->load()
182 << " "
183 << static_cast<ElasticallySupportedRingElement*>(
184 mesh_pt()->element_pt(0))->y_c()
185 << " "
186 << std::endl;
187
188} // end of doc_solution
189
190
191
192
193
194
195
196
197////////////////////////////////////////////////////////////////////////
198////////////////////////////////////////////////////////////////////////
199////////////////////////////////////////////////////////////////////////
200
201
202
203
204
205//===============start_of_driver==========================================
206/// Driver
207//========================================================================
208int main()
209{
210
211 // Set up the problem
213
214 // Initial value for the load
215 problem.load()=-0.3;
216
217 // Loop for different loads
218 //-------------------------
219
220 // Number of steps
221 unsigned nstep=5;
222
223 // Increment in load
224 double dp=0.6/double(nstep-1);
225
226 for (unsigned istep=0;istep<nstep;istep++)
227 {
228 // Solve/doc
229 problem.newton_solve();
230 problem.doc_solution();
231
232 //Increment counter for solutions
233 problem.doc_info().number()++;
234
235 // Change load on ring
236 problem.load()+=dp;
237 }
238
239} // end of driver
240
241
void demo_fish_poisson(const string &directory_name)
Demonstrate how to solve 2D Poisson problem in deformable fish-shaped domain with mesh adaptation.
Problem to demonstrate the use of a GeomObject as a GeneralisedElement: A geometric object (a Circle)...
double & load()
Return value of the "load" on the elastically supported ring.
void actions_before_newton_solve()
Update the problem specs before solve (empty)
Data * Load_pt
Pointer to data item that stores the "load" on the ring.
DocInfo & doc_info()
Access to DocInfo object.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
GeneralCircle "upgraded" to a GeneralisedElement: Circular ring whose position is given by.
int main()
Driver.
Definition circle.h:34