1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
/*===========================================================================
Copyright (C) 2006-2016 Yves Renard, Julien Pommier.
This file is a part of GetFEM++
GetFEM++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version along with the GCC Runtime Library
Exception either version 3.1 or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License and GCC Runtime Library Exception for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
===========================================================================*/
#include <getfem/getfem_mesh_level_set.h>
#include <getfem/getfem_mesh_im_level_set.h>
#include <getfem/getfem_integration.h>
#include <getfemint_misc.h>
#include <getfemint_workspace.h>
using namespace getfemint;
void gf_mesh_im_set_integ(getfem::mesh_im *mim, getfemint::mexargs_in& in);
/*@GFDOC
This object represents an integration method defined on a whole mesh (an
potentialy on its boundaries).
@*/
// Object for the declaration of a new sub-command.
struct sub_gf_mim : virtual public dal::static_stored_object {
int arg_in_min, arg_in_max, arg_out_min, arg_out_max;
virtual void run(getfemint::mexargs_in& in,
getfemint::mexargs_out& out,
const getfem::mesh * &mm,
std::shared_ptr<getfem::mesh_im> &mim) = 0;
};
typedef std::shared_ptr<sub_gf_mim> psub_command;
// Function to avoid warning in macro with unused arguments.
template <typename T> static inline void dummy_func(T &) {}
#define sub_command(name, arginmin, arginmax, argoutmin, argoutmax, code) { \
struct subc : public sub_gf_mim { \
virtual void run(getfemint::mexargs_in& in, \
getfemint::mexargs_out& out, \
const getfem::mesh * &mm, \
std::shared_ptr<getfem::mesh_im> &mim) \
{ dummy_func(in); dummy_func(out); dummy_func(mm); code } \
}; \
psub_command psubc = std::make_shared<subc>(); \
psubc->arg_in_min = arginmin; psubc->arg_in_max = arginmax; \
psubc->arg_out_min = argoutmin; psubc->arg_out_max = argoutmax; \
subc_tab[cmd_normalize(name)] = psubc; \
}
void gf_mesh_im(getfemint::mexargs_in& m_in, getfemint::mexargs_out& m_out) {
typedef std::map<std::string, psub_command > SUBC_TAB;
static SUBC_TAB subc_tab;
if (subc_tab.size() == 0) {
/*@INIT MIM = ('load', @str fname[, @tmesh m])
Load a @tmim from a file.
If the mesh `m` is not supplied (this kind of file does not store the
mesh), then it is read from the file and its descriptor is returned as
the second output argument.@*/
sub_command
("load", 1, 2, 0, 1,
std::string fname = in.pop().to_string();
if (in.remaining()) {
mm = extract_mesh_object(in.pop());
mim = std::make_shared<getfem::mesh_im>(*mm);
} else {
auto m = std::make_shared<getfem::mesh>();
m->read_from_file(fname);
store_mesh_object(m);
mm = m.get();
mim = std::make_shared<getfem::mesh_im>(*mm);
workspace().add_hidden_object(store_meshim_object(mim), m);
}
mim->read_from_file(fname);
);
/*@INIT MIM = ('from string', @str s[, @tmesh m])
Create a @tmim object from its string description.
See also ``MESH_IM:GET('char')``@*/
sub_command
("from string", 1, 2, 0, 1,
std::stringstream ss(in.pop().to_string());
if (in.remaining()) {
mm = extract_mesh_object(in.pop());
mim = std::make_shared<getfem::mesh_im>(*mm);
} else {
auto m = std::make_shared<getfem::mesh>();
m->read_from_file(ss);
store_mesh_object(m);
mm = m.get();
mim = std::make_shared<getfem::mesh_im>(*mm);
workspace().add_hidden_object(store_meshim_object(mim), m);
}
mim->read_from_file(ss);
);
/*@INIT MIM = ('clone', @tmim mim)
Create a copy of a @tmim.@*/
sub_command
("clone", 1, 1, 0, 1,
getfem::mesh_im *mim2 = to_meshim_object(in.pop());
mm = &mim2->linked_mesh();
mim = std::make_shared<getfem::mesh_im>(*mim2);
);
/*@INIT MIM = ('levelset', @tmls mls, @str where, @tinteg im[, @tinteg im_tip[, @tinteg im_set]])
Build an integration method conformal to a partition defined
implicitely by a levelset.
The `where` argument define the domain of integration with respect to
the levelset, it has to be chosen among 'ALL', 'INSIDE', 'OUTSIDE' and
'BOUNDARY'.
it can be completed by a string defining the boolean operation
to define the integration domain when there is more than one levelset.
the syntax is very simple, for example if there are 3 different
levelset,
"a*b*c" is the intersection of the domains defined by each
levelset (this is the default behaviour if this function is not
called).
"a+b+c" is the union of their domains.
"c-(a+b)" is the domain of the third levelset minus the union of
the domains of the two others.
"!a" is the complementary of the domain of a (i.e. it is the
domain where a(x)>0)
The first levelset is always referred to with "a", the second
with "b", and so on.
for intance INSIDE(a*b*c)
CAUTION: this integration method will be defined only on the element
cut by the level-set. For the 'ALL', 'INSIDE' and 'OUTSIDE' options
it is mandatory to use the method ``MESH_IM:SET('integ')`` to define
the integration method on the remaining elements.
@*/
sub_command
("levelset", 3, 5, 0, 1,
getfem::mesh_level_set &mls = *(to_mesh_levelset_object(in.pop()));
std::string swhere = in.pop().to_string();
getfem::pintegration_method pim = to_integ_object(in.pop());
getfem::pintegration_method pim2 = 0;
getfem::pintegration_method pim3 = 0;
if (in.remaining()) pim2 = to_integ_object(in.pop());
if (in.remaining()) pim3 = to_integ_object(in.pop());
int where = 0;
std::string csg_description;
if (cmd_strmatch(swhere, "all"))
where = getfem::mesh_im_level_set::INTEGRATE_ALL;
else {
const char *slst[4];
slst[0] = "inside";
slst[1] = "outside";
slst[2] = "boundary";
slst[3] = "all";
for (unsigned i=0; i < 4; ++i) {
if (cmd_strmatchn(swhere, slst[i], unsigned(strlen(slst[i])))) {
csg_description.assign(swhere.begin() + strlen(slst[i]),
swhere.end());
if (i == 0)
where = getfem::mesh_im_level_set::INTEGRATE_INSIDE;
else if (i == 1)
where = getfem::mesh_im_level_set::INTEGRATE_OUTSIDE;
else if (i == 2)
where = getfem::mesh_im_level_set::INTEGRATE_BOUNDARY;
else if (i == 3)
where = getfem::mesh_im_level_set::INTEGRATE_ALL;
}
}
}
if (where == 0) {
THROW_BADARG("expecting 'inside', 'outside', 'boundary' or 'all'");
}
if (pim->type() != getfem::IM_APPROX) {
THROW_BADARG("expecting an approximate integration method");
}
auto mimls = std::make_shared<getfem::mesh_im_level_set>(mls, where,
pim, pim2);
if (pim3)
mimls->set_integration_method(mimls->linked_mesh().convex_index(),
pim3);
else
mimls->set_integration_method(mimls->linked_mesh().convex_index(), 1);
if (csg_description.size()) {
mimls->set_level_set_boolean_operations(csg_description);
}
mim = mimls;
mimls->adapt();
mm = &mls.linked_mesh();
store_meshim_object(mim);
workspace().set_dependence(mim.get(), &mls);
);
}
if (m_in.narg() < 1) THROW_BADARG("Wrong number of input arguments");
const getfem::mesh *mm = NULL;
std::shared_ptr<getfem::mesh_im> mim;
if (m_in.front().is_string()) {
std::string init_cmd = m_in.pop().to_string();
std::string cmd = cmd_normalize(init_cmd);
SUBC_TAB::iterator it = subc_tab.find(cmd);
if (it != subc_tab.end()) {
check_cmd(cmd, it->first.c_str(), m_in, m_out, it->second->arg_in_min,
it->second->arg_in_max, it->second->arg_out_min,
it->second->arg_out_max);
it->second->run(m_in, m_out, mm, mim);
}
else bad_cmd(init_cmd);
} else {
/*@INIT MIM = ('.mesh', @tmesh m, [{@tinteg im|int im_degree}])
Build a new @tmim object.
For convenience, optional arguments (`im` or `im_degree`) can be
provided, in that case a call to ``MESH_IM:GET('integ')`` is issued
with these arguments.@*/
if (!m_out.narg_in_range(1, 1))
THROW_BADARG("Wrong number of output arguments");
mm = extract_mesh_object(m_in.pop());
mim = std::make_shared<getfem::mesh_im>(*mm);
if (m_in.remaining()) {
gf_mesh_im_set_integ(mim.get(), m_in);
}
if (m_in.remaining()) THROW_BADARG("Wrong number of input arguments");
}
if (!mim.get()) THROW_INTERNAL_ERROR;
id_type id = store_meshim_object(mim);
workspace().set_dependence(id, mm);
m_out.pop().from_object_id(id, MESHIM_CLASS_ID);
}
|